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

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 [] P,A;

    private static boolean valid(int x) {
        int pp = -1,p = -1,m = N/2;
        for (int i = 0;i < N;i++){
            A[i] = 0;
            if (P[i] >= x) A[i] = 1;
        }
        for (int i = 0;i < N;i++) {
            int v = A[i];
            if (p == v) {
                if (v == 1 && (i == m || i-1 == m)) return true;
                pp = p;
                p = v;
            }
            else {
                if (pp == v) {
                    if (v == 1 && (i-2 == m || i-1 == m || i == m)) return true;
                    pp = p = v;
                }
                else {
                    pp = p;
                    p = v;
                }
            }
        }
        return false;
    }

    public static void main(String[] args) throws Exception {
        IO io = new IO(null, null);
        n = io.getNextInt();
        N = 2*n-1;
        P = new int[N];
        A = new int[N];
        for (int i = 0;i < N;i++)
            P[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();
    }
}





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");
    }
}