Scientists have discovered some strange bacteria on Mars and are now busy studying them. They have noticed that the number of bacteria is a power of
Thus, in the first generation there was a single bacterium. It split into two bacteria of the second generation, which split into four bacteria of the third generation, and so on – until the
descendants of bacteria of the previous
generation are, in this order: .descendants of bacteria of the older
generation are, in this order: .descendants of bacteria of the even older
generation are, in this order: .…
descendants of the two bacteria of the second generation are, in this order:
and .
where curly braces denote a set of descendants of a single bacteria. That is, the
Notice that there exist many different permutations of these bacteria which still satisfy the rule that descendants of any older bacterium have consecutive sequence numbers. Scientists want to arrange the bacteria into such a sequence which also has the minimum possible length. The length of a bacteria sequence is the sum of distances between all neighbouring bacteria pairs.
Specifically, there is a certain quantifiable repulsion between every two bacteria, which is the minimum distance between them if they are next to each other in the sequence. (Repulsion plays no role between bacteria that are not immediate neighbours in the sequence). Given the repulsion values for all bacteria pairs, find the minimum possible length of a bacteria sequence (permutation) satisfying the descendant rule given above.
Input Specification
The first line of input contains the positive integer
Each of the following
Output Specification
The first and only line of output should contain the minimum possible length of a bacteria sequence satisfying the constraints.
Sample Input 1
2
0 7 2 1
7 0 4 3
2 4 0 5
1 3 5 0
Sample Output 1
13
Sample Input 2
3
0 2 6 3 4 7 1 3
2 0 7 10 9 1 3 6
6 7 0 3 5 6 5 5
3 10 3 0 9 8 9 7
4 9 5 9 0 9 8 4
7 1 6 8 9 0 8 7
1 3 5 9 8 8 0 10
3 6 5 7 4 7 10 0
Sample Output 2
32
Comments