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_{i} feet high. 

 [Image] 

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.


-----Input-----

The first line of input contains integer n (1 ≤ n ≤ 2 × 10^5), the number of bears.

The second line contains n integers separated by space, a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9), heights of bears.


-----Output-----

Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x.


-----Examples-----
Input
10
1 2 3 4 5 4 3 2 1 6

Output
6 4 4 3 3 2 2 1 1 1

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = "import math\nimport random\n\nclass AVLTree():\n    def __init__(self, x):\n        self.left = None\n        self.rght = None\n        self.val = x\n        self.height = 1\n        \ndef getHeight0(root):\n    if root==None: return 0\n    return max(getHeight0(root.left), getHeight0(root.rght))+1\n\ndef getHeight(root):\n    if root==None: return 0\n    return root.height\n    #return max(getHeight(root.left), getHeight(root.rght))+1\n\ndef insert(root, x):\n    if root==None: return AVLTree(x)\n    if x==root.val: return root\n    if x<root.val:\n        root.left = insert(root.left, x)\n    elif x>root.val:\n        root.rght = insert(root.rght, x)\n    hl = getHeight(root.left)\n    hr = getHeight(root.rght)\n    root.height = max(hl,hr)+1\n    \n    if hr-hl>1:\n        assert hr-hl==2\n        hrr=getHeight(root.rght.rght)\n        hrl=getHeight(root.rght.left)\n        if hrr==hrl+1:\n            new_root = root.rght\n            root.rght = new_root.left\n            new_root.left = root\n            root.height -= 2\n            return new_root\n        elif hrl==hrr+1:\n            new_root = root.rght.left\n            root.rght.left = new_root.rght\n            new_root.rght = root.rght\n            root.rght = new_root.left\n            new_root.left = root\n            root.height -= 2\n            new_root.height += 1\n            new_root.rght.height -= 1\n            return new_root\n        else:\n            assert False\n    elif hl-hr>1:\n        assert hl-hr==2\n        hlr=getHeight(root.left.rght)\n        hll=getHeight(root.left.left)\n        if hll==hlr+1:\n            new_root = root.left\n            root.left = new_root.rght\n            new_root.rght = root\n            root.height -= 2\n            return new_root\n        elif hlr==hll+1:\n            new_root = root.left.rght\n            root.left.rght = new_root.left\n            new_root.left = root.left\n            root.left = new_root.rght\n            new_root.rght = root\n            root.height -= 2\n            new_root.height += 1\n            new_root.left.height -= 1\n            return new_root\n        else:\n            assert False\n    return root\n\ndef findUpperBound(root, x):\n    if root==None: return None\n    if x>=root.val:\n        return findUpperBound(root.rght, x)\n    tmp_bound = findUpperBound(root.left, x)\n    if tmp_bound==None: return root.val\n    return tmp_bound\n    \ndef findLowerBound(root, x):\n    if root==None: return None\n    if x<=root.val:\n        return findLowerBound(root.left, x)\n    tmp_bound = findLowerBound(root.rght, x)\n    if tmp_bound==None: return root.val\n    return tmp_bound\n    \ndef inorder(root):\n    if root==None: return []\n    return inorder(root.left)+[root.val]+inorder(root.rght)\n\ndef checkHeight(root):\n    if root==None: return True\n    if not checkHeight(root.left): return False\n    if not checkHeight(root.rght): return False\n    return abs(getHeight0(root.left)-getHeight0(root.rght))<=1\n    \ndef testAVL():\n    l = [x for x in range(100)]\n    for i in range(100):\n        ni = random.randint(0,99)\n        l[i],l[ni] = l[ni],l[i]\n\n    tree = None\n    for v in l:\n        tree = insert(tree, v)\n    assert inorder(tree)==[i for i in range(100)]\n    assert checkHeight(tree)==True\n\n\nclass HeapObj():\n    def __init__(self, v, n):\n        self.val = v\n        self.hpidx = n\n        \ndef shiftup(n, r, hp):\n    while r>=0:\n        j = r*2+1\n        if j<n:\n            if j+1<n and hp[j+1].val>hp[j].val: j+=1\n            if hp[j].val <= hp[r].val: return\n            hp[r],hp[j] = hp[j],hp[r]\n            hp[r].hpidx = r\n            hp[j].hpidx = j\n        if r==0: break\n        r = int((r-1)/2)\n\ndef shiftdown(n, r, hp):\n    while r<n:\n        j = r*2+1\n        if j>=n: return\n        if j+1<n and hp[j+1].val>hp[j].val: j+=1\n        if hp[j].val<=hp[r].val: return\n        hp[r],hp[j] = hp[j],hp[r]\n        hp[r].hpidx = r\n        hp[j].hpidx = j\n        r = j\n\ndef testHeap():\n    hp = []\n    for _ in range(100):\n        obj = HeapObj(random.randint(0,9999), len(hp))\n        hp.append(obj)\n        shiftup(len(hp),len(hp)-1,hp)\n    res = []\n    while hp:\n        res.append(hp[0].val)\n        hp[0],hp[-1] = hp[-1],hp[0]\n        hp[0].hpidx = 0\n        hp.pop()\n        shiftdown(len(hp), 0, hp)\n    assert res==sorted(res, reverse=True)\n    \ndef calc(n, a):\n    ia = [x for x in enumerate(a)]\n    ia.sort(key=lambda tp:tp[1])\n    #print('ia={ia}'.format(ia=ia))\n    tree = None\n    tree = insert(tree, -1)\n    tree = insert(tree, n)\n    \n    hpobj = HeapObj(n,0)\n    hp = [hpobj]\n    itv2hpobj = {(0,n-1):hpobj}\n    ret = []\n    nxt = n\n    for idx,val in ia:\n        #Get interval\n        interval_end = findUpperBound(tree, idx)-1\n        interval_bgn = findLowerBound(tree, idx)+1\n        itv = (interval_bgn, interval_end)\n        assert itv in itv2hpobj\n        tree = insert(tree, idx)\n        #Delete this interval from heap\n        itv2hpobj[itv].val = 2*n\n        hpidx = itv2hpobj[itv].hpidx\n        shiftup(len(hp), hpidx, hp)\n        hp[0],hp[-1] = hp[-1],hp[0]\n        hp[0].hpidx = 0\n        hp.pop()\n        del itv2hpobj[itv]\n        shiftdown(len(hp), 0, hp)\n        \n        #Add new interval(s) to heap\n        if idx>interval_bgn:\n            new_obj = HeapObj(idx-interval_bgn, len(hp))\n            hp.append(new_obj)\n            itv2hpobj[(interval_bgn,idx-1)] = new_obj\n            shiftup(len(hp), len(hp)-1, hp)\n        if idx<interval_end:\n            new_obj = HeapObj(interval_end-idx, len(hp))\n            hp.append(new_obj)\n            itv2hpobj[(idx+1,interval_end)] = new_obj\n            shiftup(len(hp), len(hp)-1, hp)\n        NA = 0\n        if len(hp)>0: NA = hp[0].val\n        while nxt>NA:\n            ret.append(val)\n            nxt -= 1\n    assert len(ret)==n\n    ret.reverse()\n    return ret\n\ndef calc_bf(n, a):\n    ans = [None for _ in range(n)]\n    for i in range(n):\n        minij = None\n        for j in range(i,n):\n            l=j-i\n            if minij == None or minij>a[j]:\n                minij = a[j]\n            if ans[l]==None or ans[l]<minij:\n                ans[l] = minij\n    return ans\n\ndef duipai():\n    n = 10\n    a = [random.randint(1,20) for _ in range(n)]\n    res_smt = calc2(n, a)\n    res_btf = calc_bf(n,a)\n    if res_smt != res_btf:\n        print('!')\n        print(a)\n        print(res_smt)\n        print(res_btf)\n        return False\n    return True\ndef duipai_n(times):\n    for i in range(times):\n        print('Att {t}'.format(t=i))\n        if not duipai(): break\n        print()\n        \ndef calc2(n, a):\n    ans = [None for _ in range(n)]\n    bst_intvs = [None for _ in range(n)]\n    stk = [(-1,-2)]\n    for idx,v in enumerate(a+[-1]):\n        while v<=stk[-1][1]:\n            bst_intvs[stk[-1][0]] = idx-stk[-2][0]-2\n            stk.pop()\n        stk.append((idx,v))\n    for i in range(n):\n        iv = bst_intvs[i]\n        if ans[iv]==None or ans[iv]<a[i]:\n            ans[iv] = a[i]\n    #print('preans={0}'.format(ans))\n    for i in range(n-2,-1,-1):\n        if ans[i]==None or ans[i]<ans[i+1]:\n            ans[i] = ans[i+1]\n    return ans\n    \ndef serious():\n    n = int(input())\n    a = [int(x) for x in input().split()]\n    res = calc2(n, a)\n    ans = ''\n    for x in res[:-1]:\n        ans += str(x)+' '\n    ans += str(res[-1])\n    print(ans)\n\ndef main():\n    #duipai_n(1000000)\n    serious()\n    #testHeap()\ndef __starting_point():\n    main()\n\n__starting_point()"
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 22135