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 task2(childs: list) -> list:
    """
    Parameters:
    :pandas (list): panda heights list
    :return: list of maximum group powers
    """
    result = list()
    length = len(childs)
    ch = init(childs)
    if length > 1:
        max_value = max(ch)
        result.append(max_value[0])
        counter = 1
        while len(result) != length - 1:
            set1, set2, value = max_set(ch, counter)
            result.append(value)
            union(ch, set1, set2)
            counter += 1
        union(ch, 0, 1)
    max_value = min(ch[0])
    result.append(max_value)
    return result


def init(childs):
    children = list()
    for child in childs:
        children.append([child])
    return children


def find_min(children):
    maximum = 0
    for child in children:
        if min(child) > maximum:
            maximum = min(child)
    return maximum


def union(children, x, y):
    for i in children[y]:
        children[x].append(i)
    del children[y]


def max_neighbor(children, cur):
    if cur == 0:
        max_value = min(children[cur + 1])
        max_neighbor = cur + 1
        if max_value > min(children[cur]):
            max_value = min(children[cur])
        return max_neighbor, max_value
    elif cur == len(children) - 1:
        max_value = min(children[cur - 1])
        max_neighbor = cur - 1
        if max_value > min(children[cur]):
            max_value = min(children[cur])
        return max_neighbor, max_value
    else:
        max_value = min(children[cur + 1])
        max_neighbor = cur + 1
        if min(children[cur - 1]) > max_value:
            max_value = min(children[cur - 1])
            max_neighbor = cur - 1
        if max_value > min(children[cur]):
            max_value = min(children[cur])
    return max_neighbor, max_value


def max_set(children, counter):
    max = 0
    max_n = 0
    max_cur = 0
    for i in range(len(children)):
        if len(children[i]) != counter:
            continue
        max_neigbour, max_value = max_neighbor(children, i)
        # if len(children[max_neigbour]) + len(children[i]) != counter + 1:
        #     continue
        # print(i, max_neigbour, max_value)
        if max_value > max:
            max = max_value
            max_cur = i
            max_n = max_neigbour
    return max_n, max_cur, max



# class DisjointSet:
#     def __init__(self, n):
#         self.parent = list()
#         self.rank = [0] * n
#
#     def make_set(self, n, v):
#         self.parent[n] = v
#
#     def find(self, v):
#         if v == self.parent[v - 1]:
#             self.parent[v - 1] = self.find(self.parent[v - 1])
#         return v
#
#     def union(self, u, v):
#         n_u = self.find(u)
#         n_v = self.find(v)
#         if n_u != n_v:
#             if self.rank[n_u - 1] < self.rank[n_v - 1]:
#                 tmp = n_u
#                 n_u = n_v
#                 n_v = tmp
#             self.parent[n_v - 1] = n_u
#             if self.rank[n_u - 1] == self.rank[n_v - 1]:
#                 self.rank[n_u - 1] += 1


a = int(input())
arr = list(map(int, input().split()))
print(*task2(arr))
