Problem:
Score : 1300 points

Problem Statement

We have a pyramid with N steps, built with blocks.
The steps are numbered 1 through N from top to bottom.
For each 1≤i≤N, step i consists of 2i-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=4 steps

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

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

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 N was (a_1, a_2, ..., a_{2N-1}).

Find the integer written into the block of step 1.

Constraints

2≤N≤10^5

(a_1, a_2, ..., a_{2N-1}) is a permutation of (1, 2, ..., 2N-1).

Input

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

N
a_1 a_2 ... a_{2N-1}

Output

Print the integer written into the block of step 1.

Sample Input 1

4
1 6 3 7 4 5 2

Sample Output 1

4

This case corresponds to the figure in the problem statement.

Sample Input 2

2
1 2 3

Sample Output 2

2

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<bits/stdc++.h>
using namespace std;

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int n;
vector<int> a;

bool check(int mid){
    int l1 = 0, r1 = n * 2, l0 = 0, r0 = n * 2;
    if(a[0] >= mid){
        l1 = 1;
    }else{
        l0 = 1;
    }
    if(a[n * 2 - 2] >= mid){
        r1 = n * 2 - 1;
    }else{
        r0 = n * 2 - 1;
    }

    for(int i = n - 1 ; i > 0 ; --i){
        if(a[i] >= mid && a[i - 1] >= mid){
            l1 = i + 1;
            break;
        }else if(a[i] < mid && a[i - 1] < mid){
            l0 = i + 1;
            break;
        }
    }

    for(int i = n - 1 ; i < n * 2 - 2 ; ++i){
        if(a[i] >= mid && a[i + 1] >= mid){
            r1 = i + 1;
            break;
        }else if(a[i] < mid && a[i + 1] < mid){
            r0 = i + 1;
            break;
        }
    }

    return min(abs(n - l1), abs(n - r1)) < min(abs(n - l0), abs(n - r0));
}

int meguru_search(int ok, int ng){
    while(abs(ok - ng) > 1){
        int mid = (ok + ng) / 2;
        if(check(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    return ok;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;

    a.resize(n * 2 - 1);
    rep(i, n * 2 - 1){
        cin >> a[i];
    }

    int ans = meguru_search(0, n * 2);
    cout << ans << endl;

    return 0;
}