stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

#include<cstdio>

using namespace std;

int n,a[200005],l=0x7fffffff,r;

void init()

{

	cin>>n;

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

	{

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

		l=min(l,a[i]);

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

	}

}

int c[200005];

bool check(int x)

{

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

	{

		if(a[i]>=x) c[i]=1;

		else c[i]=0;

	}

	int t=0;

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

	if(c[n-j+1]==c[n-j]||c[n+j]==c[n+j-1])

	{t=j;break;}

	if(t==0)

	{

		c[n]=c[n]^((n-1)&1);

		return c[n];

	}

	if(c[n-t+1]==c[n-t])

	return c[n-t+1];

	else

	return c[n+t-1];

}

void play()

{

	int mid;

	while(l<r)

	{

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

		 if(check(mid)) l=mid;

		 else r=mid-1;

	}

	cout<<l<<endl;

}

int main()

{

	init();

	play();

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.245290234120842x):
#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;

	

}
// Slower C++ solution:
#include<bits/stdc++.h>

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

#define Rof(i,a,b) for(int i=(a);i>=(b);--i)

#define S(i) ((int)(A[i]>=Pos))

#define LL long long

using namespace std;

int N,A[300001],INF=10000000;

bool Check(int Pos){

	int m[2];

	m[0]=m[1]=INF;

//	For(i,1,2*N-1) printf("%d ",S(i));puts("");

	For(i,N,2*N-2)

		if(S(i)==S(i+1)){

			m[S(i)]=min(m[S(i)],i-N);

//			cout<<'-'<<i<<' '<<S(i)<<endl;

			break;

		}

	Rof(i,N,2)

		if(S(i)==S(i-1)){

			m[S(i)]=min(m[S(i)],N-i);

			break;

		}

//	cout<<m[1]<<' '<<m[0]<<endl;

	if(m[0]==INF&&m[1]==INF)return (S(N)^(N&1)^1);

	if(m[1]<m[0])return 1;

	return 0;

}

int main(){

	scanf("%d",&N);For(i,1,2*N-1) scanf("%d",&A[i]);

	int l=1,r=2*N-1,Mid,Ans;

//	cout<<Check(4);



	while(l<=r){

		Mid=l+r>>1;

		if(Check(Mid))

			Ans=Mid,l=Mid+1;

		else

			r=Mid-1;

	}



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



	return 0;

}

/*

3

1 5 2 4 3

*/

// Faster C++ solution for the same problem (measured speedup: 5.165156066639037x):
#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;

	

}
// Slower C++ solution:
#include <iostream>

using namespace std;

int a[200005],n;

bool b[200005];

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

	for(int 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(int i=1;i<=n*2-1;i++)cin>>a[i];

int l=1,r=n*2,A=0,md;

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

// Faster C++ solution for the same problem (measured speedup: 5.225223983646835x):
#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;

	

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define rg register int

#define il inline

#define mid ((l+r)>>1)

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

#define sma(i,j) (a[n+i]<=x&&a[n+i+j]<=x)

#define el else if

using namespace std;

il long long read(){

    register long long x=0,f=1;

    register char ch=getchar();

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

        if(ch=='-') f=-1;

        ch=getchar();

    }

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

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

        ch=getchar();

    }

    return x*f;

}

const int N=1000007;

typedef long long ll;

ll n,m,w,a[N];

bool chk(int x){

	for(rg i=0;i<n;++i){

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

		el(sma(i,1)||sma(-i,-1)) return true;

	}

	return a[1]<=x;

}

int main()

{

	n=read();

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

		a[i]=read();

	}

	ll l=1,r=n<<1;--r;

	while(l<r){//r为答案 

		if(chk(mid)) r=mid;

		else l=mid+1;

	}

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.1496816539689645x):
#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;

	

}
// Slower C++ solution:
#include <iostream>

using namespace std;

int a[200005],n,b[200005],i;

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];

int l=1,r=n*2,A=0,M;

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

// Faster C++ solution for the same problem (measured speedup: 5.224424277660469x):
#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;

	

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int N=500005;

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

int work(int x)

{

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

	{

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

		else b[i]=0;

	}

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

	}

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

}

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,ans=0;

	while(l<=r)

	{

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

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

		else r=mid-1;

	}

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.167417679326016x):
#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;

	

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int maxn=200003;

int n,a[maxn];

bool b[maxn];

#define v(i) (a[i]>=x)

bool check(int x){

	int mid=(n+1)>>1,ans=maxn,ret=-1;

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

		for(;j<=n&&v(i)==v(j);j++);

		if(i+1==j)continue;

		int tmp=min(abs(mid-i),abs(j-1-mid));

		if(tmp<ans)ans=tmp,ret=v(i);

	}

	return ~ret?ret:v(1);

}

int main(){

	scanf("%d",&n);

	n=(n<<1)-1;

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

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

	while(l<=r){

		mid=(l+r)>>1;

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

		else r=mid-1;

	}

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.168335217457128x):
#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;

	

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int maxn=2e5+10;

int a[maxn],n,m;

bool check(int mid)

{

	int mi=1e9,j=-1;

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

	{

		int a1=a[i]>=mid,a2=a[i+1]>=mid;

		if(a1==a2)

		{

			mi=m-i-1;

			j=a1;

			break;

		}

	}

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

	{

		int a1=a[i]>=mid,a2=a[i+1]>=mid;

		if(a1==a2)

		{

			if(mi>i-m)

			{

				mi=i-m;

				j=a1;

			}

			break;

		}

	}

	if(j==-1)return a[1]>=mid;

	else return j;

}

int main()

{

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

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

	int l=2e9,r=0;

	scanf("%d",&m);

	n=m*2-1;

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

		scanf("%d",a+i),l=min(l,a[i]),r=max(a[i],r);

	while(l<=r)

	{

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

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

		else r=mid-1;

	}

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.207150784795438x):
#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;

	

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.149080863519531x):
#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;

	

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.150077492640583x):
#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;

	

}
// Slower C++ solution:
// 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 

*/

// Faster C++ solution for the same problem (measured speedup: 5.149721369187089x):
#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;

	

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.17085173956345x):
#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;

	

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.204132959525219x):
#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;

	

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.223590110494496x):
#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;

	

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.200831938005787x):
#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;

}
// Slower C++ solution:
#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. 

// Faster C++ solution for the same problem (measured speedup: 5.167635264784283x):
#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;

}