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

#include <cstdio>

#include <algorithm>

#define N 1000006



using namespace std;



int n;

int a[N], b[N];



bool check(int);



int main(){

	scanf("%d", &n);n = n * 2 - 1;

	int l = 999999999, r = 0, ans;

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

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

	while(l <= r){

		int mid = l + r >> 1;

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

		else r = mid - 1;	

	//	cout << ans << endl;

	}

	cout << ans << endl;

	return 0;

}



bool check(int x){

	int cnt1 = 0, cnt2 = 0;

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

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

		else b[i] = 0, ++cnt2;

	b[0] = -1;b[n + 1] = -1;

	int pos = n / 2 + 1, tmp1 = 0, tmp2 = 0;

	while(b[pos + tmp1 + 1] != b[pos + tmp1] && pos + tmp1 <= n) ++tmp1;

	while(b[pos - tmp2 - 1] != b[pos - tmp2] && pos - tmp2 >= 1) ++tmp2;

//	cout << x << endl;for(int i = 1; i <= n; ++i) cout << b[i] << ' ';cout << endl;cout << tmp1 << ' ' << tmp2 << endl;

	if(tmp1 == tmp2){

		if(pos - tmp2 == 0)

			return cnt1 > cnt2;	

		else return b[pos - tmp1];

	}

	else{

		if(tmp1 < tmp2) return b[pos + tmp1];

		else return b[pos - tmp2];

	}

}

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

*Author        :  lrj124

*Created Time  :  2019.11.07.21:12

*Mail          :  1584634848@qq.com

*Problem       :  at2165

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

#include <cstdio>

const int maxn = 200000 + 10;

int n,l,r(maxn),x[maxn];

inline bool check(int mid) {

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

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

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

	}

	return x[1] <= mid;

}

int main() {

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

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

	scanf("%d",&n);

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

	for (int mid;l < r;mid = l+r>>1,check(mid) ? r = mid : l = mid+1);

	printf("%d",l);

	return 0;

}

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

#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

int n,s;

int a[200200];

int t[200200];

bool check(int x)

{

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

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

		else t[i]=1;

	int fl=0;

	int d0=s,d1=s;

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

	{

		int c=0,dis=abs(n-i);

		for(;t[i+c+1]==t[i]&&i+c+1<=s;c++)dis=min(dis,abs(n-(i+c+1)));

		if(c>=1)

		{

			fl=1;

			if(t[i]==0)d0=min(d0,dis);

			else d1=min(d1,dis);

		}

		i=i+c;

	}

	if(!fl)return t[1];

	if(d0<d1)return 0;

	else return 1;

}

int main()

{

	scanf("%d",&n),s=n*2-1;

	int l=0,r=0,mid;

	for(int i=1;i<=s;++i)scanf("%d",&a[i]),r=max(r,a[i]);

	while(l<=r)

	{

		mid=(l+r)/2;

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

		else r=mid-1;

	}

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

	return 0;

}


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

*Author        :  lrj124

*Created Time  :  2019.11.07.21:12

*Mail          :  1584634848@qq.com

*Problem       :  at2165

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

#include <cstdio>

const int maxn = 200000 + 10;

int n,l,r(maxn),x[maxn];

inline bool check(int mid) {

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

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

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

	}

	return x[1] <= mid;

}

int main() {

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

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

	scanf("%d",&n);

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

	for (int mid;l < r;mid = l+r>>1,check(mid) ? r = mid : l = mid+1);

	printf("%d",l);

	return 0;

}

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

#include<cmath>

#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<ctime>

#include<iomanip>

#include<iostream>

#include<map>

#include<queue>

#include<set>

#include<stack>

#include<vector>

#define rep(i,x,y) for(register int i=(x);i<=(y);++i)

#define dwn(i,x,y) for(register int i=(x);i>=(y);--i)

#define view(u,k) for(int k=fir[u];~k;k=nxt[k])

#define maxn 2000007

using namespace std;

int read()

{

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

    while(!isdigit(ch)&&ch!='-')ch=getchar();

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

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

    return x*f;

}

void write(int x)

{

    if(x==0){putchar('0'),putchar('\n');return;}

    int f=0;char ch[20];

    if(x<0)putchar('-'),x=-x;

    while(x)ch[++f]=x%10+'0',x/=10;

    while(f)putchar(ch[f--]);

    putchar('\n');

    return;

}

int n,a[maxn],b[maxn],c[maxn],l=2147483647,r=0,ans=0;

int check(int x)

{

	rep(i,1,2*n-1)b[i]=(a[i]>=x)?1:0;

	c[1]=(b[1]==b[2])?1:0,c[2*n-1]=(b[2*n-1]==b[2*n-2])?1:0;

	rep(i,2,2*n-2){if(b[i]==b[i-1]||b[i]==b[i+1])c[i]=1;else c[i]=0;}

//	cout<<"b:";rep(i,1,2*n-1)cout<<b[i]<<" ";cout<<endl;

//	cout<<"c:";rep(i,1,2*n-1)cout<<c[i]<<" ";cout<<endl;

	if(c[n])return b[n];

	int L,R;L=R=n;

	while(!c[L]&&L>1)L--;while(!c[R]&&R<2*n-1)R++;

//	cout<<"L:"<<L<<" R:"<<R<<" CL:"<<c[L]<<" CR:"<<c[R]<<endl;

	if(c[L]&&c[R])

	{

		if(b[L]==b[R])return b[L];

		int pos=(n-L)<(R-n)?L:R;

		return b[pos];

	}

	else if(c[L]||c[R]){return (c[L]&b[L])|(c[R]&b[R]);}

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

}

int main()

{

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

    n=read();

    rep(i,1,2*n-1)a[i]=read(),l=min(a[i],l),r=max(a[i],r);

    while(l<=r)

    {

    	int mid=(l+r)/2,f=check(mid);

    //	cout<<"mid:"<<mid<<" f:"<<f<<endl;

    	if(f)ans=max(ans,mid),l=mid+1;

    	else r=mid-1;

    }

    write(ans);

	return 0;

}

/*

4

1 6 3 7 4 5 2

*/

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

*Author        :  lrj124

*Created Time  :  2019.11.07.21:12

*Mail          :  1584634848@qq.com

*Problem       :  at2165

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

#include <cstdio>

const int maxn = 200000 + 10;

int n,l,r(maxn),x[maxn];

inline bool check(int mid) {

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

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

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

	}

	return x[1] <= mid;

}

int main() {

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

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

	scanf("%d",&n);

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

	for (int mid;l < r;mid = l+r>>1,check(mid) ? r = mid : l = mid+1);

	printf("%d",l);

	return 0;

}

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

#include<cstring>

#include<iostream>

#include<algorithm>

#define int long long

using namespace std;

int n;

int a[1000005];

bool val[1000005];

bool check(int lim){

	int ans=-1;

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

		if(a[i]>lim)val[i]=1;

		else val[i]=0;

	}

	for(int i=n/2+2,j=n/2;i<=n;j--,i++)

	{

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

			ans=val[i];

			break;

		}

		if(val[j]==val[j+1]){

			ans=val[j];

			break;

		}

	}

	if(ans==-1) return val[1];

	else return ans;

}

signed main(){

	scanf("%lld",&n);

	n=2*n-1;

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

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

	}

	int l=1,r=n,mid;

	while(l<r){

		mid=(l+r)>>1;

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

		else r=mid;

	}

	printf("%lld",l);

}

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

*Author        :  lrj124

*Created Time  :  2019.11.07.21:12

*Mail          :  1584634848@qq.com

*Problem       :  at2165

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

#include <cstdio>

const int maxn = 200000 + 10;

int n,l,r(maxn),x[maxn];

inline bool check(int mid) {

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

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

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

	}

	return x[1] <= mid;

}

int main() {

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

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

	scanf("%d",&n);

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

	for (int mid;l < r;mid = l+r>>1,check(mid) ? r = mid : l = mid+1);

	printf("%d",l);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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

*/

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

*Author        :  lrj124

*Created Time  :  2019.11.07.21:12

*Mail          :  1584634848@qq.com

*Problem       :  at2165

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

#include <cstdio>

const int maxn = 200000 + 10;

int n,l,r(maxn),x[maxn];

inline bool check(int mid) {

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

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

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

	}

	return x[1] <= mid;

}

int main() {

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

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

	scanf("%d",&n);

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

	for (int mid;l < r;mid = l+r>>1,check(mid) ? r = mid : l = mid+1);

	printf("%d",l);

	return 0;

}

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

using namespace std;

int n;

int a[200005];

int now[200005];

//bool check(int x){

//	int k,ans[2];

//	ans[0]=0;	ans[1]=0;

//	for(k=1;k<n+n;k++)	now[k]=a[k]>=x;



//	for(k=n-2;k>0;k--)		if(now[k]==now[k+1]){ans[now[k]]=n-k;break;}

//	for(k=n+2;k<n+n;k++)	if(now[k]==now[k-1]){ans[now[k]]=k-n;break;}

//	if(ans[0]&&ans[1])	return ans[0]<ans[1];

//	if(ans[1])	return 1;

//	if(ans[0])	return 0;

//	if(ans[0]==0&&ans[1]==0)	return now[1];	

//}

inline bool check(int x){

	int k;

	for(k=1;k<n+n;k++)	now[k]=a[k]>=x;

	if(now[n]==now[n-1]||now[n]==now[n+1])	return now[n];    

    for(k=1;k<n-1;k++){

        if((now[n+k]&&now[n+k+1])||(now[n-k]&&now[n-k-1]))return 1;

        if(!(now[n+k]||now[n+k+1])||!(now[n-k]||now[n-k-1]))return 0;

    }

    return now[1];

}

int main(){

	int k;

	cin>>n;

	for(k=1;k<=n+n-1;k++)	cin>>a[k];

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

	while(l<r){

		mid=l+r+1>>1;

		if(check(mid))	l=mid;

		else			r=mid-1;

	}

	cout<<r<<endl;

	return 0;

}

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

*Author        :  lrj124

*Created Time  :  2019.11.07.21:12

*Mail          :  1584634848@qq.com

*Problem       :  at2165

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

#include <cstdio>

const int maxn = 200000 + 10;

int n,l,r(maxn),x[maxn];

inline bool check(int mid) {

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

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

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

	}

	return x[1] <= mid;

}

int main() {

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

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

	scanf("%d",&n);

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

	for (int mid;l < r;mid = l+r>>1,check(mid) ? r = mid : l = mid+1);

	printf("%d",l);

	return 0;

}

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

using namespace std;

int len;

int n;

int a[1010100];

int b[1010100];



bool check(int x){

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

    int Mid = (1+n)>>1;

    int le=Mid-1,ri=Mid+1;

    for (;le && ri<=n;le--,ri++)

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

      else if (b[ri] == b[ri-1]) return b[ri];

    return b[1];

}



int main(){

    scanf("%d",&len);

    n = 2*len-1;

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

    int l = 0,r = 1e9;

    while (l+1<r){

	    int mid = l+r>>1;

	    if (check(mid)) l = mid;else r = mid;

	}

	printf("%d",check(l)?l:r);

	return 0;

}

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

*Author        :  lrj124

*Created Time  :  2019.11.07.21:12

*Mail          :  1584634848@qq.com

*Problem       :  at2165

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

#include <cstdio>

const int maxn = 200000 + 10;

int n,l,r(maxn),x[maxn];

inline bool check(int mid) {

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

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

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

	}

	return x[1] <= mid;

}

int main() {

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

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

	scanf("%d",&n);

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

	for (int mid;l < r;mid = l+r>>1,check(mid) ? r = mid : l = mid+1);

	printf("%d",l);

	return 0;

}

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

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){

        int mid=l+r>>1;

        if(check(mid))r=mid;

        else l=mid+1;}

    printf("%d",l);

    return 0;

}

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

*Author        :  lrj124

*Created Time  :  2019.11.07.21:12

*Mail          :  1584634848@qq.com

*Problem       :  at2165

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

#include <cstdio>

const int maxn = 200000 + 10;

int n,l,r(maxn),x[maxn];

inline bool check(int mid) {

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

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

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

	}

	return x[1] <= mid;

}

int main() {

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

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

	scanf("%d",&n);

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

	for (int mid;l < r;mid = l+r>>1,check(mid) ? r = mid : l = mid+1);

	printf("%d",l);

	return 0;

}

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

#define rg register

#define LL long long 



using namespace std;



const int N=200010;

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;

}

int n,a[N];

int l,r,ans;

bool check(int mid){

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

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

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

	}

	return a[1]<=mid;

}

int main()

{

	n=read();

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

		a[i]=read();

	l=1,r=(n<<1)-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        :  lrj124

*Created Time  :  2019.11.07.21:12

*Mail          :  1584634848@qq.com

*Problem       :  at2165

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

#include <cstdio>

const int maxn = 200000 + 10;

int n,l,r(maxn),x[maxn];

inline bool check(int mid) {

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

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

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

	}

	return x[1] <= mid;

}

int main() {

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

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

	scanf("%d",&n);

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

	for (int mid;l < r;mid = l+r>>1,check(mid) ? r = mid : l = mid+1);

	printf("%d",l);

	return 0;

}

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

#define ui unsigned int

#define ll long long

#define db double

#define ld long double

#define ull unsigned long long

#define ft first

#define sd second

#define pb(a) push_back(a)

#define mp(a,b) std::make_pair(a,b)

#define ITR(a,b) for(auto a:b)

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

#define DEP(a,b,c) for(register int a=(b),a##end=(c);a>=a##end;--a)

const int MAXN=2000000+10;

int n,A[MAXN],p[MAXN];

template<typename T> inline void read(T &x)

{

	T data=0,w=1;

	char ch=0;

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

	if(ch=='-')w=-1,ch=getchar();

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

	x=data*w;

}

template<typename T> inline void write(T x,char ch='\0')

{

	if(x<0)putchar('-'),x=-x;

	if(x>9)write(x/10);

	putchar(x%10+'0');

	if(ch!='\0')putchar(ch);

}

template<typename T> inline bool chkmin(T &x,T y){return y<x?(x=y,true):false;}

template<typename T> inline bool chkmax(T &x,T y){return y>x?(x=y,true):false;}

template<typename T> inline T min(T x,T y){return x<y?x:y;}

template<typename T> inline T max(T x,T y){return x>y?x:y;}

inline bool check(int las)

{

	REP(i,1,n+n-1)p[i]=(A[i]>=las);

	if(p[n]==p[n-1])return p[n];

	if(p[n]==p[n+1])return p[n];

	REP(i,1,n-1)

	{

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

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

	}

	return p[n]^((n-1)&1);

}

int main()

{

	read(n);

	REP(i,1,n+n-1)read(A[i]);

	if(n==1)

	{

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

		return 0;

	}

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

	while(l<=r)

	{

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

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

		else r=mid-1;

	}

	write(ans,'\n');

	return 0;

}


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

#include<algorithm>

using std::sort;

const int N=300011;

int a[N];

int n,m;

struct kkll

{

    int v,id;

    bool operator < (const kkll a)const{return v<a.v;}

}kll[N];

int pll[N],mar;

int b[N];



bool ck(int x)

{

    for(int i=1;i<=m;i++) if(a[i]<=x) b[i]=0;else b[i]=1;

    int p1=n,p2=n;

    while(p1>1)

    {

        if((b[p1]&b[p1-1])||(b[p2]&b[p2+1])) return 0;

        if(!(b[p1]|b[p1-1])||!(b[p2]|b[p2+1])) return 1;

        p1--,p2++;

    }

    return b[1]^1;

}





int main()

{

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

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

    scanf("%d",&n);

    m=n*2-1;

    for(int i=1;i<=m;i++) scanf("%d",&a[i]),kll[i].v=a[i],kll[i].id=i;

    sort(kll+1,kll+1+m);

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

        if(kll[i].v!=kll[i-1].v) pll[++mar]=kll[i].v;

        a[kll[i].id]=mar;

    }

    int l=1,r=mar;

    while(l<r)

    {

        int mid=l+r>>1;

        if(ck(mid)) r=mid;

        else l=mid+1;

    }

    printf("%d\n",pll[r]);

    return 0;

}


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

using namespace std;  

int getint()

{

	char c;

	int ans=0,k=1;

	while(c=getchar(),c>'9' || c<'0') if(c=='-') k=-1;

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

	return ans*k;

}

const int N=2e6+5;

int a[N][2];

int n;

int work(int x,int y,int z)

{

	int t;

	if(x>y) t=x,x=y,y=t;

	if(y>z) t=y,y=z,z=t;

	return x>y?x:y; 

}

int main()

{

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

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

	scanf("%d",&n);

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

	bool t=0,s;

	for(int i=1;i<=r;i++) cin>>a[i][t];

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

		s=!t;

		for(int j=l+i;j<=r-i;j++)

			a[j][s]=work(a[j-1][t],a[j][t],a[j+1][t]);

		t=!t;

	}

	cout<<a[n][s]<<endl;

}*/

#include<bits/stdc++.h>

using namespace std;

int getint()

{

	char c;

	int ans=0,k=1;

	while(c=getchar(),c>'9' || c<'0') if(c=='-') k=-1;

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

	return ans*k;

}

const int N=2e6+5;

int n;

int a[N];

inline 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()

{

	scanf("%d",&n);

	int left=0,right=(n<<1)-1;

	for(int i=1;i<=right;i++) a[i]=getint();

	int mid;

	while(left<=right){

		mid=left+right>>1;

		if(check(mid)) right=mid-1;

		else left=mid+1;

	}

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

	

}

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

#include<algorithm>

using std::sort;

const int N=300011;

int a[N];

int n,m;

struct kkll

{

    int v,id;

    bool operator < (const kkll a)const{return v<a.v;}

}kll[N];

int pll[N],mar;

int b[N];



bool ck(int x)

{

    for(int i=1;i<=m;i++) if(a[i]<=x) b[i]=0;else b[i]=1;

    int p1=n,p2=n;

    while(p1>1)

    {

        if((b[p1]&b[p1-1])||(b[p2]&b[p2+1])) return 0;

        if(!(b[p1]|b[p1-1])||!(b[p2]|b[p2+1])) return 1;

        p1--,p2++;

    }

    return b[1]^1;

}





int main()

{

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

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

    scanf("%d",&n);

    m=n*2-1;

    for(int i=1;i<=m;i++) scanf("%d",&a[i]),kll[i].v=a[i],kll[i].id=i;

    sort(kll+1,kll+1+m);

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

        if(kll[i].v!=kll[i-1].v) pll[++mar]=kll[i].v;

        a[kll[i].id]=mar;

    }

    int l=1,r=mar;

    while(l<r)

    {

        int mid=l+r>>1;

        if(ck(mid)) r=mid;

        else l=mid+1;

    }

    printf("%d\n",pll[r]);

    return 0;

}


// Fastest known solution for this problem: