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

using namespace std;

#define RI register int

#define LL long long

inline int read()

{

    int res=0,f=1;

    char ch=getchar();

    while(ch!='-'&&(ch>'9'||ch<'0'))

        ch=getchar();

    if(ch=='-')

        f=-1,ch=getchar();

    while(ch>='0'&&ch<='9')

        res=(res<<1)+(res<<3)+(ch^48),ch=getchar();

    return res*f;

}

const int N=2e5+5;

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

bool check(int mid)

{

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

		b[i]=1;

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

	{

		if(a[i]>mid)

			b[i]=0;

	}

	bool flag=1;

	for(RI i=2;i<2*n;++i)

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

			flag=0;

	/*printf("%d\n",mid);

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

		printf("%d ",b[i]);

		printf("\n\n");*/

	if(flag)

		return b[1];

	int l=n,r=n;

	while(b[l]!=b[l-1]&&b[r]!=b[r+1])

	{

		l--,r++;

	}

	if(b[l]==b[l-1])

		return b[l];

	return b[r];

}

int main()

{

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

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

	n=read();

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

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

	{

		a[i]=read();

		r=max(r,a[i]);

	}

	while(l<=r)

	{

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

		if(check(mid))

		{

			ans=mid;

			r=mid-1;

		}

		else

			l=mid+1;

	}

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

	return 0;

}


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

using namespace std;

const int MAXN=3e5+5;

int N;

int A[MAXN];



bool Check(int Key){

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

		if( (A[N+i]>Key && A[N+i+1]>Key) || (A[N-i]>Key && A[N-i-1]>Key) ){

			return 0;

		}

		if( (A[N+i]<=Key && A[N+i+1]<=Key) || (A[N-i]<=Key && A[N-i-1]<=Key) ){

			return 1;

		}

	}

	return A[1]<=Key;

}



int BS(int L,int R){

	int Ans=0;

	while(L<=R){

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

		if(Check(Mid)){

			Ans=Mid;

			R=Mid-1;

		}else{

			L=Mid+1;

		}

	}

	return Ans;

}



int main(){

	

	scanf("%d",&N);

	

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

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

	}

	

	printf("%d\n",BS(1,2*N-1));

	

	return 0;

	

} 

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

#define res register int

#define ll long long

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define INF 1000000007

#define gc getchar()

#define MAXN 1000005

#define lc pos<<1

#define rc pos<<1|1

using namespace std;



inline int read()

{

    int ch=gc,f=0;

    int x=0;

    while(ch<'0'||ch>'9')

    {

        f|=ch=='-';

        ch=gc;

    }

    while(ch>='0'&&ch<='9')

    {

        x=x*10+ch-'0';

        ch=gc;

    }

    return f?-x:x;

}

int n,m;

int a[MAXN],f[MAXN];

inline bool check(int lim)

{

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

	f[i]=a[i]<=lim;

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

	{

		if(f[n+1+i]==f[n+2+i])

		return f[n+1+i];

		if(f[n+1-i]==f[n-i])

		return f[n-i];

	}

	return f[1];

}

int main()

{

	n=read()-1;

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

	a[i]=read();

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

	while(l<r)

	{

		int mid=l+r>>1;

		if(check(mid))

		r=mid;

		else

		l=mid+1;

	}

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

	return 0;

}

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

using namespace std;

const int MAXN=3e5+5;

int N;

int A[MAXN];



bool Check(int Key){

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

		if( (A[N+i]>Key && A[N+i+1]>Key) || (A[N-i]>Key && A[N-i-1]>Key) ){

			return 0;

		}

		if( (A[N+i]<=Key && A[N+i+1]<=Key) || (A[N-i]<=Key && A[N-i-1]<=Key) ){

			return 1;

		}

	}

	return A[1]<=Key;

}



int BS(int L,int R){

	int Ans=0;

	while(L<=R){

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

		if(Check(Mid)){

			Ans=Mid;

			R=Mid-1;

		}else{

			L=Mid+1;

		}

	}

	return Ans;

}



int main(){

	

	scanf("%d",&N);

	

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

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

	}

	

	printf("%d\n",BS(1,2*N-1));

	

	return 0;

	

} 

// Fastest known solution for this problem:
// Original C++ solution (slower):
// luogu-judger-enable-o2

#include<iostream>

#include<cstdio>

#include<cmath>

using namespace std;

inline int read()

{

	int r,s=0,c;

	for(;!isdigit(c=getchar());s=c);

	for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);

	return s^45?r:-r;

}

const int N=200010;

int m,n;

int a[N],b[N];

bool check(int mid)

{

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

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

//.....00.....

// ....00.....

//所以距离中间最近的相邻元素相同的那个数

//若原序列为010101010

	int l=m,r=m;

	while(l>1)

	{

		if(b[l]==b[l-1])return b[l];

		if(b[r]==b[r+1])return b[r];

		l--,r++;

	}

	return b[1];

}

int main()

{

	m=read();

	n=m*2-1;

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

	int l,r,mid,ans;

	l=1,r=n;

	while(l<=r)

	{

		mid=(l+r)>>1;

		if(check(mid))

		{

			l=mid+1;

			ans=mid;

		}

		else

			r=mid-1;

	}	

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

	return 0;

}/*

4

7 3 2 1 5 4 6

4

3 1 5 6 4 2 7 

*/

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

using namespace std;

const int MAXN=3e5+5;

int N;

int A[MAXN];



bool Check(int Key){

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

		if( (A[N+i]>Key && A[N+i+1]>Key) || (A[N-i]>Key && A[N-i-1]>Key) ){

			return 0;

		}

		if( (A[N+i]<=Key && A[N+i+1]<=Key) || (A[N-i]<=Key && A[N-i-1]<=Key) ){

			return 1;

		}

	}

	return A[1]<=Key;

}



int BS(int L,int R){

	int Ans=0;

	while(L<=R){

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

		if(Check(Mid)){

			Ans=Mid;

			R=Mid-1;

		}else{

			L=Mid+1;

		}

	}

	return Ans;

}



int main(){

	

	scanf("%d",&N);

	

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

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

	}

	

	printf("%d\n",BS(1,2*N-1));

	

	return 0;

	

} 

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

#define ll long long

#define N 1000005

#define M 10005

using namespace std;

ll read(){

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

	while(!isdigit(ch))f=(ch=='-')?-1:1,ch=getchar();

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

	return f*x;

}

int n,w[N],g[N]={2};

bool check(int mid){

	int flag=0;

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

		g[i]=(w[i]>=mid);

		if(g[i]==g[i-1]){

			if(abs(i-n)<abs(flag-n))flag=i;

			if(abs(i-1-n)<abs(flag-n))flag=i;

		}

	}

	if(flag<=0){

		if(g[1]==0)return 0;

		else return 1;

	}

	if(g[flag]==1)return 1;

	else return 0;

}

int main(){

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

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

	n=read();

	g[n+n]=2;

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

	int l=0,r=n+n,ans;

	while(l<=r){

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

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

		else r=mid-1;

	}

	cout<<ans<<endl;

	return 0;

}

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

using namespace std;

const int MAXN=3e5+5;

int N;

int A[MAXN];



bool Check(int Key){

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

		if( (A[N+i]>Key && A[N+i+1]>Key) || (A[N-i]>Key && A[N-i-1]>Key) ){

			return 0;

		}

		if( (A[N+i]<=Key && A[N+i+1]<=Key) || (A[N-i]<=Key && A[N-i-1]<=Key) ){

			return 1;

		}

	}

	return A[1]<=Key;

}



int BS(int L,int R){

	int Ans=0;

	while(L<=R){

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

		if(Check(Mid)){

			Ans=Mid;

			R=Mid-1;

		}else{

			L=Mid+1;

		}

	}

	return Ans;

}



int main(){

	

	scanf("%d",&N);

	

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

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

	}

	

	printf("%d\n",BS(1,2*N-1));

	

	return 0;

	

} 

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

using namespace std;

int n,a[200005];

bool check(int k)

{

	for (int i=1;i<=n;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()

{

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

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

	scanf("%d",&n);

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

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

	while (l<r)

	{

		int 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>

using namespace std;

const int MAXN=3e5+5;

int N;

int A[MAXN];



bool Check(int Key){

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

		if( (A[N+i]>Key && A[N+i+1]>Key) || (A[N-i]>Key && A[N-i-1]>Key) ){

			return 0;

		}

		if( (A[N+i]<=Key && A[N+i+1]<=Key) || (A[N-i]<=Key && A[N-i-1]<=Key) ){

			return 1;

		}

	}

	return A[1]<=Key;

}



int BS(int L,int R){

	int Ans=0;

	while(L<=R){

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

		if(Check(Mid)){

			Ans=Mid;

			R=Mid-1;

		}else{

			L=Mid+1;

		}

	}

	return Ans;

}



int main(){

	

	scanf("%d",&N);

	

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

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

	}

	

	printf("%d\n",BS(1,2*N-1));

	

	return 0;

	

} 

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

#define N 2000010

using namespace std;

int n,a[N];

int sm(int x,int y,int z){

	return a[x]<=z&&a[y]<=z;

}

int bd(int x,int y,int z){

	return a[x]>z&&a[y]>z;

}

int ck(int x){

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

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

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

	}

	return sm(1,1,x);

}

int main(){

	cin>>n;

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

	int l=1,r=1e7;

	while(l<r){

		int md=(l+r)/2;

		if(ck(md))r=md;

		else l=md+1;

	}

	cout<<r;

}

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

using namespace std;

const int MAXN=3e5+5;

int N;

int A[MAXN];



bool Check(int Key){

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

		if( (A[N+i]>Key && A[N+i+1]>Key) || (A[N-i]>Key && A[N-i-1]>Key) ){

			return 0;

		}

		if( (A[N+i]<=Key && A[N+i+1]<=Key) || (A[N-i]<=Key && A[N-i-1]<=Key) ){

			return 1;

		}

	}

	return A[1]<=Key;

}



int BS(int L,int R){

	int Ans=0;

	while(L<=R){

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

		if(Check(Mid)){

			Ans=Mid;

			R=Mid-1;

		}else{

			L=Mid+1;

		}

	}

	return Ans;

}



int main(){

	

	scanf("%d",&N);

	

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

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

	}

	

	printf("%d\n",BS(1,2*N-1));

	

	return 0;

	

} 

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

#include<cstdio>

 

const int MAXN=1e5+5;

 

int n;

int a[MAXN<<1];

bool jud(int k)

{

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

	{

		if(a[n+i]<k&&a[n+i+1]<k) return false;

		if(a[n-i]<k&&a[n-i-1]<k) return false;

		if(a[n+i]>=k&&a[n+i+1]>=k) return true;

		if(a[n-i]>=k&&a[n-i-1]>=k) return true;

	}

	return a[1]>=k;

}

 

int main()

{

	int i;scanf("%d",&n);

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

	int l=0,r=n<<1;

	while(l<=r)

	{

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

		if(jud(mid)) l=mid+1;

		else r=mid-1;

	}

	printf("%d",r);

	return 0;

}

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

#include<cstring>

#include<algorithm>

using namespace std;

const int MAXN=200005;



int N,A[MAXN],B[MAXN];

bool check(int x)

{

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

	{

		if(A[N+i]>=x&&A[N+i+1]>=x)

			return true;

		if(A[N-i]>=x&&A[N-i-1]>=x)

			return true;

		if(A[N+i]<x&&A[N+i+1]<x)

			return false;

		if(A[N-i]<x&&A[N-i-1]<x)

			return false;

	}

	if(A[1]>=x)

		return true;

	return false;

}



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;

	while(L<R)

	{

		int mid=(L+R+1)/2;

		if(check(mid))

			L=mid;

		else

			R=mid-1;

	}

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

	return 0;

}


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

using namespace std;

const int maxn = 200010;

int a[maxn],n,k;

bool b[maxn];

int main()

{

	scanf("%d",&n); 

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

	int L = 1, R = (int) 1e9;

	while (L <= R)

	{

	//	cerr<<L<<' '<<R<<endl;

		int mid = L + R >> 1; k = mid;

		for (int i = 1; i <= (n << 1) - 1; ++i) b[i] = (a[i] > k);

	//	for (int i = 1; i <= (n << 1) - 1; ++i) printf("%d",b[i]); putchar(10);

		int ok = -1;

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

		{

			if ((b[n + i] && b[n + i + 1])||(b[n - i] && b[n - i - 1])){ ok = 1; break;}

			if ((!b[n + i] && !b[n + i + 1]) || (!b[n - i] && !b[n - i - 1])) {ok = 0; break;}

		}

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

		if (ok) L = mid + 1; else R = mid - 1;

	}

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

}

