D - Median Pyramid Hard Editorial /

Time Limit: 2 sec / Memory Limit: 256 MiB

配点 : 13001300

問題文

NN 段のピラミッドがあります。 段は上から順に 11, 22, ......, NN と番号が振られています。 各 1iN1≤i≤N について、ii 段目には 2i12i-1 個のブロックが横一列に並んでいます。 また、各段の中央のブロックに注目すると、これらは縦一列に並んでいます。

N=4N=4 段のピラミッド

すぬけ君は NN 段目のブロックに (11, 22, ......, 2N12N-1) を並べ替えたもの(順列)を書き込みました。 さらに、次のルールに従い、残りすべてのブロックに整数を書き込みました。

  • あるブロックに書き込まれる整数は、そのブロックの左下、真下、右下のブロックに書き込まれた整数の中央値である。

ブロックに整数を書き込む例

その後、すぬけ君はすべてのブロックに書き込まれた整数を消してしまいました。 すぬけ君は、NN 段目のブロックに書き込まれた順列が (a1a_1, a2a_2, ......, a2N1a_{2N-1}) であったことだけを覚えています。

11 段目のブロックに書き込まれた整数を求めてください。

制約

  • 2N1052≤N≤10^5
  • (a1a_1, a2a_2, ......, a2N1a_{2N-1}) は (11, 22, ......, 2N12N-1) の順列である。

入力

入力は以下の形式で標準入力から与えられる。

NN
a1a_1 a2a_2 ...... a2N1a_{2N-1}

出力

11 段目のブロックに書き込まれた整数を出力せよ。


入力例 1Copy

Copy
4
1 6 3 7 4 5 2

出力例 1Copy

Copy
4

問題文中の図の例です。


入力例 2Copy

Copy
2
1 2 3

出力例 2Copy

Copy
2

Score : 13001300 points

Problem Statement

We have a pyramid with NN steps, built with blocks. The steps are numbered 11 through NN from top to bottom. For each 1iN1≤i≤N, step ii consists of 2i12i-1 blocks aligned horizontally. The pyramid is built so that the blocks at the centers of the steps are aligned vertically.

A pyramid with N=4N=4 steps

Snuke wrote a permutation of (11, 22, ......, 2N12N-1) into the blocks of step NN. Then, he wrote integers into all remaining blocks, under the following rule:

  • The integer written into a block bb must be equal to the median of the three integers written into the three blocks directly under bb, or to the lower left or lower right of bb.

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 NN was (a1a_1, a2a_2, ......, a2N1a_{2N-1}).

Find the integer written into the block of step 11.

Constraints

  • 2N1052≤N≤10^5
  • (a1a_1, a2a_2, ......, a2N1a_{2N-1}) is a permutation of (11, 22, ......, 2N12N-1).

Input

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

NN
a1a_1 a2a_2 ...... a2N1a_{2N-1}

Output

Print the integer written into the block of step 11.


Sample Input 1Copy

Copy
4
1 6 3 7 4 5 2

Sample Output 1Copy

Copy
4

This case corresponds to the figure in the problem statement.


Sample Input 2Copy

Copy
2
1 2 3

Sample Output 2Copy

Copy
2


2025-06-14 (Sat)
02:29:03 +00:00