#abc188c. [abc188_c]ABC Tournament
[abc188_c]ABC Tournament
Problem Statement
players, labeled through , will compete against each other in a single-elimination programming tournament.
The rating of Player is . 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 in this order, the following happens.
- For each integer , among the players who have never lost, the player with the -th smallest label and the player with the -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
- are pairwise different.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the label of the player who will take second place.
Sample Input 1
2
1 4 2 5
Sample Output 1
2
First, there will be two matches between Players and and between Players and . According to the ratings, Players and will win.
Then, there will be a match between Players and , and the tournament will end with Player becoming champion.
The player who will lose in the final match is Player , so we should print .
Sample Input 2
2
3 1 5 4
Sample Output 2
1
First, there will be two matches between Players and and between Players and . According to the ratings, Players and will win.
Then, there will be a match between Players and , and the tournament will end with Player becoming champion.
The player who will lose in the final match is Player , so we should print .
Sample Input 3
4
6 13 12 5 3 7 10 11 16 9 8 15 2 1 14 4
Sample Output 3
2