405112: GYM101798 G World Mug (B)

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. World Mug (B)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

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?

Input

The 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.

Output

On 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.

ExampleInput
8
100 200 300 400 800 700 600 500
Output
2100

加入题单

上一题 下一题 算法标签: