

Time Limit: 2 sec / Memory Limit: 256 MiB
配点 : 点
問題文
段のピラミッドがあります。 段は上から順に , , , と番号が振られています。 各 について、 段目には 個のブロックが横一列に並んでいます。 また、各段の中央のブロックに注目すると、これらは縦一列に並んでいます。

段のピラミッド
すぬけ君は 段目のブロックに (, , , ) を並べ替えたもの(順列)を書き込みました。 さらに、次のルールに従い、残りすべてのブロックに整数を書き込みました。
- あるブロックに書き込まれる整数は、そのブロックの左下、真下、右下のブロックに書き込まれた整数の中央値である。

ブロックに整数を書き込む例
その後、すぬけ君はすべてのブロックに書き込まれた整数を消してしまいました。 すぬけ君は、 段目のブロックに書き込まれた順列が (, , , ) であったことだけを覚えています。
段目のブロックに書き込まれた整数を求めてください。
制約
- (, , , ) は (, , , ) の順列である。
入力
入力は以下の形式で標準入力から与えられる。
出力
段目のブロックに書き込まれた整数を出力せよ。
入力例 1Copy
4 1 6 3 7 4 5 2
出力例 1Copy
4
問題文中の図の例です。
入力例 2Copy
2 1 2 3
出力例 2Copy
2
Score : points
Problem Statement
We have a pyramid with steps, built with blocks. The steps are numbered through from top to bottom. For each , step consists of blocks aligned horizontally. The pyramid is built so that the blocks at the centers of the steps are aligned vertically.

A pyramid with steps
Snuke wrote a permutation of (, , , ) into the blocks of step . Then, he wrote integers into all remaining blocks, under the following rule:
- The integer written into a block must be equal to the median of the three integers written into the three blocks directly under , or to the lower left or lower right of .

Writing integers into the blocks
Afterwards, he erased all integers written into the blocks. Now, he only remembers that the permutation written into the blocks of step was (, , , ).
Find the integer written into the block of step .
Constraints
- (, , , ) is a permutation of (, , , ).
Input
The input is given from Standard Input in the following format:
Output
Print the integer written into the block of step .
Sample Input 1Copy
4 1 6 3 7 4 5 2
Sample Output 1Copy
4
This case corresponds to the figure in the problem statement.
Sample Input 2Copy
2 1 2 3
Sample Output 2Copy
2