for _ in range(int(input())):
    n=input()
    c0 = n.count("0")
    c1 = n.count("1")
    if c0 ==1 or c1 == 1:
        print("DA")
    elif c1 == 0 or c0 == 0 :
        print("NET")
    else:
        print("NET")


for _ in range(int(input())):
    n=input()
    c0 = n.count("0")
    c1 = n.count("1")
    if c0 ==1 and c1 == 1:
        print("DA")
    elif c1 == 0 or c0 == 0 :
        print("NET")
    else:
        if min(c0, c1)%2 == 1:
            print("DA")
        else:
            print("NET")


for _ in range(int(input())):
    n=input()
    c0 = n.count("0")
    c1 = n.count("1")
    if c0 ==1 or c1 == 1:
        print("DA")
    elif c1 == 0 or c0 == 0 :
        print("NET")
    else:
        if min(c0, c1)%2 == 1:
            print("DA")
        else:
            print("NET")


for _ in range(int(input())):
s = input()
print('DA' if min(s.count('0'), s.count('1')) % 2 == 1 else 'NET')


for _ in range(int(input())):
	s = input()
	print('DA' if min(s.count('0'), s.count('1')) % 2 == 1 else 'NET')


for _ in range(int(input())):
	s = input()
print('DA' if min(s.count('0'), s.count('1')) % 2 == 1 else 'NET')


t=int(input())
for i in range(t):
    s=input()
    if min(s.count('0'),s.count('1'))%2!=0:
        print("DA")
    else:
        print("NET")


t=int(input())
for i in range(t):
    s=input()
    if len(set(s))==1:
        print("NET")
    else:
        l=list(s)
        j=0
        c=0
        while(len(set(l))>1):
            if l[j]!=l[j+1]:
                del l[j:j+2]
                j=j-2
                c+=1
            j+=1
#         print(c)
        if c%2!=0:
            print("DA")
        else:
            print("NET")


t=int(input())
for i in range(t):
    s=input()
    n=len(s)
    c=0
    i=0
    for i in range(n):
        if i<len(s)-1:
            if s[i]!=s[i+1]:
                s=s[:i]+s[i+2:]
                c+=1
    if c==0:
        print("DA")
    elif c%2==0:
        print("DA")
    else:
        print("NET")


t=int(input())
for i in range(t):
    s=input()
    n=len(s)
    c=0
    i=0
    for i in range(n):
        if i<len(s)-1:
            if s[i]!=s[i+1]:
                s=s[:i]+s[i+2:]
                c+=1
    if c==0:
        print("NET")
    elif c%2==0:
        print("DA")
    else:
        print("NET")


t=int(input())
for i in range(t):
    s=input()
    n=len(s)
    c=0
    i=0
    for i in range(n):
        if i<len(s)-1:
            if s[i]!=s[i+1]:
                s=s[:i]+s[i+2:]
                c+=1
    if c%2==0:
        print("DA")
    else:
        print("NET")


for _ in range(int(input())):
    a = 1
    a = input()
    counter1 = a.count('1')
    counter0 = a.count('0')
    if counter0 == 0 or counter1 == 0:
        print('NET')
    elif (len(a) - counter1) % 2 ==0:
        print('NET')
    else: print('DA')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    if len(a) % 2 == 0:
        if counter1  % 2 ==0:
            print('NET')
        else: print('DA')


for _ in range(int(input())):
    a = input()
    counter = a.count('1')
    if len(a) // 2 < counter % 2 == 0 :
        print('NET')
    else: print('DA')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    even = True
    if len(a) % 2 != 0 :
        even = False
    if counter1 == len(a) or counter1 == 0:
        print('NET')
        continue
    if counter1 % 2 == 0:
            print('NET')
    else: print ('DA')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    counter0 = a.count('0')
    if len(a) % 2 == 0:
        if counter1 % 2 == 0:
            print('NET')
        else: print('DA')
    else:
        if counter1 % 2 != 0:
            print('NET')
        else: print('DA')


for _ in range(int(input())):
    a = input()
    counter = a.count('1')
    if (len(a) - counter) % 2 ==0:
        print('NET')
    else: print('DA')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    counter1 = a.count('0')
    if len(a) % 2 == 0:
        if counter1  % 2 ==0 and counter1 == counter0:
            print('NET')
        else: print('DA')


for _ in range(int(input())):
    a = 1
    a = input()
    counter1 = a.count('1')
    counter0 = a.count('0')
    if counter0 == 0 or counter1 == 0:
        print('NET')
    elif len(a) - counter1 % 2 ==0:
        print('NET')
    else: print('YES')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    counter0 = a.count('0')
    if (counter1 - counter0) % 2 == 0:
        print('NET')
    else: print('DA')


for _ in range(int(input())):
    a = input()
    a = 1
    counter1 = a.count('1')
    counter0 = a.count('0')
    if counter0 == 0 or counter1 == 0:
        print('NET')
    elif len(a) - counter1 % 2 ==0:
        print('NET')
    else: print('YES')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    counter0 = a.count('0')
    if counter0 == 0 or counter1 == 0:
        print('NET')
    elif counter1 > counter0:
        print('NET')
    else: print('DA')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    counter0 = a.count('0')
    if counter0 == len(a) or counter1 == len(a):
        print('NET')
    elif len(a) - counter1 % 2 ==0:
        if counter1 % 2 != 0:
            print('DA')
        else: print('NET')


for _ in range(int(input())):
    a = input()
    counter = a.count('1')
    if counter % 2 ==0:
        print('NET')
    else: print('DA')


for _ in range(int(input())):
    a = input()
    counter = a.count('1')
    if len(a) - counter % 2 ==0:
        print('NET')
    else: print('DA')


for _ in range(int(input())):
    a = input()
    counter = a.count('1')
    if (len(a) - counter) < len(a):
        print('NET')
    else: print('DA')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    counter0 = a.count('0')
    if len(a) - counter1 % 2 ==0:
        if counter1 % 2 != 0:
            print('DA')
        else: print('NET')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    counter0 = a.count('0')
    if counter0 == len(a) or counter1 == len(a):
        print('NET')
    elif len(a) - counter1 % 2 ==0:
        if counter1 % 2 != 0:
            print('DA')
        else: print('NET')
    elif len(a) - counter1 % 2 !=0:
        if counter1 % 2 != 0:
            print('NET')
        else: print('DA')


for _ in range(int(input())):
    a = input()
    counter = a.count('1')
    if (len(a) - counter) % 2 == 0 :
        print('NET')
    else: print('DA')


for _ in range(int(input())):
    a = input()
    counter = a.count('1')
    if len(a) == counter:
        print('NET')
    elif (len(a) - counter) % 2 ==0:
        print('NET')
    else: print('DA')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    counter0 = a.count('0')
    if counter0 == len(a) or counter1 == len(a):
        print('NeT')
    elif len(a) - counter1 % 2 ==0:
        if counter1 % 2 != 0:
            print('DA')
        else: print('NET')


for _ in range(int(input())):
    a = input()
    counter = a.count('1')
    if len(a) // 2 <= counter:
        print('NET')
    else: print('DA')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    counter0 = a.count('0')
    if counter1 == len(a) or counter1 == 0:
        print('NET')
        continue
    if min(counter1,counter0) % 2 == 0:
        print('NET')
    else: print ('DA')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    counter0 = a.count('0')
    if counter0 == 0 or counter1 == 0:
        print('NET')
    elif len(a) - counter1 % 2 ==0:
        print('NET')
    else: print('YES')


for _ in range(int(input())):
    a = input()
    counter = a.count('1')
    if len(a) == counter:
        print('NET')
    elif counter % 2 ==0:
        print('NET')
    else: print('DA')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    counter0 = a.count('0')
    if counter1 % 2 == 0:
        print('NET')
    else: print('DA')


for _ in range(int(input())):
    a = input()
    counter = a.count('1')
    if counter % 2 == 0 :
        print('NET')
    else: print('DA')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    even = True
    if len(a) % 2 != 0 :
        even = False
    if counter1 == len(a) or counter1 == 0:
        print('NET')
        continue
    if counter1 % 2 == 0:
        if even:
            print('NET')
        else: print ('DA')
    else:
        if even:
            print('DA')
        else: print ('NET')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    even = True
    if len(a) % 2 != 0 :
        even = False
    if counter1 % 2 == 0:
        if even:
            print('NET')
        else: print ('DA')
    else:
        if even:
            print('DA')
        else: print ('NET')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    if counter1 % 2 == 0:
        print('NET')
    else: print('DA')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    counter0 = a.count('0')
    if counter0 == 0 or counter1 == 0:
        print('NET')
    elif counter1 % 2 == 0:
        print('NET')
    else: print('DA')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    counter1 = a.count('0')
    if len(a) % 2 == 0:
        if counter1  % 2 ==0 and counter1 == counter0 :
            print('NET')
        else: print('DA')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    counter0 = a.count('0')
    if len(a) % 2 == 0:
        if counter1  % 2 ==0 and counter1 == counter0 :
            print('NET')
        else: print('DA')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    if counter1 % 2 == 0:
        print('DA')
    else: print('NET')


for _ in range(int(input())):
    a = input()
    counter = a.count('1')
    if len(a) // 2 < counter:
        print('NET')
    else: print('DA')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    counter0 = a.count('0')
    if counter1 % 2 == 0:
        print('DA')
    else: print('NET')


for _ in range(int(input())):
    a = input()
    counter1 = a.count('1')
    counter0 = a.count('0')
    if counter0 == len(a) or counter1 == len(a):
        print('NET')
    elif len(a) - counter1 % 2 ==0:
        if counter1 % 2 != 0:
            print('DA')
        else print('NEET')
    elif len(a) - counter1 % 2 !=0:
        if counter1 % 2 != 0:
            print('NET')
        else print('DA')


for _ in range(int(input())):
    a = input()
    counter = a.count('1')
    if counter == 0 or  counter == len(a):
        print('NET')
    elif (len(a) - counter) % 2 == 0 :
        print('NET')
    else: print('DA')


for _ in range(int(input())):
    x=input()
    c=0
    for i in range(len(x)//2+1):
        if '01' in x or '10' in x:
            c+=1
    if c%2==0:
        print('NET')

    else:
        print('DA')


for _ in range(int(input())):
    x=input()
    a=len(x)/2
    if a%2==0:
        print('NET')
    else:
        print('DA')


for _ in range(int(input())):
    x=input()
    c=0
    for i in range(len(x)//2):
        if '01' in x:
            c+=1
        if '10' in x:
            c+=1
    if c%2==0:
        print('NET')

    else:
        print('DA')


for _ in range(int(input())):
    s=input()
    ans='b'
    flag=True
    while(s and flag):
        for i in range(len(s)-1):
            if(s[i]!=s[i+1]):
                s=s[:i]+s[i+2:]
                if(ans=='b'):
                    ans='a'
                else:
                    ans='b'
                break
            else:
                continue
        else:
            flag=False
    if(ans=='a'):
        print('DA')
    else:
        print("NET")


for _ in range(int(input())):
    x=input()
    a=len(x)%2
    if a%2==0:
        print('NET')
    else:
        print('DA')


def helper(n):
    i=0
    pairs=0
    if len(n)==2:
        print('DA')
        return
    while i<len(n)-1:
        if n[i]==n[i+1]:
            i+=1
        elif n[i]!=n[i+1]:
            n.replace(n[i],'')
            n.replace(n[i+1],'')
            i+=2
            pairs+=1

    if pairs%2==0:
        print('NET')
    else:
        print('DA')
for _ in range(int(input())):
    n=input()

    helper(n)


def helper(n):
    pairs=0
    # if len(n)<=2:
    #     return
    z=0
    o=0
    for i in n:
        if i=='0':
            z+=1
        else:
            o+=1
    if len(n)==2:
        if z==o:
            print('DA')
            return
        else:
            print('NET')
            return
    elif z==0 or o==0:
        print('NET')
    elif z==o:
        print('NET')
    elif z>o:
        if o%2==0:
            print('NET')
        else:
            print("DA")
    elif o>z:
        if z%2==0:
            print('NET')
        else:
            print('DA')
for _ in range(int(input())):
    n=input()

    pairs=helper(n)
    # print(pairs)


for _ in range(int(input())):
    n=input()

    i=0
    pairs=0
    if len(n)==2:
        print('DA')
    while i<len(n)-1:
        if n[i]==n[i+1]:
            i+=1
        elif n[i]!=n[i+1]:
            n.replace(n[i],'')
            n.replace(n[i+1],'')
            i+=2
            pairs+=1

    elif pairs%2==0:
        print('NET')
    else:
        print('DA')


def helper(n):
    pairs=0
    # if len(n)<=2:
    #     return
    z=0
    o=0
    for i in n:
        if i=='0':
            z+=1
        else:
            o+=1
    if len(n)==2:
        if z==o:
            print('DA')
            return
        else:
            print('NET')
            return
    elif z==o:
        print('NET')
    elif z>o:
        pairs=z-o
        if pairs%2==0:
            print('NET')
        else:
            print('DA')
    elif o>z:
        pairs=o-z
        if pairs%2==0:
            print('NET')
        else:
            print('DA')
for _ in range(int(input())):
    n=input()

    pairs=helper(n)
    # print(pairs)


def helper(n):
    i=0
    pairs=0

    z=0
    o=0
    for i in n:
        if i=='0':
            z+=1
        else:
            o+=1
    if len(n)==2:
        if z==o:
            print('DA')
        else:
            print('NET')
    elif z-o<=0:
        print('NET')
    else:
        print('DA')

    # if pairs%2==0:
    #     print('p',pairs)
    #     print('NET')
    # else:
    #     print('p',pairs)
    #     print('DA')
for _ in range(int(input())):
    n=input()

    helper(n)


for _ in range(int(input())):
    n=input()
    if len(n)==2:
        print('DA')
    elif len(n)%2==0:
        print('NET')
    else:
        print('DA')


def helper(n):
    i=0
    pairs=0

    z=0
    o=0
    for i in n:
        if i=='0':
            z+=1
        else:
            o+=1
    if len(n)==2:
        if z==o:
            print('DA')
        else:
            print('NET')
    elif z-o<=0:
        print('NET')
    elif o-z<=0:
        print('NET')
    else:
        print('DA')

    # if pairs%2==0:
    #     print('p',pairs)
    #     print('NET')
    # else:
    #     print('p',pairs)
    #     print('DA')
for _ in range(int(input())):
    n=input()

    helper(n)


def helper(n):
    pairs=0
    # if len(n)<=2:
    #     return
    z=0
    o=0
    for i in n:
        if i=='0':
            z+=1
        else:
            o+=1
    if len(n)==2:
        if z==o:
            print('DA')
            return
        else:
            print('NET')
            return
    elif z==0 or o==0:
        print('NET')
    elif z==o:
        print('NET')
    elif z>o:
        pairs=z-o
        if pairs%2==0:
            print('NET')
        else:
            print('DA')
    elif o>z:
        pairs=o-z
        if pairs%2==0:
            print('NET')
        else:
            print('DA')
for _ in range(int(input())):
    n=input()

    pairs=helper(n)
    # print(pairs)


for _ in range(int(input())):
    n=input()

    i=0
    pairs=0
    if len(n)==2:
        print('DA')
        return
    while i<len(n)-1:
        if n[i]==n[i+1]:
            i+=1
        elif n[i]!=n[i+1]:
            n.replace(n[i],'')
            n.replace(n[i+1],'')
            i+=2
            pairs+=1

    if pairs%2==0:
        print('NET')
    else:
        print('DA')


for _ in range(int(input())):
    n=input()

    i=0
    pairs=0
    if len(n)==2:
        print('DA')
    while i<len(n)-1:
        if n[i]==n[i+1]:
            i+=1
        elif n[i]!=n[i+1]:
            n.replace(n[i],'')
            n.replace(n[i+1],'')
            i+=2
            pairs+=1

    if pairs%2==0:
        print('NET')
    else:
        print('DA')


t=int(input())
for i in range(t):
    a,b,c=map(int,input().split())
    if c<=a:
        aans=-1
        bans=b
    elif c/b==a:
        bans=-1
        aans=1
    elif a>c/b:
        aans=1
        bans=b
    elif a<c/b:
        bans=-1
        aans=1
    print(aans,bans)


n=int(input())
for i in range(n):
    a=input()
    nz=a.count("0")
    no=a.count("1")
    if min(nz,no)%2==1:
        print("DA")
    else:
        print("NET")


for i in range(int(input())):
	s=input()
	i=0
	c=0
	c1=s.count("1")
	c2=s.count("0")
	if min(c1,c2)==0:
		print("NET")
	elif min(c1,c2)%2==0:
		print("NET")
	else:
		print("DA")


def isadjdiff(l, ind):
    if ind < len(l)-1:
        if l[ind]==0 and l[ind+1]==1: return True
        if l[ind]==1 and l[ind+1]==0: return True

    else: return False

def makedigitlist(N):
    temp=[int(x) for x in str(N)]
    return (str(temp))

T=int(input())
for i in range(T):
    num=str(input())
    arr=[int(x) for x in num]
    i=0
    count=0
    while(len(arr)>0):
        if isadjdiff(arr, i)==True:
            arr.pop(i)
            arr.pop(i)
            i=0
            print(arr)
            count+=1
        else: i+=1
        if(i==len(arr)): break

    if(count%2==0): print("NET")
    else: print("DA")


def isadjdiff(l, ind):
    if ind < len(l)-1:
        if l[ind]==0 and l[ind+1]==1: return True
        if l[ind]==1 and l[ind+1]==0: return True

    else: return False
T=int(input())
for i in range(T):
    arr=list(map(int, input().split()))
    i=0
    count=0
    while(len(arr)>0):
        if isadjdiff(arr, i)==True:
            arr.pop(i)
            arr.pop(i)
            i=0
            count+=1
        else: i+=1
        if(i==len(arr)): break

    if(count%2==0): print("NET")
    else: print("DA")


def isadjdiff(l, ind):
    if ind < len(l)-1:
        if l[ind]==0 and l[ind+1]==1: return True
        if l[ind]==1 and l[ind+1]==0: return True

    else: return False

def makedigitlist(N):
    temp=[int(x) for x in str(N)]
    return (str(temp))

T=int(input())
for i in range(T):
    num=str(input())
    arr=[int(x) for x in num]
    i=0
    count=0
    while(len(arr)>0):
        if isadjdiff(arr, i)==True:
            arr.pop(i)
            arr.pop(i)
            i=0
            count+=1
        else: i+=1
        if(i==len(arr)): break

    if(count%2==0): print("NET")
    else: print("DA")


# input = open('file.txt').readline

for _ in range( int(input()) ):

  ss = list( map( int , list(input().strip()) ) )
  n = len(ss)
  i , j = 0 , 1

  if n == 1:
    print('NET')
    continue

  cnt = 0
  stck = [ ss[0] ]
  i = 1

  while i < n:

    if stck:
      bc = stck.pop()
    else:
      bc = ss[i]
      i += 1

    if i < n and ss[i] != bc:

      cnt += 1
      i += 1

      while stck and i < n:
        bc = stck.pop()
        ff = ss[i]

        if bc != ff:
          cnt += 1

        else:
          stck.append( bc )
          stck.append(ff)
          break

        i += 1

    else:
      stck.append( bc )
      stck.append( ss[i] )
      i += 1

  if cnt % 2 == 0:
    print('NET')
  else:
    print('DA')

  # print(cnt)


# input = open('file.txt').readline

def play(ss):

  n = len(ss)
  i = 0
  ns = []

  while i < n-1:

    if ss[i] != ss[i+1]:
      i += 2
      while i < n:
        ns.append( ss[i] )
        i += 1

      return ns

    else:
      ns.append( ss[i] )

    i += 1

  return False

for _ in range( int(input()) ):

  ss = list( map( int , list(input().strip()) ) )
  n = len(ss)
  i , j = 0 , 1

  if n == 1:
    print('NET')
    continue

  cnt = 0
  stck = [ ss[0] ]
  i = 1

  while True:
    ns = play(ss)
    if ns != False:
      cnt += 1
    else:
      break

    ss = ns

  if cnt % 2 == 0:
    print('NET')
  else:
    print('DA')

  # print(cnt)


#include <bits/stdc++.h>

using namespace std;

const int maxn = (int)(1e5 + 123);
const int inf = (int)(1e9 + 7);

int n, a[maxn], k, t[2][4 * maxn], e[maxn], o[maxn];

void update(int v, int l, int r, int pos, int x, int k){
    if(l == r){
        t[k][v] = x;
        return;
    }
    int m = (l + r) / 2;
    if(m >= pos) update(2 * v, l, m, pos, x, k);
    else update(2 * v + 1, m + 1, r, pos, x, k);
    if(k) t[k][v] = min(t[k][2 * v], t[k][2 * v + 1]);
    else t[k][v] = max(t[k][2 * v], t[k][2 * v + 1]);
}

int getmin(int v, int l, int r, int al, int ar, int k){
    if(al > r || ar < l) return inf;
    if(l >= al && r <= ar) return t[k][v];
    int m = (l + r) / 2;
    return min(getmin(2 * v, l, m, al, ar, k), getmin(2 * v + 1, m + 1, r, al, ar, k));
}

int getmax(int v, int l, int r, int al, int ar, int k){
    if(al > r || ar < l) return -inf;
    if(l >= al && r <= ar) return t[k][v];
    int m = (l + r) / 2;
    return max(getmax(2 * v, l, m, al, ar, k), getmax(2 * v + 1, m + 1, r, al, ar, k));
}

int main(){
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    for(int i = 2; i <= n; ++i){
        e[i] = max(a[i], a[i - 1]);
        update(1, 1, n, i, e[i], 0);
    }
    for(int i = 2; i < n; ++i){
        o[i] = max(min(a[i + 1], a[i]), min(a[i], a[i - 1]));
        update(1, 1, n, i, o[i], 1);
    }
    for(int k = 0; k < n - 1; ++k){
        if((n - k) % 2){
            //cout << k << " " << (n - k) / 2 + 1 << " " << (n - k) / 2 + 1 + k << endl;
            cout << getmax(1, 1, n, (n - k) / 2 + 1, (n - k) / 2 + 1 + k, 1) << " ";
        } else {
            int l = k + 1, r = n - k;
            cout << getmax(1, 1, n, (n - k) / 2 + 1, (n - k) / 2 + k + 1, 0) << " ";
        }
    }
    sort(a + 1, a + n + 1);
    cout << a[n];
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = (int)(3e5 + 123);
const int inf = (int)(1e9 + 7);

int n, a[maxn], k, t[2][4 * maxn], e[maxn], o[maxn];

void update(int v, int l, int r, int pos, int x, int k){
    if(l == r){
        t[k][v] = x;
        return;
    }
    int m = (l + r) / 2;
    if(m >= pos) update(2 * v, l, m, pos, x, k);
    else update(2 * v + 1, m + 1, r, pos, x, k);
    if(k) t[k][v] = min(t[k][2 * v], t[k][2 * v + 1]);
    t[k][v] = max(t[k][2 * v], t[k][2 * v + 1]);
}

int getmin(int v, int l, int r, int al, int ar, int k){
    if(al > r || ar < l) return inf;
    if(l >= al && r <= ar) return t[k][v];
    int m = (l + r) / 2;
    return min(getmin(2 * v, l, m, al, ar, k), getmin(2 * v + 1, m + 1, r, al, ar, k));
}

int getmax(int v, int l, int r, int al, int ar, int k){
    if(al > r || ar < l) return -inf;
    if(l >= al && r <= ar){
            //cout << t[k][v] << " " << l << " " << r << endl;
            return t[k][v];
    }
    int m = (l + r) / 2;
    return max(getmax(2 * v, l, m, al, ar, k), getmax(2 * v + 1, m + 1, r, al, ar, k));
}

int main(){
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    for(int i = 2; i <= n; ++i){
        e[i] = max(a[i], a[i - 1]);
        update(1, 1, n, i, e[i], 0);
    }
    for(int i = 2; i < n; ++i){
        o[i] = max(min(a[i + 1], a[i]), min(a[i], a[i - 1]));
        update(1, 1, n, i, o[i], 1);
    }
    for(int k = 0; k < n - 1; ++k){
        if((n - k) % 2){
            //if(k == 15) cout << (n - k) / 2 + 1 << " " << (n - k) / 2 + 1 + k << endl;
            cout << getmax(1, 1, n, (n - k) / 2 + 1, (n - k) / 2 + 1 + k, 1) << "\n";
        } else {
            cout << getmax(1, 1, n, (n - k) / 2 + 1, (n - k) / 2 + k + 1, 0) << "\n";
        }
    }
    sort(a + 1, a + n + 1);
    cout << a[n];
    return 0;
}


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

const int MN = 300010;

int N;
int A[MN], mx1, mx2;

void add(int l, int r) {
    int n = (r - l + 1);
    int m = (l + r)>>1;
    if(n % 2) {
        mx1 = max(mx1, min(A[m], A[m - 1]));
        mx1 = max(mx1, min(A[m], A[m + 1]));
    }
    else {
        mx2 = max(mx2, max(A[m], A[m + 1]));
    }
}

int main() {
    scanf("%d", &N);

    for(int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }

    for(int i = 0; i < N - 1; i++) {
        add(0, N - 1 - i);
        add(i, N - 1);

        if((N - i) % 2) printf("%d ", mx1);
        else printf("%d ", mx2);
    }
    int mx = 0;
    for(int i = 0; i < N; i++) mx = max(mx, A[i]);
    printf("%d", mx);
}


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

const int MN = 300010;

int N;
int A[MN], mx1, mx2;

void add(int l, int r) {
    int n = (r - l + 1);
    int m = (l + r)>>1;
    if(n % 2) {
        if(n == 1) {
            mx1 = max(mx1, A[m]);
        }
        else {
            mx1 = max(mx1, min(A[m], A[m - 1]));
            mx1 = max(mx1, min(A[m], A[m + 1]));
        }
    }
    else {
        mx2 = max(mx2, max(A[m], A[m + 1]));
    }
}

int main() {
    scanf("%d", &N);

    for(int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }

    for(int i = 0; i < N; i++) {
        add(0, N - i - 1);
        add(i, N - 1);

        if((N - i) % 2) printf("%d ", mx1);
        else printf("%d ", mx2);
    }
}


#include<bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define ll long long
using namespace std;
typedef pair<int,pair<int,int> > pii;
pii p[300010];
int n,a[300010];
int eval(int x,int y){

    if(n%2){
        if(y==n/2+1)return 0;

        if(y<n/2+1)return n-y*2;
        else {
            y=n-y+1;
            return n-y*2;
        }
    }
    else{
        if(y==n/2+1)return 0;
        if(y==n/2)return 0;

        if(y<n/2)return n-y*2;
        else {
            y=n-y+1;
            return n-y*2;
        }
    }

}
int main(){

    ///freopen("test.txt","r",stdin);

    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        p[i]={eval(a[i],i),{a[i],max(min(a[i],a[i-1]),min(a[i],a[i+1]))} };
    }

    sort(p+1,p+n+1);

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

        while(p[curr+1].ff<=i && curr<n){
            curr++;
            rez=max(rez,p[curr].ss.ff);
            rez2=max(rez2,p[curr].ss.ss);
        }

        int left=n-i;
        if(left==1)printf("%d ",rez);
        else if(left%2)printf("%d ",rez2);
        else printf("%d ",rez);
    }

    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define ll long long
using namespace std;
typedef pair<int,pair<int,int> > pii;
pii p[300010];
int n,a[300010];
int eval(int x,int y){

    if(n%2){
        if(y==n/2+1)return 0;

        if(y<n/2+1)return n-y*2;
        else {
            y=n-y+1;
            return n-y*2;
        }
    }
    else{
        if(y==n/2+1)return 0;
        if(y==n/2)return 0;

        if(y<n/2)return n-y*2;
        else {
            y=n-y+1;
            return n-y*2;
        }
    }

}
int main(){

    ///freopen("test.txt","r",stdin);

    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    a[0]=2e9;
    a[n+1]=2e9;
    for(int i=1;i<=n;i++)
        p[i]={eval(a[i],i),{a[i],max(min(a[i],a[i-1]),min(a[i],a[i+1]))} };

    sort(p+1,p+n+1);

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

        while(p[curr+1].ff<=i && curr<n){
            curr++;
            rez=max(rez,p[curr].ss.ff);
            rez2=max(rez2,p[curr].ss.ss);
        }

        int left=n-i;
        if(left==1)printf("%d ",rez);
        else if(left%2)printf("%d ",rez2);
        else printf("%d ",rez);
    }

    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define ll long long
using namespace std;
typedef pair<int,int> pii;
pii p[300010];
int n;
int eval(int x,int y){

    if(n%2){
        if(y==n/2+1)return 0;

        if(y<n/2+1)return n-y*2;
        else {
            y=n-y+1;
            return n-y*2;
        }
    }
    else{
        if(y==n/2+1)return 0;
        if(y==n/2)return 0;

        if(y<n/2)return n-y*2;
        else {
            y=n-y+1;
            return n-y*2;
        }
    }

}
int main(){

    ///freopen("test.txt","r",stdin);

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

    sort(p+1,p+n+1);

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

        while(p[curr+1].ff<=i && curr<n){
            curr++;
            rez=max(rez,p[curr].ss);
        }

        printf("%d ",rez);
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

namespace io{
	const int L=(1<<19)+1;
	char ibuf[L],*iS,*iT,obuf[L],*oS=obuf,*oT=obuf+L-1,c,st[55];int f,tp;
	char gc(){
		if(iS==iT){
			iT=(iS=ibuf)+fread(ibuf,1,L,stdin);
			return iS==iT?EOF:*iS++;
		}
		return*iS++;
	}
	void cbuf(){fwrite(obuf,1,oS-obuf,stdout);oS=obuf;}
	void putc(char x){*oS++=x;if(oS==oT)cbuf();}
	void gs(char*s){
		for(c=gc();c>'z'||c<'a';c=gc());
		for(;c>='a'&&c<='z';c=gc())*s++=c;
	}
	template<class I>void gi(I&x){
		for(f=1,c=gc();c<'0'||c>'9';c=gc())if(c=='-')f=-1;
		for(x=0;c<='9'&&c>='0';c=gc())x=x*10+(c&15);x*=f;
	}
	void ps(char*s){while(*s)putc(*s++);}
	template<class I>void print(I x){
		if(!x)putc('0');if(x<0)putc('-'),x=-x;
		while(x)st[++tp]=x%10+'0',x/=10;
		while(tp)putc(st[tp--]);
	}
	void scan(int l,...){
		va_list scan;
		va_start(scan,l);
		while(l)gi(*va_arg(scan,int*)),l--;
		va_end(scan);
	}
};
using io::putc;
using io::gi;
using io::gs;
using io::ps;
using io::scan;
using io::print;

const int N=300005,M=20;

struct maxst{
	int st[M][N],lg[N],n;
	void init(int*p,int m){
		n=m;memcpy(st[0]+1,p+1,n<<2);
		for(int l=2,i=1;l<=n;l<<=1,i++)for(int j=1;j<=n-l+1;j++)
			st[i][j]=max(st[i-1][j],st[i-1][j+(l>>1)]);
		for(int i=2;i<=n;i++)lg[i]=lg[i-1]+!(i&i-1);
	}
	int ask(int l,int r){
		int d=lg[r-l+1];
		return max(st[d][l],st[d][r-(1<<d)+1]);
	}
}A,B;
int n,a[N],b[N];

int main(){
	gi(n);
	for(int i=1;i<=n;i++)gi(a[i]);
	for(int i=1;i<n;i++)b[i]=min(a[i],a[i+1]);
	A.init(a,n),B.init(b,n-1);
	for(int k=1,ans;k<n;k++){
		int l=n-k+1;
		if(l&1)ans=B.ask(l>>1,n-(l>>1));
		else ans=A.ask(l>>1,n-(l>>1)+1);
		print(ans),putc('\n');
	}
	print(A.ask(1,n)),io::cbuf();
	return 0;
}


//By Don4ick
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qwer1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

const int N = (int)3e5 + 228;
const int LOG = 20;

using namespace std;

int n, a[N], b[N], t1[LOG][N], t2[LOG][N], f[N];

int get1(int l, int r)
{
	return max(t1[f[r - l + 1]][l], t1[f[r - l + 1]][r - (1 << f[r - l + 1]) + 1]);
}

int get2(int l, int r)
{
	return max(t2[f[r - l + 1]][l], t2[f[r - l + 1]][r - (1 << f[r - l + 1]) + 1]);
}

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

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	scanf("%d", &n);
	forn(i, n)
		scanf("%d", &a[i]);
	for (int i = 2; i < n; i++)
		b[i] = max(min(a[i - 1], a[i]), min(a[i], a[i + 1]));
	f[1] = 0;
	for (int i = 2; i < N; i++)
		f[i] = f[i / 2] + 1;
	forn(i, n)
		t1[0][i] = a[i], t2[0][i] = b[i];
	for (int j = 1; j < LOG; j++)
	{
		for (int i = 1; i + (1 << j) - 1 <= n; i++)
		{
			t1[j][i] = max(t1[j - 1][i], t1[j - 1][i + (1 << (j - 1))]);
			t2[j][i] = max(t2[j - 1][i], t2[j - 1][i + (1 << (j - 1))]);
		}
	}
	for (int k = n; k > 1; k--)
	{
		if (k % 2 == 0)
		{
			int l = k / 2;
			int r = n - k / 2 + 1;
			printf("%d ", get1(l, r));
		}
		else
		{
			int l = (k + 1) / 2;
			int r = n - (k + 1) / 2 + 1;
			printf("%d ", get2(l, r));
		}
	}
	printf("%d ", get1(1, n));

	return 0;
}


// Copyright (C) 2017 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>

#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

using std::pair;
using std::vector;
using std::string;

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

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MAXN = 3e5 + 5;
const int LOGN = 19;

int N;
int A[MAXN];

void input()
{
    read(N);
    for (int i = 1; i <= N; ++i) read(A[i]);
}

int LOG2[MAXN];
int f[2][LOGN][MAXN];

inline int getmax(int d, int l, int r)
{
    int k = LOG2[r - l + 1];
    return std::max(f[d][k][l], f[d][k][r - (1 << k) + 1]);
}

void solve()
{
    LOG2[0] = -1;
    for (int i = 1; i <= N; ++i) LOG2[i] = LOG2[i >> 1] + 1;

    for (int i = 1; i <= N; ++i) {
        f[0][0][i] = std::max(A[i], A[i + 1]);
        f[1][0][i] = std::max(std::min(A[i - 1], A[i]), std::min(A[i], A[i + 1]));
    }
    for (int k = 1; (1 << k) <= N; ++k) {
        for (int i = 1; i + (1 << k) - 1 <= N; ++i) {
            int j = i + (1 << (k - 1));
            f[0][k][i] = std::max(f[0][k - 1][i], f[0][k - 1][j]);
            f[1][k][i] = std::max(f[1][k - 1][i], f[1][k - 1][j]);
        }
    }

    for (int i = 0; i < N - 1; ++i) {
        int d = (N - i) & 1;
        int l = N - i - (N - i) / 2;
        int r = i + (N - i) / 2 + d;
        assert(l <= r);
        printf("%d ", getmax(d, l, r));
    }
    printf("%d\n", *std::max_element(A + 1, A + N + 1));
}

int main()
{
#ifdef __DEBUG
    freopen("E.in", "r", stdin);
    freopen("E.out", "w", stdout);
#endif

    input();
    solve();

    return 0;
}

// 纵然禀赋不如 怎甘愿认输
// 纵然天地孑然 无处放声哭


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int a[300001];
int ans[300001];
int b[300001];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	int mx=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		mx=max(mx,a[i]);
	}
	for(int i=0;i<n-2;i++)
	{
		b[i]=min(a[i+1],max(a[i],a[i+2]));
	}
	ans[n-1]=mx;
	int odd=n;int even=n;
	if(n&1) even=n-1;
	else odd=n-1;
	mx=0;
	for(int i=even;i>=2;i-=2)
	{
		int l = (i-1)/2; int r=n-i/2;
		assert(l<=r);
		mx=max(mx,max(a[l],a[r]));
		if(i==even)
		{
			assert(r-l<=2);
			if(r-l==2)
			{
				mx=max(mx,a[l+1]);
			}
		}
		ans[n-i]=mx;
	}
	mx=0;
	for(int i=odd;i>=3;i-=2)
	{
		int l = i/2-1; int r=n-2-i/2;
		assert(l<=r);
		if(i==odd) assert(r-l<=1);
		mx=max(mx,max(b[l],b[r]));
		ans[n-i]=mx;
	}
	for(int i=0;i<n;i++)
	{
		cout<<ans[i];
		if(i<n-1) cout<<' ';
	}
	cout<<'\n';
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <climits>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

#define fast_cin() ios_base::sync_with_stdio(false)

typedef long double ld;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int max_N = 3e5 + 10;
const int l_N = 20;

int inp[max_N];
int neigh[max_N];
int lg[max_N];

struct sparse_table {
	vector< vector<int> > st;

	sparse_table(int *arr, int N);
	int query(int i, int j);
};

int main()
{
	int lg = 0;
	for (int i = 1; i < max_N; ++i) {
		while ((1 << lg) <= i) {
			++lg;
		}
		--lg;
		::lg[i] = lg;
	}

	int N;
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) {
		scanf("%d", inp + i);
	}
	for (int i = 1; i <= N; ++i) {
		neigh[i] = min(inp[i], max(inp[i - 1], inp[i + 1]));
	}
	sparse_table even(inp, N);
	sparse_table odd(neigh, N);

	for (int k = 0; k < N; ++k) {
		int M = N - k;
		if (M == 1) {
			printf("%d ", even.query(1, N));
		} else if (M % 2) {
			int lb = (1 + M - 1) / 2;
			int ub = (N - M + 1 + N) / 2;
			printf("%d ", odd.query(lb, ub));
		} else {
			int lb = (1 + M - 1) / 2;
			int ub = (N - M + 1 + N) / 2 + 1;
			printf("%d ", even.query(lb, ub));
		}
	}
}

