#K1011. Tournament Champion
Tournament Champion
Tournament Champion
You are given n players participating in a tournament. Each player has a skill rating. In each round of the tournament, players are paired in the order they appear. For each pair, the player with the higher skill rating wins and advances to the next round. If there is an odd number of players, the last unpaired player advances automatically to the next round.
The process repeats until only one player remains. Your task is to determine the skill rating of the final tournament champion.
The recurrence of the tournament can be expressed by the following formula:
\( f(S) = \begin{cases} S[0] & \text{if } |S| = 1 \\ \max(S[2i], S[2i+1]) \text{ for } 0 \leq i 1 \end{cases} \)
inputFormat
The input is read from standard input. The first line contains an integer n representing the number of players. The second line contains n space-separated integers representing the skill ratings of the players.
outputFormat
The output is written to standard output. It should print a single integer — the skill rating of the tournament champion.
## sample1
4
4