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(n, heights):
    # Step 1: Preprocess the array to find the next smaller elements on both sides for each bear.
    # We use two stacks for this purpose.
    left_smaller = [-1] * n
    right_smaller = [n] * n
    stack = []
    
    for i in range(n):
        while stack and heights[stack[-1]] > heights[i]:
            right_smaller[stack.pop()] = i
        stack.append(i)
    
    stack.clear()
    
    for i in range(n-1, -1, -1):
        while stack and heights[stack[-1]] > heights[i]:
            left_smaller[stack.pop()] = i
        stack.append(i)
    
    # Step 2 and 3: For each bear, calculate the width of the largest group where it's the smallest
    # and update the maximum strength for this group size.
    max_strength = [0] * n
    for i in range(n):
        # Width of the largest group for the current bear
        width = right_smaller[i] - left_smaller[i] - 1
        # Update the maximum strength for this group size.
        max_strength[width-1] = max(max_strength[width-1], heights[i])
    
    # Step 4: Propagate the maximum strengths downwards.
    for i in range(n-2, -1, -1):
        max_strength[i] = max(max_strength[i], max_strength[i+1])
    
    return max_strength

# Example usage:
# n = 5
# heights = [2, 1, 4, 3, 2]
# Expected output for each group size from 1 to n is the maximum strength:
# [4, 3, 2, 1, 1]

# Replace with the actual inputs
n = input()
heights = input().split()
print(heights)

print(max_strength(n, heights))
