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: Wrong Answer)

#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<int, int>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }
 
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<40;
const ll MOD = 1000000007;

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

  ll n;
  cin >> n;
  n = 2*n-1;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  
  //         0
  //       1,0,0
  //     1,0,1,0,0
  //   1,0,1,0,1,0,0
  // 1,0,1,0,1,0,1,0,0

  auto check = [&](ll mid) -> bool {
    vector<ll> v(n);
    REP(i, n) v[i] = a[i] >= mid;

    ll prev = 0;
    FOR(i, 1, n) {
      if(v[i] == v[i-1]) {
        if(prev < i-1) {
          if(v[prev] == v[i-1]) {
            FOR(j, prev, i) v[j] = v[prev];
          } else {
            ll x = (prev+i-1)/2;
            FOR(j, prev, x) v[j] = v[prev];
            FOR(j, x, i) v[j] = v[i-1];
          }
        }
        prev = i;
      }
    }
    if(prev < n-1) {
      if(v[prev] == v[n-1]) {
        FOR(j, prev, n) v[j] = v[prev];
      } else {
        ll x = (prev+n-1)/2;
        FOR(j, prev, x) v[j] = v[prev];
        FOR(j, x, n) v[j] = v[n-1];
      }
    }
    return v[n/2];

    // ll l = n/2, r = n/2;
    // while(l>0 && v[l] != v[l-1]) l--;
    // while(r<n-1 && v[r] != v[r+1]) r++;
    // if(v[l] != v[r]) {
    //   if(l+1 <= n/2) l++;
    //   else r--;
    // }
    // // cout << l << " " << r << endl;
    // if(n/2 < (l+r)/2) return v[l-1];
    // if((l+r)/2 < n/2) return v[r+1];
    // return v[l];
  };

  ll lb = 1, ub = n+1;
  while(ub-lb > 1) {
    ll mid = (lb+ub)/2;
    if(check(mid)) lb = mid;
    else ub = mid;
  }

  cout << lb << endl;

  return 0;
}