405112: GYM101798 G World Mug (B)
Description
The organizers of the tournament wish to ensure a great amount of fun for the fans, for that, they have decided to rearrange the teams such that more goals in the tournament are scored.
Can you help out by calculating the maximum number of goals that could be scored if the teams were rearranged optimally?
InputThe first line of input contains one integer n (2 ≤ n ≤ 218), the number of teams participating in the tournament. It is guaranteed that the number of teams is a power of two (i.e., 2, 4, 8, 16, ...).
The second line contains n distinct integers, the ith integer is si (1 ≤ si ≤ 109), the strength of the ith team.
OutputOn a single line, print the maximum number of goals that could be scored in the tournament if the teams were rearranged to maximize that number.
ExampleInput8Output
100 200 300 400 800 700 600 500
2100