//二分答案k

//<=答案k的那些数都看成0。>k的那些数看成1. 当二分到的k >= 实际答案时,顶端为0，否则为1. 

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

#include<cstring>

#include<algorithm>

using namespace std;

const int MAXN=200005;



int N,A[MAXN],B[MAXN];

bool check(int x)

{

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

	{

		if(A[N+i]>=x&&A[N+i+1]>=x)

			return true;

		if(A[N-i]>=x&&A[N-i-1]>=x)

			return true;

		if(A[N+i]<x&&A[N+i+1]<x)

			return false;

		if(A[N-i]<x&&A[N-i-1]<x)

			return false;

	}

	if(A[1]>=x)

		return true;

	return false;

}



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;

	while(L<R)

	{

		int mid=(L+R+1)/2;

		if(check(mid))

			L=mid;

		else

			R=mid-1;

	}

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

	return 0;

}


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

using namespace std;



inline void read(int &x){

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

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

	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}

	x*=f;

}

/*******************************head*******************************/



const int N=200005;

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

inline bool check(int k){

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

	int l=n,r=n;

	while(l>1 && b[l-1]!=b[l]) l--;

	while(r<2*n-1 && b[r+1]!=b[r]) r++;

	if(l==1 && r==2*n-1){

		if(n&1) return b[n];

		else return (b[n]^1);

	}

	if(n-l<r-n)return b[l];

	else return b[r];

}

int main(){

	read(n);

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

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

	while(l<=r){

		int mid=(l+r)/2;

		if(check(mid)){

			ans=mid;

			l=mid+1;

		}

		else r=mid-1;

	}

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

	return 0;

}

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

#include<cstring>

#include<algorithm>

using namespace std;

const int MAXN=200005;



int N,A[MAXN],B[MAXN];

bool check(int x)

{

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

	{

		if(A[N+i]>=x&&A[N+i+1]>=x)

			return true;

		if(A[N-i]>=x&&A[N-i-1]>=x)

			return true;

		if(A[N+i]<x&&A[N+i+1]<x)

			return false;

		if(A[N-i]<x&&A[N-i-1]<x)

			return false;

	}

	if(A[1]>=x)

		return true;

	return false;

}



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;

	while(L<R)

	{

		int mid=(L+R+1)/2;

		if(check(mid))

			L=mid;

		else

			R=mid-1;

	}

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

	return 0;

}


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

#include <iostream>

#include <cstring>

#include <cstdio>



using namespace std;



const int MAXN = 2e5 + 10;



int N;

int A[MAXN];

bool B[MAXN];



bool check(int mid)

{

	const int Nmid = (N + 1) >> 1;

	int Lft = 0, Rht = N + 1;



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

		B[i] = (A[i] >= mid);



	for (int i = Nmid; i > 1; i--)

		if (B[i] == B[i - 1])

		{

			Lft = i;

			break;

		}

	for (int i = Nmid; i < N; i++)

		if (B[i] == B[i + 1])

		{

			Rht = i;

			break;

		}

	if(Lft == 0 && Rht == N + 1)

		return B[1];

	else if(Nmid - Lft > Rht - Nmid)

		return B[Rht];

	else

		return B[Lft];

}



int main()

{

	cin >> N;

	N = (N << 1) - 1;

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

		cin >> A[i];



	// [L, R)

	int L = 1, R = N + 1;

	while (L + 1 < R)

	{

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

		//cerr << L << " " << mid << " " << R << endl ;



		if (check(mid))

			L = mid;

		else

			R = mid;

	}



	cout << L << endl;



	return 0;

}


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

#include<cstring>

#include<algorithm>

using namespace std;

const int MAXN=200005;



int N,A[MAXN],B[MAXN];

bool check(int x)

