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

using namespace std;



#define maxn 100000

#define maxm 200000



int n,m;

int a[maxm+5];

int c[maxm+5];



void readin(){

    scanf("%d",&n);

    m=n*2-1;

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

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

    }

}



void Turn(int x) {

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

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

    }

}



bool judge(int x){

    Turn(x);

    int p1=0,p2=m+1;

    for(int i=n;i>=2;i--){

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

            p1=i;

            break;

        }

    }

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

        if(c[i]==c[i+1]) {

            p2=i;

            break;

        }

    }

    if(p1==0&&p2==m+1) return c[1];

    if(n-p1>p2-n) return c[p2];

    else return c[p1]; 

}



int binsearch() {

    int l=0,r=m;

    while(l+1<r) {

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

        if(judge(mid)) l=mid;

        else r=mid;

    }

    if(judge(l+1)) return l+1;

    if(!judge(l)) return l-1;

    else return l;

}



int main(){

    readin();

    int ans=binsearch();

    printf("%d",ans);

    return 0;

}

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

#include<math.h> 

using namespace std;

long long a[200001],i,n;

bool pd(long long h)

{

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

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

	for (long long i=1;i<n-1;i++)

	{

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

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

	}

	return a[1]<=h;

}

long long erfen(long long l,long long r)

{

	if (l==r) return l;

	long long mid=(l+r)/2;

	if (pd(mid)) return erfen(l,mid);

	else return erfen(mid+1,r);

}

int main()

{

	scanf("%lld",&n);

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

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

	printf("%lld",erfen(1,n*2-1));

	return 0;

}

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

#include<iostream>

#include<cstring>

#define RG register

using namespace std;

const int N=2e5+10;

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

template<typename I> inline void read(I &ot){

	I ch=getchar(), x=0, f=1;

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

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

	ot=x*f;}

template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}

inline bool chck(int x)

{

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

	for(RG int i=0;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 b[1];

}

int main()

{

//	freopen("Median Pyramid Hard.in","r",stdin);

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

	read(n); m=n*2-1;

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

	int l=1, r=m;

	while(l<=r)

	{

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

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

		else r=mid-1;

	}

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

	//fclose(stdin); fclose(stdout);

	return 0;

}

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

#include<math.h> 

using namespace std;

long long a[200001],i,n;

bool pd(long long h)

{

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

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

	for (long long i=1;i<n-1;i++)

	{

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

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

	}

	return a[1]<=h;

}

long long erfen(long long l,long long r)

{

	if (l==r) return l;

	long long mid=(l+r)/2;

	if (pd(mid)) return erfen(l,mid);

	else return erfen(mid+1,r);

}

int main()

{

	scanf("%lld",&n);

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

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

	printf("%lld",erfen(1,n*2-1));

	return 0;

}

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

#include <cstring>

#include <cmath>

#include <algorithm>

#include <iostream>

#include <cctype>

#include <utility>

#include <set>

#include <map>

#include <queue>

#include <vector>

#include <stack>

#include <cstdio>

#include <iomanip>

#include <numeric>

#include <list>

#include <bitset>

#include <ctime>

#include <deque>

#include <functional>

int a[200005],n,l,r,mid;



inline bool check(const int &k)

{

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

        return 1;

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

        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((k<a[n+i]&&k<a[n+i+1])||(k<a[n-i]&&k<a[n-i-1]))

            return 0;

    }

    return (a[1]<=k&&a[1]<=k);

}



int main()

