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.
n = int(input())
heights = list(map(int, input().split()))

# Step 1: Initialize
max_strength = [0] * n
stack = []

# Step 2: Iterate over bears
for i, height in enumerate(heights):
    # Step 3: Determine group sizes
    start = i
    while stack and stack[-1][0] >= height:
        last_height, last_index = stack.pop()
        max_strength[i - last_index] = max(max_strength[i - last_index], last_height)
        start = last_index

    # Update max strength for the current bear
    max_strength[i - start] = max(max_strength[i - start], height)

    stack.append((height, start))

# Step 5: Handle the end of the array
while stack:
    last_height, last_index = stack.pop()
    max_strength[n - last_index - 1] = max(max_strength[n - last_index - 1], last_height)

# Step 6: Output
# We need to fill in the max_strengths for group sizes that might not be directly computed
# We iterate backwards to ensure that we're getting the maximum strength of larger groups
for i in range(n - 2, -1, -1):
    max_strength[i] = max(max_strength[i], max_strength[i + 1])

print(' '.join(map(str, max_strength)))