{

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

	{

		if(A[N+i]>=x&&A[N+i+1]>=x)

			return true;

		if(A[N-i]>=x&&A[N-i-1]>=x)

			return true;

		if(A[N+i]<x&&A[N+i+1]<x)

			return false;

		if(A[N-i]<x&&A[N-i-1]<x)

			return false;

	}

	if(A[1]>=x)

		return true;

	return false;

}



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;

	while(L<R)

	{

		int mid=(L+R+1)/2;

		if(check(mid))

			L=mid;

		else

			R=mid-1;

	}

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

	return 0;

}


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

using namespace std;

const int maxn = 1e6 + 7;

int n, a[maxn];

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

int M(int i, int j, int k) {return a[i] > k && a[j] > k;}

int check(int k) {

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

		if(M(n + i, n + i + 1, k) || M(n - i, n - i - 1, k)) return 0;

		if(S(n + i, n + i + 1, k) || S(n - i, n - i - 1, k)) return 1;

	}

	return S(1, 1, k);

} 

int main() {

	scanf("%d", &n);

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

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

	while(l <= r) {

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

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

		else l = mid + 1;

	}

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

	return 0;

}

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

Author:Morning_Glory

LANG:C++

Created Time:2019年07月23日 星期二 10时12分43秒

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

#include <cstdio>

#include <fstream>

#include <algorithm>

using namespace std;

const int maxn = 200005;

//{{{cin

struct IO{

	template<typename T>

	IO & operator>>(T&res){

		res=0;

		bool flag=false;

		char ch;

		while((ch=getchar())>'9'||ch<'0')	 flag|=ch=='-';

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

		if (flag)	 res=~res+1;

		return *this;

	}

}cin;

//}}}

int n,m,l,r;

int a[maxn],b[maxn],c[maxn];

bool flag=true;

bool check (int x)

{

	int tl=m,tr=m,ans=c[m];

	c[0]=c[1],c[n+1]=c[n];

	for (;tl>=1&&c[tl]!=c[tl-1]&&c[tr]!=c[tr+1];--tl,++tr)	ans^=1;

	return ans;

}

int main()

{

	cin>>m;

	n=2*m-1;

	for (int i=1;i<=n;++i)	cin>>a[i],b[i]=a[i];

	sort(b+1,b+n+1);

	l=1,r=n;

	while (l<r){

		int mid=(l+r)/2+1;

		for (int i=1;i<=n;++i)	c[i]=a[i]>=b[mid];

		if (check(mid))	l=mid;

		else	r=mid-1;

	}

	printf("%d\n",b[l]);

	return 0;

}


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

#include<cstdio>

#include<cstring>

#include<algorithm>

#define MAXN 200010

using namespace std;

int n,l,r,mid;

int a[MAXN];

inline bool check_large(int x,int y)

{

    if(a[x]>mid&&a[y]>mid) return true;

    return false;

}

inline bool check_small(int x,int y)

{

    if(a[x]<=mid&&a[y]<=mid) return true;

    return false;

}

inline bool solve()

{

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

    {

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

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

    }

    if(a[1]<=mid) return false;

    else return true;

}

int main()

{

    scanf("%d",&n);

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

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

    while(l<r)

    {

        mid=(l+r)>>1;

        if(solve()==true) l=mid+1;

        else r=mid; 

    }

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

    return 0;

}

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

Author:Morning_Glory

LANG:C++

Created Time:2019年07月23日 星期二 10时12分43秒

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

#include <cstdio>

#include <fstream>

#include <algorithm>

using namespace std;

const int maxn = 200005;

//{{{cin

struct IO{

	template<typename T>

	IO & operator>>(T&res){

		res=0;

		bool flag=false;

		char ch;

		while((ch=getchar())>'9'||ch<'0')	 flag|=ch=='-';

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

		if (flag)	 res=~res+1;

		return *this;

	}

}cin;

//}}}

int n,m,l,r;

int a[maxn],b[maxn],c[maxn];

bool flag=true;

bool check (int x)

{

	int tl=m,tr=m,ans=c[m];

	c[0]=c[1],c[n+1]=c[n];

	for (;tl>=1&&c[tl]!=c[tl-1]&&c[tr]!=c[tr+1];--tl,++tr)	ans^=1;

	return ans;

}

int main()

