The firefighters of a distant country want to protect the grannies inside schools. All the schools are in a row on a street, numbered in order from 1 to . At each school there are grannies. The firefighters can form groups, and each group can only go to a single school. If a group goes to school , it protects all the grannies there. In addition, it also indirectly protects half the grannies in school , assuming that it exists and that it is not already fully protected by another group; and similarly with school .
What is the maximum number of grannies that can be protected?
Input consists of several cases, each one with and , followed by the ’s. You can assume , and that all the ’s are even natural numbers between 2 and .
For every case, print how many grannies can be protected.
The expected solution for this problem is a reasonable backtracking.
Input
1 1 100000 1 2 10 20 1 3 10 80 20 1 3 10 20 80 3 3 10 20 80 3 9 4 8 2 4 8 8 6 2 8 9 9 2 2 2 2 2 2 2 2 2
Output
100000 25 95 90 110 36 18