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.
class DisjointSet:
    def __init__(self, childs):
        indx = [indx for indx, _ in enumerate(childs)]
        self.disjoint = indx
        self.size = [1 for _ in childs]
        self.childs = childs
        self.child_size = len(childs)
        self.borders = [elem for elem in indx]

    def find_set(self, elem):
        par = self.disjoint[elem]
        if elem == par:
            return elem
        res = self.find_set(par)
        self.disjoint[par] = res
        return res

    def union_set(self, a, b):
        set_a = self.find_set(a)
        set_b = self.find_set(b)
        if self.childs[set_a] > self.childs[set_b]:
            set_a, set_b = set_b, set_a
        self.disjoint[set_b] = set_a
        self.size[set_a] = self.size[set_b] + self.size[set_a]
        self.size[set_b] = 0
        self.borders[set_a] = max(self.borders[set_a], self.borders[set_b])

    def find_size(self, a):
        return self.size[self.find_set(a)]

    def find_set_min(self, a):
        return self.childs[self.find_set(a)]

    def find_set_border(self, a):
        return self.borders[self.find_set(a)]




def get_power_list(disjoint_set):
    res = [max(disjoint_set.childs)]
    if len(disjoint_set.childs) ==1:
        return res
    count_current_size = 2
    while True:

        indx = 0
        pair_sum = -1
        pair_pos = -2
        while indx < disjoint_set.child_size - 1:
            indx += 1
            if disjoint_set.find_set(indx) == disjoint_set.find_set(indx - 1):
                indx = disjoint_set.find_set_border(indx)
                # continue
            else:
                if min(disjoint_set.find_set_min(indx), disjoint_set.find_set_min(indx - 1)) > pair_sum:
                    pair_sum = min(disjoint_set.find_set_min(indx), disjoint_set.find_set_min(indx - 1))
                    pair_pos = indx - 1
        disjoint_set.union_set(pair_pos, pair_pos + 1)
        new_set_size = disjoint_set.find_size(pair_pos)
        if new_set_size >= count_current_size:
            while new_set_size >= count_current_size:
                res.append(disjoint_set.find_set_min(pair_pos))
                count_current_size += 1
        if count_current_size > disjoint_set.child_size:
            break

    return res


def task2(childs: list) -> list:
    """
    Parameters:
    :pandas (list): panda heights list
    :return: list of maximum group powers
    """
    pass

    disjoint_set = DisjointSet(childs)
    return get_power_list(disjoint_set)



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