#RELAYC. 硬度フェスティバル

硬度フェスティバル

Score : 100100 points

Problem Statement

Kode Festival is an anual contest where the hardest stone in the world is determined. (Kode is a Japanese word for "hardness".)

This year, 2N2^N stones participated. The hardness of the ii-th stone is AiA_i.

In the contest, stones are thrown at each other in a knockout tournament.

When two stones with hardness XX and YY are thrown at each other, the following will happen:

  • When XX > YY: The stone with hardness YY will be destroyed and eliminated. The hardness of the stone with hardness XX will become XYX-Y.
  • When XX = YY: One of the stones will be destroyed and eliminated. The hardness of the other stone will remain the same.
  • When XX < YY: The stone with hardness XX will be destroyed and eliminated. The hardness of the stone with hardness YY will become YXY-X.

The 2N2^N stones will fight in a knockout tournament as follows:

  1. The following pairs will fight: (the 11-st stone versus the 22-nd stone), (the 33-rd stone versus the 44-th stone), ...
  2. The following pairs will fight: (the winner of (11-st versus 22-nd) versus the winner of (33-rd versus 44-th)), (the winner of (55-th versus 66-th) versus the winner of (77-th versus 88-th)), ...
  3. And so forth, until there is only one stone remaining.

Determine the eventual hardness of the last stone remaining.

Constraints

  • 1N181 \leq N \leq 18
  • 1Ai1091 \leq A_i \leq 10^9
  • AiA_i is an integer.

Input

The input is given from Standard Input in the following format:

NN

A1A_1

A2A_2

:

A2NA_{2^N}

Output

Print the eventual hardness of the last stone remaining.

2
1
3
10
19
7
3
1
3
2
4
6
8
100
104
2