sparse_table::sparse_table(int *arr, int N)
	: st(l_N, vector<int>(N + 1, -1))
{
	for (int i = 1; i <= N; ++i) {
		st[0][i] = arr[i];
	}
	for (int j = 1; (1 << j) <= N; ++j) {
		for (int i = 1; i <= N && i + (1 << j) - 1 <= N; ++i) {
			st[j][i] = max(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]);
		}
	}
}

int sparse_table::query(int i, int j)
{
	int k = lg[j - i + 1];
	return max(st[k][i], st[k][j - (1 << k) + 1]);
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <climits>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

#define fast_cin() ios_base::sync_with_stdio(false)

typedef long double ld;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int max_N = 3e5 + 10;
const int l_N = 20;

int inp[max_N];
int neigh[max_N];
int lg[max_N];

struct sparse_table {
	vector< vector<int> > st;

	sparse_table(int *arr, int N);
	int query(int i, int j);
};

int main()
{
	int lg = 0;
	for (int i = 1; i < max_N; ++i) {
		if ((1 << lg) <= i) {
			++lg;
		}
		--lg;
		::lg[i] = lg;
	}

	int N;
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) {
		scanf("%d", inp + i);
	}
	for (int i = 1; i <= N; ++i) {
		neigh[i] = min(inp[i], max(inp[i - 1], inp[i + 1]));
	}
	sparse_table even(inp, N);
	sparse_table odd(neigh, N);

	for (int k = 0; k < N; ++k) {
		int M = N - k;
		if (M == 1) {
			printf("%d ", even.query(1, N));
		} else if (M % 2) {
			int lb = (1 + M - 1) / 2;
			int ub = (N - M + 1 + N) / 2;
			printf("%d ", odd.query(lb, ub));
		} else {
			int lb = (1 + M - 1) / 2;
			int ub = (N - M + 1 + N) / 2 + 1;
			printf("%d ", even.query(lb, ub));
		}
	}
}

sparse_table::sparse_table(int *arr, int N)
	: st(l_N, vector<int>(N + 1, -1))
{
	for (int i = 1; i <= N; ++i) {
		st[0][i] = arr[i];
	}
	for (int j = 1; (1 << j) <= N; ++j) {
		for (int i = 1; i <= N && i + (1 << j) - 1 <= N; ++i) {
			st[j][i] = min(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]);
		}
	}
}

int sparse_table::query(int i, int j)
{
	int k = lg[j - i + 1];
	return max(st[k][i], st[k][j - (1 << k) + 1]);
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <climits>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

#define fast_cin() ios_base::sync_with_stdio(false)

typedef long double ld;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int max_N = 3e5 + 10;
const int l_N = 20;

int inp[max_N];
int neigh[max_N];
int lg[max_N];

struct sparse_table {
	vector< vector<int> > st;

	sparse_table(int *arr, int N);
	int query(int i, int j);
};

int main()
{
	int lg = 0;
	for (int i = 1; i < max_N; ++i) {
		while ((1 << lg) <= i) {
			++lg;
		}
		--lg;
		::lg[i] = lg;
	}

	int N;
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) {
		scanf("%d", inp + i);
	}
	for (int i = 1; i <= N; ++i) {
		neigh[i] = min(inp[i], max(inp[i - 1], inp[i + 1]));
	}
	sparse_table even(inp, N);
	sparse_table odd(neigh, N);

	cerr << odd.query(5, 36) << endl;

	for (int k = 0; k < N; ++k) {
		int M = N - k;
		if (M == 1) {
			printf("%d ", even.query(1, N));
		} else if (M % 2) {
			int lb = (1 + M) / 2;
			int ub = (N - M + 1 + N) / 2;
//			cerr << M << ' ' << lb << ' ' << ub << endl;
			printf("%d ", odd.query(lb, ub));
		} else {
			int lb = (1 + M) / 2;
			int ub = (N - M + 1 + N) / 2 + 1;
			printf("%d ", even.query(lb, ub));
		}
	}
}

sparse_table::sparse_table(int *arr, int N)
	: st(l_N, vector<int>(N + 1, -1))
{
	for (int i = 1; i <= N; ++i) {
		st[0][i] = arr[i];
	}
	for (int j = 1; (1 << j) <= N; ++j) {
		for (int i = 1; i <= N && i + (1 << j) - 1 <= N; ++i) {
			st[j][i] = max(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]);
		}
	}
}

int sparse_table::query(int i, int j)
{
	int k = lg[j - i + 1];
	return max(st[k][i], st[k][j - (1 << k) + 1]);
}


#include<bits/stdc++.h>
using namespace std;
const int N = 3e5+10, M = 20;
int n, a[N], b[N][M], c[N][M];
int mx(int L, int R, int f = 0) {
	int t = 31-__builtin_clz(R-L+1);
	return f == 0 ? max(b[L][t], b[R-(1<<t)+1][t]) : max(c[L][t], c[R-(1<<t)+1][t]);
}
int solve(int k) {
	if(k == 1) return mx(1, n-1);
	if(k&1) return mx(1+k/2, n-k/2, 1);
	return mx(k/2, n-k/2);
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	scanf("%d", &n); for(int i=1; i<=n; i++) scanf("%d", a+i);
	for(int j=0; j<M; j++) {
		for(int i=1; i<=n; i++) {
			if(j) {
				b[i][j] = max(b[i][j-1], b[min(n, i+(1<<j-1))][j-1]);
				c[i][j] = max(c[i][j-1], c[min(n, i+(1<<j-1))][j-1]);
			}
			else {
				b[i][j] = max(a[i], a[i+1]);
				c[i][j] = min(a[i], max(a[i-1], a[i+1]));
			}
		}
	}
	for(int k=0; k<n; k++) {
		printf("%d%c", solve(n-k), " \n"[k==n-1]);
	}
	return 0;
}


#include <bits/stdc++.h>

#define NN 300030

using namespace std;

typedef long long INT;
typedef pair <int, int> pii;

int mx[3][NN][20], a[NN], b[NN], ans[NN];

int rmq(int L, int R, int id){
	int l=31-__builtin_clz(R-L+1);
	return max(mx[id][L][l], mx[id][R-(1<<l)+1][l]);
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n; cin>>n;
	for(int i=0; i<n; i++) cin>>a[i];
	b[0]=a[0]; b[n-1]=a[n-1];
	for(int i=1; i<n-1; i++){
		if(a[i]<=a[i-1] && a[i]<=a[i+1]) b[i]=a[i];
		else b[i]=max(min(a[i-1], a[i]), min(a[i], a[i+1]));
	}

	for(int i=0; i<n; i++) mx[0][i][0]=a[i], mx[1][i][0]=b[i];

	for(int j=1; j<20; j++){
		for(int i=0; i<n; i++){
			for(int k=0; k<2; k++) mx[k][i][j]=max(mx[k][i][j-1], mx[k][min(n, i+(1<<j-1))][j-1]);
		}
	}

	for(int i=0; i<n; i++){
		if((n-i)%2==0){
			int l=(n-i)/2-1;
			int r=n-(n-i)/2;
			ans[i] = rmq(l, r, 0);
		}
		else {
			if(n-i==1) ans[i] = rmq(0, n-1, 0);
			else {
				int l=(n-i)/2;
				int r=n-(n-i)/2-1;
				ans[i] = rmq(l, r, 1);
			}
		}
	}
	for(int i=0; i<n; i++) printf("%d ", ans[i]);

	return 0;
}


#include <bits/stdc++.h>

const int NN = 303030;

using namespace std;

typedef long long INT;
typedef pair <int, int> pii;

int a[NN], b[NN], ans[NN];
int mx[3][NN][20];

int rmq(int L, int R, int id){
	int l=31-__builtin_clz(R-L+1);
	return max(mx[id][L][l], mx[id][R-(1<<l)+1][l]);
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n; cin>>n;
	for(int i=0; i<n; i++) cin>>a[i];
	if(n==1) {
		cout<<a[0]<<endl;
		return 0;
	}

	b[0]=a[0]; b[n-1]=a[n-1];
	for(int i=1; i<n-1; i++){
		if(a[i]<=a[i-1] && a[i]<=a[i+1]) b[i]=a[i];
		else b[i]=max(min(a[i-1], a[i]), min(a[i], a[i+1]));
	}

	for(int i=0; i<n; i++) mx[0][i][0]=a[i], mx[1][i][0]=b[i];

	for(int j=1; j<20; j++){
		for(int i=0; i<n; i++){
			for(int k=0; k<2; k++) mx[k][i][j]=max(mx[k][i][j-1], mx[k][min(n, i+(1<<j-1))][j-1]);
		}
	}

	for(int i=0; i<n; i++){
		if((n-i)%2==0){
			int l=(n-i)/2-1;
			int r=n-(n-i)/2;
			ans[i] = rmq(l, r, 0);
		}
		else {
			if(i==n-1) ans[i] = rmq(0, n-1, 0);
			else {
				int l=(n-i)/2;
				int r=n-(n-i)/2-1;
				ans[i] = rmq(l, r, 1);
			}
		}
	}
	for(int i=0; i<n; i++) printf("%d ", ans[i]);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int NN = 303030;

int a[NN];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n; cin>>n;
	for(int i=1; i<=n; i++) cin>>a[i];
	sort(a+1, a+n+1);
	for(int i=1; i<=n; i++) {
		int mid=(i+n+1)/2;
		printf("%d ", a[mid]);
	}

    return 0;
}


#include <bits/stdc++.h>
#define ls (u << 1)
#define rs (ls | 1)
#define mid (l + r >> 1)
#define NN 300100
using namespace std;

typedef long long INT;
typedef pair<int, int> pii;

int mxe[NN], mxo[NN];

int mx1[NN << 2], mx2[NN << 2];
void push_up_1(int u){
	mx1[u] = max(mx1[ls], mx1[rs]);
}
void build_1(int u, int l, int r){
	if(l == r - 1){
		mx1[u] = mxe[l];
		return ;
	}
	build_1(ls, l, mid);
	build_1(rs, mid, r);
	push_up_1(u);
}

int calc_1(int u, int l, int r, int st, int ed){
	if(l >= ed || r <= st) return 0;
	if(l >= st && r <= ed) return mx1[u];
	return max(calc_1(ls, l, mid, st, ed), calc_1(rs, mid, r, st, ed));
}

void push_up_2(int u){
	mx2[u] = max(mx2[ls], mx2[rs]);
}
void build_2(int u, int l, int r){
	if(l == r - 1){
		mx2[u] = mxo[l];
		return ;
	}
	build_2(ls, l, mid);
	build_2(rs, mid, r);
	push_up_2(u);
}

int calc_2(int u, int l, int r, int st, int ed){
	if(l >= ed || r <= st) return 0;
	if(l >= st && r <= ed) return mx2[u];
	return max(calc_2(ls, l, mid, st, ed), calc_2(rs, mid, r, st, ed));
}

int a[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	ios_base :: sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 2; i <= n; i++) mxe[i] = max(a[i], a[i - 1]);
	for(int i = 2; i < n; i++) mxo[i] = min(a[i], max(a[i - 1], a[i + 1]));
	int Mx = 0;
	for(int i = 1; i <= n; i++) Mx = max(Mx, a[i]);
	build_1(1, 1, n + 1);
	build_2(1, 1, n + 1);
	for(int i = 0; i < n; i++){
		int ans;
		int L = n - i;
		int st, ed;
		if(L & 1){
			if(L == 1) {
				cout << Mx << " ";
				continue;
			}
			st = L / 2 + 1;
			ed = n - L / 2;
			ans = calc_2(1, 1, n + 1, st, ed + 1);
			cout << ans << " ";
		}
		else {
			st = L / 2 + 1;
			ed = n - L / 2 + 1;
			ans = calc_1(1, 1, n + 1, st, ed + 1);
			cout << ans << " ";
		}
	}

	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
