Mike is the president of country What-The-Fatherland. There are *n* bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to *n* from left to right. *i*-th bear is exactly *a*<sub class="lower-index">*i*</sub> feet high. 

A group of bears is a non-empty contiguous segment of the line. The size of a group is the number of bears in that group. The strength of a group is the minimum height of the bear in that group.

Mike is a curious to know for each *x* such that 1 ≤ *x* ≤ *n* the maximum strength among all groups of size *x*.
The first line of input contains integer *n* (1 ≤ *n* ≤ 2 × 10<sup class="upper-index">5</sup>), the number of bears.

The second line contains *n* integers separated by space, *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>), heights of bears.
# from sys import stdin,stdout
# input = stdin.readline
n=int(input())
ar=list(map(int,input().split()))

def c(ar,reverse=False):
	s=list()
	ind=list()
	ans=[]
	for i in range(len(ar)):
		while(len(s)>0 and s[-1]>ar[i]):
			s.pop()
			ind.pop()

		if(len(s)==0):
			if(reverse==True):
				ans.append(len(ar)-1)
			else:
				ans.append(0)
		else:
			if(reverse==True):
				ans.append(len(ar)-ind[-1]-1)
			else:
				ans.append(ind[-1])
		s.append(ar[i])
		ind.append(i)
	return ans

a=c(ar)
b=c(ar[::-1],True)[::-1]

d={}
# print(a)
# print(b)
# print(ar)
for i in range(n):
	l=a[i]
	r=b[i]
	if(ar[a[i]]<ar[i]):
		l=min(l+1,len(ar)-1)
	if(ar[b[i]]<ar[i]):
		r=max(r-1,0)
	if(d.get(r-l+1)==None):
		d[r-l+1]=ar[i]
	else:
		d[r-l+1]=max(d[r-l+1],ar[i])

mx=[]
k=list(d.keys())
v=list(d.values())
for i in range(len(k)):
	mx.append([k[i],v[i]])
i=len(k)-2
mx.sort()
while(i>=0):
	mx[i][1]=max(mx[i][1],mx[i+1][1])
	i-=1

mn=min(ar)
def bs(mx,i):
	ans=-1
	l=0
	r=len(mx)-1
	while(l<=r):
		m=(l+r)//2
		if(mx[m][0]>=i):
			ans=mx[m][1]
			r=m-1
		else:
			l=m+1
	return ans

# print(d)
# print(a)
# print(b)
# print(mn)
ans=[]
for i in range(n):
	aaa=bs(mx,i+1)
	if(aaa==-1):
		ans.append(mn)
	else:
		ans.append(aaa)
print(*ans)