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.
def max_strength_groups(n, heights):
    # Initialize two empty stacks to keep track of indices and heights
    indices_stack = []
    heights_stack = []

    # Initialize a list to store the result for each group size
    result = [0] * n

    for i in range(n):
        # While the current bear is shorter than the bear on top of the stack
        while indices_stack and heights[i] < heights_stack[-1]:
            # Pop the bear on top of the stack and calculate its strength
            idx = indices_stack.pop()
            height = heights_stack.pop()
            result[i - idx] = max(result[i - idx], height)

        # Push the current bear's index and height onto the stacks
        indices_stack.append(i)
        heights_stack.append(heights[i])

    # Calculate the remaining maximum strengths
    for i in range(n, 0, -1):
        result[i - 1] = max(result[i - 1], result[i])

    return result

# Input
n = int(input())
heights = list(map(int, input().split()))

# Calculate and print the maximum strength for each group size
result = max_strength_groups(n, heights)
print(" ".join(map(str, result)))