{

	cin>>m;

	n=2*m-1;

	for (int i=1;i<=n;++i)	cin>>a[i],b[i]=a[i];

	sort(b+1,b+n+1);

	l=1,r=n;

	while (l<r){

		int mid=(l+r)/2+1;

		for (int i=1;i<=n;++i)	c[i]=a[i]>=b[mid];

		if (check(mid))	l=mid;

		else	r=mid-1;

	}

	printf("%d\n",b[l]);

	return 0;

}


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

using namespace std;

int n,a[20000010];

bool s(int i,int j,int k)

{

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

}

bool b(int i,int j,int k)

{

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

}

bool check(int k)

{

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

	{

        if(b(n+i,n+i+1,k)||b(n-i,n-i-1,k))

			return 0;

        if(s(n+i,n+i+1,k)||s(n-i,n-i-1,k))

			return 1;

    }

    return s(1,1,k);

}

int main()

{

    scanf("%d",&n);

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

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

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

    while(l<r)

	{

        int mid=l+(r-l)/2;

        if(check(mid))

            r=mid;

        else

			l=mid+1;

    }

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

    return 0; 

}

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

Author:Morning_Glory

LANG:C++

Created Time:2019年07月23日 星期二 10时12分43秒

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

#include <cstdio>

#include <fstream>

#include <algorithm>

using namespace std;

const int maxn = 200005;

//{{{cin

struct IO{

	template<typename T>

	IO & operator>>(T&res){

		res=0;

		bool flag=false;

		char ch;

		while((ch=getchar())>'9'||ch<'0')	 flag|=ch=='-';

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

		if (flag)	 res=~res+1;

		return *this;

	}

}cin;

//}}}

int n,m,l,r;

int a[maxn],b[maxn],c[maxn];

bool flag=true;

bool check (int x)

{

	int tl=m,tr=m,ans=c[m];

	c[0]=c[1],c[n+1]=c[n];

	for (;tl>=1&&c[tl]!=c[tl-1]&&c[tr]!=c[tr+1];--tl,++tr)	ans^=1;

	return ans;

}

int main()

{

	cin>>m;

	n=2*m-1;

	for (int i=1;i<=n;++i)	cin>>a[i],b[i]=a[i];

	sort(b+1,b+n+1);

	l=1,r=n;

	while (l<r){

		int mid=(l+r)/2+1;

		for (int i=1;i<=n;++i)	c[i]=a[i]>=b[mid];

		if (check(mid))	l=mid;

		else	r=mid-1;

	}

	printf("%d\n",b[l]);

	return 0;

}


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

#include<cstdio>

using namespace std;

int n,a[200010];

bool check(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<<1;i++) scanf("%d",a+i);

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

    int ans=0;

    while(l<r){

        int mid=(l+r)/2;

        if(check(mid)){

            r=mid;ans=mid;

        }

        else l=mid+1;

    }

    cout<<ans<<endl;

}


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

Author:Morning_Glory

LANG:C++

Created Time:2019年07月23日 星期二 10时12分43秒

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

#include <cstdio>

#include <fstream>

#include <algorithm>

using namespace std;

const int maxn = 200005;

//{{{cin

struct IO{

	template<typename T>

	IO & operator>>(T&res){

		res=0;

		bool flag=false;

		char ch;

		while((ch=getchar())>'9'||ch<'0')	 flag|=ch=='-';

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

		if (flag)	 res=~res+1;

		return *this;

	}

}cin;

//}}}

int n,m,l,r;

int a[maxn],b[maxn],c[maxn];

bool flag=true;

bool check (int x)

{

	int tl=m,tr=m,ans=c[m];

	c[0]=c[1],c[n+1]=c[n];

	for (;tl>=1&&c[tl]!=c[tl-1]&&c[tr]!=c[tr+1];--tl,++tr)	ans^=1;

	return ans;

}

int main()

{

	cin>>m;

	n=2*m-1;

	for (int i=1;i<=n;++i)	cin>>a[i],b[i]=a[i];

	sort(b+1,b+n+1);

	l=1,r=n;

	while (l<r){

		int mid=(l+r)/2+1;

		for (int i=1;i<=n;++i)	c[i]=a[i]>=b[mid];

		if (check(mid))	l=mid;

		else	r=mid-1;

	}

	printf("%d\n",b[l]);

	return 0;

}


// Fastest known solution for this problem: