跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F2431. Ilya and Matrix

    ID: 2437 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>构造贪心模拟排序算法思想编程与模拟基础难度共享题库Codeforces英文题面题目来源题面语言

Ilya and Matrix

题目描述

C. Ilya and Matrix
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Ilya is a very good-natured lion. He likes maths. Of all mathematical objects, his favourite one is matrices. Now he's faced a complicated matrix problem he needs to solve.

He's got a square 2n×2n-sized matrix and 4n integers. You need to arrange all these numbers in the matrix (put each number in a single individual cell) so that the beauty of the resulting matrix with numbers is maximum.

The beauty of a 2n×2n-sized matrix is an integer, obtained by the following algorithm:

  1. Find the maximum element in the matrix. Let's denote it as m.
  2. If n=0, then the beauty of the matrix equals m. Otherwise, a matrix can be split into 4 non-intersecting 2n-1×2n-1-sized submatrices, then the beauty of the matrix equals the sum of number m and other four beauties of the described submatrices.

As you can see, the algorithm is recursive.

Help Ilya, solve the problem and print the resulting maximum beauty of the matrix.

Input

The first line contains integer 4n (1≤4n≤2·106). The next line contains 4n integers ai (1≤ai≤109) − the numbers you need to arrange in the 2n×2n-sized matrix.

Output

On a single line print the maximum value of the beauty of the described matrix.

Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples
Input
1
13
Output
13
Input
4
1 2 3 4
Output
14
Note

Consider the second sample. You need to arrange the numbers in the matrix as follows:


1 2
3 4

Then the beauty of the matrix will equal: 4 + 1 + 2 + 3 + 4 = 14.


题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 2061 题。保留原作者与原赛事署名。