{

    scanf("%d",&n);

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

    for (r=(n<<1)-1,mid=l+r>>1;l<r;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>

#include<math.h> 

using namespace std;

long long a[200001],i,n;

bool pd(long long h)

{

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

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

	for (long long i=1;i<n-1;i++)

	{

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

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

	}

	return a[1]<=h;

}

long long erfen(long long l,long long r)

{

	if (l==r) return l;

	long long mid=(l+r)/2;

	if (pd(mid)) return erfen(l,mid);

	else return erfen(mid+1,r);

}

int main()

{

	scanf("%lld",&n);

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

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

	printf("%lld",erfen(1,n*2-1));

	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):
#include<stdio.h>

#include<math.h> 

using namespace std;

long long a[200001],i,n;

bool pd(long long h)

{

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

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

	for (long long i=1;i<n-1;i++)

	{

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

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

	}

	return a[1]<=h;

}

long long erfen(long long l,long long r)

{

	if (l==r) return l;

	long long mid=(l+r)/2;

	if (pd(mid)) return erfen(l,mid);

	else return erfen(mid+1,r);

}

int main()

{

	scanf("%lld",&n);

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

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

	printf("%lld",erfen(1,n*2-1));

	return 0;

}

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

using namespace std;

int a[200005],n;

bool b[200005];

inline bool pd(int x)

{

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

	{

		if(a[i]>=x)

			b[i]=1;

		else

			b[i]=0;

	}

	b[0]=b[1];

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

		return b[n];

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

	}

	return b[1];

}

int main(int argc, char** argv) {

	cin >> n;

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

		cin >> a[i];

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

	while(l<=r)

	{

		int md=(l+r)/2;

		if(pd(md))

		{

			l=md+1;

			ans=max(ans,md);

		}

		else

			r=md-1;

	}

	cout << ans << endl;

	return 0;

}

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

#include<math.h> 

using namespace std;

long long a[200001],i,n;

bool pd(long long h)

{

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

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

	for (long long i=1;i<n-1;i++)

	{

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

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

	}

	return a[1]<=h;

}

long long erfen(long long l,long long r)

{

	if (l==r) return l;

	long long mid=(l+r)/2;

	if (pd(mid)) return erfen(l,mid);

	else return erfen(mid+1,r);

}

int main()

{

	scanf("%lld",&n);

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

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

	printf("%lld",erfen(1,n*2-1));

	return 0;

}

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

}

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

#include<math.h> 

using namespace std;

long long a[200001],i,n;

bool pd(long long h)

{

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

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

	for (long long i=1;i<n-1;i++)

	{

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

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

	}

	return a[1]<=h;

}

long long erfen(long long l,long long r)

{

	if (l==r) return l;

	long long mid=(l+r)/2;

	if (pd(mid)) return erfen(l,mid);

	else return erfen(mid+1,r);

}

int main()

{

	scanf("%lld",&n);

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

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

	printf("%lld",erfen(1,n*2-1));

	return 0;

}

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

using namespace std;

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

bool check(int now)

{

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

	  if (a[i]>=now) b[i]=1;else b[i]=0;

	int m=(2*n-1)/2+1;

	int k=-1,Min=1e9;

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

	  if (i!=1&&b[i]==b[i-1]&&min(abs(i-m)+1,abs(i-1-m)+1)<Min) 

	    Min=min(abs(i-m)+1,abs(i-1-m)+1),k=b[i];

	if (k==-1)

	{

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

		else return !b[m];

    }

    return k;

}

int main()

{

	scanf("%d",&n);

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

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

	int l=1,r=2e5;

	while (l+1<r)

	{

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

		if (check(mid)) l=mid;

		else r=mid-1;

    }

    if (check(r)) printf("%d\n",r);else printf("%d\n",l);

    return 0;

}

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

#include<math.h> 

using namespace std;

long long a[200001],i,n;

bool pd(long long h)

{

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

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

	for (long long i=1;i<n-1;i++)

	{

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

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

	}

	return a[1]<=h;

}

long long erfen(long long l,long long r)

{

	if (l==r) return l;

	long long mid=(l+r)/2;

	if (pd(mid)) return erfen(l,mid);

	else return erfen(mid+1,r);

}

int main()

{

	scanf("%lld",&n);

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

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

	printf("%lld",erfen(1,n*2-1));

	return 0;

}

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

using namespace std;



const int N=200010;

int n,a[N];

bool f[N];



bool check(int x)

{

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

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

	{

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

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

	}

	return f[1];

}



int main()

{

	scanf("%d",&n);

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

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

	while(l<r)

	{

		mid=(l+r)/2;

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

		else r=mid-1;

	}

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

	return 0;

}

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

int n,m,i,l,r,a[1<<21];int f(){for(i=1;i<n;i++){if(a[n+i-1]>m==a[n+i]>m)return a[n+i]>m;if(a[n-i+1]>m==a[n-i]>m)return a[n-i]>m;}return a[1]>m;}main(){scanf("%d",&n);for(i=1;i<n+n;i++)scanf("%d",a+i);for(l=1,r=n+n-1;l<=r?1:!printf("%d",l);f()?l=m+1:r=m-1)m=(l+r)/2;}

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

#include<cstdio>

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

}

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

int n,m,i,l,r,a[1<<21];int f(){for(i=1;i<n;i++){if(a[n+i-1]>m==a[n+i]>m)return a[n+i]>m;if(a[n-i+1]>m==a[n-i]>m)return a[n-i]>m;}return a[1]>m;}main(){scanf("%d",&n);for(i=1;i<n+n;i++)scanf("%d",a+i);for(l=1,r=n+n-1;l<=r?1:!printf("%d",l);f()?l=m+1:r=m-1)m=(l+r)/2;}

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

#include<cstdio>

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

}

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

int n,m,i,l,r,a[1<<21];int f(){for(i=1;i<n;i++){if(a[n+i-1]>m==a[n+i]>m)return a[n+i]>m;if(a[n-i+1]>m==a[n-i]>m)return a[n-i]>m;}return a[1]>m;}main(){scanf("%d",&n);for(i=1;i<n+n;i++)scanf("%d",a+i);for(l=1,r=n+n-1;l<=r?1:!printf("%d",l);f()?l=m+1:r=m-1)m=(l+r)/2;}

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

using namespace std;



int n,a[200010];



template <typename T> inline void read(T &a) {

	a = 0;char c = getchar();int f = 1;

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

	while(isdigit(c)) {a = (a<<3) + (a<<1) + (c ^ 48); c = getchar();}

	a*=f;

}



inline bool check (int k) {

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

		return true;

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

		return false;

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

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

			return false;

	}

	return a[1] <= k;

}



int main () {

	read(n);

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

		read(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;

	}

	cout<<l<<endl;

	return 0;

}

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

int n,m,i,l,r,a[1<<21];int f(){for(i=1;i<n;i++){if(a[n+i-1]>m==a[n+i]>m)return a[n+i]>m;if(a[n-i+1]>m==a[n-i]>m)return a[n-i]>m;}return a[1]>m;}main(){scanf("%d",&n);for(i=1;i<n+n;i++)scanf("%d",a+i);for(l=1,r=n+n-1;l<=r?1:!printf("%d",l);f()?l=m+1:r=m-1)m=(l+r)/2;}

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

#define N 500005

using namespace std;



inline void rd(int &x){

	x=0;char ch=0;int w=0;

	while(!isdigit(ch)) ch=getchar(),w|=ch=='-';

	while( isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();

	x=w?-x:x;

}



int l,r;

int n,m;

int a[N],b[N];



bool ok(int x){

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

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

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

		if((b[n-i] and b[n-i-1]) or (b[n+i] and b[n+i+1])) return 1;

		if((!b[n-i] and !b[n-i-1]) or (!b[n+i] and !b[n+i+1])) return 0;

	}

	return b[1];

}

signed main(){

	rd(n);m=n*2-1;l=1;r=m+1;

	for(int i=1;i<=m;i++) rd(a[i]);

	while(l<r){

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

		ok(mid) ? l=mid+1 : r=mid;

	}

	cout<<l-1<<endl;

}


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

int n,m,i,l,r,a[1<<21];int f(){for(i=1;i<n;i++){if(a[n+i-1]>m==a[n+i]>m)return a[n+i]>m;if(a[n-i+1]>m==a[n-i]>m)return a[n-i]>m;}return a[1]>m;}main(){scanf("%d",&n);for(i=1;i<n+n;i++)scanf("%d",a+i);for(l=1,r=n+n-1;l<=r?1:!printf("%d",l);f()?l=m+1:r=m-1)m=(l+r)/2;}

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



using namespace std; 

int N,a[200001];

bool b[200001];

bool check(int x)

{ 	

		for(int i=1;i<=(N<<1)-1;++i)b[i]=(a[i]<=x); 

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

} 



int main(){ 

	 scanf("%d",&N);

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

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

		int l=1,r=(N<<1)-1,m;

	while(l<r)

	   if(check(m=l+r>>1))r=m;

	   else 

	   	l=m+1; 

	   	printf("%d",l); 

}


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

int n,m,i,l,r,a[1<<21];int f(){for(i=1;i<n;i++){if(a[n+i-1]>m==a[n+i]>m)return a[n+i]>m;if(a[n-i+1]>m==a[n-i]>m)return a[n-i]>m;}return a[1]>m;}main(){scanf("%d",&n);for(i=1;i<n+n;i++)scanf("%d",a+i);for(l=1,r=n+n-1;l<=r?1:!printf("%d",l);f()?l=m+1:r=m-1)m=(l+r)/2;}

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

#include<cmath>

#include<stack>

#include<queue>

#include<cstdio>

#include<vector>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

typedef long long ll;

template<class Read>void in(Read &x){

    x=0;

    int f=0;

    char ch=getchar();

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

        f|=(ch=='-');

        ch=getchar();

    }

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

        x=(x<<1)+(x<<3)+(ch^48);

        ch=getchar();

    }

    x=f?-x:x;

    return;

}

int n,a[200005],l=1,r=(n*2-1),ans;

bool check(int x){

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

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

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

	}

	if(a[1]>x)return 0;

	else return 1;

}

int main(){

	in(n);

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

	r=n*2-1;

	while(l<=r){

		int mid=(l+r)/2;

		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<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 reg register



const int maxn = 2e5 + 5; //!



int N;

int A[maxn];

int B[maxn];



bool chk(int x){

        for(reg int i = 1; i <= 2*N-1; i ++) B[i] = (A[i]>x);

        for(reg int d = 1; d < N; d ++)

                if((B[N+d-1]&&B[N+d]) || (B[N-d+1]&&B[N-d])) return 1;

                else if(((!B[N+d-1])&&(!B[N+d])) || ((!B[N-d+1])&&(!B[N-d]))) return 0;

        return B[1];

}



int main(){

        scanf("%d", &N);

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

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

        while(l < r){

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

                int mid = l+r >> 1;

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

                else r = mid;

        }

        printf("%d\n", 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 <algorithm>

#include <cstdio>

#include <iostream>

using namespace std;

int read();



int N, x[200005], st[200005], a[200005];

int work() {

    int m = N / 2 + 1, res = a[m], l = m, r = m;

    a[0] = a[1], a[N + 1] = a[N];

    for (; l >= 1 && a[l] != a[l - 1] && a[r] != a[r + 1]; --l, ++r) res ^= 1;

    return res;

}



int main() {



    N = read() * 2 - 1;

    for (int i = 1; i <= N; ++i) st[i] = x[i] = read();

    sort(st + 1, st + 1 + N);

    int l = 1, r = N, res = r;

    while (l <= r) {

        int mid = l + r >> 1;

        for (int i = 1; i <= N; ++i) a[i] = x[i] > st[mid];

        if (!work())

            r = mid - 1, res = mid;

        else

            l = mid + 1;

    }

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

    return 0;

}

int read() {

    int x = 0, f = 1;

    char c = getchar();

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

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

    return x * f;

}

// 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 a[400005],n;

int small(int i,int k)

{

	return a[i+1]<=k&&a[i]<=k;//  

}

int big(int i,int k)

{

	return a[i+1]>k&&a[i]>k;

}

int check(int k)

{

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

	{

		if(small(n+i,k)==1||small(n-i-1,k)==1)

		{

			return 1;

		}

		if(big(n+i,k)==1||big(n-i-1,k)==1)

		{

			return 0;

		}

	}

	if(a[1]<=k)

	{

		return 1;

	}else

	{

		return 0;

	}

}

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;

		if(check(mid)==1)

		{

			r=mid;

		}else

		{

			l=mid+1;

		}

	}

	cout<<r;

	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: