stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <iostream>

using namespace std;

int a[200005],n,b[200005],i,l,A,M,r=200005;

int P(int x){for(i=1;i<=n*2-1;i++)b[i]=(a[i]>=x);b[0]=b[1];

for(i=n;i<=n+n;i++){if(b[i]==b[i+1])return b[i];if(b[n+n-i]==b[n+n-i-1])return b[n+n-i];}}

int main(){

cin>>n;for(i=1;i<=n*2-1;i++)cin>>a[i];

while(l<=r){M=(l+r)/2;if(P(M))l=M+1,A=M;else r=M-1;}cout<<A;}

// Optimized solution to the same problem (faster):
#include<stdio.h>

const int maxn=1000005;

int i,j,k,m,n,l,r;

int a[maxn];

int check(int x){

	for(int i=n,j=n;i>1&&j<m;i--,j++){

		if((a[i]<=x&&a[i-1]<=x)||(a[j]<=x&&a[j+1]<=x))

			return 1;

		if((a[i]>x&&a[i-1]>x)||(a[j]>x&&a[j+1]>x))

			return 0;

	}

	return a[1]<=x;

}

int main(){

	scanf("%d",&n);

	m=(n<<1)-1;

	for(i=1;i<=m;i++)

		scanf("%d",&a[i]);

	l=0,r=m+1;

	while(l+1<r){

		int mid=(l+r)>>1;

		if(check(mid))

			r=mid;

		else l=mid;

	}

	printf("%d\n",r);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

int a[200005],n,b[200005],i,l,A,M,r=200005;

int P(int x){for(i=1;i<n*2;i++)b[i]=(a[i]>=x);b[0]=b[1];

for(i=n;i<=n+n;i++){if(b[i]==b[i+1])return b[i];if(b[n+n-i]==b[n+n-i-1])return b[n+n-i];}}

int main(){std::cin>>n;for(i=1;i<n*2;i++)std::cin>>a[i];

while(l<=r){M=(l+r)/2;if(P(M))l=M+1,A=M;else r=M-1;}std::cout<<A;}

// Optimized solution to the same problem (faster):
#include<stdio.h>

const int maxn=1000005;

int i,j,k,m,n,l,r;

int a[maxn];

int check(int x){

	for(int i=n,j=n;i>1&&j<m;i--,j++){

		if((a[i]<=x&&a[i-1]<=x)||(a[j]<=x&&a[j+1]<=x))

			return 1;

		if((a[i]>x&&a[i-1]>x)||(a[j]>x&&a[j+1]>x))

			return 0;

	}

	return a[1]<=x;

}

int main(){

	scanf("%d",&n);

	m=(n<<1)-1;

	for(i=1;i<=m;i++)

		scanf("%d",&a[i]);

	l=0,r=m+1;

	while(l+1<r){

		int mid=(l+r)>>1;

		if(check(mid))

			r=mid;

		else l=mid;

	}

	printf("%d\n",r);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define int long long

using namespace std;

int read(){

    int x=0,f=1;char ch=getchar();

    for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;

    for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';

    return x*f;

}

const int N=2e5+28;

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

signed main(){

    //freopen("night.in","r",stdin);

    //freopen("night.out","w",stdout);

    n=read()*2-1;

    for(int i=1;i<=n;i++)a[i]=read();

    int l=0,r=0x7fffffff,ans=0x7fffffff;

    while(l<=r){

	int mid=(l+r)>>1;

	for(int i=1;i<=n;i++)

	    b[i]=(a[i]>mid);

	int p1=n/2,p2=n/2+2;

	int re=-1;

	for(;p1;p1--,p2++){

	    if(b[p1]==b[p1+1]){

		re=b[p1];

		break;

	    }

	    if(b[p2]==b[p2-1]){

		re=b[p2];

		break;

	    }

	}

	if(re==-1)re=b[1];

	if(re==0)ans=mid,r=mid-1;

	else l=mid+1;

    }

    printf("%lld",ans);

    return 0;

}

/*

7

1 2 3 4 3 2 1

5

1 9 2 3 6

*/


// Optimized solution to the same problem (faster):
#include<stdio.h>

const int maxn=1000005;

int i,j,k,m,n,l,r;

int a[maxn];

int check(int x){

	for(int i=n,j=n;i>1&&j<m;i--,j++){

		if((a[i]<=x&&a[i-1]<=x)||(a[j]<=x&&a[j+1]<=x))

			return 1;

		if((a[i]>x&&a[i-1]>x)||(a[j]>x&&a[j+1]>x))

			return 0;

	}

	return a[1]<=x;

}

int main(){

	scanf("%d",&n);

	m=(n<<1)-1;

	for(i=1;i<=m;i++)

		scanf("%d",&a[i]);

	l=0,r=m+1;

	while(l+1<r){

		int mid=(l+r)>>1;

		if(check(mid))

			r=mid;

		else l=mid;

	}

	printf("%d\n",r);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <vector>

#include <stdio.h>

#include <cstdlib>

#include <cstring>

#include <iostream>

#include <algorithm>



using namespace std;



const int N = 5e5 + 10;



inline void Read(int &x) {

	x = 0; register char cc = '\0'; int fff = 1;

	for (; cc < '0' || cc > '9'; cc = getchar())

		if (cc == '-') fff = -1;

	for (; cc >= '0' && cc <= '9'; cc = getchar())

		x = (x << 1) + (x << 3) + (cc & 15);

	x *= fff;

}



int n, mxn, a[N], b[N];



inline int Check(int x) {

	for (int i = 1; i <= mxn; ++i)

		if (a[i] <= x) b[i] = 0;

		else b[i] = 1;

	if (mxn == 1) return b[1];

	//printf("%d : ", x);

	//for (int i = 1; i <= mxn; ++i) printf("%d ", b[i]);

	//printf("\n");

	for (int i = 0; i < n - 1; ++i) {

		if (b[n - i] == b[n - i - 1]) return b[n - i];

		if (b[n + i] == b[n + i + 1]) return b[n + i];

	}

	if (n & 1 /*mxn & 1*/) return b[n];

	else return (!b[n]);

}



int main()

{

	Read(n);

	mxn = n * 2 - 1;

	for (int i = 1; i <= mxn; ++i) Read(a[i]);

	int L = 1, R = mxn/* n */, mid = 0, fps = 0;

	while (L <= R) {

		mid = (L + R) >> 1;

		if (!Check(mid)) {

			fps = mid;

			R = mid - 1;

		}

		else L = mid + 1;

	}

	printf("%d\n", fps);

	

	return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

const int maxn=1000005;

int i,j,k,m,n,l,r;

int a[maxn];

int check(int x){

	for(int i=n,j=n;i>1&&j<m;i--,j++){

		if((a[i]<=x&&a[i-1]<=x)||(a[j]<=x&&a[j+1]<=x))

			return 1;

		if((a[i]>x&&a[i-1]>x)||(a[j]>x&&a[j+1]>x))

			return 0;

	}

	return a[1]<=x;

}

int main(){

	scanf("%d",&n);

	m=(n<<1)-1;

	for(i=1;i<=m;i++)

		scanf("%d",&a[i]);

	l=0,r=m+1;

	while(l+1<r){

		int mid=(l+r)>>1;

		if(check(mid))

			r=mid;

		else l=mid;

	}

	printf("%d\n",r);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<algorithm>

using namespace std;

int n,ans,a[20000001];

int check1(int i,int j,int x){return a[i]<=x&&a[j]<=x;}

int check2(int i,int j,int x){return a[i]>x&&a[j]>x;} 

int check(int x)

{

    for(int i=0;i<n-1;i++)

	{

        if(check2(n+i,n+i+1,x)||check2(n-i,n-i-1,x))return 0;

        if(check1(n+i,n+i+1,x)||check1(n-i,n-i-1,x))return 1;

    }

    return check1(1,1,x);

}

int main()

{

	scanf("%d",&n);

	for(int i=1;i<=n*2-1;i++)scanf("%d",&a[i]);

	int l=1,r=n*2-1;

	while(l<=r)

	{

		int mid=(l+r)>>1;

		if(check(mid))	r=mid-1,ans=mid;

		else			l=mid+1;

	}

	printf("%d",ans);return 0; 

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

const int maxn=1000005;

int i,j,k,m,n,l,r;

int a[maxn];

int check(int x){

	for(int i=n,j=n;i>1&&j<m;i--,j++){

		if((a[i]<=x&&a[i-1]<=x)||(a[j]<=x&&a[j+1]<=x))

			return 1;

		if((a[i]>x&&a[i-1]>x)||(a[j]>x&&a[j+1]>x))

			return 0;

	}

	return a[1]<=x;

}

int main(){

	scanf("%d",&n);

	m=(n<<1)-1;

	for(i=1;i<=m;i++)

		scanf("%d",&a[i]);

	l=0,r=m+1;

	while(l+1<r){

		int mid=(l+r)>>1;

		if(check(mid))

			r=mid;

		else l=mid;

	}

	printf("%d\n",r);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define LL long long 

using namespace std;



inline int read(){

	int res=0,f=1;char ch=' ';

	while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}

	while(isdigit(ch)){res=res*10+ch-'0';ch=getchar();}

	return res*f;

}

const int N=200005;

int n;

int a[N];

inline bool big(int i,int j,int mid){

	return a[i]>mid&&a[j]>mid;

}

inline bool small(int i,int j,int mid){

	return a[i]<=mid&&a[j]<=mid;

}

inline bool check(int mid){

	for(register int i=0;i<n-1;i++){

		if(big(n+i,n+i+1,mid)||big(n-i,n-i-1,mid)) return false;

		if(small(n+i,n+i+1,mid)||small(n-i,n-i-1,mid)) return true;

	}

	return small(1,1,mid);

}

int main(){

	n=read();

	for(register int i=1;i<=n*2-1;i++) a[i]=read();

	int l=0,r=2*n-1,ans=0;

	while(l<=r){

		int mid=(l+r)/2;

		if(check(mid)){

			r=mid-1;ans=mid;

		}

		else l=mid+1;

	}

	printf("%d\n",ans);

	return 0;

}

/*

7

1 2

3 1

3 4

5 4

4 7

6 2

3

1

2

3

*/

// Optimized solution to the same problem (faster):
#include<stdio.h>

const int maxn=1000005;

int i,j,k,m,n,l,r;

int a[maxn];

int check(int x){

	for(int i=n,j=n;i>1&&j<m;i--,j++){

		if((a[i]<=x&&a[i-1]<=x)||(a[j]<=x&&a[j+1]<=x))

			return 1;

		if((a[i]>x&&a[i-1]>x)||(a[j]>x&&a[j+1]>x))

			return 0;

	}

	return a[1]<=x;

}

int main(){

	scanf("%d",&n);

	m=(n<<1)-1;

	for(i=1;i<=m;i++)

		scanf("%d",&a[i]);

	l=0,r=m+1;

	while(l+1<r){

		int mid=(l+r)>>1;

		if(check(mid))

			r=mid;

		else l=mid;

	}

	printf("%d\n",r);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cmath>

#include <queue>

#include <cstdio>

#include <vector>

#include <cstring>

#include <iostream>

#include <algorithm>

#define il inline 

#define re register

#define LL long long

using namespace std;

const int mod = 1e9 + 7;

const int INF = (1 << 30);

const int maxn = 2e5 + 50;

LL read() {

    LL res = 0, f = 1; char ch = ' ';

    while (!isdigit(ch)) { ch = getchar(); if (ch == '-') f = -1; } 

    while (isdigit(ch)) res = (res << 3) + (res << 1) + ch - '0', ch = getchar();

    return res * f;

}



int n, a[maxn], ans;

bool Check(int k) {

	for (re int i = 0; i < n - 1; ++i) {

		if ((a[n + i] > k && a[n + i + 1] > k) || (a[n - i] > k && a[n - i - 1] > k)) return 0;

		if ((a[n + i] <= k && a[n + i + 1] <= k) || (a[n - i] <= k && a[n - i - 1] <= k)) return 1;

	}

	return a[1] <= k;

}

int main() {

	n = read();

	for (re int i = 1; i < 2 * n; ++i) a[i] = read();

	int l = 1, r = 2 * n - 1;

	while (l <= r) {

		int mid = (l + r >> 1);

		if (Check(mid)) r = mid - 1, ans = mid;

		else l = mid + 1;

	}

	printf("%d\n", ans);

	return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

const int maxn=1000005;

int i,j,k,m,n,l,r;

int a[maxn];

int check(int x){

	for(int i=n,j=n;i>1&&j<m;i--,j++){

		if((a[i]<=x&&a[i-1]<=x)||(a[j]<=x&&a[j+1]<=x))

			return 1;

		if((a[i]>x&&a[i-1]>x)||(a[j]>x&&a[j+1]>x))

			return 0;

	}

	return a[1]<=x;

}

int main(){

	scanf("%d",&n);

	m=(n<<1)-1;

	for(i=1;i<=m;i++)

		scanf("%d",&a[i]);

	l=0,r=m+1;

	while(l+1<r){

		int mid=(l+r)>>1;

		if(check(mid))

			r=mid;

		else l=mid;

	}

	printf("%d\n",r);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



const int N =2e5+10;

int n,a[N];

inline int read()

{

    int x = 0, f = 1; char ch = getchar();

    while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }

    while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); }

    return x * f;

}

inline bool check(const int &k)

{

    if((a[n-1]<=k&&a[n]<=k)||(a[n]<=k&&a[n+1]<=k))return 1;

    if((a[n-1]> k&&a[n]> k)||(a[n]> k&&a[n+1]> k))return 0;

    for(int i=1;i<n-1;i++){

        if((a[n+i]<=k&&a[n+i+1]<=k)||(a[n-i]<=k&&a[n-i-1]<=k))return 1;

        if((a[n+i]> k&&a[n+i+1]> k)||(a[n-i]> k&&a[n-i-1]> k))return 0;

    }

    return a[1]<=k;

}



int main(){

    n=read();

    for(int i=1;i<n<<1;i++)a[i]=read();

    int l=1,r=(n<<1)-1;

    while(l<r){

        int mid=l+r>>1;

        if(check(mid))

            r=mid;

        else

            l=mid+1;

    }

    printf("%d",l);

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

const int maxn=1000005;

int i,j,k,m,n,l,r;

int a[maxn];

int check(int x){

	for(int i=n,j=n;i>1&&j<m;i--,j++){

		if((a[i]<=x&&a[i-1]<=x)||(a[j]<=x&&a[j+1]<=x))

			return 1;

		if((a[i]>x&&a[i-1]>x)||(a[j]>x&&a[j+1]>x))

			return 0;

	}

	return a[1]<=x;

}

int main(){

	scanf("%d",&n);

	m=(n<<1)-1;

	for(i=1;i<=m;i++)

		scanf("%d",&a[i]);

	l=0,r=m+1;

	while(l+1<r){

		int mid=(l+r)>>1;

		if(check(mid))

			r=mid;

		else l=mid;

	}

	printf("%d\n",r);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int n,a[200005];

int check(int x) 

{

	 for(register int i=0;i<n-1;i++) 

	 {

	 	if((a[n+i]>x&&a[n+i+1]>x)||(a[n-i]>x&&a[n-i-1]>x)) return 0;

	 	else if((a[n+i]<=x&&a[n+i+1]<=x)||(a[n-i]<=x&&a[n-i-1]<=x)) return 1;

	 }

	 return a[1]<=x;

}

int main() 

{

	scanf("%d",&n);

	for(register int i=1;i<=2*n-1;i++)

	{

		scanf("%d",&a[i]);

	}

	int ans=0;

	int l=0,r=2*n-1;

	while(l<=r)

	{

		int mid=(l+r)/2;

		if(check(mid))

		{

			r=mid-1;

			ans=mid;

		}

		else 

		{

			l=mid+1;

		}

	}

	printf("%d",ans);

	return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

const int maxn=1000005;

int i,j,k,m,n,l,r;

int a[maxn];

int check(int x){

	for(int i=n,j=n;i>1&&j<m;i--,j++){

		if((a[i]<=x&&a[i-1]<=x)||(a[j]<=x&&a[j+1]<=x))

			return 1;

		if((a[i]>x&&a[i-1]>x)||(a[j]>x&&a[j+1]>x))

			return 0;

	}

	return a[1]<=x;

}

int main(){

	scanf("%d",&n);

	m=(n<<1)-1;

	for(i=1;i<=m;i++)

		scanf("%d",&a[i]);

	l=0,r=m+1;

	while(l+1<r){

		int mid=(l+r)>>1;

		if(check(mid))

			r=mid;

		else l=mid;

	}

	printf("%d\n",r);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
/*************************************************************************

	> File Name: pyramid.cpp

	> Author: wangyifan

	> Created Time: 2019年11月07日 星期四 08时33分17秒

 ************************************************************************/



#include<iostream>

#include<cstdio>

#include<algorithm>

#define ll long long

#define REP(i,a,b) for(register int i = a;i <= b;++i)

using namespace std;

const int maxn = 1e6+10;

int a[maxn],b[maxn];

int ans,n,num;

inline int read(){

	int res = 0,tmp = 1;

	char ch = getchar();

	while(ch < '0' || ch > '9'){if(ch == '-')tmp = -1;ch = getchar();}

	while(ch >= '0' && ch <= '9')res = (res<<1)+(res<<3)+(ch^48),ch = getchar();

	return res*tmp;

}

inline bool check(int x){

	REP(i,1,num)b[i] = a[i]>x;

	REP(i,0,n-1){

		if((b[n+i] && b[n+i+1]) || (b[n-i] && b[n-i-1]))return false;

		if((!b[n+i] && !b[n+i+1]) || (!b[n-i] && !b[n-i-1]))return true;

	}

	return a[1] <= x;

}

int main(){

	n = read();

	num = (n<<1)-1;

	REP(i,1,num)a[i] = read();

	int l = 1,r = num;

	while(l < r){

		int mid = (l+r)>>1;

		if(check(mid))ans = mid,r = mid;

		else l = mid+1;

	}

	cout<<ans<<endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

const int maxn=1000005;

int i,j,k,m,n,l,r;

int a[maxn];

int check(int x){

	for(int i=n,j=n;i>1&&j<m;i--,j++){

		if((a[i]<=x&&a[i-1]<=x)||(a[j]<=x&&a[j+1]<=x))

			return 1;

		if((a[i]>x&&a[i-1]>x)||(a[j]>x&&a[j+1]>x))

			return 0;

	}

	return a[1]<=x;

}

int main(){

	scanf("%d",&n);

	m=(n<<1)-1;

	for(i=1;i<=m;i++)

		scanf("%d",&a[i]);

	l=0,r=m+1;

	while(l+1<r){

		int mid=(l+r)>>1;

		if(check(mid))

			r=mid;

		else l=mid;

	}

	printf("%d\n",r);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
/*************************************************************************

	> File Name: pyramid.cpp

	> Author: codecode

	> Created Time: 2019年11月07日 星期四 08时31分48秒

 ************************************************************************/



#include<bits/stdc++.h>

using namespace std;

const int maxn=1000000+5;

int n,a[maxn];

inline int read(){

	int s=0,w=1;

	char ch=getchar();

	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}

	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();

	return s*w;

}

inline bool jujuakioi(const int &k){

	 if((a[n-1]<=k&&a[n]<=k)||(a[n]<=k&&a[n+1]<=k))return 1;

	 if((a[n-1]>k&&a[n]>k)||(a[n]>k&&a[n+1]>k))return 0;

	 for(int i=1;i<n-1;i++){

		 if((a[n+i]<=k&&a[n+i+1]<=k)||(a[n-i]<=k&&a[n-i-1]<=k))return 1;

		 if((a[n+i]>k&&a[n+i+1]>k)||(a[n-i]>k&&a[n-i-1]>k))return 0;

	 }

	 return a[1]<=k;

}

int main(){

	cin>>n;

	for(int i=1;i<n*2;i++)a[i]=read();

	int l=1,r=n*2-1;

	while(l<r){

		int mid=(l+r)/2;

		if(jujuakioi(mid))r=mid;

		else l=mid+1;

	}

	cout<<l;

	return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

const int maxn=1000005;

int i,j,k,m,n,l,r;

int a[maxn];

int check(int x){

	for(int i=n,j=n;i>1&&j<m;i--,j++){

		if((a[i]<=x&&a[i-1]<=x)||(a[j]<=x&&a[j+1]<=x))

			return 1;

		if((a[i]>x&&a[i-1]>x)||(a[j]>x&&a[j+1]>x))

			return 0;

	}

	return a[1]<=x;

}

int main(){

	scanf("%d",&n);

	m=(n<<1)-1;

	for(i=1;i<=m;i++)

		scanf("%d",&a[i]);

	l=0,r=m+1;

	while(l+1<r){

		int mid=(l+r)>>1;

		if(check(mid))

			r=mid;

		else l=mid;

	}

	printf("%d\n",r);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int n,a[20000010];

bool x(int i,int j,int k) {

    return a[i]<=k&&a[j]<=k;

}

bool y(int i,int j,int k){

    return a[i]>k&&a[j]>k;

} 

bool check(int a){

    for(int i=0;i<n-1;i++){

        if(y(n+i,n+i+1,a)||y(n-i,n-i-1,a)) return 0;

        if(x(n+i,n+i+1,a)||x(n-i,n-i-1,a)) return 1;

    }

    return x(1,1,a);

}

int main(){

    scanf("%d",&n);

    for(int i=1;i<=2*n-1;i++) scanf("%d",&a[i]);

    int l=1,r=2*n-1,mid;

    while(l<r){

	 	mid=(l+r)/2;

        if(check(mid)) r=mid;

        else l=mid+1;

    }

    printf("%d",l);

    return 0; 

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cctype>

#include <algorithm>

#define big(i, j) (a[i] >= x && a[j] >= x)

#define small(i, j) (a[i] < x && a[j] < x)

using namespace std;



int a[200005];

int n;



inline void in(register int &x){

	register char ch;

	x = 0;

	while(isspace(ch = getchar()));

	do x = x*10 + ch-'0'; while(isdigit(ch = getchar()));

}



bool check(int x){

	for(int i=1; i<n; i++){

		if(big(n-i, n-i+1) || big(n+i, n+i-1)) return true;

		if(small(n-i, n-i+1) || small(n+i, n+i-1)) return false;

	}

	return a[1] >= x;

}



int main(){

//	freopen("at2165.in", "r", stdin);

//	freopen("at2165.out", "w", stdout);

	in(n);

	for(int i=1; i<=n*2-1; i++)

		in(a[i]);

	int l = 1, r = n * 2 - 1, mid, ans;

	while(l <= r){

		mid = (l+r) >> 1;

		if(check(mid)){

//			printf("%d is valid.\n", mid);

			ans = mid;

			l = mid + 1;

		}

		else r = mid - 1;//, printf("%d is invaild.\n", mid);

	}

	printf("%d\n", ans);

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<algorithm>

#include<iostream>

#include<cstring>

#include<cstdio>

#include<cmath>

#define LL long long

#define M 400020

using namespace std;

int read(){

	int nm=0,fh=1;char cw=getchar();

	for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;

	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');

	return nm*fh;

}

int n,m,L,R,md,t[M],ans,p[M],t1,t2;

bool solve(int x){

	t1=0,t2=(n<<1);

	for(int i=1;i<=m;i++) p[i]=(t[i]>=x);

	for(int i=2;i<=n;i++) if(p[i]==p[i-1]) t1=i;

	for(int i=m-1;i>=n;i--) if(p[i]==p[i+1]) t2=i;

	if(t1==n||t2==n) return p[n]>0;

	if(t1>1&&t2<m&&p[t1]==p[t2]) return p[t1]>0;

	if(t2-n<n-t1) return p[t2]>0;

	if(t2-n>n-t1) return p[t1]>0;

	return (p[n]^(n&1)^1)>0;

}

int main(){

	n=read(),L=1,R=n,R<<=1,R--,m=R;

	for(int i=1;i<=n+n-1;i++) t[i]=read();

    while(L<=R){

    	md=(L+R>>1);

    	if(!solve(md)) R=md-1;

		else L=md+1,ans=md;

	}

	printf("%d\n",ans);

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cctype>

#include <algorithm>

#define big(i, j) (a[i] >= x && a[j] >= x)

#define small(i, j) (a[i] < x && a[j] < x)

using namespace std;



int a[200005];

int n;



inline void in(register int &x){

	register char ch;

	x = 0;

	while(isspace(ch = getchar()));

	do x = x*10 + ch-'0'; while(isdigit(ch = getchar()));

}



bool check(int x){

	for(int i=1; i<n; i++){

		if(big(n-i, n-i+1) || big(n+i, n+i-1)) return true;

		if(small(n-i, n-i+1) || small(n+i, n+i-1)) return false;

	}

	return a[1] >= x;

}



int main(){

//	freopen("at2165.in", "r", stdin);

//	freopen("at2165.out", "w", stdout);

	in(n);

	for(int i=1; i<=n*2-1; i++)

		in(a[i]);

	int l = 1, r = n * 2 - 1, mid, ans;

	while(l <= r){

		mid = (l+r) >> 1;

		if(check(mid)){

//			printf("%d is valid.\n", mid);

			ans = mid;

			l = mid + 1;

		}

		else r = mid - 1;//, printf("%d is invaild.\n", mid);

	}

	printf("%d\n", ans);

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
/*

---------------------------------

题解：

我还是太蒟了，没有想到能二分答案……

我们二分塔顶的值，把小于等于这个值的变为1，大于变为0。

我们可以发现如果有多个个1或0连在一起，那么他们就无法被分开，他会一直往上走。

那也就是说，最后那组先走到顶那组就赢了，那就要看那组离中心更近。

那会不会存在两个不同阵营的组距离一样远能，你会发现这是不可能的。

因为，如果距离相等，那么中间一定是奇数个位置，我们用1和0,交替隔开两组，

那么最后一个位置肯定会和左边或者右边一样，又形成一个组，所这两个组要么都是1，要么都是0。

解决了这些问题就能愉快的判断了！

CODE：

---------------------------------题解1



最后还有一种特殊情况。就是没有任何两个相邻的。

大概长这样。。

    0

  0 1 0

0 1 0 1 0

我们只需要特判一下就行了。

总结，一道二分贪心题，需要一定的手推过程找到规律。

---------------------------------题解2

*/

#include<iostream>

#include<cstdio>

#include<cassert>

using namespace std;



int n,a[200005];



inline bool check(const int &k){

    if((a[n-1]<=k&&a[n]<=k)||(a[n]<=k&&a[n+1]<=k))return 1;

    if((a[n-1]> k&&a[n]> k)||(a[n]> k&&a[n+1]> k))return 0;

    for(int i=1;i<n-1;i++){

        if((a[n+i]<=k&&a[n+i+1]<=k)||(a[n-i]<=k&&a[n-i-1]<=k))return 1;

        if((a[n+i]> k&&a[n+i+1]> k)||(a[n-i]> k&&a[n-i-1]> k))return 0;

    }

    return a[1]<=k;

}



int main(){

    scanf("%d",&n);

    for(int i=1;i<n<<1;i++)scanf("%d",a+i);

    int l=1,r=(n<<1)-1;

    while(l<r){//满足 l<=k<=r

        int mid=l+r>>1;

        if(check(mid))r=mid;//结果可能小于等于k

        else l=mid+1;//不可能-->结果大于k-->往右半部分搜

    }

    assert(l==r);

    printf("%d",l);

}

// Optimized solution to the same problem (faster):
//AT2165

#include <cstdio>



const int MAXN = (int)1e5;

int n, a[2*MAXN+5];



inline bool check(int x) {

	for (int i = 0; i < n-1; i++) {

		if ((a[n+i] <= x && a[n+i+1] <= x) || (a[n-i] <= x && a[n-i-1] <= x)) return true;

		if ((a[n+i] > x && a[n+i+1] > x) || (a[n-i] > x && a[n-i-1] > x)) return false;

	}

	return a[1] <= x;

}



int main() {

	scanf("%d", &n);

	for (register int i = 1; i < 2*n; i++)

		scanf("%d", a+i);

	int L = 0, R = 2*n-1;

	while (L < R) {

		int mid = (L+R)>>1;

		if (check(mid)) R = mid;

		else L = mid + 1;

	}

	printf("%d", L);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#pragma GCC optimize(2)

#pragma GCC optimize(3)

#include<bits/stdc++.h>

using namespace std;

int n,m,a[500050],k,b[500050],ans,ok[2];

int check(int x)

{

	ok[0]=ok[1]=1000000;

	for(int i=1;i<=k;i++)

	b[i]=(a[i]>=x);

	b[0]=b[k+1]=10;

	for(int i=1;i<=k;i++)

	{

		if(b[i]==b[i-1]||b[i]==b[i+1])

		{

			ok[b[i]]=min(ok[b[i]],abs(i-n));

		}

	}

	//cout<<x<<" "<<ok[0]<<" "<<ok[1]<<endl;

	if(ok[1]==ok[0]) return b[1];

	return ok[1]<ok[0];

}

int main()

{

	cin>>n;

	k=2*n-1;

	for(int i=1;i<=k;i++)

	{

		scanf("%d",&a[i]);

	}

	int l=1,r=k;

	while(l<=r)

	{

		int mid=(l+r)/2;

		if(check(mid)) ans=mid,l=mid+1;

		else r=mid-1;

	}

	cout<<ans;

}

// Optimized solution to the same problem (faster):
//AT2165

#include <cstdio>



const int MAXN = (int)1e5;

int n, a[2*MAXN+5];



inline bool check(int x) {

	for (int i = 0; i < n-1; i++) {

		if ((a[n+i] <= x && a[n+i+1] <= x) || (a[n-i] <= x && a[n-i-1] <= x)) return true;

		if ((a[n+i] > x && a[n+i+1] > x) || (a[n-i] > x && a[n-i-1] > x)) return false;

	}

	return a[1] <= x;

}



int main() {

	scanf("%d", &n);

	for (register int i = 1; i < 2*n; i++)

		scanf("%d", a+i);

	int L = 0, R = 2*n-1;

	while (L < R) {

		int mid = (L+R)>>1;

		if (check(mid)) R = mid;

		else L = mid + 1;

	}

	printf("%d", L);

	return 0;

}

// Fastest known solution for this problem: