题目描述
Problem Description
The "Hardness Festival" is an annual event to determine the hardest stone in the world.
This year, $2^N$ stones are participating in the Hardness Festival. The hardness of the $i$-th stone is $A_i$.
In the competition, stones are pitted against each other in a tournament format to determine the hardest stone.
When a stone with hardness $X$ collides with a stone with hardness $Y$, the following results occur:
- If $X > Y$: The stone with hardness $Y$ breaks, and the stone with hardness $X$ remains with hardness $X - Y$. The stone with hardness $X$ wins.
- If $X = Y$: One of the stones breaks, and the other stone remains with its original hardness. The stone that did not break wins.
- If $X < Y$: The stone with hardness $X$ breaks, and the stone with hardness $Y$ remains with hardness $Y - X$. The stone with hardness $Y$ wins.
The $2^N$ stones compete in the following tournament format:
- The stones are paired as (1st stone, 2nd stone), (3rd stone, 4th stone), ... and collide.
- The winners are paired as ((1, 2) winner, (3, 4) winner), ((5, 6) winner, (7, 8) winner), ... and collide.
- This continues until only one stone remains.
Determine the hardness of the stone that remains until the end.
Input Format
The input is given from the standard input in the following format:
$N$ $A_1$ $A_2$ $:$ $A_{2^N}$
Output Format
Output the hardness of the stone that remains until the end.
Sample Input and Output
Sample Input #1
2
1
3
10
19
Sample Output #1
7
Sample Input #2
3
1
3
2
4
6
8
100
104
Sample Output #2
2
Notes/Hints
Constraints
- $1 \leq N \leq 18$
- $1 \leq A_i \leq 10^9$
- $A_i$ is an integer.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分