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 Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

import java.io.*;
import java.lang.reflect.Array;
import java.math.*;
import java.text.DecimalFormat;
import java.util.*;




public class Main {
    private static int n,N;
    private static int [] A;
    private static int [] B;

    private static int getLeft(){
        int s = N/2 + 1;
        while (s > 1 && B[s] != B[s-1]) s--;
        return s;
    }
    private static int getRight(){
        int e = N/2+1;
        while (e < N && B[e] != B[e+1]) e++;
        return e;
    }

    private static boolean valid(int x) {
        for (int i = 1;i <= N;i++)
            B[i] = (A[i] >= x) ? 1 : 0;
        int s = getLeft(),e = getRight(),mid = N/2 + 1;
        if (s == mid || e == mid) return B[mid] == 1;

//        System.err.println(s + " " + e);
        int prv = 0;
        int l = B[s],r = B[e];

        while (s <= e) {
            int h = Math.max(s,e);
            h = Math.min(h,N+1-h) - 1;
            int rem = h - prv;
            prv = h;
            if (rem == 0) break;
            int len = e-s-1;
            if (2*rem <= len) {
                s += rem;
                e -= rem;
            }
            else {
                if (l == r) return l == 1;
                if (mid-s < e-mid) return l == 1;
                else return r==1;
            }
        }
//        System.err.println(": " + s + " " + e);
        if (l == r) return l == 1;
        int pos = mid - s;
        if (l == 0) return pos%2 == 0;
        return pos%2 == 1;
    }
    public static void main(String[] args) throws Exception {
        IO io = new IO(null,null);
        n = io.getNextInt();
        N = 2*n-1;
        A = new int[N+1];
        B = new int[N+1];
        for (int i = 1;i <= N;i++)
            A[i] = io.getNextInt();

        int s = 1,e = N;
        while (s < e) {
            int m = s + (e-s+1)/2;
            if (valid(m)) s = m;
            else e = m - 1;
        }
        io.println(s);

        io.close();
    }
    private static void bf(int n) {
        ArrayList<Integer> A = new ArrayList<>();
        for (int i = 0;i < n;i++)
            A.add(i&1);
        TreeSet<ArrayList<Integer>> vis = new TreeSet<>(new Comparator<ArrayList<Integer>>() {
            @Override
            public int compare(ArrayList<Integer> o1, ArrayList<Integer> o2) {
                for (int i = 0;i < n;i++)
                    if (!o1.get(i).equals(o2.get(i)))
                        return o1.get(i) - o2.get(i);
                return 0;
            }
        });

        while (!vis.contains(A)) {
            System.err.println(A);
            vis.add((ArrayList<Integer>)A.clone());
            int prv = A.get(0);
            for (int i = 1;i+1 < n;i++){
                int cur = A.get(i);
                if (prv != cur) A.set(i,A.get(i+1));
                prv = cur;
            }
        }
    }

    private static void bftri(int n) {
        ArrayList<Integer> A = new ArrayList<>();
        for (int i = 0;i < n;i++)
            A.add(i&1);
        while (!A.isEmpty()) {
            System.err.println(A);

            ArrayList<Integer> B = new ArrayList<>();
            int prv = A.get(0);
            for (int i = 1;i+1 < A.size();i++){
                int cur = A.get(i);
                if (prv != cur) B.add(A.get(i+1));
                else B.add(cur);
                prv = cur;
            }
            A = B;
        }
    }
}

class pair{
    int s,e,v;
    public pair(int s,int e,int v) {
        this.s = s;
        this.e = e;
        this.v = v;
    }
    public int getLen(){
        return e-s+1;
    }
    @Override
    public String toString(){
        return "(" + s + ":" + e + ", " + v + ")";
    }
}


class IO{
    private BufferedReader br;
    private StringTokenizer st;
    private PrintWriter writer;
    private String inputFile,outputFile;

    public boolean hasMore() throws IOException{
        if(st != null && st.hasMoreTokens()) return true;
        if(br != null && br.ready()) return true;
        return false;
    }
    public String getNext() throws FileNotFoundException, IOException{
        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public String getNextLine() throws FileNotFoundException, IOException{
        return br.readLine().trim();
    }

    public int getNextInt() throws FileNotFoundException, IOException{
        return Integer.parseInt(getNext());
    }
    public long getNextLong() throws FileNotFoundException, IOException{
        return Long.parseLong(getNext());
    }

    public void print(double x,int num_digits) throws  IOException{
        writer.printf("%." + num_digits + "f" ,x);
    }
    public void println(double x,int num_digits) throws  IOException{
        writer.printf("%." + num_digits + "f\n" ,x);
    }
    public void print(Object o) throws  IOException{
        writer.print(o.toString());
    }

    public void println(Object o) throws  IOException{
        writer.println(o.toString());
    }
    public IO(String x,String y) throws FileNotFoundException, IOException{
        inputFile = x;
        outputFile = y;
        if(x != null) br = new BufferedReader(new FileReader(inputFile));
        else br = new BufferedReader(new InputStreamReader(System.in));
        if(y != null) writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFile)));
        else writer = new PrintWriter(new OutputStreamWriter(System.out));
    }

    protected void close() throws IOException{
        br.close();
        writer.close();
    }
    public void outputArr(Object [] A) throws IOException{
        int L = A.length;
        for (int i = 0;i < L;i++) {
            if(i > 0) writer.print(" ");
            writer.print(A[i]);
        }
        writer.print("\n");
    }
}