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.
from typing import Union


class DsuItem:
    def __init__(self, data):
        self.data = data

    def data(self):
        return self.data


class DSU:

    def __init__(self, size: int, initializer: int = 0):
        self.parent = list(range(initializer, size + initializer))
        self.rank = [0] * size

    def make_set(self, index, data=None):
        if data:
            self.parent[index] = DsuItem(data)
        self.parent[index] = index
        self.rank[index] = 0

    def union(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a != b:
            if self.rank[a] < self.rank[b]:
                a, b = b, a
            self.parent[b] = a
            if self.rank[a] == self.rank[b]:
                self.rank[a] += 1

    def find(self, v: int) -> int:
        if v == self.parent[v]:
            return v
        self.parent[v] = self.find(self.parent[v])
        return self.parent[v]


class Stack:
    """
    Implementation of an abstract data type - a stack, by means of a built-in list
    """

    def __init__(self):
        """
        Constructor create instance field `self.nodes`
        """
        self.nodes = []

    def put(self, node):
        """
        Adding an item to the top of the stack
        Parameters
        ----------
        node : object
            any object
        """
        self.nodes.append(node)

    def get(self) -> int:
        """
        Getting an item from the top of the stack and removing it from their stack
        (essentially an implementation of the pop() method)
        Returns
        -------
        object :
            any object - an item from the top of the stack, or None if the stack is empty
        """
        return self.nodes.pop()

    def empty(self) -> bool:
        """
        Checking the stack for emptiness
        Returns
        -------
        bool :
            False if stack is not empty, True otherwise
        """
        return not bool(self.nodes)

    def peek(self) -> Union[int, None]:
        if self.empty():
            return None
        return self.nodes[-1]


class Query:
    def __init__(self, L, R, idx):
        self.L = L
        self.R = R
        self.idx = idx


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

    dsu = DSU(size)
    for i in range(size):
        dsu.make_set(i)

    container = []
    for i in range(size):
        tmp = []
        for j in range(i + 1):
            tmp.append(Query(L=j, R=i, idx=i * size + j))
        container.append(tmp)

    stack = Stack()
    real_answer = [min(childs)] * size
    for i in range(size):
        while not stack.empty() and childs[stack.peek()] > childs[i]:
            dsu.parent[stack.peek()] = i
            stack.get()

        stack.put(i)
        for q in container[i]:
            real_answer[i - q.L] = max(real_answer[i - q.L], childs[dsu.find(q.L)])

    return real_answer


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