atcoder#ABC263F. [ABC263F] Tournament

[ABC263F] Tournament

Score : 500500 points

Problem Statement

2N2^N people, numbered 11 to 2N2^N, will participate in a rock-paper-scissors tournament.

The tournament proceeds as follows:

  • The participants are arranged in a row in the order Person 11, Person 22, \ldots, Person 2N2^N from left to right.
  • Let 2M2M be the current length of the row. For each i (1iM)i\ (1\leq i \leq M), the (2i1)(2i-1)-th and (2i)(2i)-th persons from the left play a game against each other. Then, the MM losers are removed from the row. This process is repeated NN times.

Here, if Person ii wins exactly jj games, they receive Ci,jC_{i,j} yen (Japanese currency). A person winning zero games receives nothing. Find the maximum possible total amount of money received by the 2N2^N people if the results of all games can be manipulated freely.

Constraints

  • 1N161 \leq N \leq 16
  • 1Ci,j1091 \leq C_{i,j} \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

C1,1C_{1,1} C1,2C_{1,2} \ldots C1,NC_{1,N}

C2,1C_{2,1} C2,2C_{2,2} \ldots C2,NC_{2,N}

\vdots

C2N,1C_{2^N,1} C2N,2C_{2^N,2} \ldots C2N,NC_{2^N,N}

Output

Print the answer.

2
2 5
6 5
2 1
7 9
15

The initial row of the people is (1,2,3,4)(1,2,3,4).

If Person 22 wins the game against Person 11, and Person 44 wins the game against Person 33, the row becomes (2,4)(2,4).

Then, if Person 44 wins the game against Person 22, the row becomes (4)(4), and the tournament ends.

Here, Person 22 wins exactly 11 game, and Person 44 wins exactly 22 games, so they receive 0+6+0+9=150+6+0+9=15 yen in total, which is the maximum possible sum.

3
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
4