Codeforces Round 186 (Div. 2)
C
Ilya and Matrix
Codeforces
1400
原题
← BD →
翻译中…

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 $2^{*n*} × 2^{*n*}$-sized matrix and $4^{*n*}$ 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 $2^{*n*} × 2^{*n*}$-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 $2^{*n* - 1} × 2^{*n* - 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 $4^{*n*}$ $(1 ≤ 4^{*n*} ≤ 2·10^{6})$. The next line contains $4^{*n*}$ integers $*a*_{*i*}$ $(1 ≤ *a*_{*i*} ≤ 10^{9})$ — the numbers you need to arrange in the $2^{*n*} × 2^{*n*}$-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 С++. It is preferred to use the cin, cout streams or the %I64d specifier.

翻译中…

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.

翻译中…

样例

Input #1
1
13
Output #1
13
InputCopy OutputCopy
Input #2
4
1 2 3 4
Output #2
14
InputCopy OutputCopy
题目信息
题号
313C
时间限制
1 s
内存限制
256 MB
标签
构造
贪心
模拟
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。