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 <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

using std::complex;

long long min(long long a, long long b) {return a < b ? a : b;}
long long min(int a, long long b) {return a < b ? a : b;}
long long min(long long a, int b) {return a < b ? a : b;}
long long min(int a, int b) {return a < b ? a : b;}

long long max(long long a, long long b) {return a > b ? a : b;}
long long max(int a, long long b) {return a > b ? a : b;}
long long max(long long a, int b) {return a > b ? a : b;}
long long max(int a, int b) {return a > b ? a : b;}

#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;
typedef complex<double> cd;

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

int n, N;
int a[500000];
int b[500000];
int c[500000];

void kek()
{
    fill(c, c + N, -1);
    c[0] = b[0], c[N - 1] = b[N - 1];
    for (int i = 0; i + 1 < N; i++)
    {
        if (b[i] == b[i + 1])
        {
            c[i] = b[i], c[i + 1] = b[i + 1];
        }
    }
    for (int i = 0; i < N; i++)
    {
        if (c[i] == -1)
        {
            int j = i;
            while (c[j + 1] == -1) j++;
            if (i % 2 == j % 2)
            {
                for (int k = i; k <= j; k++) c[k] = c[i - 1];
            }
            else
            {
                int m = (i + j) / 2;
                for (int k = i; k <= m; k++) c[k] = c[i - 1];
                for (int k = m + 1; k <= j; k++) c[k] = c[j + 1];
            }
            i = j;
        }
    }
}

signed main()
{
    srand(time(NULL));
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    N = 2 * n - 1;
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    int l = 0, r = N + 1;
    while (l + 1 < r)
    {
        int mid = (l + r) / 2;
        for (int i = 0; i < N; i++)
        {
            if (a[i] >= mid) b[i] = 1;
            else b[i] = 0;
        }
        kek();
        //cout << mid << endl;
        //for (int i = 0; i < N; i++) cout << c[i] << " ";
        //cout << endl;
        if (c[n - 1] == 1)
        {
            l = mid;
        }
        else
        {
            r = mid;
        }
    }
    cout << l;
}