stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

const int MAX=4e5+10;

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

      T w=1;a=0;

	  char ch=getchar();

	  for(;!isdigit(ch);ch=getchar()){

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

	  }

	  for(;isdigit(ch);ch=getchar()){

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

	  }

	  a*=w;

}

int n;

int a[MAX];



int ck(int k){

    for(register int i=0;i<n;++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(){

		read(n);

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

		    read(a[i]);

		}

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

		while(l<r){

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

		   if(ck(mid)) r=mid;

		   else l=mid+1;

		}

		cout<<l;



}

// Faster C++ solution for the same problem (measured speedup: 5.157459074116346x):
/************************************************

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

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

using namespace std;

int n,a[200010],l=0,r=2e9,mid,b[200010],ans;



void get_b(){

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

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

		else b[i]=0;

	}

}



int work(){

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

	int g=n-1,f=n+1;

	while(g){

		if(b[g]==b[g-1]) break;

		g--;

	}

	while(f<=2*n-1){

		if(b[f]==b[f+1]) break;

		f++;

	}

	if(g==0&&f==2*n){

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

		else return b[n]^1;

	}

	if(f-n<n-g)	return b[f];

	else return b[g];

}



int main(){

	scanf("%d",&n);

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

	b[0]=-1;

	while(l<=r){

		mid=(l+r)/2;

		get_b();

		if(work()==0) 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.167244210986316x):
/************************************************

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

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

using namespace std;

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

bool check(int k){

	int i, j;

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

		b[i] = a[i] >= k;

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

		return b[n];

	i = n - 1, j = n + 1;

	while(i){

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

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

		--i, ++j;

	}

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

}

int main(){

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

	scanf("%d", &n);

	for(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(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.163673538637735x):
/************************************************

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

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

using namespace std;

int a[222222];

int n,l,r,ans,mid;

inline int big(int x,int y,int z){ return a[x]>z&&a[y]>z; }

inline int small(int x,int y,int z){ return a[x]<=z&&a[y]<=z; }

inline bool Trial(int k)

{

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

    {

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

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

    }

    return small(1,1,k);

}

int main()

{

    scanf("%d",&n);

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

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

    while(l<r)

    {

        mid=(l+r)/2;

        if(Trial(mid)) r=mid;

        else l=mid+1;

    }

    ans=r;

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

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.163681166734692x):
/************************************************

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

}
// Slower C++ solution:
/*

ID:xmydada1

LANG:C++

TASK:

*/

#include<bits/stdc++.h>

#define reg register



using namespace std;

const int N=2e5+7;

int m,n,ans=0,sum=0,p,q;

int a[N],b[N];

inline int read() {

reg int s = 0, t = 0; reg char ch = getchar();

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

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

return t ? -s : s;

}



inline void print(reg long long x) {

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

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

putchar(x % 10 + 48);

}

int main()

{

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

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

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

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

	int l=0,r=1e9+7;

	while(l<=r)

	{

		int mid=l+r>>1;

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

		{  

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

			else b[i]=0;

		}

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

		b[0]=b[1];

		p=0;

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

		{

			if(b[i-1]!=b[i]){p++;}

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

			{

				if(p%2==0)for(int j=i-p;j<=i-1;j++)b[j]=b[i];

				else 

				{

					q=p>>1;

					for(int j=i-p;j<=i-q-2;j++)b[j]=b[i-p-1];

					for(int j=i-q-1;j<=i-1;j++)b[j]=b[i];	

				}

				p=0;

			}

		}

		

		if(b[n/2+1]){l=mid+1;}

		else {r=mid-1;ans=mid;}

		memset(b,0,sizeof(b));

	}

	printf("%d",ans);



return 0;

}




// Faster C++ solution for the same problem (measured speedup: 22.575778584880602x):
/************************************************

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

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

	}

}

// Faster C++ solution for the same problem (measured speedup: 5.18572104055328x):
/************************************************

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

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

}


// Faster C++ solution for the same problem (measured speedup: 5.165707496181046x):
/************************************************

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

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

*/

// Faster C++ solution for the same problem (measured speedup: 5.126255863988877x):
/************************************************

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

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

}

// Faster C++ solution for the same problem (measured speedup: 5.161319569885696x):
/************************************************

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

}
// 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.163757698531441x):
/************************************************

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

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

}

// Faster C++ solution for the same problem (measured speedup: 5.231314884286564x):
/************************************************

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

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

}

// Faster C++ solution for the same problem (measured speedup: 5.1660007721640735x):
/************************************************

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

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

}

// Faster C++ solution for the same problem (measured speedup: 5.201781356874968x):
/************************************************

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

}