using namespace std;
long n,i,a[300005],l,k,v[300005],ans[300005],last,j;
vector < pair < long ,long > > b;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(i=0;i<n;++i)
    {
        cin>>a[i];
        b.pb({a[i],i});
    }
    if(i<3) {cout<<max(a[0],a[1])<<" "<<max(a[0],a[1])<<" "<<max(a[0],a[1]);exit(0);}
    for(i=0;i<n;++i)
    {
        l=min(2*(i+1),2*(n-i));
        if(l>n) l-=2;
        k=n-l;
        if(i<n/2)
        {
            if(a[i]>=a[i+2] && a[i]<=a[i+1])
            k--;
        }
        else
        {
            if(a[i]>=a[i-2] && a[i]<=a[i-1])
            k--;
        }
        v[i]=k;
    }
    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    last=n;
    for(i=0;i<n;++i)
    {
        for(j=v[b[i].second];j<last;++j)
        ans[j]=b[i].first;
        last=v[b[i].second];
    }
    for(i=0;i<n;++i)
    cout<<ans[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
/*================Header Template==============*/
#define PAUSE printf("Press Enter key to continue..."); fgetc(stdin);
const int N=3e5+500;
int n;
int a[N],res[N][3];
int ans1,ans2,L1,R1,L2,R2,Mx;
/*==================Define Area================*/
int main() {
	read(n);
	for(int i=1;i<=n;i++) {
		read(a[i]);Mx=max(Mx,a[i]);
	}
	for(int i=1;i<=n;i++) {
		if(i==1) res[i][0]=res[i][2]=a[i],res[i][1]=max(a[i],a[i+1]);
		else if(i==n) res[i][0]=res[i][1]=a[i],res[i][2]=max(a[i],a[i-1]);
		else res[i][0]=max(min(a[i],a[i-1]),min(a[i],a[i+1])),res[i][1]=max(a[i],a[i+1]),res[i][2]=max(a[i],a[i-1]);
	}
	// for(int i=1;i<=n;i++) {
	// 	printf("%d ",res[i][1]);
	// }
	// puts("");
	if(n&1) {
		ans1=res[(n+1)/2][0];
		ans2=max(res[(n+1)/2][1],res[(n+1)/2][2]);
		L1=L2=(n+1)/2-1;R1=R2=(n+1)/2+1;
		printf("%d %d ",ans1,ans2);
	}
	else {
		ans2=res[n/2][1];
		ans1=max(res[n/2][0],res[n/2+1][0]);
		L2=n/2;R2=n/2+1;L1=n/2-1;R1=n/2+2;
		printf("%d %d ",ans2,ans1);
	}
	// printf("%d %d %d %d\n",L1,R1,L2,R2);
	for(int i=2;i<n-2;i++) {
		if((n-i)&1) {
			ans1=max(ans1,max(res[L1--][0],res[R1++][0]));
			printf("%d ",ans1);
		}
		else {
			ans2=max(ans2,max(res[L2--][2],res[R2++][1]));
			printf("%d ",ans2);
		}
	}
	printf("%d %d\n",Mx,Mx);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
/*================Header Template==============*/
#define PAUSE printf("Press Enter key to continue..."); fgetc(stdin);
const int N=3e5+500;
int n;
int a[N];
/*==================Define Area================*/
int main() {
	read(n);
	for(int i=1;i<=n;i++) {
		read(a[i]);
	}
	int mid=(n+1)>>1;
	if(n&1) {
		printf("%d ",a[mid]);
		int ans=a[mid];
		for(int i=1;i<=(n>>1);i++) {
			ans=max(ans,max(a[mid-i],a[mid+i]));
			printf("%d %d ",ans,ans);
		}
		puts("");
	}
	else {
		int ans=max(a[mid],a[n-mid+1]);
		printf("%d %d ",ans,ans);
		for(int i=mid-1;i>=1;i--) {
			ans=max(ans,max(a[i],a[n-i+1]));
			printf("%d %d ",ans,ans);
		}
		puts("");
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
/*================Header Template==============*/
#define PAUSE printf("Press Enter key to continue..."); fgetc(stdin);
const int N=3e5+500;
int n;
int a[N],res[N][3];
int ans1,ans2,L1,R1,L2,R2,Mx;
/*==================Define Area================*/
int main() {
	read(n);
	for(int i=1;i<=n;i++) {
		read(a[i]);Mx=max(Mx,a[i]);
	}
	for(int i=1;i<=n;i++) {
		if(i==1) res[i][0]=res[i][2]=a[i],res[i][1]=max(a[i],a[i+1]);
		else if(i==n) res[i][0]=res[i][1]=a[i],res[i][2]=max(a[i],a[i-1]);
		else res[i][0]=max(min(a[i],a[i-1]),min(a[i],a[i+1])),res[i][1]=max(a[i],a[i+1]),res[i][2]=max(a[i],a[i-1]);
	}
	if(n<=2) {
		for(int i=1;i<=n;i++) printf("%d\n",Mx);
		return 0;
	}
	if(n==3) {
		printf("%d %d %d\n",res[2][0],Mx,Mx);
		return 0;
	}
	if(n&1) {
		ans1=res[(n+1)/2][0];
		ans2=max(res[(n+1)/2][1],res[(n+1)/2][2]);
		L1=L2=(n+1)/2-1;R1=R2=(n+1)/2+1;
		printf("%d %d ",ans1,ans2);
	}
	else {
		ans2=res[n/2][1];
		ans1=max(res[n/2][0],res[n/2+1][0]);
		L2=n/2;R2=n/2+1;L1=n/2-1;R1=n/2+2;
		printf("%d %d ",ans2,ans1);
	}
	// printf("%d %d %d %d\n",L1,R1,L2,R2);
	for(int i=2;i<n-2;i++) {
		if((n-i)&1) {
			ans1=max(ans1,max(res[L1--][0],res[R1++][0]));
			printf("%d ",ans1);
		}
		else {
			ans2=max(ans2,max(res[L2--][2],res[R2++][1]));
			printf("%d ",ans2);
		}
	}
	printf("%d %d\n",Mx,Mx);
	return 0;
}


/*

      #     #     #####  #####  #           #  #
     # #   # #    #      #   #  #     #     #  #
    #   # #   #   #####  #   #   #   # #   #   #
   #     #     #  #      #   #    # #   # #
   #           #  #####  #####     #     #     @

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 123;
const ll LINF = (ll) 1e18 + 123;
const ld EPS = (ld) 1e-8;
const ll MOD = (ll) 1e9 + 7;

#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (int i = f; i < t; i++)

ll power(ll x, ll y, ll mod = MOD) {
    if (y == 0) {
        return 1;
    }
    if (y & 1) {
        return power(x, y - 1, mod) * x % mod;
    } else {
        ll tmp = power(x, y / 2, mod);
        return tmp * tmp % mod;
    }
}

void add(ll &x, ll y, ll mod = MOD) {
    x += y;
    if (x >= mod) x -= mod;
    if (x < 0) x += mod;
}

ll sum(ll x, ll y, ll mod = MOD) {
    add(x, y, mod);
    return x;
}

ll mult(ll x, ll y, ll mod = MOD) {
    return (x * y) % mod;
}

ll div(ll x, ll y, ll mod) {
    return x * power(y, mod - 2, mod);
}

template<typename A, typename B> bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

template<typename A, typename B> bool maxi(A &x, const B &y) {
    if (y > x) {
        x = y;
        return true;
    }
    return false;
}

template<typename T> void read(T first, T last) {
    while (first != last) {
        cin >> *(first++);
    }
}

template<typename T> void print(T first, T last) {
    while (first != last) {
        cout << *(first++) << " ";
    }
    cout << "\n";
}

void run();

#define TASK ""

int main() {
#ifdef LOCAL
    if (strlen(TASK) > 0) {
        cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
    }
#endif
#ifndef LOCAL
    if (strlen(TASK)) {
        freopen(TASK ".in", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    cout << fixed << setprecision(12);
    run();
    return 0;
}

// == SOLUTION == //

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

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

void run() {
    cin >> n;
    read(a, a + n);

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

    rep(i, 1, n - 1) b[i] = min(a[i], max(a[i - 1], a[i + 1]));
    ans[n - 1] = *max_element(a, a + n);

    if (n % 2 == 0) {
        int cur = 0;
        for (int i = 0; i < n - 1; i += 2) {
            maxi(cur, max(a[n / 2 - i / 2 - 1], a[n / 2 + i / 2]));
            ans[i] = cur;
        }

        cur = 0;
        for (int i = 1; i < n - 1; i += 2) {
            maxi(cur, max(a[n / 2 - i / 2 - 1], a[n / 2 + i / 2]));
            ans[i] = cur;
        }
    } else {
        int cur = 0;
        for (int i = 0; i < n - 1; i += 2) {
            maxi(cur, max(b[n / 2 - i / 2], b[n / 2 + i / 2]));
            ans[i] = cur;
        }

        cur = a[n / 2];
        for (int i = 1; i < n - 1; i += 2) {
            maxi(cur, max(a[n / 2 - i / 2 - 1], a[n / 2 + i / 2 + 1]));
            ans[i] = cur;
        }
    }

    print(ans, ans + n);
}


/*

      #     #     #####  #####  #           #  #
     # #   # #    #      #   #  #     #     #  #
    #   # #   #   #####  #   #   #   # #   #   #
   #     #     #  #      #   #    # #   # #
   #           #  #####  #####     #     #     @

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 123;
const ll LINF = (ll) 1e18 + 123;
const ld EPS = (ld) 1e-8;
const ll MOD = (ll) 1e9 + 7;

#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (int i = f; i < t; i++)

ll power(ll x, ll y, ll mod = MOD) {
    if (y == 0) {
        return 1;
    }
    if (y & 1) {
        return power(x, y - 1, mod) * x % mod;
    } else {
        ll tmp = power(x, y / 2, mod);
        return tmp * tmp % mod;
    }
}

void add(ll &x, ll y, ll mod = MOD) {
    x += y;
    if (x >= mod) x -= mod;
    if (x < 0) x += mod;
}

ll sum(ll x, ll y, ll mod = MOD) {
    add(x, y, mod);
    return x;
}

ll mult(ll x, ll y, ll mod = MOD) {
    return (x * y) % mod;
}

ll div(ll x, ll y, ll mod) {
    return x * power(y, mod - 2, mod);
}

template<typename A, typename B> bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

template<typename A, typename B> bool maxi(A &x, const B &y) {
    if (y > x) {
        x = y;
        return true;
    }
    return false;
}

template<typename T> void read(T first, T last) {
    while (first != last) {
        cin >> *(first++);
    }
}

template<typename T> void print(T first, T last) {
    while (first != last) {
        cout << *(first++) << " ";
    }
    cout << "\n";
}

void run();

#define TASK ""

int main() {
#ifdef LOCAL
    if (strlen(TASK) > 0) {
        cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
    }
#endif
#ifndef LOCAL
    if (strlen(TASK)) {
        freopen(TASK ".in", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    cout << fixed << setprecision(12);
    run();
    return 0;
}

// == SOLUTION == //

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

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

void run() {
    cin >> n;
    read(a, a + n);

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

    rep(i, 1, n - 1) b[i] = min(a[i], max(a[i - 1], a[i + 1]));
    ans[n - 1] = *max_element(a, a + n);

    if (n % 2 == 0) {
        int cur = 0;
        for (int i = 0; i < n - 1; i += 2) {
            maxi(cur, max(a[n / 2 - i / 2 - 1], a[n / 2 + i / 2]));
            ans[i] = cur;
        }

        cur = 0;
        for (int i = 1; i < n - 1; i += 2) {
            maxi(cur, max(b[n / 2 - i / 2 - 1], b[n / 2 + i / 2]));
            ans[i] = cur;
        }
    } else {
        int cur = 0;
        for (int i = 0; i < n - 1; i += 2) {
            maxi(cur, max(b[n / 2 - i / 2], b[n / 2 + i / 2]));
            ans[i] = cur;
        }

        cur = a[n / 2];
        for (int i = 1; i < n - 1; i += 2) {
            maxi(cur, max(a[n / 2 - i / 2 - 1], a[n / 2 + i / 2 + 1]));
            ans[i] = cur;
        }
    }

    print(ans, ans + n);
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j)       for(int i = 0 ; i < j ; i++)
#define REPNM(i,j,k)   for(int i = j ; i < k ; i++)
#define RREP(i,j,k)    for(int i = j ; i >=k ; i--)
#define A    first
#define B    second
#define pb   push_back
#define mp   make_pair
#define PII pair<int , int>
#define VI  vector<int>
#define VPII vector<PII>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define RI(i)       scanf("%d" , &i)
#define RII(i,j)    scanf("%d%d" , &i , &j)
#define RIII(i,j,k) scanf("%d%d%d" , &i , &j , &k)
#define RL(i)       scanf("%lld" , &i)
#define RLL(i,j)    scanf("%lld%lld" , &i , &j)
#define RLLL(i,j,k) scanf("%lld%lld%lld" , &i , &j , &k)
#define AS assert
#define IOS cin.tie() , cout.sync_with_stdio(0)
///------------------------------------------------------------
#define MAX 300090
#define INF 0x3f3f3f3f

int n , x[MAX];
int ans[MAX];
int32_t main(){
	cin >> n;
	REP(i , n) cin >> x[i];
	int l , r;
	if(n % 2 == 0) l = n / 2 - 1 , r = n / 2;
	else l = n / 2 , r = n / 2 + 1;
	// DBGG(l , r);
	REP(i , n){
		int tn = n - i , tml , tmr;
		if(tn % 2 == 0) tml = tn / 2 - 1 , tmr = tn / 2 + i;
		else tml = tn / 2 , tmr = tn / 2 + i;
		if(i % 2 == 0){
		// DB4("i = " , i , tml , tmr);
			int tmp = 0;
			if(tn % 2 == 0){
				x[n] = -INF;
				while(tml <= l) tmp = max(tmp , max(x[l] , x[l + 1])) , l--;
				while(r < tmr) tmp = max(tmp , max(x[r] , x[r + 1])) , r++;
			}
			else {
				while(tml <= l){
					if(tn == 1) tmp = max(tmp , x[l]);
					else if(x[l] >= x[l - 1] && x[l] >= x[l + 1])
						tmp = max(tmp , max(x[l - 1] , x[l + 1]));
					else  tmp = max(tmp , x[l]);
					l --;
				}
				while(r <= tmr){
					if(tn == 1) tmp = max(tmp , x[r]);
					else if(x[r] >= x[r - 1] && x[r] >= x[r + 1])
						tmp = max(tmp , max(x[r - 1] , x[r + 1]));
					else tmp = max(tmp , x[r]);
					r ++;
				}
			}
			if(i > 1) ans[i] = max(tmp , ans[i - 2]);
			else ans[i] = tmp;
		}
	}

	// 	if(n % 2 == 0) l = n / 2 - 1 , r = n / 2;
	// else l = n / 2 , r = n / 2 ;

	if((n - 1) % 2 == 0) l = (n - 1) / 2 - 1 , r = (n - 1) / 2;
	else l = (n - 1) / 2 , r = (n - 1) / 2 + 1;
	// DB4("75" , " " , l , r);
	REP(i , n){
		int tn = n - i , tml , tmr;
		if(tn % 2 == 0) tml = tn / 2 - 1 , tmr = tn / 2 + i;
		else tml = tn / 2 , tmr = tn / 2 + i;
		if(i % 2 == 1){
		// DB4(i , tml , tmr , "80");
			int tmp = 0;
			if(tn % 2 == 0){
				x[n] = -INF;
				while(tml <= l) tmp = max(tmp , max(x[l] , x[l + 1])) , l--;
				while(r < tmr) tmp = max(tmp , max(x[r] , x[r + 1])) , r++;
			}
			else {
				while(tml <= l){
					if(tn == 1) tmp = max(tmp , x[l]);
					else if(x[l] >= x[l - 1] && x[l] >= x[l + 1])
						tmp = max(tmp , max(x[l - 1] , x[l + 1]));
					else  tmp = max(tmp , x[l]);
					l --;
				}
				while(r <= tmr){
					if(tn == 1) tmp = max(tmp , x[r]);
					else if(x[r] >= x[r - 1] && x[r] >= x[r + 1])
						tmp = max(tmp , max(x[r - 1] , x[r + 1]));
					else tmp = max(tmp , x[r]);
					r ++;
				}
			}
			if(i > 1) ans[i] = max(tmp , ans[i - 2]);
			else ans[i] = tmp;

		}
	}
	REP(i , n) ans[n - 1] = max(ans[n - 1] , x[i]);
	REP(i , n) cout << ans[i] << " " ; cout << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j)       for(int i = 0 ; i < j ; i++)
#define REPNM(i,j,k)   for(int i = j ; i < k ; i++)
#define RREP(i,j,k)    for(int i = j ; i >=k ; i--)
#define A    first
#define B    second
#define pb   push_back
#define mp   make_pair
#define PII pair<int , int>
#define VI  vector<int>
#define VPII vector<PII>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define RI(i)       scanf("%d" , &i)
#define RII(i,j)    scanf("%d%d" , &i , &j)
#define RIII(i,j,k) scanf("%d%d%d" , &i , &j , &k)
#define RL(i)       scanf("%lld" , &i)
#define RLL(i,j)    scanf("%lld%lld" , &i , &j)
#define RLLL(i,j,k) scanf("%lld%lld%lld" , &i , &j , &k)
#define AS assert
#define IOS cin.tie() , cout.sync_with_stdio(0)
///------------------------------------------------------------
#define MAX 300090
#define INF 0x3f3f3f3f

int n , x[MAX];
int ans[MAX];
int32_t main(){
	cin >> n;
	REP(i , n) cin >> x[i];
	int l , r;
	if(n % 2 == 0) l = n / 2 - 1 , r = n / 2;
	else l = n / 2 , r = n / 2 + 1;
	// DBGG(l , r);
	REP(i , n){
		int tn = n - i , tml , tmr;
		if(tn % 2 == 0) tml = tn / 2 - 1 , tmr = tn / 2 + i;
		else tml = tn / 2 , tmr = tn / 2 + i;
		if(i % 2 == 0){
		// DB4("i = " , i , tml , tmr);
			int tmp = 0;
			if(tn % 2 == 0){
				x[n] = -INF;
				while(tml <= l) tmp = max(tmp , max(x[l] , x[l + 1])) , l--;
				while(r < tmr) tmp = max(tmp , max(x[r] , x[r + 1])) , r++;
			}
			else {
				while(tml <= l){
					if(tn == 1) tmp = max(tmp , x[l]);
					else if(x[l] >= x[l - 1] && x[l] >= x[l + 1])
						tmp = max(tmp , max(x[l - 1] , x[l + 1]));
					else  tmp = max(tmp , x[l]);
					l --;
				}
				while(r <= tmr){
					if(tn == 1) tmp = max(tmp , x[r]);
					else if(x[r] >= x[r - 1] && x[r] >= x[r + 1])
						tmp = max(tmp , max(x[r - 1] , x[r + 1]));
					else tmp = max(tmp , x[r]);
					r ++;
				}
			}
			if(tmp > 1) ans[i] = max(tmp , ans[i - 2]);
			else ans[i] = tmp;
		}
	}

	// 	if(n % 2 == 0) l = n / 2 - 1 , r = n / 2;
	// else l = n / 2 , r = n / 2 ;

	if((n - 1) % 2 == 0) l = (n - 1) / 2 - 1 , r = (n - 1) / 2;
	else l = (n - 1) / 2 , r = (n - 1) / 2 + 1;
	// DB4("75" , " " , l , r);
	REP(i , n){
		int tn = n - i , tml , tmr;
		if(tn % 2 == 0) tml = tn / 2 - 1 , tmr = tn / 2 + i;
		else tml = tn / 2 , tmr = tn / 2 + i;
		if(i % 2 == 1){
		// DB4(i , tml , tmr , "80");
			int tmp = 0;
			if(tn % 2 == 0){
				x[n] = -INF;
				while(tml <= l) tmp = max(tmp , max(x[l] , x[l + 1])) , l--;
				while(r < tmr) tmp = max(tmp , max(x[r] , x[r + 1])) , r++;
			}
			else {
				while(tml <= l){
					if(tn == 1) tmp = max(tmp , x[l]);
					else if(x[l] >= x[l - 1] && x[l] >= x[l + 1])
						tmp = max(tmp , max(x[l - 1] , x[l + 1]));
					else  tmp = max(tmp , x[l]);
					l --;
				}
				while(r <= tmr){
					if(tn == 1) tmp = max(tmp , x[r]);
					else if(x[r] >= x[r - 1] && x[r] >= x[r + 1])
						tmp = max(tmp , max(x[r - 1] , x[r + 1]));
					else tmp = max(tmp , x[r]);
					r ++;
				}
			}
			if(tmp > 1) ans[i] = max(tmp , ans[i - 2]);
			else ans[i] = tmp;

		}
	}
	REP(i , n) ans[n - 1] = max(ans[n - 1] , x[i]);
	REP(i , n) cout << ans[i] << " " ; cout << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j)       for(int i = 0 ; i < j ; i++)
#define REPNM(i,j,k)   for(int i = j ; i < k ; i++)
#define RREP(i,j,k)    for(int i = j ; i >=k ; i--)
#define A    first
#define B    second
#define pb   push_back
#define mp   make_pair
#define PII pair<int , int>
#define VI  vector<int>
#define VPII vector<PII>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define RI(i)       scanf("%d" , &i)
#define RII(i,j)    scanf("%d%d" , &i , &j)
#define RIII(i,j,k) scanf("%d%d%d" , &i , &j , &k)
#define RL(i)       scanf("%lld" , &i)
#define RLL(i,j)    scanf("%lld%lld" , &i , &j)
#define RLLL(i,j,k) scanf("%lld%lld%lld" , &i , &j , &k)
#define AS assert
#define IOS cin.tie() , cout.sync_with_stdio(0)
///------------------------------------------------------------
#define MAX 300090
#define INF 0x3f3f3f3f

int n , x[MAX];
int ans[MAX];
int32_t main(){
	cin >> n;
	REP(i , n) cin >> x[i];
	int l , r;
	if(n % 2 == 0) l = n / 2 - 1 , r = n / 2;
	else l = n / 2 , r = n / 2 + 1;
	// DBGG(l , r);
	REP(i , n){
		int tn = n - i , tml , tmr;
		if(tn % 2 == 0) tml = tn / 2 - 1 , tmr = tn / 2 + i;
		else tml = tn / 2 , tmr = tn / 2 + i;
		if(i % 2 == 0){
		// DB4("i = " , i , tml , tmr);
			int tmp = 0;
			if(tn % 2 == 0){
				x[n] = -INF;
				while(tml <= l) tmp = max(tmp , max(x[l] , x[l + 1])) , l--;
				while(r < tmr) tmp = max(tmp , max(x[r] , x[r + 1])) , r++;
			}
			else {
				while(tml <= l){
					if(tn == 1) tmp = max(tmp , x[l]);
					else if(x[l] >= x[l - 1] && x[l] >= x[l + 1])
						tmp = max(tmp , max(x[l - 1] , x[l + 1]));
					else  tmp = max(tmp , x[l]);
					l --;
				}
				while(r <= tmr){
					if(tn == 1) tmp = max(tmp , x[r]);
					else if(x[r] >= x[r - 1] && x[r] >= x[r + 1])
						tmp = max(tmp , max(x[r - 1] , x[r + 1]));
					else tmp = max(tmp , x[r]);
					r ++;
				}
			}
			if(tmp > 1) ans[i] = max(tmp , ans[i - 2]);
			else ans[i] = tmp;
		}
	}

	// 	if(n % 2 == 0) l = n / 2 - 1 , r = n / 2;
	// else l = n / 2 , r = n / 2 ;

	if((n - 1) % 2 == 0) l = (n - 1) / 2 - 1 , r = (n - 1) / 2;
	else l = (n - 1) / 2 , r = (n - 1) / 2 + 1;
	// DB4("75" , " " , l , r);
	REP(i , n){
		int tn = n - i , tml , tmr;
		if(tn % 2 == 0) tml = tn / 2 - 1 , tmr = tn / 2 + i;
		else tml = tn / 2 , tmr = tn / 2 + i;
		if(i % 2 == 1){
		// DB4(i , tml , tmr , "80");
			int tmp = 0;
			if(tn % 2 == 0){
				x[n] = -INF;
				while(tml <= l) tmp = max(tmp , max(x[l] , x[l + 1])) , l--;
				while(r < tmr) tmp = max(tmp , max(x[r] , x[r + 1])) , r++;
			}
			else {
				while(tml <= l){
					if(tn == 1) tmp = max(tmp , x[l]);
					else if(x[l] >= x[l - 1] && x[l] >= x[l + 1])
						tmp = max(tmp , max(x[l - 1] , x[l + 1]));
					else  tmp = max(tmp , x[l]);
					l --;
				}
				while(r <= tmr){
					if(tn == 1) tmp = max(tmp , x[r]);
					else if(x[r] >= x[r - 1] && x[r] >= x[r + 1])
						tmp = max(tmp , max(x[r - 1] , x[r + 1]));
					else tmp = max(tmp , x[r]);
					r ++;
				}
			}
			if(tmp > 1) ans[i] = max(tmp , ans[i - 2]);
			else ans[i] = tmp;

		}
	}
	REP(i , n) cout << ans[i] << " " ; cout << endl;
    return 0;
}


#include "bits/stdc++.h"

using namespace std;

stack<int> st;
int A[300005];
priority_queue<int> evenPQ, oddPQ;
int even[300005];
int odd[300005];
map<int, int> mpEven, mpOdd;
int main() {
	int N;
	scanf("%d", &N);
	int mx = 0;
	for(int i = 1 ; i <= N ; i++) {
		scanf("%d", A + i);
		mx = max(mx, A[i]);
	}
	st.push(mx);
	for(int i = 2 ; i <= N ; i++) {
		even[i] = max(A[i], A[i-1]);
		mpEven[even[i]]++;
		evenPQ.push(even[i]);
	}
	for(int i = 2 ; i < N ; i++) {
		odd[i] = min(A[i], max(A[i-1], A[i+1]));
		mpOdd[odd[i]]++;
		oddPQ.push(odd[i]);
	}
	int evenI = 2;
	int evenJ = N;
	int oddI = 2;
	int oddJ = N - 1;
	for(int i = 2 ; i <= N ; i++) {

		if(i % 2 == 0) {
			st.push(evenPQ.top());
			mpEven[even[evenI++]]--;
			mpEven[even[evenJ--]]--;
			while(evenPQ.size() && mpEven[evenPQ.top()] == 0)
				evenPQ.pop();
		}
		else {
			st.push(oddPQ.top());
			mpOdd[odd[oddI++]]--;
			mpOdd[odd[oddJ--]]--;
			while(oddPQ.size() && mpOdd[oddPQ.top()] == 0)
				oddPQ.pop();
		}
	}
	while(st.size()) {
		printf("%d ", st.top());
		st.pop();
	}
	return 0;
}


#include "bits/stdc++.h"

using namespace std;

stack<int> st;
int A[300005];
priority_queue<int> evenPQ, oddPQ;
int even[300005];
int odd[300005];

int main() {
	int N;
	scanf("%d", &N);
	int mx = 0;
	for(int i = 1 ; i <= N ; i++) {
		scanf("%d", A + i);
		mx = max(mx, A[i]);
	}
	st.push(mx);
	for(int i = 2 ; i <= N ; i++) {
		even[i] = max(A[i], A[i-1]);
		evenPQ.push(even[i]);
	}
	for(int i = 2 ; i < N ; i++) {
		odd[i] = min(A[i], max(A[i-1], A[i+1]));
		oddPQ.push(odd[i]);
	}
	for(int i = 2 ; i <= N ; i++) {
		if(i % 2 == 0) {
			st.push(evenPQ.top());
			evenPQ.pop();
		}
		else {
			st.push(oddPQ.top());
			oddPQ.pop();
		}
	}
	while(st.size()) {
		printf("%d ", st.top());
		st.pop();
	}
	return 0;
}


#include <bits/stdc++.h>

#define FOR(i, a, b)  for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a); i >= (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << "\n"
#define _ << " _ " <<
#define ll long long

using namespace std;

ll arr[300010];
ll sol[300010];
ll sol1[300010];
ll sol2[300010];

ll solve(int a, int b) {
  int n = b - a + 1;
  int mi = (a + b) / 2;
  if (n % 2 == 0) return max(arr[mi], arr[mi + 1]);
  return min(arr[mi], max(arr[mi + 1], arr[mi - 1]));
}

int main() {
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  ll ma = 0;
  REP(i, n) {
    cin >> arr[i];
    ma = max(arr[i], ma);
  }

  FOR(i, 1, (n + 1) / 2) {
    int l = i;
    int r = n - i - 1;
    sol1[l - 1] = max(solve(0, 2 * l), solve(r - l, r + l));
  }

  FOR(i, 0, n / 2) {
    int l = i;
    int r = n - i - 2;
    sol2[l] = max(solve(0, 2 * l + 1), solve(r - l, r + l + 1));
  }

  for (int i = n - 1; i > 0; i--) {
    sol[i] = sol[i + 2];
    if (i % 2 == 1) sol[i] = max(sol[i], sol2[(i + 1) / 2 - 1]);
    else            sol[i] = max(sol[i], sol1[(i + 1) / 2 - 1]);

  }
  REP(i, n - 1) cout << sol[n - i - 1] << " ";
  cout << ma << endl;

  return 0;
}


#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar()
#define pc(x) putchar(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
const int MM = 3e5+69;

mt19937 g1(time(0));
int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}

int n, in[MM], a[MM], b[MM], ans[MM];
int *at = in+14;

int dp[MM][MM];
int go(int l, int r, int t){
    if(l == r)
        return a[l];
    int &ret = dp[l][r];
    if(ret) return ret;
    t++;
    if(t&1)
        return ret = max(go(l, r-1, t), go(l+1, r, t));
    else
        return ret = min(go(l, r-1, t), go(l+1, r, t));
}

int main(){
    scan(n);
    for(int i = 0; i < n; i++){
        scan(a[i]);
    }
    /*
    for(int i = 0; i < n; i++){
        b[i] = max(at[i], at[i+1]);
        vector<int> v = {at[i-1], at[i], at[i+1]};
        sort(all(v));
        a[i] = v[1];
    }

    int aa = 0, bb = 0, m = (n-1)/2;
    int tb = n&1, ta = !tb;
    int d1 = 0, d2 = 0;

    for(int i = 0; i < n-1; i++){
        //rm how many
        if((n-i)&1){
            aa = max(aa, max(a[m-d1], a[m+d1+ta]));
            d1++;
        }
        else{
            bb = max(bb, max(b[m-d2-tb], b[m+d2]));
            d2++;
        }
        printf("%d ", max(aa,bb));
    }
    print(*max_element(at, at+n));

    return 0;
    */
    for(int l = n; l; l--){
        int v = 0;
        for(int i = 0; i+l-1 < n; i++){
            memset(dp, 0, sizeof dp);
            v = max(v, go(i, i+l-1, 0));
        }
        printf("%d ", v);
    }

    return 0;
}
/*
5
4 2 3 2 1
3 3 3 4 4
2 3 2 4 4
 */


#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar()
#define pc(x) putchar(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
const int MM = 3e5+9;

mt19937 g1(time(0));
int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}

int n, in[MM], a[MM], b[MM], ans[MM];
int *at = in+3;

int dp[21][21];
int go(int l, int r, int t){
    if(l == r)
        return a[l];
    int &ret = dp[l][r];
    if(ret) return ret;
    t++;
    if(t&1)
        return ret = max(go(l, r-1, t), go(l+1, r, t));
    else
        return ret = min(go(l, r-1, t), go(l+1, r, t));
}

int main(){
    scan(n);
    for(int i = 0; i < n; i++){
        scan(at[i]);
    }
    for(int i = 0; i < n; i++){
        b[i] = max(at[i], at[i+1]);
        vector<int> v = {a[i-1], a[i], a[i+1]};
        sort(all(v));
        a[i] = v[1];
    }

    int aa = 0, bb = 0, m = (n-1)/2;
    int tb = n&1, ta = !tb;
    int d1 = 0, d2 = 0;

    for(int i = 0; i < n; i++){
        //rm how many
        if((n-i)&1){
            aa = max(aa, max(a[m-d1], a[m+d1+ta]));
            d1++;
        }
        else{
            bb = max(bb, max(b[m-d2-tb], b[m+d2]));
            d2++;
        }
        printf("%d ", max(aa,bb));
    }
    pc(10);

    return 0;

    for(int l = n; l; l--){
        int v = 0;
        for(int i = 0; i+l-1 < n; i++){
            memset(dp, 0, sizeof dp);
            v = max(v, go(i, i+l-1, 0));
            for(int k = 0; k < n; k++){
                for(int j = 0; j < n; j++)
                    printf("%d ", dp[k][j]);
                pc(10);
            }
            return 0;
        }
        printf("%d ", v);
    }

    return 0;
}
/*
5
4 2 3 2 1
3 3 3 4 4
2 3 2 4 4
 */


#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar()
#define pc(x) putchar(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
const int MM = 3e5+9;

mt19937 g1(time(0));
int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}

int n, in[MM], a[MM], b[MM], ans[MM];
int *at = in+3;

int dp[21][21];
int go(int l, int r, int t){
    if(l == r)
        return a[l];
    int &ret = dp[l][r];
    if(ret) return ret;
    t++;
    if(t&1)
        return ret = max(go(l, r-1, t), go(l+1, r, t));
    else
        return ret = min(go(l, r-1, t), go(l+1, r, t));
}

int main(){
    scan(n);
    for(int i = 0; i < n; i++){
        scan(at[i]);
    }
    for(int i = 0; i < n; i++){
        b[i] = max(at[i], at[i+1]);
        vector<int> v = {at[i-1], at[i], at[i+1]};
        sort(all(v));
        a[i] = v[1];
    }

    int aa = 0, bb = 0, m = (n-1)/2;
    int tb = n&1, ta = !tb;
    int d1 = 0, d2 = 0;

    for(int i = 0; i < n-1; i++){
        //rm how many
        if((n-i)&1){
            aa = max(aa, max(a[m-d1], a[m+d1+ta]));
            d1++;
        }
        else{
            bb = max(bb, max(b[m-d2-tb], b[m+d2]));
            d2++;
        }
        printf("%d ", max(aa,bb));
    }
    print(*max_element(at, at+n));

    return 0;

    for(int l = n; l; l--){
        int v = 0;
        for(int i = 0; i+l-1 < n; i++){
            memset(dp, 0, sizeof dp);
            v = max(v, go(i, i+l-1, 0));
            for(int k = 0; k < n; k++){
                for(int j = 0; j < n; j++)
                    printf("%d ", dp[k][j]);
                pc(10);
            }
            return 0;
        }
        printf("%d ", v);
    }

    return 0;
}
/*
5
4 2 3 2 1
3 3 3 4 4
2 3 2 4 4
 */


#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar()
#define pc(x) putchar(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
const int MM = 3e5+69;

mt19937 g1(time(0));
int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}

int n, in[MM], a[MM], b[MM];
int *at = in+9;

int main(){
    scan(n);
    for(int i = 0; i < n; i++){
        scan(at[i]);
    }

    for(int i = 0; i < n; i++){
        b[i] = max(at[i], at[i+1]);
        a[i] = min(at[i], max(at[i+1], at[i-1]));
    }

    int aa = 0, bb = 0, m = (n-1)/2;
    int tb = n&1, ta = !tb;
    int d1 = 0, d2 = 0;

    for(int i = 0; i < n-1; i++){
        //rm how many
        if((n-i)&1){
            aa = max(aa, max(a[m-d1], a[m+d1+ta]));
            d1++;
        }
        else{
            bb = max(bb, max(b[m-d2-tb], b[m+d2]));
            d2++;
        }
        printf("%d ", max(aa,bb));
    }
    print(*max_element(at, at+n));

    return 0;

    return 0;
}


#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar()
#define pc(x) putchar(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
const int MM = 3e5+69;

mt19937 g1(time(0));
int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}

int n, in[MM], a[MM], b[MM];
int *at = in+9;

int main(){
    scan(n);
    for(int i = 0; i < n; i++){
        scan(at[i]);
    }

    for(int i = 0; i < n; i++){
        b[i] = max(at[i], at[i+1]);
        a[i] = min(at[i], max(at[i+1], at[i-1]));
    }

    int aa = 0, bb = 0, m = (n-1)/2;
    int tb = n&1, ta = !tb;
    int d1 = 0, d2 = 0;

    for(int i = 0; i < n-1; i++){
        //rm how many
        if((n-i)&1){
            aa = max(aa, max(a[m-d1], a[m+d1+ta]));
            d1++;
            printf("%d ", aa);
        }
        else{
            bb = max(bb, max(b[m-d2-tb], b[m+d2]));
            d2++;
            printf("%d ", bb);
        }
    }
    print(*max_element(at, at+n));

    return 0;

    return 0;
}


#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar()
#define pc(x) putchar(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
const int MM = 3e5+2;

mt19937 g1(time(0));
int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}

int n, a[MM], b[MM], ans[MM];
/*
int dp[21][21];
int go(int l, int r, int t){
    if(l == r)
        return a[l];
    int &ret = dp[l][r];
    if(ret) return ret;
    t++;
    if(t&1)
        return ret = max(go(l, r-1, t), go(l+1, r, t));
    else
        return ret = min(go(l, r-1, t), go(l+1, r, t));
}
*/
int main(){
    scan(n);
//    n = randint(5, 8);
//    print(n);
    for(int i = 0; i < n; i++){
        scan(a[i]);
//        a[i] = randint(1, n);
//        printf("%d ", a[i]);
    }
//    pc(10);
    for(int i = 0; i < n; i++)
        b[i] = max(a[i], a[i+1]);

    int aa = 0, bb = 0, m = (n-1)/2;
    int tb = n&1, ta = !tb;
    int d1 = 0, d2 = 0;

    for(int i = 0; i < n; i++){
        //rm how many
        if((n-i)&1){
            aa = max(aa, max(a[m-d1], a[m+d1+ta]));
            d1++;
        }
        else{
            bb = max(bb, max(b[m-d2-tb], b[m+d2]));
            d2++;
        }
        printf("%d ", max(aa,bb));
    }
    pc(10);
    /*
    for(int l = n; l; l--){
        int v = 0;
        for(int i = 0; i+l-1 < n; i++){
            memset(dp, 0, sizeof dp);
            v = max(v, go(i, i+l-1, 0));
        }
        printf("%d ", v);
    }
    */
    return 0;
}
/*
5
4 2 3 2 1
3 3 3 4 4
2 3 2 4 4
 */


#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar()
#define pc(x) putchar(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
const int MM = 3e5+69;

mt19937 g1(time(0));
int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}

int n, in[MM], a[MM], b[MM], ans[MM];
int *at = in+14;

int dp[1000][1000];
int go(int l, int r, int t){
    if(l == r)
        return a[l];
    int &ret = dp[l][r];
    if(ret) return ret;
    t++;
    if(t&1)
        return ret = max(go(l, r-1, t), go(l+1, r, t));
    else
        return ret = min(go(l, r-1, t), go(l+1, r, t));
}

int main(){
    scan(n);
    for(int i = 0; i < n; i++){
        scan(a[i]);
    }
    /*
    for(int i = 0; i < n; i++){
        b[i] = max(at[i], at[i+1]);
        vector<int> v = {at[i-1], at[i], at[i+1]};
        sort(all(v));
        a[i] = v[1];
    }

    int aa = 0, bb = 0, m = (n-1)/2;
    int tb = n&1, ta = !tb;
    int d1 = 0, d2 = 0;

    for(int i = 0; i < n-1; i++){
        //rm how many
        if((n-i)&1){
            aa = max(aa, max(a[m-d1], a[m+d1+ta]));
            d1++;
        }
        else{
            bb = max(bb, max(b[m-d2-tb], b[m+d2]));
            d2++;
        }
        printf("%d ", max(aa,bb));
    }
    print(*max_element(at, at+n));

    return 0;
    */
    for(int l = n; l; l--){
        int v = 0;
        for(int i = 0; i+l-1 < n; i++){
            memset(dp, 0, sizeof dp);
            v = max(v, go(i, i+l-1, 0));
        }
        printf("%d ", v);
    }

    return 0;
}
/*
5
4 2 3 2 1
3 3 3 4 4
2 3 2 4 4
 */


#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar()
#define pc(x) putchar(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
const int MM = 3e5+9;

mt19937 g1(time(0));
int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}

int n, in[MM], a[MM], b[MM], ans[MM];
int *at = in+3;

int dp[21][21];
int go(int l, int r, int t){
    if(l == r)
        return a[l];
    int &ret = dp[l][r];
    if(ret) return ret;
    t++;
    if(t&1)
        return ret = max(go(l, r-1, t), go(l+1, r, t));
    else
        return ret = min(go(l, r-1, t), go(l+1, r, t));
}

int main(){
    scan(n);
    for(int i = 0; i < n; i++){
        scan(at[i]);
    }
    for(int i = 0; i < n; i++){
        b[i] = max(at[i], at[i+1]);
        vector<int> v = {at[i-1], at[i], at[i+1]};
        sort(all(v));
        a[i] = v[1];
    }

    int aa = 0, bb = 0, m = (n-1)/2;
    int tb = n&1, ta = !tb;
    int d1 = 0, d2 = 0;

    for(int i = 0; i < n; i++){
        //rm how many
        if((n-i)&1){
            aa = max(aa, max(a[m-d1], a[m+d1+ta]));
            d1++;
        }
        else{
            bb = max(bb, max(b[m-d2-tb], b[m+d2]));
            d2++;
        }
        printf("%d ", max(aa,bb));
    }
    pc(10);

    return 0;

    for(int l = n; l; l--){
        int v = 0;
        for(int i = 0; i+l-1 < n; i++){
            memset(dp, 0, sizeof dp);
            v = max(v, go(i, i+l-1, 0));
            for(int k = 0; k < n; k++){
                for(int j = 0; j < n; j++)
                    printf("%d ", dp[k][j]);
                pc(10);
            }
            return 0;
        }
        printf("%d ", v);
    }

    return 0;
}
/*
5
4 2 3 2 1
3 3 3 4 4
2 3 2 4 4
 */


#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar()
#define pc(x) putchar(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
const int MM = 3e5+2;

int n, a[MM], b[MM], ans[MM];

int main(){
    scan(n);
    for(int i = 0; i < n; i++)
        scan(a[i]);
    for(int i = 0; i < n; i++)
        b[i] = max(a[i], a[i+1]);

    int aa = 0, bb = 0, m = (n-1)/2;
    int t = n&1;
    int d1 = 0, d2 = 0;

    for(int i = 0; i < n; i++){
        //rm how many
        if((n-i)&1){
            aa = max(aa, max(a[m-d1], a[m+d1]));
            d1++;
        }
        else{
            bb = max(bb, max(b[m-d2], b[m+d2]));
            d2++;
        }
        printf("%d ", max(aa,bb));
    }

    return 0;
}


#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar()
#define pc(x) putchar(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
const int MM = 3e5+69;

mt19937 g1(time(0));
int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}

int n, in[MM], a[MM], b[MM];
int *at = in+9;

int main(){
    scan(n);
    for(int i = 0; i < n; i++){
        scan(at[i]);
    }

    for(int i = 0; i < n; i++){
        b[i] = max(at[i], at[i+1]);
//        a[i] = min(at[i], max(at[i+1], at[i-1]));
        vector<int> v = {at[i-1], at[i], at[i+1]};
        sort(all(v));
        a[i] = v[1];
    }

    int aa = 0, bb = 0, m = (n-1)/2;
    int tb = n&1, ta = !tb;
    int d1 = 0, d2 = 0;

    for(int i = 0; i < n-1; i++){
        //rm how many
        if((n-i)&1){
            aa = max(aa, max(a[m-d1], a[m+d1+ta]));
            d1++;
            printf("%d ", aa);
        }
        else{
            bb = max(bb, max(b[m-d2-tb], b[m+d2]));
            d2++;
            printf("%d ", bb);
        }
    }
    print(*max_element(at, at+n));

    return 0;

    return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll a[300005];
ll ans[300005];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
		int rest=n-i-1;
		ans[i]=a[n-1-rest/2];
	}
	for(int i=0;i<n;i++){
		printf("%lld%c",ans[i],(i+1)==n?'\n':' ');
	}
	return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

class segtree{
public:
	static const int N=1<<19;
	int dp[1<<20];
	segtree(){
		memset(dp,0,sizeof(dp));
	}
	void update(int k,int v){
		k+=N-1;
		dp[k]+=v;
		while(k>0){
			k=(k-1)/2;
			dp[k]=max(dp[k*2+1],dp[k*2+2]);
		}
	}
	int query(int a,int b,int k=0,int l=0,int r=N){
		if(b<=l || r<=a)return 0;
		if(a<=l && r<=b)return dp[k];
		int mid=(l+r)/2;
		int vl=query(a,b,k*2+1,l,(l+r)/2);
		int vr=query(a,b,k*2+2,(l+r)/2,r);
		return max(vl,vr);
	}
};

segtree eve,odd;

int n;
int a[300005];

int main(void){
	scanf("%d",&n);
	int ma=0;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		ma=max(ma,a[i]);
	}
	for(int i=0;i<n-1;i++){
		eve.update(i,max(a[i],a[i+1]));
	}
	for(int i=0;i<n-2;i++){
		odd.update(i,min(a[i+1],max(a[i],a[i+2])));
	}
	for(int i=0;i<n;i++){
		int x=(n-i)/2;
		if((n-i)%2==0){
			printf("%d%c",eve.query(x-1,n-x),i+1==n?'\n':' ');
		}else{
			if(i==n-1)printf("%d\n",ma);
			else printf("%d%c",odd.query(x-1,n-1-x),i+1==0?'\n':' ');
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define x first
#define y second
#define bg begin()
#define ed end()
#define pb push_back
#define mp make_pair
#define sz(a) int((a).size())
#define R(i,n) for(int i(0);i<(n);++i)
#define L(i,n) for(int i((n)-1);~i;--i)
const int iinf=0x3f3f3f3f;
const ll linf=0x3f3f3f3f3f3f3f3f;

//Data
const int N=3e5;
int n,a[N],mx[N];

//Main
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n;
    R(i,n){
        cin>>a[i];
        int c=abs(i-(n-1-i));
        mx[c]=max(mx[c],a[i]);
    }
    R(i,n-1){
        int c=abs(i-(n-2-i));
        mx[c]=max(mx[c],min(a[i],a[i+1]));
    }
    R(i,n)if(i>=2) mx[i]=max(mx[i],mx[i-2]);
    R(i,n)if(i) cout<<mx[i]<<' ';
    cout<<mx[n-1]<<'\n';
    return 0;
}


#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()
{
	ios_base::sync_with_stdio(false);

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