100 atcoder#ABC188C. [ABC188C] ABC Tournament

[ABC188C] ABC Tournament

Score : 300300 points

Problem Statement

2N2^N players, labeled 11 through 2N2^N, will compete against each other in a single-elimination programming tournament. The rating of Player ii is AiA_i. Any two players have different ratings, and a match between two players always results in the victory of the player with the higher rating.

The tournament looks like a perfect binary tree. Formally, the tournament will proceed as follows:

  • For each integer i=1,2,3,,Ni = 1, 2, 3, \dots, N in this order, the following happens.- For each integer j(1j2Ni)j (1 \le j \le 2^{N - i}), among the players who have never lost, the player with the (2j1)(2j - 1)-th smallest label and the player with the 2j2j-th smallest label play a match against each other.

Find the label of the player who will take second place, that is, lose in the final match.

Constraints

  • 1N161 \le N \le 16
  • 1Ai1091 \le A_i \le 10^9
  • AiA_i are pairwise different.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 A3A_3 \dots A2NA_{2^N}

Output

Print the label of the player who will take second place.

2
1 4 2 5
2

First, there will be two matches between Players 11 and 22 and between Players 33 and 44. According to the ratings, Players 22 and 44 will win. Then, there will be a match between Players 22 and 44, and the tournament will end with Player 44 becoming champion. The player who will lose in the final match is Player 22, so we should print 22.

2
3 1 5 4
1

First, there will be two matches between Players 11 and 22 and between Players 33 and 44. According to the ratings, Players 11 and 33 will win. Then, there will be a match between Players 11 and 33, and the tournament will end with Player 33 becoming champion. The player who will lose in the final match is Player 11, so we should print 11.

4
6 13 12 5 3 7 10 11 16 9 8 15 2 1 14 4
2