#include<bits/stdc++.h>
using namespace std;

#define llong long long int
#define ll long long int
#define mod 1000000007

ll oddinput[4000007];
ll oddsegTree[4000007];
ll eveninput[4000007];
ll evensegTree[4000007];

void constructTree(ll *segTree, ll *input, llong l, llong r, llong pos)
{
	if(l==r)
	{
		segTree[pos] = input[l];
		return;
	}

	llong mid = (l+r)/2;

	constructTree(segTree, input, l, mid, pos*2);
	constructTree(segTree, input, mid+1, r, pos*2+1);

	segTree[pos] = max(segTree[pos*2], segTree[pos*2+1]);
}

void Update(ll *segTree, llong l, llong r, llong pos, llong val, llong valpos)
{
	if(valpos < l || valpos > r)
		return;

	if(l==r)
	{
		segTree[pos] = val;
		return;
	}

	llong mid = (l+r)/2;

	Update(segTree, l, mid, pos*2, val, valpos);
	Update(segTree, mid+1, r, pos*2+1, val, valpos);

	segTree[pos] = max(segTree[pos*2], segTree[pos*2+1]);
}

ll query(ll *segTree, llong ql, llong qr, llong l, llong r, llong pos)
{
	if(l > qr || r < ql)
		return 0;

	if(l>=ql && r<=qr)
		return segTree[pos];

	llong mid = (l+r)/2;

	return 	max( query(segTree, ql, qr, l, mid, pos*2),
			query(segTree, ql, qr, mid+1, r, pos*2+1) );
}

int main()
{
	llong n;
	cin>>n;

	llong a[n+5];

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

	if( n==1 )
	{
		cout<<a[1]<<" \n";
		return 0;
	}

	for( int i=1;i<=n-1;i++ )
		eveninput[i] = max(a[i], a[i+1]);
	constructTree( evensegTree, eveninput, 1, n-1, 1 );

	for( int i=1;i<=n-2;i++ )
		oddinput[i] = min(a[i+1], max(a[i], a[i+2]));
	constructTree( oddsegTree, oddinput, 1, n-2, 1 );

//	cout<<"Even seg tree : \n";
//	for( int i=1;i<=n-1;i++ )
//		cout<<eveninput[i]<<" ";
//	cout<<endl;
//
//	cout<<"Odd seg tree : \n";
//	for( int i=1;i<=n-2;i++ )
//		cout<<oddinput[i]<<" ";
//	cout<<endl;

	llong ans[n+5];
	ans[n-1] = a[1];
	for( int i=1;i<=n;i++ )
		ans[n-1] = max( ans[n-1], a[i] );

	for( int i=0;i<n-1;i++ )
	{
		if( (n-i)%2==0 )
		{
			llong l = (n-i)/2;
			llong r = l+i;

			ans[i] = query( evensegTree, l, r, 1, n-1, 1 );
		}
		else
		{
			llong l = (n-i)/2;
			llong r = l+i;

			ans[i] = query( oddsegTree, l, r, 1, n-2, 1 );
		}
	}

	for( int i=0; i<n; i++ )
		cout<<ans[i]<<" ";
	cout<<endl;

	return 0;
}


#include<iostream>
using namespace std;
int arr[300005],t[1000005],t2[1000005],off=1;
void update(int x,int v) {
	t[off+x]=v;
	for(int i=(off+x)/2;i>=1;i/=2) {
		t[i]=max(t[i*2],t[i*2+1]);
	}
}
void update2(int x,int v) {
	t2[off+x]=v;
	for(int i=(off+x)/2;i>=1;i/=2) {
		t2[i]=max(t2[i*2],t2[i*2+1]);
	}
}
int query(int x,int lo,int hi,int l,int r) {
	if(lo>r or hi<l) return 0;
	if(lo>=l && hi<=r) return t[x];
	return max(query(x*2,lo,(lo+hi)/2,l,r),query(x*2+1,(lo+hi)/2+1,hi,l,r));
}
int query2(int x,int lo,int hi,int l,int r) {
	if(lo>r or hi<l) return 0;
	if(lo>=l && hi<=r) return t2[x];
	return max(query2(x*2,lo,(lo+hi)/2,l,r),query2(x*2+1,(lo+hi)/2+1,hi,l,r));
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	while(off<n) off*=2;
	for(int i=0;i<n;i++) {
		cin >> arr[i];
		update(i,arr[i]);
	}
	for(int i=1;i<n;i++) {
		update2(i,min(arr[i],arr[i-1]));
		update2(i-1,min(arr[i],arr[i-1]));
	}
	for(int i=0;i<n;i++) {
		if((n-i)%2==0 or i==n-1) cout << query(1,0,off-1,(n-i-1)/2,n-1-(n-i-1)/2) << " ";
		else cout << query2(1,0,off-1,(n-i-1)/2,n-1-(n-i-1)/2) << " ";
	}
	return 0;
}


#include<iostream>
using namespace std;
int arr[300005],t[1000005],off=1;
void update(int x,int v) {
	t[off+x]=v;
	for(int i=(off+x)/2;i>=1;i/=2) {
		t[i]=max(t[i*2],t[i*2+1]);
	}
}
int query(int x,int lo,int hi,int l,int r) {
	if(lo>r or hi<l) return 0;
	if(lo>=l && hi<=r) return t[x];
	return max(query(x*2,lo,(lo+hi)/2,l,r),query(x*2+1,(lo+hi)/2+1,hi,l,r));
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	while(off<n) off*=2;
	for(int i=0;i<n;i++) {
		cin >> arr[i];
		update(i,arr[i]);
	}
	for(int i=0;i<n;i++) {
		cout << query(1,0,off-1,(n-i-1)/2,n-1-(n-i-1)/2) << " ";
	}
	return 0;
}


#include<iostream>
using namespace std;
int arr[300005],t[1000005],t2[1000005],off=1;
void update(int x,int v) {
	t[off+x]=v;
	for(int i=(off+x)/2;i>=1;i/=2) {
		t[i]=max(t[i*2],t[i*2+1]);
	}
}
void update2(int x,int v) {
	t2[off+x]=v;
	for(int i=(off+x)/2;i>=1;i/=2) {
		t2[i]=max(t2[i*2],t2[i*2+1]);
	}
}
int query(int x,int lo,int hi,int l,int r) {
	if(lo>r or hi<l) return 0;
	if(lo>=l && hi<=r) return t[x];
	return max(query(x*2,lo,(lo+hi)/2,l,r),query(x*2+1,(lo+hi)/2+1,hi,l,r));
}
int query2(int x,int lo,int hi,int l,int r) {
	if(lo>r or hi<l) return 0;
	if(lo>=l && hi<=r) return t2[x];
	return max(query2(x*2,lo,(lo+hi)/2,l,r),query2(x*2+1,(lo+hi)/2+1,hi,l,r));
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	while(off<n) off*=2;
	for(int i=0;i<n;i++) {
		cin >> arr[i];
		update(i,arr[i]);
	}
	for(int i=1;i<n-1;i++) {
		if(arr[i]<=arr[i-1] or arr[i]<=arr[i+1]) update2(i,arr[i]);
	}
	for(int i=0;i<n;i++) {
		if((n-i)%2==0 or i==n-1) cout << query(1,0,off-1,(n-i-1)/2,n-1-(n-i-1)/2) << " ";
		else cout << query2(1,0,off-1,(n-i-1)/2,n-1-(n-i-1)/2) << " ";
	}
	return 0;
}


#include<iostream>
using namespace std;
int arr[300005],t[1000005],t2[1000005],off=1;
void update(int x,int v) {
	t[off+x]=v;
	for(int i=(off+x)/2;i>=1;i/=2) {
		t[i]=max(t[i*2],t[i*2+1]);
	}
}
void update2(int x,int v) {
	t2[off+x]=v;
	for(int i=(off+x)/2;i>=1;i/=2) {
		t2[i]=max(t2[i*2],t2[i*2+1]);
	}
}
int query(int x,int lo,int hi,int l,int r) {
	if(lo>r or hi<l) return 0;
	if(lo>=l && hi<=r) return t[x];
	return max(query(x*2,lo,(lo+hi)/2,l,r),query(x*2+1,(lo+hi)/2+1,hi,l,r));
}
int query2(int x,int lo,int hi,int l,int r) {
	if(lo>r or hi<l) return 0;
	if(lo>=l && hi<=r) return t2[x];
	return max(query2(x*2,lo,(lo+hi)/2,l,r),query2(x*2+1,(lo+hi)/2+1,hi,l,r));
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	while(off<n) off*=2;
	for(int i=0;i<n;i++) {
		cin >> arr[i];
		update(i,arr[i]);
	}
	for(int i=1;i<n-1;i++) {
		update2(i,max(min(arr[i],arr[i-1]),min(arr[i],arr[i+1])));
	}
	if(n>1) update2(0,min(arr[0],arr[1]));
	if(n>1) update2(n-1,min(arr[n-1],arr[n-2]));
	for(int i=0;i<n;i++) {
		if((n-i)%2==0 or i==n-1) cout << query(1,0,off-1,(n-i-1)/2,n-1-(n-i-1)/2) << " ";
		else cout << query2(1,0,off-1,(n-i-1)/2,n-1-(n-i-1)/2) << " ";
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define _ << " " <<

typedef long long ll;
typedef pair<int, int> P;
#define X first
#define Y second

const int MAX = 1<<19, TOUR = MAX;

int p[MAX], f[MAX], g[MAX]; //f ako prvi igra onaj koji zeli veci, g inace
int parni_f[MAX], parni_g[MAX];
int n;

int t_f[2*TOUR], t_parni[2*TOUR];

void init() {
  REP(i, n) {
    t_f[i+TOUR] = f[i];
    t_parni[i+TOUR] = parni_f[i];
  }

  for (int i=TOUR-1; i; i--) {
    t_f[i] = max(t_f[2*i], t_f[2*i+1]);
    t_parni[i] = max(t_parni[2*i], t_parni[2*i+1]);
  }
}

int vrati(int t[MAX], int pos, int lo, int hi, int begin, int end) {
  if (lo >= end || hi <= begin) return 0;
  if (lo >= begin && hi <= end) return t[pos];
  return max(vrati(t, 2*pos+0, lo, (lo+hi)/2, begin, end),
	     vrati(t, 2*pos+1, (lo+hi)/2, hi, begin, end));
}

int main()
{
  scanf("%d", &n);
  REP(i, n) scanf("%d", &p[i]);

  REP(i, n) {
    if (!i || i + 1 == n) f[i] = g[i] = p[i];
    else {
      if (p[i] >= max(p[i-1], p[i+1])) f[i] = max(p[i-1], p[i+1]);
      else f[i] = p[i];

      if (p[i] <= min(p[i-1], p[i+1])) g[i] = min(p[i-1], p[i+1]);
      else g[i] = p[i];
    }
  }

  REP(i, n) {
    parni_f[i] = max(g[i], g[i+1]);
    parni_g[i] = min(f[i], f[i+1]);
  }

  init();

  REP(k, n) {
    int parnost = (n - k) % 2, rje;
    int l = (0 + (n - 1 - k)) / 2;
    int r = (k + n - 1) / 2;

    if (parnost)
      rje = vrati(t_f, 1, 0, TOUR, l, r + 1);
    else
      rje = vrati(t_parni, 1, 0, TOUR, l, r + 1);

    printf("%d ", rje);
  }
  printf("\n");

  return 0;
}


#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define _ << " " <<

typedef long long ll;
typedef pair<int, int> P;
#define X first
#define Y second

const int MAX = 1<<19, TOUR = MAX;

int p[MAX], f[MAX], g[MAX]; //f ako prvi igra onaj koji zeli veci, g inace
int parni_f[MAX], parni_g[MAX];
int n;

int t_f[2*TOUR], t_parni[2*TOUR];

void init() {
  REP(i, n) {
    t_f[i+TOUR] = f[i];
    t_parni[i+TOUR] = parni_f[i];
  }

  for (int i=TOUR-1; i; i--) {
    t_f[i] = max(t_f[2*i], t_f[2*i+1]);
    t_parni[i] = max(t_parni[2*i], t_parni[2*i+1]);
  }
}

int vrati(int t[MAX], int pos, int lo, int hi, int begin, int end) {
  if (lo >= end || hi <= begin) return 0;
  if (lo >= begin && hi <= end) return t[pos];
  return max(vrati(t, 2*pos+0, lo, (lo+hi)/2, begin, end),
	     vrati(t, 2*pos+1, (lo+hi)/2, hi, begin, end));
}

int main()
{
  scanf("%d", &n);
  REP(i, n) scanf("%d", &p[i]);

  REP(i, n) {
    if (!i || i + 1 == n) f[i] = g[i] = p[i];
    else {
      if (p[i] >= max(p[i-1], p[i+1])) f[i] = max(p[i-1], p[i+1]);
      else f[i] = p[i];

      if (p[i] <= min(p[i-1], p[i+1])) g[i] = min(p[i-1], p[i+1]);
      else g[i] = p[i];
    }
  }

  REP(i, n) {
    parni_f[i] = max(g[i], g[i+1]);
    parni_g[i] = min(f[i], f[i+1]);
  }

  init();

  int mx = 0;
  REP(i, n) mx = max(mx, p[i]);

  REP(k, n) {
    int parnost = (n - k) % 2, rje;
    int l = (0 + (n - 1 - k)) / 2;
    int r = (k + n - 1) / 2;

    if (n - k <= 2) rje = mx;
    else {
      if (parnost)
	rje = vrati(t_f, 1, 0, TOUR, l, r + 1);
      else
	rje = vrati(t_parni, 1, 0, TOUR, l, r + 1);
    }

    printf("%d ", rje);
  }
  printf("\n");

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pii;

const int N = 3e5 + 10;
int n, m, tmp, ans, k, khas1, khas2, khas3;
int a[N], b[N], dp[N];

void read_input() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		khas1 = max(khas1, a[i]);
	}
	if (n == 1) {
		cout << a[1];
		return;
	}
	if (n == 2) {
		cout << max(a[1], a[2]);
		return;
	}
	for (int i = 1; i < n; i++) {
		int mx = max(a[i], a[i + 1]);
		int x = i - 1;
		int y = n - (i + 1);
		dp[abs(x - y)] = max(mx, dp[abs(x - y)]);
	}
	for (int i = 1; i < n - 1; i++) {
		int mn = min(a[i + 1], max(a[i], a[i + 2]));
		int x = i - 1;
		int y = n - (i + 2);
		dp[abs(x - y)] = max(dp[abs(x - y)], mn);
	}
	for (int i = 2; i < n - 1; i++) {
		dp[i] = max(dp[i], dp[i - 2]);
	}
	for (int i = 0; i < n - 1; i++) {
		cout << dp[i] << ' ';
	}
	cout << khas1;
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	read_input();

	return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;

const int MAX_N = 300005, base = 300007, MOD = 2147483647;
typedef long long LL;
typedef pair<int, int> pii;

class Edge {
public:
  int nxt, to;
} e[MAX_N << 2];

int head1[MAX_N], head2[MAX_N];
void addedge(int u, int v, int *head) {
  static int cnt = 0;
  e[++cnt] = (Edge){head[u], v}, head[u] = cnt;
  e[++cnt] = (Edge){head[v], u}, head[v] = cnt;
}

int N, M, id[MAX_N], val[MAX_N], deg[MAX_N];
LL mul[MAX_N], HASH[MAX_N], cp[MAX_N];

bool flag;
void dfs(int u, int v) {
  for (int i = head2[u]; i; i = e[i].nxt)
    if (e[i].to != v) {
      if (val[e[i].to]) {
	flag = 0;
	return;
      }

      val[e[i].to] = val[u] + 1;
      dfs(e[i].to, u);
    }
}

map<pii, bool> vis;

int main() {
#ifndef ONLINE_JUDGE
  freopen("d.in", "r", stdin);
#endif

  scanf("%d%d", &N, &M);

  mul[0] = 1;
  for (int i = 1; i <= N; ++i) mul[i] = mul[i - 1] * base % MOD;

  for (int i = 1, u, v; i <= M; ++i) {
    scanf("%d%d", &u, &v);
    addedge(u, v, head1);
    HASH[u] = (HASH[u] + mul[v]) % MOD, HASH[v] = (HASH[v] + mul[u]) % MOD;
  }

  int tot = 0;
  for (int i = 1; i <= N; ++i) HASH[i] = (HASH[i] + mul[i]) % MOD, cp[++tot] = HASH[i];

  sort(cp + 1, cp + tot + 1);
  tot = unique(cp + 1, cp + tot + 1) - cp - 1;

  for (int i = 1; i <= N; ++i) id[i] = lower_bound(cp + 1, cp + tot + 1, HASH[i]) - cp;

  for (int i = 1; i <= N; ++i)
    for (int j = head1[i]; j; j = e[j].nxt)
      if (e[j].to > i && id[e[j].to] != id[i] && !vis[make_pair(id[e[j].to], id[i])]) {
	addedge(id[i], id[e[j].to], head2);
	deg[id[i]]++, deg[id[e[j].to]]++;
	vis[make_pair(id[e[j].to], id[i])] = 1;
      }

  for (int i = 1; i <= tot; ++i)
    if (deg[i] >= 3) {
      puts("NO");
      return 0;
    }

  for (int i = 1; i <= tot; ++i)
    if (deg[i] <= 1) {
      flag = 1, val[i] = 1, dfs(i, 0);
      break;
    }

  if (!flag && N > 2) {
    puts("NO");
    return 0;
  }

  puts("YES");
  for (int i = 1; i <= N; ++i)
    printf("%d ", val[id[i]]);
  puts("");

  return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAX_N = 300005;

int N, A[MAX_N];

class Sparse_Table {
public:
  int val[MAX_N], f[MAX_N][20], bin[MAX_N];
  void init() {
    for (int i = 1; i <= N; ++i) f[i][0] = val[i];

    for (int i = 1; i < 20; ++i)
      for (int j = 1; j <= N; ++j) {
	f[j][i] = f[j][i - 1];
	if (j + (1 << i - 1) <= N)
	  f[j][i] = max(f[j][i], f[j + (1 << i - 1)][i - 1]);
      }
    bin[1] = 0;
    for (int i = 1; i < 20; ++i) bin[1 << i] = i;
    for (int i = 2; i <= N; ++i)
      if (!bin[i]) bin[i] = bin[i - 1];
  }
  int query(int l, int r) {
    int len = r - l + 1, x = bin[len];
    return max(f[l][x], f[r - (1 << x) + 1][x]);
  }
} even, odd;

int res[MAX_N];

int main() {
#ifndef ONLINE_JUDGE
  freopen("e.in", "r", stdin);
#endif

  scanf("%d", &N);
  for (int i = 1; i <= N; ++i)
    scanf("%d", &A[i]), res[N - 1] = max(res[N - 1], A[i]);
  for (int i = 1; i <= N; ++i) {
    even.val[i] = max(A[i], A[i + 1]);
    odd.val[i] = min(A[i], max(A[i - 1], A[i + 1]));
  }

  even.init(), odd.init();

  for (int i = 0; i < N - 1; ++i) {
    int len = N - i;
    if (len & 1) {
      res[i] = odd.query((len + 1) / 2, N - len / 2);
    } else {
      res[i] = even.query(len / 2, N - len / 2);
    }
  }

  for (int i = 0; i < N; ++i)
    printf("%d ", res[i]);
  puts("");
  return 0;
}


#include <iostream>

using namespace std;

int niz[300010];

int main (){

    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> niz[i];
    }

    if (n == 1){
        cout << niz[0] << "\n";
        return 0;
    }

    if (n%2 == 0){

        int x = n/2 - 1, y = x;
        int par = max(niz[x], niz[x+1]);
        int nep = min(niz[x], niz[x+1]);

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

            if (i%2 == 0){
                int a = max(niz[x], niz[x+1]), b = max(niz[y], niz[y+1]);
                par = max(par, max(a, b));
                cout << par << " ";
            }
            if (i%2 == 1){
                x--; y++;
                int a = min(niz[x], niz[x+1]), b = min(niz[y], niz[y+1]);
                nep = max(nep, max(a, b));
                cout << nep << " ";
            }

        }
        cout << par << "\n";
    }
    if (n%2 == 1){

        int x = (n-1) / 2, y = x-1;
        int nep = 0, par = 0;

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

            if (i%2 == 0){
                x--; y++;
                int a = min(niz[x], niz[x+1]), b = min(niz[y], niz[y+1]);
                nep = max(nep, max(a, b));
                cout << nep << " ";

            }
            if (i%2 == 1){
                int a = max(niz[x], niz[x+1]), b = max(niz[y], niz[y+1]);
                par = max(par, max(a, b));
                cout << par << " ";
            }

        }
        cout << par << "\n";
    }

    return 0;
}


#include <iostream>

using namespace std;

int niz[300010];

int main (){

    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> niz[i];
    }

    if (n%2 == 0){

        int x = n/2 - 1, y = x;
        int par = max(niz[x], niz[x+1]);
        int nep = min(niz[x], niz[x+1]);

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

            if (i%2 == 0){
                int a = max(niz[x], niz[x+1]), b = max(niz[y], niz[y+1]);
                par = max(par, max(a, b));
                cout << par << " ";
            }
            if (i%2 == 1){
                x--; y++;
                int a = min(niz[x], niz[x+1]), b = min(niz[y], niz[y+1]);
                nep = max(nep, max(a, b));
                cout << nep << " ";
            }

        }
        cout << par << "\n";
    }
    if (n%2 == 1){

        int x = (n-1) / 2, y = x-1;
        int nep = 0, par = 0;

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

            if (i%2 == 0){
                x--; y++;
                int a = min(niz[x], niz[x+1]), b = min(niz[y], niz[y+1]);
                nep = max(nep, max(a, b));
                cout << nep << " ";

            }
            if (i%2 == 1){
                int a = max(niz[x], niz[x+1]), b = max(niz[y], niz[y+1]);
                par = max(par, max(a, b));
                cout << par << " ";
            }

        }
        cout << par << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = int( 3e5 );

int N;
int _A[ MAXN + 2 ], *A = &_A[ 1 ];

int ans[ MAXN ];

signed main() {
  ios::sync_with_stdio( 0 );
  cin >> N;
  for( int i = 0; i < N; ++i ) {
    cin >> A[ i ];
  }
  for( int i = N - ( N & 1 ), best = 0, lp = N / 2 - 1, rp = ( N + 1 ) / 2; i >= 1; i -= 2, --lp, ++rp ) { // how many left
    best = max( { best, max( A[ lp ], A[ lp + 1 ] ), max( A[ rp - 1 ], A[ rp ] ) } );
    ans[ N - i ] = best;
  }
  for( int i = N - ( ~N & 1 ), best = 0, lp = ( N - 1 ) / 2, rp = N / 2; i >= 1; i -= 2, --lp, ++rp ) {
    best = max( { best, min( A[ lp ], max( A[ lp - 1 ], A[ lp + 1 ] ) ),
                        min( A[ rp ], max( A[ rp - 1 ], A[ rp + 1 ] ) ) } );
    ans[ N - i ] = best;
  }
  for( int i = 0; i < N; ++i ) {
    ans[ N - 1 ] = max( ans[ N - 1 ], A[ i ] );
  }
  for( int i = 0; i < N; ++i ) {
    cout << ans[ i ] << " \n"[ i + 1 == N ];
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = int( 3e5 );

int N;
int _A[ MAXN + 2 ], *A = &_A[ 1 ];

int ans[ MAXN ];

signed main() {
  ios::sync_with_stdio( 0 );
  cin >> N;
  for( int i = 0; i < N; ++i ) {
    cin >> A[ i ];
  }
  for( int i = N, best = 0, lp = N / 2 - 1, rp = N / 2; i >= 0; i -= 2, --lp, ++rp ) { // reverse( took how much )
    best = max( { best, max( A[ lp ], A[ lp + 1 ] ), max( A[ rp - 1 ], A[ rp ] ) } );
    ans[ N - i ] = best;
  }
  for( int i = N - 1, best = 0, lp = N / 2, rp = N / 2; i >= 0; i -= 2, --lp, ++rp ) {
    best = max( { best, min( A[ lp ], max( A[ lp - 1 ], A[ lp + 1 ] ) ),
                        min( A[ rp ], max( A[ rp - 1 ], A[ rp + 1 ] ) ) } );
    ans[ N - i ] = best;
  }
  for( int i = 0; i < N; ++i ) {
    ans[ N - 1 ] = max( ans[ N - 1 ], A[ i ] );
  }
  for( int i = 0; i < N; ++i ) {
    cout << ans[ i ] << " \n"[ i + 1 == N ];
  }
  return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int>pii;
typedef pair<pii, int>p;
typedef long long ll;
typedef long double ld;
const int maxn=3e5+100;
int n, arr[maxn], one[maxn], two[maxn];
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin>>n;
    int mx=0;
    for(int i=1; i<=n; i++)
    {
        cin>>arr[i];
        mx=max(mx, arr[i]);
    }
    for(int i=1; i<=n; i++)
    {
        int lef=i-1, rig=n-i;
        int len=max(lef, rig)-min(lef, rig);
        one[len]=max(one[len], arr[i]);
    }
    for(int i=1; i<n; i++)
    {
        int lef=i-1, rig=n-(i+1);
        int len=max(lef, rig)-min(lef, rig);
        two[len]=max(two[len], min(arr[i], arr[i+1]));
    }
    int o=one[0], t=two[0];
    for(int i=1; i<n-1; i++)
    {
        o=max(o, one[i]);
        t=max(t, two[i]);
        if((n-i)%2==0)cout<<t<<" ";
        else cout<<o<<" ";
    }
    cout<<mx<<" ";
    if(n!=1)cout<<mx;
    return 0;
}


#include <bits/stdc++.h>

#define F first
#define S second
#define x1 privet1
#define x2 privet2
#define y1 privet3
#define y2 privet4
#define left privet6

using namespace std;
typedef long long ll;
typedef long double ld;

const long long max_n = 300022, log_n = 32, max_m = 111, mod = 1000000007, inf = 1000000009;

int n, a[max_n];

int get_ans(int i, int k, bool mx) {
    if (k == 3) {
        if (mx) {
            return max(min(a[i], a[i + 1]), min(a[i + 1], a[i + 2]));
        } else {
            return min(max(a[i], a[i + 1]), max(a[i + 1], a[i + 2]));
        }
    } else {
        return max(get_ans(i, 3, 0), get_ans(i + 1, 3, 0));
    }
}

int main() {
    //freopen("input.txt", "r", stdin);
    cin >> n;
    int mx = -1;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        mx = max(mx, a[i]);
    }
    int ans0 = -1, ans1 = -1;
    for (int i = 0; i < n - 1; ++i) {
        if (i % 2 == 0) {
            if (n % 2 == 1) {
                int mid1 = n / 2 - i / 2, mid2 = n / 2 + i / 2;
                ans0 = max(ans0, max(get_ans(mid1 - 1, 3, 1), get_ans(mid2 - 1, 3, 1)));
            } else {
                int mid1 = n / 2 - i / 2, mid2 = n / 2 + i / 2;
                ans0 = max(ans0, max(get_ans(mid1 - 2, 4, 1), get_ans(mid2 - 2, 4, 1)));
            }
            printf("%d ", ans0);
        } else {
            if (n % 2 == 0) {
                int mid1 = n / 2 - i / 2 - 1, mid2 = n / 2 + i / 2;
                ans1 = max(ans1, max(get_ans(mid1 - 1, 3, 1), get_ans(mid2 - 1, 3, 1)));
            } else {
                int mid1 = n / 2 - i / 2 - 1, mid2 = n / 2 + i / 2;
                ans1 = max(ans1, max(get_ans(mid1 - 2, 4, 1), get_ans(mid2 - 2, 4, 1)));
            }
            printf("%d ", ans1);
        }
    }
    cout << mx << endl;
    return 0;
}


#include <bits/stdc++.h>

#define F first
#define S second
#define x1 privet1
#define x2 privet2
#define y1 privet3
#define y2 privet4
#define left privet6

using namespace std;
typedef long long ll;
typedef long double ld;

const long long max_n = 300022, log_n = 32, max_m = 111, mod = 1000000007, inf = 1000000009;

int n, a[max_n];

int get_ans(int i, int k, bool mx) {
    if (k == 3) {
        if (mx) {
            return max(min(a[i], a[i + 1]), min(a[i + 1], a[i + 2]));
        } else {
            return min(max(a[i], a[i + 1]), max(a[i + 1], a[i + 2]));
        }
    } else {
        return max(get_ans(i, 3, 0), get_ans(i + 1, 3, 0));
    }
}

int main() {
    //freopen("input.txt", "r", stdin);
    cin >> n;
    int mx = -1;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        mx = max(mx, a[i]);
    }
    int ans0 = -1, ans1 = -1;
    for (int i = 0; i < n - 1; ++i) {
        if (i % 2 == 0) {
            if (n % 2 == 1) {
                int mid1 = n / 2 - i / 2, mid2 = n / 2 + i / 2;
                ans0 = max(ans0, max(get_ans(mid1 - 1, 3, 1), get_ans(mid2 - 1, 3, 1)));
            } else {
                int mid1 = n / 2 - i / 2, mid2 = n / 2 + i / 2;
                ans0 = max(ans0, max(get_ans(mid1 - 2, 4, 1), get_ans(mid2 - 2, 4, 1)));
            }
            printf("%d ", ans0);
        } else {
            if (n % 2 == 0) {
                int mid1 = n / 2 - i / 2 - 1, mid2 = n / 2 + i / 2 + 1;
                ans1 = max(ans1, max(get_ans(mid1 - 1, 3, 1), get_ans(mid2 - 1, 3, 1)));
            } else {
                int mid1 = n / 2 - i / 2 - 1, mid2 = n / 2 + i / 2 + 1;
                ans1 = max(ans1, max(get_ans(mid1 - 2, 4, 1), get_ans(mid2 - 2, 4, 1)));
            }
            printf("%d ", ans1);
        }
    }
    cout << mx;
    return 0;
}


#include <bits/stdc++.h>

#define F first
#define S second
#define x1 privet1
#define x2 privet2
#define y1 privet3
#define y2 privet4
#define left privet6

using namespace std;
typedef long long ll;
typedef long double ld;

const long long max_n = 300022, log_n = 32, max_m = 111, mod = 1000000007, inf = 1000000009;

int n, a[max_n];

int get_ans(int i, int k, bool mx) {
    if (k == 3) {
        if (mx) {
            return max(min(a[i], a[i + 1]), min(a[i + 1], a[i + 2]));
        } else {
            return min(max(a[i], a[i + 1]), max(a[i + 1], a[i + 2]));
        }
    } else {
        return max(get_ans(i, 3, 0), get_ans(i + 1, 3, 0));
    }
}

int main() {
    //freopen("input.txt", "r", stdin);
    cin >> n;
    int mx = -1;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        mx = max(mx, a[i]);
    }
    int ans0 = -1, ans1 = -1;
    for (int i = 0; i < n - 1; ++i) {
        if (i % 2 == 0) {
            if (n % 2 == 1) {
                int mid1 = n / 2 - i / 2, mid2 = n / 2 + i / 2;
                ans0 = max(ans0, max(get_ans(mid1 - 1, 3, 1), get_ans(mid2 - 1, 3, 1)));
            } else {
                int mid1 = n / 2 - i / 2, mid2 = n / 2 + i / 2;
                ans0 = max(ans0, max(get_ans(mid1 - 2, 4, 1), get_ans(mid2 - 2, 4, 1)));
            }
            printf("%d ", ans0);
        } else {
            if (n % 2 == 0) {
                int mid1 = n / 2 - i / 2 - 1, mid2 = n / 2 + i / 2;
                ans1 = max(ans1, max(get_ans(mid1 - 1, 3, 1), get_ans(mid2 - 1, 3, 1)));
            } else {
                int mid1 = n / 2 - i / 2, mid2 = n / 2 + i / 2 + 1;
                ans1 = max(ans1, max(get_ans(mid1 - 2, 4, 1), get_ans(mid2 - 2, 4, 1)));
            }
            printf("%d ", ans1);
        }
    }
    cout << mx << endl;
    return 0;
}


// Nurbakyt Madibek
// Look at my code! IT'S AWESOME

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)3e5 + 5;
const int mod = (int)1e9 + 7;

int n;
int a[MAX_N];

int ans[MAX_N];

int val(int x) {
    return min(a[x], max(a[x - 1], a[x + 1]));
}

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++)
        ans[n - 1] = max(ans[n - 1], a[i]);
    int maxi = 0;
    for (int i = (n % 2 == 0 ? n : n - 1); i >= 2; i -= 2) {
        int l = i / 2, r = n - i / 2 + 1;
        maxi = max(maxi, max(a[l], a[r]));
        if (n % 2 == 1)
            maxi = max(maxi, a[l + 1]);
        ans[n - i] = maxi;
    }
    maxi = 0;
    for (int i = (n % 2 == 1 ? n : n - 1); i >= 3; i -= 2) {
        int l = i / 2, r = n - i / 2 + 1;
        maxi = max(maxi, max(val(l + 1), val(r - 1)));
        ans[n - i] = maxi;
    }
    for (int i = 0; i < n; i++)
        printf("%d ", ans[i]);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define sz size
#define pb push_back

const int maxn = (int)(3e5 + 123);

int n, a[maxn], b[maxn], t1[maxn * 4], t2[maxn * 4];

void build(int v, int tl, int tr) {
    if(tl == tr) {
        t1[v] = a[tl];
        t2[v] = max(min(a[tr - 1], a[tr]), min(a[tr], a[tr + 1]));
        return;
    }

    int tm = (tl + tr) / 2;

    build(v + v, tl, tm);
    build(v +v + 1, tm + 1, tr);

    t1[v] = max(t1[v + v], t1[v + v + 1]);
    t2[v] = max(t2[v + v], t2[v + v + 1]);
}

int get1(int v, int tl, int tr, int l, int r) {
    if(l > r) return -1;

    if(tl == l && tr == r) return t1[v];

    int tm = (tl + tr) / 2;

    return max(get1(v + v, tl, tm, l, min(tm, r)), get1(v + v + 1, tm + 1, tr, max(tm + 1, l), r));
}

int get2(int v, int tl, int tr, int l, int r) {
    if(l > r) return -1;

    if(tl == l && tr == r) return t2[v];

    int tm = (tl + tr) / 2;

    return max(get2(v + v, tl, tm, l, min(tm, r)), get2(v + v + 1, tm + 1, tr, max(tm + 1, l), r));
}

int main(){
	cin >> n;
	for(int i = 1; i <= n; i++) {
	    cin >> a[i];
	}
	build(1, 1, n);

	for(int i = n; i >=1; i--) {
	    if(i & 1) if(i != 1) printf("%d ", get2(1, 1, n, i / 2 + 1, n - i / 2));
	    else printf("%d ", get1(1, 1, n, 1, n));
	    else printf("%d ", get1(1, 1, n, i / 2, n - i / 2 + 1));
	}
	return 0;
}


# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
using namespace std;
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) ((x)&1)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define mem(a,x) memset(a,x,sizeof(a))
#define rep(i,a,b) for (int i=(a); i<=(b); ++i)
#define per(i,a,b) for (int i=(a); i>=(b); --i)
#define rep_it(it,x) for (__typeof((x).begin()) it=(x).begin(); it!=(x).end(); it++)
#define ____ puts("\n_______________\n\n")
#define debug(x) ____; cout<< #x << " => " << (x) << endl
#define debug_pair(x) cout<<"\n{ "<<(x).fir<<" , "<<(x).sec<<" }\n"
#define debug_arr(x,n) ____; cout<<#x<<":\n"; rep(i,0,n) cout<<#x<<"["<<(i)<<"] => "<<x[i]<<endl
#define debug_arr2(x,n,m) ____; cout<<#x<<":\n"; rep(i,0,n) rep(j,0,m) cout<<#x<<"["<<(i)<<"]["<<(j)<<"]= "<<x[i][j]<<((j==m)?"\n\n":"    ")
#define debug_set(x) ____; cout<<#x<<": \n"; rep_it(it,x) cout<<(*it)<<" "; cout<<endl
#define debug_map(x) ____; cout<<#x<<": \n"; rep_it(it,x) debug_pair(*it)
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const ll ooo=9223372036854775807ll;
const int _cnt = 1000 * 1000 + 7;
const int _p = 1000 * 1000 * 1000 + 7;
const int N=300005;
const double PI=acos(-1.0);
const double eps=1e-9;
int o(int x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }

void file_put() {
	string s="/home/jslijin/jslijin/code/";
    freopen((s+"code.in").c_str(), "r", stdin);
    freopen((s+"code.out").c_str(), "w", stdout);
}

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

int h1(int i) { return min(a[i],max(a[i-1],a[i+1])); }
int h2(int i) { return max(a[i],a[i+1]); }

int main() {
    //file_put();

    scanf("%d",&n);
    rep(i,1,n) scanf("%d",&a[i]);
    if (n&1) {
    	for (int l=n+1>>1,r=l,L=n,p=h1(l); L>=3; L-=2,--l,++r,p=max(p,max(h1(l),h1(r)))) ans[L]=p;
    	for (int l=n>>1,r=l+1,L=n-1,p=max(h2(l),h2(r)); L>=2; L-=2,--l,++r,p=max(p,max(h2(l),h2(r)))) ans[L]=p;
    	} else {
		for (int l=n>>1,r=l,L=n,p=h2(l); L>=2; L-=2,--l,++r,p=max(p,max(h2(l),h2(r)))) ans[L]=p;
		for (int l=n>>1,r=l+1,L=n-1,p=max(h1(l),h1(r)); L>=3; L-=2,--l,++r,p=max(p,max(h1(l),h1(r)))) ans[L]=p;
	}
	rep(i,1,n) ans[1]=max(ans[1],a[i]);
	per(i,n,1) printf("%d ",ans[i]); printf("\n");

    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author glebushka98
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <algorithm>
using namespace std;

template<typename T>
class IntegerIterator {
public:
    using value_type = T;

    constexpr explicit IntegerIterator(const value_type value) : value_(value) {}

    IntegerIterator& operator++() {
        ++value_;
        return *this;
    }

    constexpr value_type operator*() const {
        return value_;
    }

    constexpr bool operator ==(const IntegerIterator rhs) const {
        return value_ == rhs.value_;
    }

    constexpr bool operator !=(const IntegerIterator rhs) const {
        return !(*this == rhs);
    }

private:
    value_type value_;

};

template<typename T>
class IntegerRange {
public:
    using const_iterator = IntegerIterator<T>;

    constexpr IntegerRange(const T begin, const T end) : begin_(begin), end_(end) {}

    constexpr const_iterator begin() const {
        return const_iterator(begin_);
    }

    constexpr const_iterator end() const {
        return const_iterator(end_);
    }

private:
    T begin_;
    T end_;

};
template<typename t>
constexpr IntegerRange<t> range(const t from, const t to) {
    return IntegerRange<t>(from, to);
}

typedef long long ll;
typedef long double ld;

class TaskE {
public:
    static const int maxN = 4e5 + 100;
    static const int INF = 2e9;
    int d1[maxN];
    int d0[maxN];
    int a[maxN];
    int ans[maxN];

    void minEq(int &rel, int val) {
        rel = min(rel, val);
    }

    void maxEq(int &rel, int val) {
        rel = max(rel, val);
    }

    void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        int mx = 0;
        for (int i : range(0, n)) {
            in >> a[i];
            mx = max(a[i], mx);
            if (i > 0) {
                d0[i - 1] = max(a[i - 1], a[i]);
                int id = i - 1;
                maxEq(ans[n - 2 * min(id, n - 1 - id - 1) - 2], d0[id]);
            }
        }
        if (n == 1) {
            out << mx << endl;
            return;
        }

        for (int i : range(1, n - 1)) {
            d1[i] = min(max(a[i - 1], a[i + 1]), a[i]);
            int dis = min(i - 1, n - 1 - (i + 1));
            maxEq(ans[n - 2 * dis - 3], d1[i]);
        }
        int curMax0 = -1e9;
        int curMax1 = -1e9;
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                curMax0 = max(ans[i], curMax0);
                ans[i] = curMax0;
            } else {
                curMax1 = max(ans[i], curMax1);
                ans[i] = curMax1;
            }
            out << (i < n - 1 ? ans[i] : mx)<< " ";
        }
	}
};

int main() {
	TaskE solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>

template<typename T>
class IntegerIterator {
public:
    using value_type = T;

    constexpr explicit IntegerIterator(const value_type value) : value_(value) {}

    IntegerIterator& operator++() {
        ++value_;
        return *this;
    }

    constexpr value_type operator*() const {
        return value_;
    }

    constexpr bool operator ==(const IntegerIterator rhs) const {
        return value_ == rhs.value_;
    }

    constexpr bool operator !=(const IntegerIterator rhs) const {
        return !(*this == rhs);
    }

private:
    value_type value_;

};

template<typename T>
class IntegerRange {
public:
    using const_iterator = IntegerIterator<T>;

    constexpr IntegerRange(const T begin, const T end) : begin_(begin), end_(end) {}

    constexpr const_iterator begin() const {
        return const_iterator(begin_);
    }

    constexpr const_iterator end() const {
        return const_iterator(end_);
    }

private:
    T begin_;
    T end_;

};
template<typename t>
constexpr IntegerRange<t> range(const t from, const t to) {
    return IntegerRange<t>(from, to);
}
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxN = 4e5 + 100;
const int INF = 2e9;
int d1[maxN];
int d0[maxN];
int a[maxN];
int ans[maxN];

void minEq(int &rel, int val) {
    rel = min(rel, val);
}

void maxEq(int &rel, int val) {
    rel = max(rel, val);
}

int main(void) {
    int n;
    cin >> n;
    int mx = 0;
    for (int i : range(0, n)) {
        cin >> a[i];
        mx = max(a[i], mx);
        if (i > 0) {
            d0[i - 1] = max(a[i - 1], a[i]);
            int id = i - 1;
            maxEq(ans[n - 2 * min(id, n - 1 - id - 1) - 2], d0[id]);
        }
    }
    if (n == 1) {
        cout << mx << endl;
        return 0;
    }

    for (int i : range(1, n - 1)) {
        d1[i] = min(max(a[i - 1], a[i + 1]), a[i]);
        int dis = min(i - 1, n - 1 - (i + 1));
        maxEq(ans[n - 2 * dis - 3], d1[i]);
    }
    int curMax0 = -1e9;
    int curMax1 = -1e9;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            curMax0 = max(ans[i], curMax0);
            ans[i] = curMax0;
        } else {
            curMax1 = max(ans[i], curMax1);
            ans[i] = curMax1;
        }
        cout << (i < n - 1 ? ans[i] : mx)<< "\n";
    }

    return 0;
}


#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>

template<typename T>
class IntegerIterator {
public:
    using value_type = T;

    constexpr explicit IntegerIterator(const value_type value) : value_(value) {}

    IntegerIterator& operator++() {
        ++value_;
        return *this;
    }

    constexpr value_type operator*() const {
        return value_;
    }

    constexpr bool operator ==(const IntegerIterator rhs) const {
        return value_ == rhs.value_;
    }

    constexpr bool operator !=(const IntegerIterator rhs) const {
        return !(*this == rhs);
    }

private:
    value_type value_;

};

template<typename T>
class IntegerRange {
public:
    using const_iterator = IntegerIterator<T>;

    constexpr IntegerRange(const T begin, const T end) : begin_(begin), end_(end) {}

    constexpr const_iterator begin() const {
        return const_iterator(begin_);
    }

    constexpr const_iterator end() const {
        return const_iterator(end_);
    }

private:
    T begin_;
    T end_;

};
template<typename t>
constexpr IntegerRange<t> range(const t from, const t to) {
    return IntegerRange<t>(from, to);
}
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxN = 4e5 + 100;
const int INF = 2e9;
int d1[maxN];
int d0[maxN];
int a[maxN];
int ans[maxN];

void minEq(int &rel, int val) {
    rel = min(rel, val);
}

void maxEq(int &rel, int val) {
    rel = max(rel, val);
}

int main(void) {
    int n;
    cin >> n;
    for (int i : range(0, n)) {
        cin >> a[i];
        if (i > 0) {
            d0[i - 1] = max(a[i - 1], a[i]);
            int id = i - 1;
            maxEq(ans[n - 2 * min(id, n - 1 - id - 1) - 2], d0[id]);
        }
    }

    for (int i : range(1, n - 1)) {
        d1[i] = min(max(a[i - 1], a[i + 1]), a[i]);
        int dis = min(i - 1, n - 1 - (i + 1));
        maxEq(ans[n - 2 * dis - 3], d1[i]);
    }
    int curMax0 = -1e9;
    int curMax1 = -1e9;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            curMax0 = max(ans[i], curMax0);
            ans[i] = curMax0;
        } else {
            curMax1 = max(ans[i], curMax1);
            ans[i] = curMax1;
        }
        cout << ans[i] << "\n";
    }

    return 0;
}


#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>

template<typename T>
class IntegerIterator {
public:
    using value_type = T;

    constexpr explicit IntegerIterator(const value_type value) : value_(value) {}

    IntegerIterator& operator++() {
        ++value_;
        return *this;
    }

    constexpr value_type operator*() const {
        return value_;
    }

    constexpr bool operator ==(const IntegerIterator rhs) const {
        return value_ == rhs.value_;
    }

    constexpr bool operator !=(const IntegerIterator rhs) const {
        return !(*this == rhs);
    }

private:
    value_type value_;

};

template<typename T>
class IntegerRange {
public:
    using const_iterator = IntegerIterator<T>;

    constexpr IntegerRange(const T begin, const T end) : begin_(begin), end_(end) {}

    constexpr const_iterator begin() const {
        return const_iterator(begin_);
    }

    constexpr const_iterator end() const {
        return const_iterator(end_);
    }

private:
    T begin_;
    T end_;

};
template<typename t>
constexpr IntegerRange<t> range(const t from, const t to) {
    return IntegerRange<t>(from, to);
}
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxN = 4e5 + 100;
const int INF = 2e9;
int d1[maxN];
int d0[maxN];
int a[maxN];
int ans[maxN];

void minEq(int &rel, int val) {
    rel = min(rel, val);
}

void maxEq(int &rel, int val) {
    rel = max(rel, val);
}

int main(void) {
    int n;
    cin >> n;
    int mx = 0;
    for (int i : range(0, n)) {
        cin >> a[i];
        mx = max(a[i], mx);
        if (i > 0) {
            d0[i - 1] = max(a[i - 1], a[i]);
            int id = i - 1;
            maxEq(ans[n - 2 * min(id, n - 1 - id - 1) - 2], d0[id]);
        }
    }

    for (int i : range(1, n - 1)) {
        d1[i] = min(max(a[i - 1], a[i + 1]), a[i]);
        int dis = min(i - 1, n - 1 - (i + 1));
        maxEq(ans[n - 2 * dis - 3], d1[i]);
    }
    int curMax0 = -1e9;
    int curMax1 = -1e9;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            curMax0 = max(ans[i], curMax0);
            ans[i] = curMax0;
        } else {
            curMax1 = max(ans[i], curMax1);
            ans[i] = curMax1;
        }
        cout << (i < n - 1 ? ans[i] : mx)<< "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 400000;
int ai[N], vi[N];
int chkmax(int &t, int d) {t = max(t, d); return t;}
int main()
{
    ios :: sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; ++ i) cin >> ai[i];
    for (int i = 1; i < n; ++ i) chkmax(vi[abs((i - 1) - (n - i - 1))], max(ai[i], ai[i + 1]));
    for (int i = 2; i < n; ++ i) chkmax(vi[abs((i - 2) - (n - i - 1))], min(ai[i], max(ai[i - 1], ai[i + 1])));
    for (int i = 0; i + 2 < n; ++ i) chkmax(vi[i + 2], vi[i]);
    for (int i = 1; i <= n; ++ i) chkmax(vi[n - 1], ai[i]);
    for (int i = 0; i < n; ++ i) cout << vi[i] << " ";
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

template <class T>
inline void relax(T &a, const T &b)
{
	if (b > a)
		a = b;
}

const int MaxN = 300005;

int n, a[MaxN];
int outcome[MaxN];

inline int get_o(int x)
{
	return min(a[x], max(a[x - 1], a[x + 1]));
}
inline int expand_o(int x, int d, int l)
{
	int y = x + d;
	if (y - l + 1 < 1)
		return x;
	if (y + l - 1 > n)
		return x;
	return y;
}

inline void solve_all_o(int st)
{
	int len = st / 2;
	int now = 0, l = 0, r;
	for (int i = 1; i <= n; ++i)
	{
		if (i - len + 1 < 1)
			continue;
		if (i + len - 1 > n)
			continue;
		l = (r = i, !l) ? i : l;
		relax(now, get_o(i));
	}

	for (int i = st; i > 1; i -= 2)
	{
		outcome[i] = now;
		l = expand_o(l, -1, i / 2 - 1);
		r = expand_o(r, +1, i / 2 - 1);
		relax(now, get_o(l));
		relax(now, get_o(r));
	}
}

inline int get_e(int x)
{
	return max(a[x], a[x + 1]);
}
inline int expand_e(int x, int d, int l)
{
	int y = x + d;
	if (y - l + 1 < 1)
		return x;
	if (y + l > n)
		return x;
	return y;
}

inline void solve_all_e(int st) // oushu
{
	int len = st / 2;
	int now = 0, l = 0, r;
	for (int i = 1; i <= n; ++i)
	{
		if (i - len < 0 || i + len > n)
			continue;
		l = (r = i, !l) ? i : l;
		relax(now, get_e(i));
	}

	for (int i = st; i > 1; i -= 2)
	{
		outcome[i] = now;
		l = expand_e(l, -1, i / 2 - 1);
		r = expand_e(r, +1, i / 2 - 1);
		relax(now, get_e(l));
		relax(now, get_e(r));
	}
}

int main()
{
	n = getint();
	for (int i = 1; i <= n; ++i)
		a[i] = getint();

	outcome[1] = *max_element(a + 1, a + n + 1);
	solve_all_o(n - (n % 2 ? 0 : 1));
	solve_all_e(n - (n % 2 ? 1 : 0));

	for (int i = n; i; --i)
		printf("%d ", outcome[i]);

	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

template <class T>
inline void relax(T &a, const T &b)
{
	if (b > a)
		a = b;
}

const int MaxN = 300005;

int n, a[MaxN];
int outcome[MaxN];

inline int get_o(int x)
{
	return min(a[x], max(a[x - 1], a[x + 1]));
}
inline int expand_o(int x, int d, int l)
{
	int y = x + d;
	if (y - l < 1)
		return x;
	if (y + l > n)
		return x;
	return y;
}

inline void solve_all_o(int st)
{
	int len = st / 2;
	int now = 0, l = 0, r;
	for (int i = 1; i <= n; ++i)
	{
		if (i - len < 1 || i + len > n)
			continue;
		l = (r = i, !l) ? i : l;
		relax(now, get_o(i));
	}

	for (int i = st; i > 1; i -= 2)
	{
		outcome[i] = now;
		l = expand_o(l, -1, i / 2 - 1);
		r = expand_o(r, +1, i / 2 - 1);
		relax(now, get_o(l));
		relax(now, get_o(r));
	}
}

inline int get_e(int x)
{
	return max(a[x], a[x + 1]);
}
inline int expand_e(int x, int d, int l)
{
	int y = x + d;
	if (y - l + 1 < 1)
		return x;
	if (y + l > n)
		return x;
	return y;
}

inline void solve_all_e(int st) // oushu
{
	int len = st / 2;
	int now = 0, l = 0, r;
	for (int i = 1; i <= n; ++i)
	{
		if (i - len < 0 || i + len > n)
			continue;
		l = (r = i, !l) ? i : l;
		relax(now, get_e(i));
	}

	for (int i = st; i > 1; i -= 2)
	{
		outcome[i] = now;
		l = expand_e(l, -1, i / 2 - 1);
		r = expand_e(r, +1, i / 2 - 1);
		relax(now, get_e(l));
		relax(now, get_e(r));
	}
}

int main()
{
	n = getint();
	for (int i = 1; i <= n; ++i)
		a[i] = getint();

	outcome[1] = *max_element(a + 1, a + n + 1);
	solve_all_o(n - (n % 2 ? 0 : 1));
	solve_all_e(n - (n % 2 ? 1 : 0));

	for (int i = n; i; --i)
		printf("%d ", outcome[i]);

	return 0;
}


#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

typedef long long s64;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

const int MaxN = 100005;
const int MaxM = 100005;
const int ND = 10;
const int MaxSegN = MaxN * 8;

int n, m;

s64 val[MaxSegN];
s64 sum[MaxSegN][ND];
int rep[MaxSegN][ND];

inline void seg_calc(int p)
{
	val[p] = 0;
	for (int i = 0; i < ND; ++i)
		val[p] += rep[p][i] * sum[p][i];
}

inline void seg_tag_replace(int p, int *tag)
{
	int rep_t[ND];
	for (int i = 0; i < ND; ++i)
		rep_t[i] = tag[rep[p][i]];
	for (int i = 0; i < ND; ++i)
		rep[p][i] = rep_t[i];
	seg_calc(p);
}

inline void seg_tag_down(int p)
{
	seg_tag_replace(p << 1 | 0, rep[p]);
	seg_tag_replace(p << 1 | 1, rep[p]);

	s64 sum_t[ND];
	for (int i = 0; i < ND; ++i)
		sum_t[i] = 0;
	for (int i = 0; i < ND; ++i)
		sum_t[rep[p][i]] += sum[p][i];
	for (int i = 0; i < ND; ++i)
		rep[p][i] = i, sum[p][i] = sum_t[i];
}

inline void seg_update(int p)
{
	int lc = p << 1, rc = lc | 1;
	for (int i = 0; i < ND; ++i)
		sum[p][i] = 0;
	for (int i = 0; i < ND; ++i)
	{
		sum[p][rep[lc][i]] += sum[lc][i];
		sum[p][rep[rc][i]] += sum[rc][i];
	}
	seg_calc(p);
}

void seg_build(int p, int pL, int pR)
{
	for (int i = 0; i < ND; ++i)
		rep[p][i] = i;

	if (pL == pR)
	{
		int x = val[p] = getint(), v = 1;
		while (x > 0)
		{
			sum[p][x % 10] += v;
			v *= 10, x /= 10;
		}
	}
	else
	{
		int pM = pL + pR >> 1;
		seg_build(p << 1 | 0, pL, pM);
		seg_build(p << 1 | 1, pM + 1, pR);
		seg_update(p);
	}
}
void seg_replace(int p, int pL, int pR, int qL, int qR, int *tag)
{
	if (qL <= pL && qR >= pR)
	{
		seg_tag_replace(p, tag);
		return;
	}

	seg_tag_down(p);

	int pM = pL + pR >> 1;
	if (qL <= pM)
		seg_replace(p << 1 | 0, pL, pM, qL, qR, tag);
	if (qR > pM)
		seg_replace(p << 1 | 1, pM + 1, pR, qL, qR, tag);

	seg_update(p);
}
s64 seg_query(int p, int pL, int pR, int qL, int qR)
{
	if (qL <= pL && qR >= pR)
		return val[p];

	seg_tag_down(p);

	int pM = pL + pR >> 1;
	s64 res = 0;
	if (qL <= pM)
		res += seg_query(p << 1 | 0, pL, pM, qL, qR);
	if (qR > pM)
		res += seg_query(p << 1 | 1, pM + 1, pR, qL, qR);
	return res;
}

int main()
{
	cin >> n >> m;

	seg_build(1, 1, n);

	while (m--)
	{
		int op = getint();
		if (op == 1)
		{
			int l = getint(), r = getint();
			int u = getint(), v = getint();

			int tag[ND];
			for (int i = 0; i < ND; ++i)
				tag[i] = i;
			tag[u] = v;
			seg_replace(1, 1, n, l, r, tag);
		}
		else
		{
			int l = getint(), r = getint();
			printf("%lld\n", seg_query(1, 1, n, l, r));
		}
	}

	return 0;
}


#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill( x, y ) memset( x, y, sizeof x )
#define copy( x, y ) memcpy( x, y, sizeof x )
using namespace std;

typedef long long LL;
typedef pair < int, int > pa;

inline int read()
{
	int sc = 0, f = 1; char ch = getchar();
	while( ch < '0' || ch > '9' ) { if( ch == '-' ) f = -1; ch = getchar(); }
	while( ch >= '0' && ch <= '9' ) sc = sc * 10 + ch - '0', ch = getchar();
	return sc * f;
}

const int MAXN = 300005;

int n, mx, a[MAXN], b[MAXN], ans[MAXN];

int main()
{
#ifdef wxh010910
	freopen( "data.in", "r", stdin );
#endif
	n = read();
	for( int i = 1 ; i <= n ; i++ ) a[ i ] = read(), mx = max( mx, a[ i ] );
	for( int i = 2 ; i < n ; i++ ) b[ i ] = max( a[ i ], min( a[ i - 1 ], a[ i + 1 ] ) );
	ans[ n - 1 ] = mx;
	mx = ( n & 1 ) ? a[ n + 1 >> 1 ] : 0;
	for( int i = n - ( n & 1 ) ; i ; i -= 2 )
	{
		int l = i >> 1, r = n - ( i >> 1 ) + 1;
		mx = max( mx, max( a[ l ], a[ r ] ) );
		ans[ n - i ] = mx;
	}
	mx = 0;
	for( int i = n - ( ( n & 1 ) ^ 1 ) ; i ^ 1 ; i -= 2 )
	{
		int l = i + 1 >> 1, r = n - ( i >> 1 );
		mx = max( mx, max( b[ l ], b[ r ] ) );
		ans[ n - i ] = mx;
	}
	for( int i = 0 ; i < n ; i++ ) printf( "%d%c", ans[ i ], i == n - 1 ? '\n' : ' ' );
	return 0;
}


#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill( x, y ) memset( x, y, sizeof x )
#define copy( x, y ) memcpy( x, y, sizeof x )
using namespace std;

typedef long long LL;
typedef pair < int, int > pa;

inline int read()
{
	int sc = 0, f = 1; char ch = getchar();
	while( ch < '0' || ch > '9' ) { if( ch == '-' ) f = -1; ch = getchar(); }
	while( ch >= '0' && ch <= '9' ) sc = sc * 10 + ch - '0', ch = getchar();
	return sc * f;
}

const int MAXN = 300005;

int n, mx, a[MAXN], b[MAXN], ans[MAXN];

int main()
{
#ifdef wxh010910
	freopen( "data.in", "r", stdin );
#endif
	n = read();
	for( int i = 1 ; i <= n ; i++ ) a[ i ] = read(), mx = max( mx, a[ i ] );
	for( int i = 2 ; i < n ; i++ ) b[ i ] = min( a[ i ], max( a[ i - 1 ], a[ i + 1 ] ) );
	ans[ n - 1 ] = mx;
	mx = ( n & 1 ) ? a[ n + 1 >> 1 ] : 0;
	for( int i = n - ( n & 1 ) ; i ; i -= 2 )
	{
		int l = i >> 1, r = n - ( i >> 1 ) + 1;
		mx = max( mx, max( a[ l ], a[ r ] ) );
		ans[ n - i ] = mx;
	}
	mx = 0;
	for( int i = n - ( ( n & 1 ) ^ 1 ) ; i ^ 1 ; i -= 2 )
	{
		int l = i + 1 >> 1, r = n - ( i >> 1 );
		mx = max( mx, max( b[ l ], b[ r ] ) );
		ans[ n - i ] = mx;
	}
	for( int i = 0 ; i < n ; i++ ) printf( "%d%c", ans[ i ], i == n - 1 ? '\n' : ' ' );
	return 0;
}


#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill( x, y ) memset( x, y, sizeof x )
#define copy( x, y ) memcpy( x, y, sizeof x )
using namespace std;

typedef long long LL;
typedef pair < int, int > pa;

inline int read()
{
	int sc = 0, f = 1; char ch = getchar();
	while( ch < '0' || ch > '9' ) { if( ch == '-' ) f = -1; ch = getchar(); }
	while( ch >= '0' && ch <= '9' ) sc = sc * 10 + ch - '0', ch = getchar();
	return sc * f;
}

const int MAXN = 200005;
const LL INF = 1e18;

int n, m, K, c[MAXN], a[4][MAXN], cnt[4];
bool A[MAXN], B[MAXN];
LL ans = INF, sum[4][MAXN];

inline int chk(int x, int p, int m)
{
	int A = upper_bound( a[ 1 ] + 1, a[ 1 ] + cnt[ 1 ] + 1, x ) - a[ 1 ] - 1,
		B = upper_bound( a[ 2 ] + 1, a[ 2 ] + cnt[ 2 ] + 1, x ) - a[ 2 ] - 1,
		C = upper_bound( a[ 3 ] + 1, a[ 3 ] + cnt[ 3 ] + 1, x ) - a[ 3 ] - 1;
	A = max( A, p ); B = max( B, p );
	return A + B + C <= m;
}

inline LL cal(int x, int p, int m)
{
	int A = upper_bound( a[ 1 ] + 1, a[ 1 ] + cnt[ 1 ] + 1, x ) - a[ 1 ] - 1,
		B = upper_bound( a[ 2 ] + 1, a[ 2 ] + cnt[ 2 ] + 1, x ) - a[ 2 ] - 1,
		C = upper_bound( a[ 3 ] + 1, a[ 3 ] + cnt[ 3 ] + 1, x ) - a[ 3 ] - 1;
	A = max( A, p ); B = max( B, p );
	LL ret = sum[ 1 ][ A ] + sum[ 2 ][ B ] + sum[ 3 ][ C ];
	ret -= 1LL * ( A + B + C - m ) * x;
	return ret;
}

int main()
{
#ifdef wxh010910
	freopen( "data.in", "r", stdin );
#endif
	n = read(); m = read(), K = read();
	for( int i = 1 ; i <= n ; i++ ) c[ i ] = read();
	for( int c = read() ; c ; c-- ) A[ read() ] = 1;
	for( int c = read() ; c ; c-- ) B[ read() ] = 1;
	for( int i = 1 ; i <= n ; i++ )
	{
		if( A[ i ] && B[ i ] ) a[ 0 ][ ++cnt[ 0 ] ] = c[ i ];
		else if( A[ i ] ) a[ 1 ][ ++cnt[ 1 ] ] = c[ i ];
		else if( B[ i ] ) a[ 2 ][ ++cnt[ 2 ] ] = c[ i ];
		else a[ 3 ][ ++cnt[ 3 ] ] = c[ i ];
	}
	for( int i = 0 ; i < 4 ; i++ ) sort( a[ i ] + 1, a[ i ] + cnt[ i ] + 1 );
	for( int i = 0 ; i < 4 ; i++ )
		for( int j = 1 ; j <= cnt[ i ] ; j++ )
			sum[ i ][ j ] = sum[ i ][ j - 1 ] + a[ i ][ j ];
	for( int i = 0 ; i <= m && i <= cnt[ 0 ] ; i++ )
	{
		LL ret = sum[ 0 ][ i ];
		if( i + cnt[ 1 ] < K || i + cnt[ 2 ] < K || m - i < ( K - i ) * 2 || cnt[ 1 ] + cnt[ 2 ] + cnt[ 3 ] + i < m ) continue;
		int p = max( 0, K - i ), L = 0, R = 1e9, cur = 1e9;
		while( L <= R )
		{
			int mid = L + R >> 1;
			if( chk( mid, p, m - i ) ) L = mid + 1;
			else cur = mid, R = mid - 1;
		}
		ret += cal( cur, p, m - i );
		ans = min( ans, ret );
	}
	if( ans == INF ) ans = -1;
	cout << ans << endl;
}


#include <iostream>
#include <cmath>

using namespace std;

const int MAXN = 3 * 1e5 + 10;

int max(int a, int b)
{
    if (a > b)
        return a;
    return b;
}

int min(int a, int b)
{
    if (a < b)
        return a;
    return b;
}

int a[MAXN] = { 0 };
int b[MAXN] = { 0 };
int c[MAXN] = { 0 };

int main()
{
    int n;

    cin >> n;

    int maxi = 0;

    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        maxi = max(maxi, a[i]);
    }

    for (int i = 2; i < n; ++i)
        b[i] = min(max(a[i - 1], a[i + 1]), a[i]);

    for (int i = 1; i < n; ++i)
        c[i] = max(a[i], a[i + 1]);

    int solb = 0;
    int solc = 0;

    for (int k = 0; k < n - 1; ++k)
    {
        if ((n - k) % 2 == 1)
        {
            solb = max(solb, max(b[(1 + n - k) / 2], b[(k + 1 + n) / 2]));

            cout << solb << " ";
        }
        else
        {
            solc = max(solc, max(c[(1 + n - k) / 2], c[(k + 1 + n) / 2]));

            cout << solc << " ";
        }
    }
    cout << maxi << endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <cmath>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <bitset>
#include <deque>
#include <string>
#include <list>
#include <cstdlib>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 300000 + 100;
typedef long long ll;
typedef long double ld;
int a[maxn];
int b[maxn];
bool check(int L, int R)
{
	const int mid = (L + R) / 2;
	const int len = R - L;
	if (len == 1) return b[L];
	if (len == 2) return b[L] || b[L + 1];
	if (len & 1)
	{
		return (b[mid] == 1 && (b[mid + 1] == 1 || b[mid - 1] == 1));
	}
	else
	{
		return b[mid] == 1 || b[mid - 1] == 1;
	}
}
int ans[maxn];
int main()
{
	int n;
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 0; i < n; i++)
		{
			scanf("%d", a + i);
		}
		for (int k = 0; k < n; k++)
		{
			const int len = n - k;
			int L = 1, R = 1e9 + 1;
			while (L + 1 < R)
			{
				const int mid = L + (R - L) / 2;
				for (int i = 0; i < n; i++)
				{
					if (a[i] >= mid)
					{
						b[i] = 1;
					}
					else b[i] = 0;
				}
				bool ok = false;
				for (int i = 0; i <= k; i++)
				{
					if (check(i, i + len))
					{
						ok = true;
						break;
					}
				}
				if (ok)
				{
					L = mid;
				}
				else
				{
					R = mid;
				}
			}
			ans[k] = L;
		}
		for (int i = 0; i < n; i++)
		{
			printf("%d ", ans[i]);
		}
		printf("\n");
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <cmath>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <bitset>
#include <deque>
#include <string>
#include <list>
#include <cstdlib>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 300000 + 100;
typedef long long ll;
typedef long double ld;
int a[maxn];
int n;
int b[maxn << 2];
int c[maxn << 2];
int dn;
void init(int arr[], int val[], int L = 0, int R = dn, int o = 1)
{
	if (L + 1 == R)
	{
		arr[o] = val[L];
		return;
	}
	const int mid = (L + R) / 2;
	init(arr, val, L, mid, o << 1);
	init(arr, val, mid, R, o << 1 | 1);
	arr[o] = max(arr[o << 1], arr[o << 1 | 1]);
}
int query(int arr[], int ql, int qr, int L = 0, int R = dn, int o = 1)
{
	if (ql <= L && R <= qr)
	{
		return arr[o];
	}
	const int mid = (L + R) / 2;
	int ret = 0;
	if (ql < mid)
		ret = query(arr, ql, qr, L, mid, o << 1);
	if (qr > mid)
		ret = max(ret, query(arr, ql, qr, mid, R, o << 1 | 1));
	return ret;
}
int main()
{
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 1; i <= n; i++)
		{
			scanf("%d", a + i);
		}
		a[0] = a[n + 1] = inf;
		dn = n + 1;
		for (int i = 0; i < dn; i++)
		{
			b[i] = min(a[i], a[i + 1]);
		}
		init(c, b);
		init(b, a);
		for (int k = 0; k < n; k++)
		{
			const int len = n - k;
			const int lmargin = len / 2 ;
			const int rmargin = n - lmargin;
			int ans = 0;
			if (len == 1)
			{
				ans = query(b, 1, dn);
			}
			else if (len & 1)
			{
				ans = query(c, lmargin, rmargin + 1);
			}
			else
			{
				ans = query(b, lmargin, rmargin + 2);
			}
			printf("%d ", ans);
		}
		printf("\n");
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <cmath>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <bitset>
#include <deque>
#include <string>
#include <list>
#include <cstdlib>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 300000 + 100;
typedef long long ll;
typedef long double ld;
int a[maxn];
int n;
int b[maxn << 2];
int main()
{
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 1; i <= n; i++)
		{
			scanf("%d", a + i);
		}
		a[0] = a[n + 1] = inf;
		for (int k = 0; k < n; k++)
		{
			const int len = n - k;
			int ans = 0;
			if (len & 1)
			{
				const int lmargin = len / 2 ;
				const int rmargin = n - lmargin;
				for (int i = lmargin; i <= rmargin; i++)
				{
					ans = max(ans, min(a[i], a[i + 1]));
				}
			}
			else
			{
				const int lmargin = len / 2 ;
				const int rmargin = n - lmargin;
				for (int i = lmargin; i <= rmargin; i++)
				{
					ans = max(ans, max(a[i], a[i + 1]));
				}
			}
			printf("%d ", ans);
		}
		printf("\n");
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <cmath>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <bitset>
#include <deque>
#include <string>
#include <list>
#include <cstdlib>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 300000 + 100;
typedef long long ll;
typedef long double ld;
int a[maxn];
int b[maxn];
bool check(int L, int R)
{
	const int mid = (L + R) / 2;
	const int len = R - L;
	if (len == 1) return b[L];
	if (len == 2) return b[L] || b[L + 1];
	if (len & 1)
	{
		return (b[mid] == 1 && (b[mid + 1] == 1 || b[mid - 1] == 1));
	}
	else
	{
		return b[mid] == 1 || b[mid - 1] == 1;
	}
}
int ans[maxn];
int main()
{
	int n;
	ios::sync_with_stdio(false);
	while (cin >> n)
	{
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		for (int k = 0; k < n; k++)
		{
			const int len = n - k;
			int L = 1, R = 1e9 + 1;
			while (L + 1 < R)
			{
				const int mid = L + (R - L) / 2;
				for (int i = 0; i < n; i++)
				{
					if (a[i] >= mid)
					{
						b[i] = 1;
					}
					else b[i] = 0;
				}
				bool ok = false;
				for (int i = 0; i <= k; i++)
				{
					if (check(i, i + len))
					{
						ok = true;
						break;
					}
				}
				if (ok)
				{
					L = mid;
				}
				else
				{
					R = mid;
				}
			}
			ans[k] = L;
		}
		for (int i = 0; i < n; i++)
		{
			cout << ans[i] << " ";
		}
		cout << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <cmath>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <bitset>
#include <deque>
#include <string>
#include <list>
#include <cstdlib>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 300000 + 100;
typedef long long ll;
typedef long double ld;
int a[maxn];
int b[maxn];
bool check(int L, int R)
{
	const int mid = (L + R) / 2;
	const int len = R - L;
	if (len == 1) return b[L];
	if (len == 2) return b[L] || b[L + 1];
	if (len & 1)
	{
		return (b[mid]&& (b[mid + 1] || b[mid - 1] ));
	}
	else
	{
		return b[mid] || b[mid - 1] ;
	}
}
int ans[maxn];
int main()
{
	int n;
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 0; i < n; i++)
		{
			scanf("%d", a + i);
		}
		for (int k = 0; k < n; k++)
		{
			const int len = n - k;
			int L = 1, R = 1e9 + 1;
			while (L + 1 < R)
			{
				const int mid = L + (R - L) / 2;
				for (int i = 0; i < n; i++)
				{
					if (a[i] >= mid)
					{
						b[i] = 1;
					}
					else b[i] = 0;
				}
				bool ok = false;
				for (int i = 0; i <= k; i++)
				{
					if (check(i, i + len))
					{
						ok = true;
						break;
					}
				}
				if (ok)
				{
					L = mid;
				}
				else
				{
					R = mid;
				}
			}
			ans[k] = L;
		}
		for (int i = 0; i < n; i++)
		{
			printf("%d ", ans[i]);
		}
		printf("\n");
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <cmath>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <bitset>
#include <deque>
#include <string>
#include <list>
#include <cstdlib>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 300000 + 100;
typedef long long ll;
typedef long double ld;
int a[maxn];
int n;
int b[maxn << 2];
int main()
{
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 1; i <= n; i++)
		{
			scanf("%d", a + i);
		}
		a[0] = a[n + 1] = inf;
		for (int k = 0; k < n; k++)
		{
			const int len = n - k;
				const int lmargin = len / 2 ;
				const int rmargin = n - lmargin;
			int ans = 0;
			if (len == 1)
			{
				ans = *max_element(a + 1, a + n + 1);
			}
			else if (len & 1)
			{
				for (int i = lmargin; i <= rmargin; i++)
				{
					ans = max(ans, min(a[i], a[i + 1]));
				}
			}
			else
			{
				const int lmargin = len / 2 ;
				const int rmargin = n - lmargin;
				for (int i = lmargin; i <= rmargin; i++)
				{
					ans = max(ans, max(a[i], a[i + 1]));
				}
			}
			printf("%d ", ans);
		}
		printf("\n");
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <cmath>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <bitset>
#include <deque>
#include <string>
#include <list>
#include <cstdlib>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 300000 + 100;
typedef long long ll;
typedef long double ld;
int a[maxn];
int b[maxn];
bool check(int L, int R)
{
	const int mid = (L + R) / 2;
	const int len = R - L;
	if (len == 1) return b[L];
	if (len == 2) return b[L] || b[L + 1];
	if (len & 1)
	{
		return (b[mid]&& (b[mid + 1] || b[mid - 1] ));
	}
	else
	{
		return b[mid] || b[mid - 1] ;
	}
}
int ans[maxn];
int main()
{
	int n;
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 0; i < n; i++)
		{
			scanf("%d", a + i);
		}
		for (int k = 0; k < n; k++)
		{
			const int len = n - k;
			int L = 1, R = 1e9 + 1;
			while (L + 1 < R)
			{
				const int mid = L + (R - L) / 2;
				for (int i = 0; i < n; i++)
				{
					if (a[i] >= mid)
					{
						b[i] = 1;
					}
					else b[i] = 0;
				}
				bool ok = check(0, len) || check(k, n);
				/*
				for (int i = 0; i <= k; i++)
				{
					if (check(i, i + len))
					{
						ok = true;
						break;
					}
				}
				*/
				if (ok)
				{
					L = mid;
				}
				else
				{
					R = mid;
				}
			}
			if (k)
				ans[k] = max(L, ans[k - 1]);
			else
				ans[k] = L;
		}
		for (int i = 0; i < n; i++)
		{
			printf("%d ", ans[i]);
		}
		printf("\n");
	}
}


// Game of removal from ends where 1 adversary wants to maximize the left number and the other adversary wants to minimize the left number
// If adversary 1 starts the game then the solution is
// max(a[n / 2], a[n / 2 + 1]) if n is even and
// max(min(a[n / 2], a[n / 2 + 1]), min(a[n / 2 + 1], a[n / 2] + 2)) if n is odd (assuming one based indexing)

#include<stdio.h>
#include"iostream"
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#define X first
#define Y second
#define INF 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
int main(){
  ll n, gmx = -1;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
    gmx = max(gmx, a[i]);
  }
  if(n == 1){
    cout << a[0] << "\n";
    return 0;
  }
  if(n == 2){
    cout << max(a[0], a[1]) << " " << max(a[0], a[1]) << "\n";
    return 0;
  }
  vector<ll> even(n - 1), odd(n - 2), k(n);
  for(int i = 0; i < n - 1; i++) even[i] = max(a[i], a[i + 1]);
  for(int i = 0; i < n - 2; i++) odd[i] = max(min(a[i], a[i + 1]), min(a[i + 1], a[i + 2]));

  ll ks = 0, mx = -1;
  if(n % 2 == 1) ks = 1;
  for(int j = ks; j < n; j += 2){
    mx = max(mx, even[(0 + n - 1 - j) / 2]);
    mx = max(mx, even[(j + n - 1) / 2]);
    k[j] = mx;
  }
  ks = 0, mx = -1;
  if(n % 2 == 0) ks = 1;
  for(int j = ks; j < n; j += 2){
    if(n - j >= 3){
      mx = max(mx, odd[(0 + n - 1 - j) / 2 - 1]);
      mx = max(mx, odd[(j + n - 1) / 2 - 1]);
    }
    else mx = gmx;
    k[j] = mx;
  }
  for(int i = 0; i < n; i++) cout << k[i] << " ";
  cout << "\n";
  return 0;
}


// Game of removal from ends where 1 adversary wants to maximize the left number and the other adversary wants to minimize the left number
// If adversary 1 starts the game then the solution is
// max(a[n / 2], a[n / 2 + 1]) if n is even and
// max(min(a[n / 2], a[n / 2 + 1]), min(a[n / 2 + 1], a[n / 2] + 2)) if n is odd (assuming one based indexing)

#include<stdio.h>
#include"iostream"
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#define X first
#define Y second
#define INF 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  if(n == 1){
    cout << a[0] << "\n";
    return 0;
  }
  if(n == 2){
    cout << max(a[0], a[1]) << " " << max(a[0], a[1]) << "\n";
    return 0;
  }
  vector<ll> even(n - 1), odd(n - 2), k(n);
  for(int i = 0; i < n - 1; i++) even[i] = max(a[i], a[i + 1]);
  for(int i = 0; i < n - 2; i++) odd[i] = max(min(a[i], a[i + 1]), min(a[i + 1], a[i + 2]));

  ll ks = 0, mx = -1;
  if(n % 2 == 1) ks = 1;
  for(int j = ks; j < n; j += 2){
    mx = max(mx, even[(0 + n - 1 - j) / 2]);
    mx = max(mx, even[(j + n - 1) / 2]);
    k[j] = mx;
  }
  ks = 0, mx = -1;
  if(n % 2 == 0) ks = 1;
  for(int j = ks; j < n; j += 2){
    if(n - j >= 3){
      mx = max(mx, odd[(0 + n - 1 - j) / 2 - 1]);
      mx = max(mx, odd[(j + n - 1) / 2 - 1]);
    }
    else mx = max(mx, max(a[n - 1], a[0]));
    k[j] = mx;
  }
  for(int i = 0; i < n; i++) cout << k[i] << " ";
  cout << "\n";
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5+5;

inline int read(){
	int x = 0,f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch  = getchar();}
	while(ch <= '9' && ch >= '0') x = x * 10+ch-'0',ch = getchar();
	return x * f;
}

int N , A[maxn],ans[maxn];

inline void cmax(int &x,int y){if(y > x) x = y;}

int main(){
	N = read(); int mx = 0;
	for(int i = 1 ; i <= N ; ++i)A[i] = read(),cmax(mx , A[i]);
	for(int i = 1 ; i < N ; ++i){
		int ret = max(A[i] , A[i + 1]);
		cmax(ans[min(N-i,i)*2] , ret);
	}
	for(int i = 2 ; i <= N ; ++i){
		int ret = min(A[i] , max(A[i-1] , A[i+1]));
		cmax(ans[min(N-i+1,i)*2 - 1] , ret);
	}
	for(int i = N ; ~i ; --i) cmax(ans[i] , ans[i + 2]);
	for(int i = 0 ; i < N - 1 ; ++i)
		printf("%d ",ans[N-i]);
	printf("%d\n",mx);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans[n];
	memset(ans, 0, sizeof(ans));

	for (int i = 0; i < n-1; ++i) {
		//when I leave an even number of objects + I start
		int v = max(a[i], a[i+1]);
		int left = 2;
		left += min(i , n-i-2) << 1;
		ans[n - left] = max(ans[n - left], v);
	}

	for (int i = 0; i < n-2; i++) {
		//when I leave an odd number of objects + I start
		int v = max(min(a[i+1], a[i]),min(a[i+1], a[i+2]));
		int left = 3;
		left += min(i , n-i-3) << 1;
		ans[n - left] = max(ans[n - left], v);
	}

	//with 2+ movements I can always do better or as good;
	for (int i = 2; i < n; i++) {
		ans[i] = max(ans[i-2], ans[i]);
	}
	ans[n-1] = max(a[0],ans[n-2]);
	//taking everything is the same as taking everything but 1
	for (int i : ans) cout << i << ' ';
	cout << endl;

}


#include<bits/stdc++.h>
using namespace std;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans[n];
	memset(ans, 0, sizeof(ans));

	for (int i = 0; i < n-1; ++i) {
		//when I leave an even number of objects + I start
		int v = max(a[i], a[i+1]);
		int left = 2;
		left += min(i , n-i-2) << 1;
		ans[n - left] = max(ans[n - left], v);
	}

	for (int i = 0; i < n-2; i++) {
		//when I leave an odd number of objects + I start
		int v = max(min(a[i+1], a[i]),min(a[i+1], a[i+2]));
		int left = 3;
		left += min(i , n-i-3) << 1;
		ans[n - left] = max(ans[n - left], v);
	}

	//with 2+ movements I can always do better or as good;
	for (int i = 2; i < n; i++) {
		ans[i] = max(ans[i-2], ans[i]);
	}
	ans[n-1] = ans[n-2];
	//taking everything is the same as taking everything but 1
	for (int i : ans) cout << i << ' ';
	cout << endl;

}


#include <bits/stdc++.h>
using namespace std;

const int MaxN = 300010;
int v[MaxN];

int S[MaxN * 4];

void build(int id, int l, int r) {
	if(l + 1 == r) {
		S[id] = v[l];
		return ;
	}
	int m = (l + r) >> 1;
	build(id << 1, l, m);
	build((id << 1) + 1, m, r);
	S[id] = max(S[id << 1], S[(id << 1) + 1]);
}

int query(int id, int l, int r, int x, int y) {
	if(l >= x and r <= y) return S[id];
	if(l >= y or r <= x) return 0;
	int m = (l + r) >> 1;
	return max(query((id << 1), l, m, x , y), query((id << 1) + 1, m, r, x, y));
}

int main() {
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i) {
		cin >> v[i];
	}
	build(1,0,n);
	for(int i = 0; i < n; ++i) {
	    cout << query(1, 0, n, (n-i)/2, (n+i+2)/2) << ' ';
	    //cout <<  (n-i-1)/2 << ' ' <<  (n+i+2)/2 << endl;
		if((n - i) % 2) {
			//cout << query(1, 0, n, n/2 - i/2, n/2 + i/2 + 1) << ' ';
		}
		else {
			//cout <<
		}
	}
}


#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
#define fst first
#define snd second
const int UNDEF = -1;
//const int INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

static char stdinBuffer[1024];
static char* stdinDataEnd = stdinBuffer + sizeof (stdinBuffer);
static const char* stdinPos = stdinDataEnd;

void readAhead(size_t amount)
{
    size_t remaining = stdinDataEnd - stdinPos;
    if (remaining < amount) {
       memmove(stdinBuffer, stdinPos, remaining);
       size_t sz = fread(stdinBuffer + remaining, 1, sizeof (stdinBuffer) - remaining, stdin);
       stdinPos = stdinBuffer;
       stdinDataEnd = stdinBuffer + remaining + sz;
       if (stdinDataEnd != stdinBuffer + sizeof (stdinBuffer))
         *stdinDataEnd = 0;
    }
}

int readInt()
{
    readAhead(16);

    int x = 0;
    bool neg = false;
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    if (*stdinPos == '-') {
       ++stdinPos;
       neg = true;
    }

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

    return neg ? -x : x;
}
const int mn=3e5+4;

int t[2][2*mn];
int segn;
void modify(int *t, int l, int r, int value) {
  int n=segn;
  r++;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l&1) chkmax(t[l++],value);
    if (r&1) chkmax(t[--r],value);
  }
}
void push(int *t) {
  int n=segn;
  for (int i = 1; i < n; ++i) {
    chkmax(t[i<<1], t[i]);
    chkmax(t[i<<1|1], t[i]);
    //t[i] = 0;
  }
}

int p[mn];
int pl[mn],pr[mn];
int ffind(int x) {
  if (p[x] != x) {
    p[x] = ffind(p[x]);
  }
  return p[x];
}
void funion(int x, int y) {
  if (rand()&1) swap(x,y);
  int xr = ffind(x);
  int yr = ffind(y);
  // Merge xr into yr
  p[xr] = yr;
  chkmin(pl[yr],pl[xr]);
  chkmax(pr[yr],pr[xr]);
}
bitset<mn> tick;
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n=readInt();
  vector<pair<int,int> > v;
  int big=0;
  for (int x=1;x<=n;x++) {
    int val=readInt();
    v.PB(MP(-val,x));
    chkmax(big,val);
  }
  sort(v.begin(),v.end());
  for (int x=0;x<=n+1;x++) {
    p[x]=pl[x]=pr[x]=x;
  }
  segn=n;
  for (auto &w:v) {
    int val=-w.fst,x=w.snd;
    tick[x]=true;
    if (tick[x-1]) funion(x-1,x);
    if (tick[x+1]) funion(x,x+1);
    int vl[2],vr[2];
    vl[0]=pl[ffind(x)];
    vl[1]=pl[ffind(vl[0]-1)];
    vr[0]=pr[ffind(x)];
    vr[1]=pr[ffind(vr[0]+1)];
    for (int ls=0;ls<2;ls++) for (int rs=0;rs<2;rs++) {
      if (ls+rs<=1) {
        int L=vl[ls],R=vr[rs];
        if (R-L+1<3&&ls+rs>0) continue;
        int min_need=(ls+rs==0)?1:3;
        for (int need=min_need;need<=min_need+1;need++) {
          vector<int> vl;
          vl.PB(L);
          vl.PB(R-need+1);
          vl.PB((n-need)/2 - 1);
          vl.PB((n-need)/2);
          vl.PB((n-need)/2 + 1);
          for (auto &l: vl) {
            int r=l+need-1;
            if (!(L<=l&&l<=r&&r<=R)) continue;
            int lspace=l-1,rspace=n-r;
            int rm_small=n-(2*min(lspace,rspace)+r-l+1)-1;
            chkmax(rm_small,0);
            int rm_large=n-(r-l+1)-1;
            chkmax(rm_large,0);
            int mod=rm_large%2;
            if (rm_small%2!=mod) rm_small++;
            //printf("val:%d l:%d r:%d lspace:%d rspace:%d rm_small:%d rm_large:%d\n",val,l,r,lspace,rspace,rm_small,rm_large);
            if (rm_small<=rm_large) {
              modify(t[mod],rm_small/2,rm_large/2,val);
            }
          }
        }
        //chkmax(vans[rm],val);
      }
    }
  }
  push(t[0]);push(t[1]);
  for (int rm=0;rm<n-1;rm++) printf("%d ",t[rm%2][n+rm/2]);
  printf("%d\n",big);
}


#include <stdio.h>
int main()
{
    long long int n,a[105],i,min,mark;
    scanf("%I64d",&n);
        mark=0;
        scanf("%I64d",&a[0]);
        min=a[0];
        for(i=1; i<n; i++)
        {
            scanf("%I64d",&a[i]);
            if(min<a[i])
            {
                mark++;
            }
            if(min>a[i])
            {
                min=a[i];
            }
        }
        long long int min2;
        for(i=0; i<n; i++)
        {
            if(a[i]!=min)
                min2=a[i];
        }
        for(i=0; i<n; i++)
        {
            if(a[i]!=min&&min2>a[i])
            {
                min2=a[i];
            }
        }
        if(mark!=0)
            printf("%d\n",min2);
        else
            printf("NO\n");
    return 0;
}
//2018-11-17 00:18:01.733


#include<stdio.h>
int main()
{
    long long int n;
    long long int a[105];
    long long int i;
    scanf("%I64d",&n);
    long long int q;
    if(n==1)
    {
        printf("NO\n");
    }
    else
    {
        for(i = 0; i < n; i++)
        {
            scanf("%I64d",&a[i]);
        }
        long long int j;
        long long int temp;
        for(i = 0; i < n; i++)
            for(j = 0; j < n - i - 1; j++)
            {
                if(a[j] > a[j+1])
                {
                    temp = a[j];
                    a[j] = a[j+1];
                    a[j+1] = temp;
                }
            }
        long long int count = 0;
        for(i = 0; i < n; i++)
        {
            if(a[i]==a[0])
            {
                count++;
            }
        }
        if(count==n)
         printf("NO\n");
         else{
        long long int min;
        for(i = 1; i < n; i++)
        {
            if(a[i]==a[0])
            {
                a[i]=10000;
            }
        }
        for(i = 1; i < n; i++)
        {
            if(a[i] < a[1])
            {
                a[1] = a[i];
            }
        }
         printf("%I64d\n",a[1]);
         }
    }
    return 0;
}
//2018-11-07 20:33:40.462


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,t,i;
	while(cin>>n) {
	set<int>p;
	for(i=0;i<n;++i) cin>>t,p.insert(t);
	priority_queue<int,vector<int>,greater<int> >q;
	for(set<int>::iterator it=p.begin();it!=p.end();++it)
	q.push(*it);
	q.pop();
	cout<<q.top()<<endl;
	}
	return 0;
}//2020-07-31 19:53:59.324


#include <iostream>
#include <cstdio>
using namespace std;
int a[300];
int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        a[x + 100] = 1;
    }
    int cnt = 0;
    for(int i = 0; i <= 200; i++){
        if(a[i]){
            cnt++;
            if(cnt == 2){
                cout << i - 100 << endl;
                break;
            }
        }
    }
    if(cnt < 2) puts("NO");
    return 0;
}//2020-09-24 09:24:16.876


#include<stdio.h>
int main()
{
	int n,a[101],min,min2,i,flag;
	while(scanf("%d",&n)!=EOF)
	{
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	min=a[0];
	flag=0;
	for(i=1;i<n;i++)
		if(a[i]!=min)
			flag=1;
	for(i=1;i<n;i++)
		if(a[i]<min)
			min=a[i];
	if(min==a[0])
     	min2=a[1];
	else
		min2=a[0];
	for(i=0;i<n;i++)
		if(a[i]<min2&&a[i]>min)
			min2=a[i];
	if(flag==1)
     	printf("%d\n",min2);
	else if(flag==0)
		printf("NO\n");
	}
	return 0;
}
//2019-03-04 10:27:31.714


#include<iostream>
#include<set>
using namespace std;
int main()
{
    set<int> x;
    int n,k,t=0;
    cin>>n;
    while(n--)
    {
        cin>>k;
        x.insert(k);
    }
    for(set<int>::reverse_iterator rit = x.rbegin(); rit != x.rend(); rit++)
    {
        t++;
    	if(t==2)
        {
            cout<<*rit;
            break;
        }
    }
    x.clear();
}//2019-11-09 16:44:21.873


#include<bits/stdc++.h>
#define ll long long
#define reg register
using namespace std;
ll n,x;
set<ll>s;
inline ll read()
{
   reg int s=0,w=1;
   reg char ch=getchar();
   while(ch<='0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
int main()
{
    n=read();
    for(reg int i=1;i<=n;i++)s.insert(read());
    s.erase(s.begin());
    if(s.empty())puts("NO");
    else printf("%lld",*s.begin());
    return 0;
}#include<bits/stdc++.h>
#define reg register
using namespace std;
int n,x;
set<int>s;
inline int read()
{
   reg int s=0,w=1;
   reg char ch=getchar();
   while(ch<='0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
int main()
{
    n=read();
    for(reg int i=1;i<=n;i++)s.insert(read());
    s.erase(s.begin());
    if(s.empty())puts("NO");
    else printf("%lld",*s.begin());
    return 0;
}


#include<bits/stdc++.h>
#define reg register
using namespace std;
int n,x;
set<int>s;
inline int read()
{
   reg int s=0,w=1;
   reg char ch=getchar();
   while(ch<='0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
int main()
{
    n=read();
    for(reg int i=1;i<=n;i++)s.insert(read());
    s.erase(s.begin());
    if(s.empty())puts("NO");
    else printf("%lld",*s.begin());
    return 0;
}


#include<bits/stdc++.h>
#define reg register
using namespace std;
int n,x;
set<int>s;
inline int read()
{
    reg int x=0,f=1;
    reg char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int main()
{//爱的vfbsdjhgbsfhk
    n=read();
    for(reg int i=1;i<=n;i++)s.insert(read());
    s.erase(s.begin());
    if(s.empty())puts("NO");
    else printf("%d",*s.begin());
    return 0;
}


#include<bits/stdc++.h>
#define reg register
using namespace std;
int n,x;
set<int>s;
inline int read()
{
   reg int s=0,w=1;
   reg char ch=getchar();
   while(ch<='0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
int main()
{
    n=read();
    for(reg int i=1;i<=n;i++)s.insert(read());
    s.erase(s.begin());
    if(s.empty())puts("NO");
    else printf("%d",*s.begin());
    return 0;
}


#include<bits/stdc++.h>
#define reg register
using namespace std;
int n,x;
set<int>s;
inline int read()
{
    reg int x=0,f=1;
    reg char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int main()
{
    n=read();
    for(reg int i=1;i<=n;i++)s.insert(read());
    s.erase(s.begin());
    if(s.empty())puts("NO");
    else printf("%d",*s.begin());
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define reg register
using namespace std;
ll n,x;
set<ll>s;
inline ll read()
{
	reg ll x=0;
	reg char ch=getchar();
	while(ch>'9'||ch<'0')ch=getchar();
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	return x;
}
int main()
{
    n=read();
    for(reg int i=1;i<=n;i++)s.insert(read());
    s.erase(s.begin());
    if(s.empty())puts("NO");
    else printf("%lld",*s.begin());
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define reg register
using namespace std;
ll n,x;
set<ll>s;
inline ll read()
{
   reg int s=0,w=1;
   reg char ch=getchar();
   while(ch<='0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
int main()
{
    n=read();
    for(reg int i=1;i<=n;i++)s.insert(read());
    s.erase(s.begin());
    if(s.empty())puts("NO");
    else printf("%lld",*s.begin());
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    set<int> a;
    int n;
    cin >> n;

    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.insert(x);
    }

    set<int>::iterator it = a.begin();
    advance(it, k - 1);

    // if (k < n) {
        cout << *it << endl;
    // } else {
    //     cout << "NO\n";
    // }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    set<int> a;
    int n;
    cin >> n;
    int k = 2;

    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.insert(x);
    }

    set<int>::iterator it = a.begin();
    advance(it, k - 1);

    if(a.size() < n || n < k) {
        cout << "NO\n" << endl;
    } else {
        cout << *it << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    set<int> a;
    int n;
    cin >> n;
    int k = 2;

    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.insert(x);
    }

    set<int>::iterator it = a.begin();
    advance(it, k - 1);

    if(a.size() < k) {
        cout << "NO\n" << endl;
    } else {
        cout << *it << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    set<int> a;
    int n;
    cin >> n;
    int k = 2;

    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.insert(x);
    }

    set<int>::iterator it = a.begin();
    advance(it, k - 1);

    if (k <= n) {
        cout << *it << endl;
    } else {
        cout << "NO\n";
    }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    set<int> a;
    int n;
    cin >> n;
    int k = 2;

    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.insert(x);
    }

    set<int>::iterator it = a.begin();
    advance(it, k - 1);

    if(a.size() < n) {
        cout << "NO\n" << endl;
    } else {
        cout << *it << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    set<int> a;
    int n;
    cin >> n;
    int k = 2;

    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.insert(x);
    }

    set<int>::iterator it = a.begin();
    advance(it, k - 1);

    if(a.size() > n || n < k) {
        cout << "NO\n" << endl;
    } else {
        cout << *it << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    set<int> a;
    int n;
    cin >> n;
    int k = 2;

    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.insert(x);
    }

    set<int>::iterator it = a.begin();
    advance(it, k - 1);

    if(a.size() > n) {
        cout << "NO\n" << endl;
    } else {
        cout << *it << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    set<int> a;
    int n;
    cin >> n;
    int k = 2;

    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.insert(x);
    }

    set<int>::iterator it = a.begin();
    advance(it, k - 1);

    if (k < n) {
        cout << *it << endl;
    } else {
        cout << "NO\n";
    }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    set<int> a;
    int n, k;
    cin >> n >> k;

    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.insert(x);
    }

    set<int>::iterator it = a.begin();
    advance(it, k - 1);

    if (k < n) {
        cout << *it << endl;
    } else {
        cout << "NO\n";
    }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    set<int> a;
    int n;
    cin >> n;
    int k = 2;

    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.insert(x);
    }

    set<int>::iterator it = a.begin();
    advance(it, k - 1);

    if (k <= n) {
        cout << *it << endl;
    } else if (k > n) {
        cout << "NO\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int numero;
    cin>>n;
    vector <int> v;
    for(int i=0;i<n;i++){
        cin>>numero;
        v.push_back(numero);
    }
    sort(v.begin(),v.end());
    if(n<=1) cout<<"NO";
    else{
        cout<<v[1];
    }

}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int numero;
    int flag=-1;
    cin>>n;
    vector <int> v;
    for(int i=0;i<n;i++){
        cin>>numero;
        v.push_back(numero);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++){
        if(i!=0){
            if(v[i]!=v[0]){
                cout<<i;
                flag=0;
                break;
            }
        }
    }
    if(flag==0) cout<<"NO";
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int numero;
    int flag=-1;
    cin>>n;
    vector <int> v;
    for(int i=0;i<n;i++){
        cin>>numero;
        v.push_back(numero);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++){
        if(i!=0){
            if(v[i]!=v[0]){
                cout<<v[i];
                flag=0;
                break;
            }
        }
    }
    if(flag!=0) cout<<"NO";
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int numero;
    int flag=-1;
    cin>>n;
    vector <int> v;
    for(int i=0;i<n;i++){
        cin>>numero;
        v.push_back(numero);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++){
        if(i!=0){
            if(v[i]!=v[0]){
                cout<<i;
                flag=0;
                break;
            }
        }
    }
    if(flag!=0) cout<<"NO";
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector <int> v;
    for(int i=0;i<n;i++){
        cin>>numero;
        v.push_back(numero);
    }
    sort(v.begin(),v.end());
    if(n<=1) cout<<"NO";
    else{
        cout<<v[1];
    }

}


#include<bits/stdc++.h>
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container),element) != container.end())
#define sz(a) int((a).size())
#define pb push_back
#define loop(start,end) for(int i=start;i<end;i++)
#define ll long long int
#define pii pair < int , int >
#define mset(x,v) memset(x, v, sizeof(x)) //search it
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;

int main ()
{
    ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

    int n;cin>>n;
    set<int> a;
    loop(0,n)
    {
        int k;
        cin>>k;
        a.insert(k);
    }
    sort(all(a));
    cout<<*(s.begin()+1);
    return 0;
}


#include<bits/stdc++.h>
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container),element) != container.end())
#define sz(a) int((a).size())
#define pb push_back
#define loop(start,end) for(int i=start;i<end;i++)
#define ll long long int
#define pii pair < int , int >
#define mset(x,v) memset(x, v, sizeof(x)) //search it
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;

int main ()
{
    ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

    int n;cin>>n;
    set<int> a;
    loop(0,n)
    {
        int k;
        cin>>k;
        a.insert(k);
    }
    sort(all(a));
    cout<<*(a.begin()+1);
    return 0;
}


#include<bits/stdc++.h>
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container),element) != container.end())
#define sz(a) int((a).size())
#define pb push_back
#define loop(start,end) for(int i=start;i<end;i++)
#define ll long long int
#define pii pair < int , int >
#define mset(x,v) memset(x, v, sizeof(x)) //search it
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;

int main ()
{
    ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

    int n;cin>>n;
    set<int> a;
    loop(0,n)
    {
        int k;
        cin>>k;
        a.insert(k);
    }
    if(int(a.size())!=1)
    { set<int>::iterator it=a.begin();it++;
    cout<<*it;}
    else
    cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container),element) != container.end())
#define sz(a) int((a).size())
#define pb push_back
#define loop(start,end) for(int i=start;i<end;i++)
#define ll long long int
#define pii pair < int , int >
#define mset(x,v) memset(x, v, sizeof(x)) //search it
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;

int main ()
{
    ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

    int n;cin>>n;
    set<int> a;
    loop(0,n)
    {
        int k;
        cin>>k;
        a.insert(k);
    }
    set<int>::iterator it=a.begin();it++;
    cout<<*it;
    return 0;
}


#include<bits/stdc++.h>
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container),element) != container.end())
#define sz(a) int((a).size())
#define pb push_back
#define loop(start,end) for(int i=start;i<end;i++)
#define ll long long int
#define pii pair < int , int >
#define mset(x,v) memset(x, v, sizeof(x)) //search it
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;

int main ()
{
    ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

    int n;cin>>n;
    set<int> a;
    loop(0,n)
    {
        int k;
        cin>>k;
        a.insert(k);
    }
    if(int(a.size())!=1)
    { set<int>::iterator it=a.begin();it++;
    cout<<*it;}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
set<int> s;
int main(){
    int n;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        s.insert(t);
    }
    auto it=s.begin();
    s.erase(s.begin());
    if(s.empty()){
        cout<<"NO"<<endl;
        return 0;
    }

    cout<<*it<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
set<int> s;
int main(){
    int n;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        s.insert(t);
    }

    s.erase(s.begin());
    if(s.empty()){
        cout<<"NO"<<endl;
        return 0;
    }

    cout<<*s.begin()<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n+1],i;
    for (i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    i=1;
    int fxt;
    fxt=a[1];
    while (i<n)
    {
        i++;
        if (a[i]!=fxt)
        {
            cout<<a[i]<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
set<int> s;
int main(){
    int n;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        s.insert(t);
    }
    auto it=s.begin();
    s.erase(s.begin())
    if(s.empty()){
        cout<<"NO"<<endl;
        return 0;
    }

    cout<<*it<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
set<int> s;
int main(){
    int n;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        s.insert(t);
    }
    auto it=s.begin();
    if(s.size()==1){
        cout<<"NO"<<endl;
        return 0;
    }
    it++;
    cout<<*it<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
set<int> s;
int main(){
    int n;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        s.insert(t);
    }
    auto it=s.begin();
    if(s.size()<=1){
        cout<<"NO"<<endl;
        return 0;
    }
    it++;
    cout<<*it<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
set<int> s;
int main(){
    int n;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        s.insert(t);
    }
    auto it=s.begin();
    if(s.empty()){
        cout<<"NO"<<endl;
        return 0;
    }

    cout<<*it<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,b=0;
	cin>>n;
	vector<int> v1;
	for(int i=0;i<n;i++)
	{	int input;
	cin>>input;
	v1.push_back(input);}
	sort(v1.begin(),v1.end());
	if(n>1){

	for(int i=0;i<n;i++){
	if(v1.at(i)>v1.at(0)){
		cout<<v1.at(i);
		break;
	}
	}}
	else
	cout<<"NO"<<endl;
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,b=0;
	cin>>n;
	vector<int> v1;
	for(int i=0;i<n;i++)
	{	int input;
	cin>>input;
	v1.push_back(input);}
	sort(v1.begin(),v1.end());
	for(int i=0;i<n;i++){
		if(v1.at(i)<v1.at(i+1)){
			b=b+1;
		}
		if(b==1){
			cout<<v1.at(i+1)<<endl;
			break;
		}
	}
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,b=0;
	cin>>n;
	vector<int> v1;
	for(int i=0;i<n;i++)
	{	int input;
	cin>>input;
	v1.push_back(input);}
	sort(v1.begin(),v1.end());
	if(n>1){

	for(int i=0;i<n;i++){
	if(v1.at(i)>v1.at(0)){
		cout<<v1.at(i);
		break;
	}
	else if(i=n-1){
		cout<<"NO"<<endl;
	}
	}}
	else
	cout<<"NO"<<endl;
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,b=0;
	cin>>n;
	vector<int> v1;
	for(int i=0;i<n;i++)
	{	int input;
	cin>>input;
	v1.push_back(input);}
	sort(v1.begin(),v1.end());
	for(int i=0;i<n;i++){
	if(v1.at(i)>v1.at(0)){
		cout<<v1.at(i);
		break;
	}
	}
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,b=0;
	cin>>n;
	vector<int> v1;
	for(int i=0;i<n;i++)
	{	int input;
	cin>>input;
	v1.push_back(input);}
	sort(v1.begin(),v1.end());
    unique(v1.begin(),v1.end());
    cout<<v1.at(1)<<endl;
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,b=0;
	cin>>n;
	vector<int> v1;
	for(int i=0;i<n;i++)
	{	int input;
	cin>>input;
	v1.push_back(input);}
	sort(v1.begin(),v1.end());
	if(n>1){

	for(int i=0;i<n;i++){
	if(v1.at(i)>v1.at(0)){
		cout<<v1.at(i);
		break;
	}
	else if(i==n-1){
		cout<<"NO"<<endl;
	}
	}}
	else
	cout<<"NO"<<endl;
	return 0;

}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;

#define MOD 1000000007

#define sz(v) ((int)v.size())
#define sqr(x) ((x) * (x))

#define rep(i, n) for (int i = 0; i < n; ++i)

#define fi first
#define se second
#define mp make_pair

#define pb push_back
#define eb emplace_back
int main() {
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	int m1 = 200, m2 = 200;
	rep(i, n) {
		int v;
		cin >> v;
		if (v <= m1) m2 = m1, m1 = v;
		else if (v < m2) m2 = v;
	}
	cout << m2 << "\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;

#define MOD 1000000007

#define sz(v) ((int)v.size())
#define sqr(x) ((x) * (x))

#define rep(i, n) for (int i = 0; i < n; ++i)

#define fi first
#define se second
#define mp make_pair

#define pb push_back
#define eb emplace_back
int a[201];
int main() {
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	int m1 = 200, m2 = 200;
	rep(i, n) {
		int v;
		cin >> v;
		if (v < m1) m2 = m1, m1 = v;
		else if (v != m1 && v < m2) m2 = v;
	}
	cout << m2 << "\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;

#define MOD 1000000007

#define sz(v) ((int)v.size())
#define sqr(x) ((x) * (x))

#define rep(i, n) for (int i = 0; i < n; ++i)

#define fi first
#define se second
#define mp make_pair

#define pb push_back
#define eb emplace_back
bool a[211];
int main() {
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	rep(i, n) {
		int v;
		cin >> v;
		a[v + 100] = 1;
	}
	int ctr = 0;
	rep(i, 205) {
		ctr += a[i];
		if (ctr == 2) {
			cout << i - 100 << "\n";
			return 0;
		}
	}
	cout << "NO\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;

#define MOD 1000000007

#define sz(v) ((int)v.size())
#define sqr(x) ((x) * (x))

#define rep(i, n) for (int i = 0; i < n; ++i)

#define fi first
#define se second
#define mp make_pair

#define pb push_back
#define eb emplace_back
int main() {
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	int m1 = 200, m2 = 200;
	rep(i, n) {
		int v;
		cin >> v;
		if (v < m1) m1 = v;
		else if (v < m2) m2 = v;
	}
	cout << m2 << "\n";
	return 0;
}