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.
import random, math, sys
from copy import deepcopy as dc
from bisect import bisect_left, bisect_right
from collections import Counter

input = sys.stdin.readline

# Function to call the actual solution
def solution(li):
	n = len(li)
	pse = [-1]*n
	nse = [n+1-1]*n
	stack = []
	for i in range(len(li)):
		if (stack and li[stack[-1]] < li[i]):
			stack.append(i)
		else:
			while stack and li[stack[-1]] > li[i]:
				tmp = stack.pop()
				nse[tmp] = i + 1- 1
			stack.append(i)
	stack = []
	for i in range(len(li)-1, -1, -1):
		if stack and li[stack[-1]] < li[i]:
			stack.append(i)
		else:
			while stack and li[stack[-1]] > li[i]:
				tmp = stack.pop()
				pse[tmp] = i + 1- 1
			stack.append(i)
	mini = 0
	out = [-1]*n
	li1 = [[li[i], i] for i in range(n)]
	li1.sort(key = lambda x: x[0], reverse = True)
	for i in range(n):
		y = nse[li1[i][1]]
		x = pse[li1[i][1]]
		cur = y - x - 1
		for j in range(mini, cur):
			out[j] = li1[i][0]
		mini = cur + 1 - 1
	return out


# Function to take input
def input_test():
	# for _ in range(int(input())):
		n = int(input())
		# a, b = map(int, input().strip().split(" "))
		# a, b, c = map(int, input().strip().split(" "))
		li = list(map(int, input().strip().split(" ")))
		out = solution(li)
		print(*out)

# Function to test my code
def test():
	pass


input_test()
# test()