#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
const ll maxx=1e5+2;
struct node
{
    ll value;
    ll msize;
    bool operator < (const node &t) const
    {
        return value>t.value;
    }
}arr[maxx];
/**int cmp(const void *a,const void *b){
        return (*(node *)a).msize>(*(node *)b).msize?1:-1;
}*/
int main()
{
    std::ios::sync_with_stdio(false);
    ll left[maxx];
    ll right[maxx];
    ll ans[maxx];
    ll n;
    cin >> n;
    for(ll i = 1; i <= n; i++){
        cin >> arr[i].value;
        arr[i].msize=1;
        left[i]=1;
        right[i]=1;
    }
    for(ll i = 1; i <= n; i++){
        for(ll j = i - 1; j > 0; ){
            if(arr[j].value >= arr[i].value && j > 0){
                left[i] += left[j];
                j = j - left[j];
            }
            else break;
        }
    }
    for(ll i = n; i > 0;i--){
        for(ll j = i + 1; j <= n; ){
            if(arr[j].value >= arr[i].value && j <= n){
                right[i] += right[j];
                j = j + right[j];
            }
            else break;
        }
    }
    ll maxx=0;
    /**for(ll i = 1; i <= n; i++){
            maxx=0;
        for(ll j = 1; j <= n; j++){
            if(left[j] + right[j] - 1 >= i){
                if(arr[j].value > maxx){
                    maxx=arr[j].value;
                }
            }
        }
        printf("%lld ",maxx);
    }*/
    for(ll i = 1; i <= n; i++)
        arr[i].msize = left[i] + right[i] - 1;
    /**qsort(arr,n+1,sizeof(arr[0]),cmp);
    for(ll j = 1; j <= n; j++){
            maxx=0;
    for(ll i = n; i > 0; i--){
        if(arr[i].msize < j) break;
        else{
            if(arr[i].value > maxx) maxx=arr[i].value;
        }
    }
        printf("%d ",maxx);
    }*/
    sort(arr,arr+n+1);
    for(ll i=1,j=0;i<=n;i++)
    {
        while(arr[j].msize<i)
            j++;
        ans[i-1]=arr[j].value;
    }
    for(ll i=0;i<n;i++)
    {
        printf("%d ",ans[i]);
    }
    /**printf("\n");
    for(int i=1;i<=n;i++)
        printf("%d ",arr[i].msize);
    printf("\n");
    for(int i=1;i<=n;i++)
        printf("%d ",arr[i].value);*/
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
const ll maxx=1e4+2;
struct node
{
    ll value;
    ll msize;
};

int main()
{
    struct node arr[maxx];
    ll left[maxx];
    ll right[maxx];
    ll n;
    cin >> n;
    for(ll i = 1; i <= n; i++){
        cin >> arr[i].value;
        arr[i].msize=1;
        left[i]=1;
        right[i]=1;
    }
    for(ll i = 1; i <= n; i++){
        for(ll j = i - 1; j > 0; ){
            if(arr[j].value >= arr[i].value && j > 0){
                left[i] += left[j];
                j = j - left[j];
            }
            else break;
        }
    }
    for(ll i = n; i > 0;i--){
        for(ll j = i + 1; j <= n; ){
            if(arr[j].value >= arr[i].value && j <= n){
                right[i] += right[j];
                j = j + right[j];
            }
            else break;
        }
    }
    ll maxx=0;
    for(ll i = 1; i <= n; i++){
            maxx=0;
        for(ll j = 1; j <= n; j++){
            if(left[j] + right[j] - 1 >= i){
                if(arr[j].value > maxx){
                    maxx=arr[j].value;
                }
            }
        }
        printf("%lld ",maxx);
    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
const ll maxx=1e6+5;
struct node
{
    ll value;
    ll msize;
    bool operator < (const node &t) const
    {
        return value>t.value;
    }
}arr[maxx];
int cmp(const void *a,const void *b){
        return (*(node *)a).value<(*(node *)b).value ? 1:-1;
}
int main()
{
    ll left[maxx];
    ll right[maxx];
    ll ans[maxx];
    ll n;
    cin >> n;
    for(ll i = 1; i <= n; i++){
        cin >> arr[i].value;
        arr[i].msize=1;
        left[i]=1;
        right[i]=1;
    }
    for(ll i = 1; i <= n; i++){
        for(ll j = i - 1; j > 0; ){
            if(arr[j].value >= arr[i].value && j > 0){
                left[i] += left[j];
                j = j - left[j];
            }
            else break;
        }
    }
    for(ll i = n; i > 0;i--){
        for(ll j = i + 1; j <= n; ){
            if(arr[j].value >= arr[i].value && j <= n){
                right[i] += right[j];
                j = j + right[j];
            }
            else break;
        }
    }
    ll maxx=0;
    for(ll i = 1; i <= n; i++)
        arr[i].msize = left[i] + right[i] - 1;
        sort(arr,arr+n+1);
    ///qsort(arr,n+1,sizeof(arr[0]),cmp);
    for(ll j = 1; j <= n; j++){
        for(ll i = 0; i <= n; i++){
            if(arr[i].msize >= j){
                printf("%d ",arr[i].value);
                break;
            }
        }
    }
    /**for(ll i=1,j=0;i<=n;i++)
    {
        while(arr[j].msize<i)
            j++;
        ans[i-1]=arr[j].value;
    }
    for(ll i=0;i<n;i++)
    {
        printf("%d ",ans[i]);
    }*/
    /**printf("\n");
    for(int i=0;i<n;i++)
        printf("%d ",arr[i].msize);
    printf("\n");
    for(int i=0;i<n;i++)
        printf("%d ",arr[i].value);*/
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
const ll maxx=1e4+2;
struct node
{
    ll value;
    ll msize;
};

int main()
{
    struct node arr[maxx];
    ll left[maxx];
    ll right[maxx];
    ll n;
    cin >> n;
    for(ll i = 1; i <= n; i++){
        cin >> arr[i].value;
        arr[i].msize=1;
        left[i]=1;
        right[i]=1;
    }
    for(ll i = 1; i <= n; i++){
        for(ll j = i - 1; j > 0; ){
            if(arr[j].value >= arr[i].value && j > 0){
                left[i] += left[j];
                j = j - left[j];
            }
            else break;
        }
    }
    for(ll i = n; i > 0;i--){
        for(ll j = i + 1; j <= n; ){
            if(arr[j].value >= arr[i].value && j <= n){
                right[i] += right[j];
                j = j + right[j];
            }
            else break;
        }
    }
    ll maxx=0;
    for(ll i = 1; i <= n; i++){
            maxx=0;
        for(ll j = 1; j <= n; j++){
            if(left[j] + right[j] >= i){
                if(arr[j].value > maxx){
                    maxx=arr[j].value;
                }
            }
        }
        printf("%lld ",maxx);
    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
const ll maxx=1e4+2;
struct node
{
    ll value;
    ll msize;
}arr[maxx];
int cmp(const void *a,const void *b){
        return (*(node *)a).msize>(*(node *)b).msize?1:-1;
}
int main()
{
    ///struct node arr[maxx];
    ll left[maxx];
    ll right[maxx];
    ll n;
    cin >> n;
    for(ll i = 1; i <= n; i++){
        cin >> arr[i].value;
        arr[i].msize=1;
        left[i]=1;
        right[i]=1;
    }
    for(ll i = 1; i <= n; i++){
        for(ll j = i - 1; j > 0; ){
            if(arr[j].value >= arr[i].value && j > 0){
                left[i] += left[j];
                j = j - left[j];
            }
            else break;
        }
    }
    for(ll i = n; i > 0;i--){
        for(ll j = i + 1; j <= n; ){
            if(arr[j].value >= arr[i].value && j <= n){
                right[i] += right[j];
                j = j + right[j];
            }
            else break;
        }
    }
    ll maxx=0;
    /**for(ll i = 1; i <= n; i++){
            maxx=0;
        for(ll j = 1; j <= n; j++){
            if(left[j] + right[j] - 1 >= i){
                if(arr[j].value > maxx){
                    maxx=arr[j].value;
                }
            }
        }
        printf("%lld ",maxx);
    }*/
    for(ll i = 1; i <= n; i++)
        arr[i].msize = left[i] + right[i] - 1;
    qsort(arr,n+1,sizeof(arr[0]),cmp);
    for(ll j = 1; j <= n; j++){
            maxx=0;
    for(ll i = n; i > 0; i--){
        if(arr[i].msize < j) break;
        else{
            if(arr[i].value > maxx) maxx=arr[i].value;
        }
    }
        printf("%d ",maxx);
    }
    /**printf("\n");
    for(int i=1;i<=n;i++)
        printf("%d ",arr[i].msize);
    printf("\n");
    for(int i=1;i<=n;i++)
        printf("%d ",arr[i].value);*/
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
const ll maxx=1e5+5;
struct node
{
    ll value;
    ll msize;
    /**bool operator < (const node &t) const
    {
        return value>t.value;
    }*/
}arr[maxx];
int cmp(const void *a,const void *b){
        return (*(node *)a).value<(*(node *)b).value ? 1:-1;
}
int main()
{
    ll left[maxx];
    ll right[maxx];
    ll ans[maxx];
    ll n;
    cin >> n;
    for(ll i = 1; i <= n; i++){
        cin >> arr[i].value;
        arr[i].msize=1;
        left[i]=1;
        right[i]=1;
    }
    for(ll i = 1; i <= n; i++){
        for(ll j = i - 1; j > 0; ){
            if(arr[j].value >= arr[i].value && j > 0){
                left[i] += left[j];
                j = j - left[j];
            }
            else break;
        }
    }
    for(ll i = n; i > 0;i--){
        for(ll j = i + 1; j <= n; ){
            if(arr[j].value >= arr[i].value && j <= n){
                right[i] += right[j];
                j = j + right[j];
            }
            else break;
        }
    }
    ll maxx=0;
    for(ll i = 1; i <= n; i++)
        arr[i].msize = left[i] + right[i] - 1;
    qsort(arr,n+1,sizeof(arr[0]),cmp);
    /**for(ll j = 1; j <= n; j++){
        for(ll i = 0; i <= n; i++){
            if(arr[i].msize >= j){
                printf("%d ",arr[i].value);
                break;
            }
        }
    }*/
    ///sort(arr,arr+n+1);
    for(ll i=1,j=0;i<=n;i++)
    {
        while(arr[j].msize<i)
            j++;
        ans[i-1]=arr[j].value;
    }
    for(ll i=0;i<n;i++)
    {
        printf("%d ",ans[i]);
    }
    /**printf("\n");
    for(int i=0;i<n;i++)
        printf("%d ",arr[i].msize);
    printf("\n");
    for(int i=0;i<n;i++)
        printf("%d ",arr[i].value);*/
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
const ll maxx=1e3+5;
struct node
{
    ll value;
    ll msize;
    /**bool operator < (const node &t) const
    {
        return value>t.value;
    }*/
}arr[maxx];
int cmp(const void *a,const void *b){
        return (*(node *)a).value<(*(node *)b).value ? 1:-1;
}
int main()
{
    ll left[maxx];
    ll right[maxx];
    ll ans[maxx];
    ll n;
    cin >> n;
    for(ll i = 1; i <= n; i++){
        cin >> arr[i].value;
        arr[i].msize=1;
        left[i]=1;
        right[i]=1;
    }
    for(ll i = 1; i <= n; i++){
        for(ll j = i - 1; j > 0; ){
            if(arr[j].value >= arr[i].value && j > 0){
                left[i] += left[j];
                j = j - left[j];
            }
            else break;
        }
    }
    for(ll i = n; i > 0;i--){
        for(ll j = i + 1; j <= n; ){
            if(arr[j].value >= arr[i].value && j <= n){
                right[i] += right[j];
                j = j + right[j];
            }
            else break;
        }
    }
    ll maxx=0;
    for(ll i = 1; i <= n; i++)
        arr[i].msize = left[i] + right[i] - 1;
    qsort(arr,n+1,sizeof(arr[0]),cmp);
    for(ll j = 1; j <= n; j++){
        for(ll i = 0; i <= n; i++){
            if(arr[i].msize >= j){
                printf("%d ",arr[i].value);
                break;
            }
        }
    }
    /**sort(arr,arr+n+1);
    for(ll i=1,j=0;i<=n;i++)
    {
        while(arr[j].msize<i)
            j++;
        ans[i-1]=arr[j].value;
    }
    for(ll i=0;i<n;i++)
    {
        printf("%d ",ans[i]);
    }
    printf("\n");
    for(int i=0;i<n;i++)
        printf("%d ",arr[i].msize);
    printf("\n");
    for(int i=0;i<n;i++)
        printf("%d ",arr[i].value);*/
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
const ll maxx=1e6+5;
struct node
{
    ll value;
    ll msize;
    /**bool operator < (const node &t) const
    {
        return value>t.value;
    }*/
}arr[maxx];
int cmp(const void *a,const void *b){
        return (*(node *)a).value<(*(node *)b).value ? 1:-1;
}
int main()
{
    ll left[maxx];
    ll right[maxx];
    ll ans[maxx];
    ll n;
    cin >> n;
    for(ll i = 1; i <= n; i++){
        cin >> arr[i].value;
        arr[i].msize=1;
        left[i]=1;
        right[i]=1;
    }
    for(ll i = 1; i <= n; i++){
        for(ll j = i - 1; j > 0; ){
            if(arr[j].value >= arr[i].value && j > 0){
                left[i] += left[j];
                j = j - left[j];
            }
            else break;
        }
    }
    for(ll i = n; i > 0;i--){
        for(ll j = i + 1; j <= n; ){
            if(arr[j].value >= arr[i].value && j <= n){
                right[i] += right[j];
                j = j + right[j];
            }
            else break;
        }
    }
    ll maxx=0;
    for(ll i = 1; i <= n; i++)
        arr[i].msize = left[i] + right[i] - 1;
    qsort(arr,n+1,sizeof(arr[0]),cmp);
    /**for(ll j = 1; j <= n; j++){
        for(ll i = 0; i <= n; i++){
            if(arr[i].msize >= j){
                printf("%d ",arr[i].value);
                break;
            }
        }
    }*/
    ///sort(arr,arr+n+1);
    for(ll i=1,j=0;i<=n;i++)
    {
        while(arr[j].msize<i)
            j++;
        ans[i-1]=arr[j].value;
    }
    for(ll i=0;i<n;i++)
    {
        printf("%d ",ans[i]);
    }
    /**printf("\n");
    for(int i=0;i<n;i++)
        printf("%d ",arr[i].msize);
    printf("\n");
    for(int i=0;i<n;i++)
        printf("%d ",arr[i].value);*/
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
const ll maxx=1e6+5;
struct node
{
    ll value;
    ll msize;
    bool operator < (const node &t) const
    {
        return value>t.value;
    }
}arr[maxx];
int cmp(const void *a,const void *b){
        return (*(node *)a).value<(*(node *)b).value ? 1:-1;
}
int main()
{
    ll left[maxx];
    ll right[maxx];
    ll ans[maxx];
    ll n;
    cin >> n;
    for(ll i = 1; i <= n; i++){
        cin >> arr[i].value;
        arr[i].msize=1;
        left[i]=1;
        right[i]=1;
    }
    for(ll i = 1; i <= n; i++){
        for(ll j = i - 1; j > 0; ){
            if(arr[j].value >= arr[i].value && j > 0){
                left[i] += left[j];
                j = j - left[j];
            }
            else break;
        }
    }
    for(ll i = n; i > 0;i--){
        for(ll j = i + 1; j <= n; ){
            if(arr[j].value >= arr[i].value && j <= n){
                right[i] += right[j];
                j = j + right[j];
            }
            else break;
        }
    }
    ll maxx=0;
    for(ll i = 1; i <= n; i++)
        arr[i].msize = left[i] + right[i] - 1;
        ///sort(arr,arr+n+1);
    qsort(arr,n+1,sizeof(arr[0]),cmp);
    for(ll j = 1,i=0; j <= n; j++){
        for(; i <= n; i++){
            if(arr[i].msize >= j){
                printf("%d ",arr[i].value);
                break;
            }
        }
    }
    /**for(ll i=1,j=0;i<=n;i++)
    {
        while(arr[j].msize<i)
            j++;
        ans[i-1]=arr[j].value;
    }
    for(ll i=0;i<n;i++)
    {
        printf("%d ",ans[i]);
    }*/
    /**printf("\n");
    for(int i=0;i<n;i++)
        printf("%d ",arr[i].msize);
    printf("\n");
    for(int i=0;i<n;i++)
        printf("%d ",arr[i].value);*/
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
const ll maxx=1e4+2;
struct node
{
    ll value;
    ll msize;
    bool operator < (const node &t) const
    {
        return value>t.value;
    }
}arr[maxx];
/**int cmp(const void *a,const void *b){
        return (*(node *)a).msize>(*(node *)b).msize?1:-1;
}*/
int main()
{
    std::ios::sync_with_stdio(false);
    ll left[maxx];
    ll right[maxx];
    ll ans[maxx];
    ll n;
    cin >> n;
    for(ll i = 1; i <= n; i++){
        cin >> arr[i].value;
        arr[i].msize=1;
        left[i]=1;
        right[i]=1;
    }
    for(ll i = 1; i <= n; i++){
        for(ll j = i - 1; j > 0; ){
            if(arr[j].value >= arr[i].value && j > 0){
                left[i] += left[j];
                j = j - left[j];
            }
            else break;
        }
    }
    for(ll i = n; i > 0;i--){
        for(ll j = i + 1; j <= n; ){
            if(arr[j].value >= arr[i].value && j <= n){
                right[i] += right[j];
                j = j + right[j];
            }
            else break;
        }
    }
    ll maxx=0;
    /**for(ll i = 1; i <= n; i++){
            maxx=0;
        for(ll j = 1; j <= n; j++){
            if(left[j] + right[j] - 1 >= i){
                if(arr[j].value > maxx){
                    maxx=arr[j].value;
                }
            }
        }
        printf("%lld ",maxx);
    }*/
    for(ll i = 1; i <= n; i++)
        arr[i].msize = left[i] + right[i] - 1;
    /**qsort(arr,n+1,sizeof(arr[0]),cmp);
    for(ll j = 1; j <= n; j++){
            maxx=0;
    for(ll i = n; i > 0; i--){
        if(arr[i].msize < j) break;
        else{
            if(arr[i].value > maxx) maxx=arr[i].value;
        }
    }
        printf("%d ",maxx);
    }*/
    sort(arr,arr+n+1);
    for(ll i=1,j=0;i<=n;i++)
    {
        while(arr[j].msize<i)
            j++;
        ans[i-1]=arr[j].value;
    }
    for(ll i=0;i<n;i++)
    {
        printf("%d ",ans[i]);
    }
    /**printf("\n");
    for(int i=1;i<=n;i++)
        printf("%d ",arr[i].msize);
    printf("\n");
    for(int i=1;i<=n;i++)
        printf("%d ",arr[i].value);*/
    return 0;
}


#include <bits/stdc++.h>
typedef  long long ll;

using namespace std;

const ll maxx=1e5+2;
ll segtree[maxx*4+1];
ll arr[maxx];
void build(ll node, ll left, ll right)
{
    if(left == right){
        segtree[node]=arr[left];
    }
    else{
        build(node* 2, left, (left+right)/2);
        build(node *2+1, (left+right)/2+1, right);
        segtree[node]=min(segtree[node*2], segtree[node*2+1]);
    }
}
ll findd(ll node, ll begin, ll end, ll left, ll right)
{
    ll p1,p2;
    if(left > end || right < begin)
        return -1;
    if(left <= begin && right >= end)
        return segtree[node];
    p1=findd(node * 2, begin, (begin + end)/2, left, right);
    p2=findd(node * 2 + 1, (begin + end)/2 + 1, end, left, right);
    if(p1==-1) return p2;
    if(p2==-1) return p1;
    return min(p1,p2);
}
int main()
{
    ll n;
    cin >> n;
    for(ll i=1;i<=n;i++)
        cin >> arr[i];
    build(1,1,n);
    for(ll i = 0; i < n; i++){
        ll maxx=0;
        for(ll j = 1; j <= n - i; j++){
            ll ma = findd(1,1,n,j,j+i);
            if(ma > maxx){
                maxx = ma;
            }
        }
        printf("%lld ",maxx);
    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
const ll maxx=1e6+5;
struct node
{
    ll value;
    ll msize;
    bool operator < (const node &t) const
    {
        return value>t.value;
    }
}arr[maxx];
int cmp(const void *a,const void *b){
        return (*(node *)a).value<(*(node *)b).value ? 1:-1;
}
int main()
{
    ll left[maxx];
    ll right[maxx];
    ll ans[maxx];
    ll n;
    cin >> n;
    for(ll i = 1; i <= n; i++){
        cin >> arr[i].value;
        arr[i].msize=1;
        left[i]=1;
        right[i]=1;
    }
    for(ll i = 1; i <= n; i++){
        for(ll j = i - 1; j > 0; ){
            if(arr[j].value >= arr[i].value && j > 0){
                left[i] += left[j];
                j = j - left[j];
            }
            else break;
        }
    }
    for(ll i = n; i > 0;i--){
        for(ll j = i + 1; j <= n; ){
            if(arr[j].value >= arr[i].value && j <= n){
                right[i] += right[j];
                j = j + right[j];
            }
            else break;
        }
    }
    ll maxx=0;
    for(ll i = 1; i <= n; i++)
        arr[i].msize = left[i] + right[i] - 1;
        sort(arr,arr+n+1);
    ///qsort(arr,n+1,sizeof(arr[0]),cmp);
    for(ll j = 1,i=0; j <= n; j++){
        for(; i <= n; i++){
            if(arr[i].msize >= j){
                printf("%d ",arr[i].value);
                break;
            }
        }
    }
    /**for(ll i=1,j=0;i<=n;i++)
    {
        while(arr[j].msize<i)
            j++;
        ans[i-1]=arr[j].value;
    }
    for(ll i=0;i<n;i++)
    {
        printf("%d ",ans[i]);
    }*/
    /**printf("\n");
    for(int i=0;i<n;i++)
        printf("%d ",arr[i].msize);
    printf("\n");
    for(int i=0;i<n;i++)
        printf("%d ",arr[i].value);*/
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
const ll maxx=1e3+5;
struct node
{
    ll value;
    ll msize;
    /**bool operator < (const node &t) const
    {
        return value>t.value;
    }*/
}arr[maxx];
int cmp(const void *a,const void *b){
        return (*(node *)a).value<(*(node *)b).value ? 1:-1;
}
int main()
{
    ll left[maxx];
    ll right[maxx];
    ll ans[maxx];
    ll n;
    cin >> n;
    for(ll i = 1; i <= n; i++){
        cin >> arr[i].value;
        arr[i].msize=1;
        left[i]=1;
        right[i]=1;
    }
    for(ll i = 1; i <= n; i++){
        for(ll j = i - 1; j > 0; ){
            if(arr[j].value >= arr[i].value && j > 0){
                left[i] += left[j];
                j = j - left[j];
            }
            else break;
        }
    }
    for(ll i = n; i > 0;i--){
        for(ll j = i + 1; j <= n; ){
            if(arr[j].value >= arr[i].value && j <= n){
                right[i] += right[j];
                j = j + right[j];
            }
            else break;
        }
    }
    ll maxx=0;
    for(ll i = 1; i <= n; i++)
        arr[i].msize = left[i] + right[i] - 1;
    qsort(arr,n+1,sizeof(arr[0]),cmp);
    /**for(ll j = 1; j <= n; j++){
        for(ll i = 0; i <= n; i++){
            if(arr[i].msize >= j){
                printf("%d ",arr[i].value);
                break;
            }
        }
    }*/
    ///sort(arr,arr+n+1);
    for(ll i=1,j=0;i<=n;i++)
    {
        while(arr[j].msize<i)
            j++;
        ans[i-1]=arr[j].value;
    }
    for(ll i=0;i<n;i++)
    {
        printf("%d ",ans[i]);
    }
    /**printf("\n");
    for(int i=0;i<n;i++)
        printf("%d ",arr[i].msize);
    printf("\n");
    for(int i=0;i<n;i++)
        printf("%d ",arr[i].value);*/
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
const ll maxx=1e6+5;
struct node
{
    ll value;
    ll msize;
    bool operator < (const node &t) const
    {
        return value>t.value;
    }
}arr[maxx];
/**int cmp(const void *a,const void *b){
        return (*(node *)a).msize>(*(node *)b).msize?1:-1;
}*/
int main()
{
    ll left[maxx];
    ll right[maxx];
    ll ans[maxx];
    ll n;
    cin >> n;
    for(ll i = 1; i <= n; i++){
        cin >> arr[i].value;
        arr[i].msize=1;
        left[i]=1;
        right[i]=1;
    }
    for(ll i = 1; i <= n; i++){
        for(ll j = i - 1; j > 0; ){
            if(arr[j].value >= arr[i].value && j > 0){
                left[i] += left[j];
                j = j - left[j];
            }
            else break;
        }
    }
    for(ll i = n; i > 0;i--){
        for(ll j = i + 1; j <= n; ){
            if(arr[j].value >= arr[i].value && j <= n){
                right[i] += right[j];
                j = j + right[j];
            }
            else break;
        }
    }
    ll maxx=0;
    /**for(ll i = 1; i <= n; i++){
            maxx=0;
        for(ll j = 1; j <= n; j++){
            if(left[j] + right[j] - 1 >= i){
                if(arr[j].value > maxx){
                    maxx=arr[j].value;
                }
            }
        }
        printf("%lld ",maxx);
    }*/
    for(ll i = 1; i <= n; i++)
        arr[i].msize = left[i] + right[i] - 1;
    /**qsort(arr,n+1,sizeof(arr[0]),cmp);
    for(ll j = 1; j <= n; j++){
            maxx=0;
    for(ll i = n; i > 0; i--){
        if(arr[i].msize < j) break;
        else{
            if(arr[i].value > maxx) maxx=arr[i].value;
        }
    }
        printf("%d ",maxx);
    }*/
    sort(arr,arr+n+1);
    for(ll i=1,j=0;i<=n;i++)
    {
        while(arr[j].msize<i)
            j++;
        ans[i-1]=arr[j].value;
    }
    for(ll i=0;i<n;i++)
    {
        printf("%d ",ans[i]);
    }
    /**printf("\n");
    for(int i=1;i<=n;i++)
        printf("%d ",arr[i].msize);
    printf("\n");
    for(int i=1;i<=n;i++)
        printf("%d ",arr[i].value);*/
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
const ll maxx=1e4+2;
struct node
{
    ll value;
    ll msize;
}arr[maxx];
int cmp(const void *a,const void *b){
        return (*(node *)a).msize>(*(node *)b).msize?1:-1;
}
int main()
{
    std::ios::sync_with_stdio(false);
    ///struct node arr[maxx];
    ll left[maxx];
    ll right[maxx];
    ll n;
    cin >> n;
    for(ll i = 1; i <= n; i++){
        cin >> arr[i].value;
        arr[i].msize=1;
        left[i]=1;
        right[i]=1;
    }
    for(ll i = 1; i <= n; i++){
        for(ll j = i - 1; j > 0; ){
            if(arr[j].value >= arr[i].value && j > 0){
                left[i] += left[j];
                j = j - left[j];
            }
            else break;
        }
    }
    for(ll i = n; i > 0;i--){
        for(ll j = i + 1; j <= n; ){
            if(arr[j].value >= arr[i].value && j <= n){
                right[i] += right[j];
                j = j + right[j];
            }
            else break;
        }
    }
    ll maxx=0;
    /**for(ll i = 1; i <= n; i++){
            maxx=0;
        for(ll j = 1; j <= n; j++){
            if(left[j] + right[j] - 1 >= i){
                if(arr[j].value > maxx){
                    maxx=arr[j].value;
                }
            }
        }
        printf("%lld ",maxx);
    }*/
    for(ll i = 1; i <= n; i++)
        arr[i].msize = left[i] + right[i] - 1;
    qsort(arr,n+1,sizeof(arr[0]),cmp);
    for(ll j = 1; j <= n; j++){
            maxx=0;
    for(ll i = n; i > 0; i--){
        if(arr[i].msize < j) break;
        else{
            if(arr[i].value > maxx) maxx=arr[i].value;
        }
    }
        printf("%d ",maxx);
    }
    /**printf("\n");
    for(int i=1;i<=n;i++)
        printf("%d ",arr[i].msize);
    printf("\n");
    for(int i=1;i<=n;i++)
        printf("%d ",arr[i].value);*/
    return 0;
}


// ICPC champion is here
#include <bits/stdc++.h>
#include<iostream>
#include<map>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<long double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int MAX=524288,inf=1e9+1000000;
int n,tree[MAX],arr[200009],ans[200009];

void build(int s,int e,int b)
{

    if(s==e)
    {
        tree1[b]=arr[s];
        return;
    }

    int mid=(s+e)>>1;

    build(s,mid,b<<1);
    build(mid+1,e,(b<<1)+1);

    tree1[b]=min(tree1[b<<1],tree1[(b<<1)+1]);
}

int querymin(int a,int b,int s=0,int e=n-1,int p=1)
{

    if(s>b||e<a)
      return inf;

    if(s>=a&&e<=b)
    {
        return tree1[p];
    }

    int mid=(s+e)>>1;
   return min(querymin(a,b,s,mid,p<<1),querymin(a,b,mid+1,e,(p<<1)+1));

}

int BS(int val,int id)
{

   int l=id; int h=n-1; int ans1;

   while(l<=h)
   {
       int mid=(l+h)>>1;

       if(querymin(id,mid)==val)
        l=mid+1,ans1=mid;
        else
         h=mid-1;
   }

    l=0;  h=id; int ans2;

   while(l<=h)
   {
       int mid=(l+h)>>1;

       if(querymin(mid,id)==val)
        h=mid-1,ans2=mid;
        else
         l=mid+1;
   }

  return ans1-ans2+1;
}

int main()
{
    M();

    scanf("%d",&n);

   for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);

   build(0,n-1,1);

   int val,siz;
   for(int i=0;i<n;i++)
   {

       val=arr[i];

       siz= BS(val,i);

       ans[siz]=max(ans[siz],val);
   }

   for(int i=n;i>=1;i--)
    ans[i-1]=max(ans[i],ans[i-1]);

   for(int i=1;i<=n;i++)
    printf("%d ",ans[i]);

}


// ICPC champion is here
#include <bits/stdc++.h>
#include<iostream>
#include<map>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<long double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int MAX=524288,inf=1e9+1000000;
int n,arr[200009],ans[200009];
stack< pair<int,int> >st;

int main()
{
    M();

    scanf("%d",&n);

   for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);
   arr[n]=0;
   for(int i=0;i<=n;i++)
   {
       int pos=i;

       while(sz(st)!=0&&st.top().first>=arr[i])
       {
           pos=st.top().second;
          int val=st.top().first;
           st.pop();
           ans[i-pos]=val;
       }

       st.push(mp(arr[i],pos));
   }

   for(int i=n;i>=1;i--)
    ans[i-1]=max(ans[i],ans[i-1]);

   for(int i=1;i<=n;i++)
    printf("%d ",ans[i]);

}


// ICPC champion is here
#include <bits/stdc++.h>
#include<iostream>
#include<map>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<long double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int MAX=524288,inf=1e9+1000000;
int n,tree1[MAX],tree2[MAX],lazy[MAX],arr[200009];

void build(int s,int e,int b)
{

    if(s==e)
    {
        tree1[b]=arr[s];
        return;
    }

    int mid=(s+e)>>1;

    build(s,mid,b*2);
    build(mid+1,e,b*2+1);

    tree1[b]=min(tree1[b*2],tree1[b*2+1]);
}

int querymin(int a,int b,int s=0,int e=n-1,int p=1)
{

    if(s>b||e<a)
      return inf;

    if(s>=a&&e<=b)
    {
        return tree1[p];
    }

    int mid=(s+e)>>1;

   return min(querymin(a,b,s,mid,p*2),querymin(a,b,mid+1,e,p*2+1));

}
void apply(int s,int mid,int e,int p)
{
    if(!lazy[p])
        return;

    int lf=p*2;
    int rg=lf+1;

    lazy[lf]=max(lazy[lf],lazy[p]);

    lazy[rg]=max(lazy[rg],lazy[p]);
    tree2[lf]=lazy[lf];
    tree2[rg]=lazy[rg];

    lazy[p]=0;

}

void update(int s,int e,int a,int b,int p,int val)
{
    if(s>b||e<a)
      return ;

    if(s>=a&&e<=b)
    {

        if(val>tree2[p])
        {
            tree2[p]=val;
            lazy[p]=val;
        }

        return ;
    }

    int mid=(s+e)>>1;
     apply(s,mid,e,p);

     update(s,mid,a,b,p*2,val);
     update(mid+1,e,a,b,p*2+1,val);
}

int query(int s,int e,int a,int b,int p)
{
    if(s>b||e<a)
      return inf;

    if(s>=a&&e<=b)
    {
        return tree2[p];
    }

    int mid=(s+e)>>1;
    apply(s,mid,e,p);

   return min(query(s,mid,a,b,p*2),query(mid+1,e,a,b,p*2+1));

}
bool ok(int l,int r,int val)
{
    if(querymin(l,r)==val)
        return 1;
    return 0;
}
int BS(int val,int id)
{

   int l=id; int h=n-1; int ans1;

   while(l<=h)
   {
       int mid=(l+h)/2;

       if(ok(id,mid,val))
        l=mid+1,ans1=mid;
        else
         h=mid-1;
   }

    l=0;  h=id; int ans2;

   while(l<=h)
   {
       int mid=(l+h)/2;

       if(ok(mid,id,val))
        h=mid-1,ans2=mid;
        else
         l=mid+1;
   }

  return ans1-ans2+1;
}

int main()
{
    M();
    scanf("%d",&n);

   for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);

   build(0,n-1,1);

   for(int i=0;i<n;i++)
   {

       int val=arr[i];

      int siz= BS(val,i);

       update(1,n,1,siz,1,val);
   }

   for(int i=1;i<=n;i++)
        printf("%d ",query(1,n,i,i,1));
}


// ICPC champion is here
#include <bits/stdc++.h>
#include<iostream>
#include<map>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<long double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int MAX=524288,inf=1e9+1000000;
int n,arr[200009],ans[200009];
stack< pair<int,int> >st;

int main()
{
    M();

    scanf("%d",&n);

   for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);
   arr[n]=0;
   for(int i=0;i<=n;i++)
   {
       int pos=i;

       while(sz(st)!=0&&st.top().first>arr[i])
       {
           pos=st.top().second;
          int val=st.top().first;
           st.pop();
           ans[i-pos]=val;
       }

       st.push(mp(arr[i],pos));
   }

   for(int i=n;i>=1;i--)
    ans[i-1]=max(ans[i],ans[i-1]);

   for(int i=1;i<=n;i++)
    printf("%d ",ans[i]);

}


// ICPC champion is here
#include <bits/stdc++.h>
#include<iostream>
#include<map>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<long double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int MAX=524288,inf=1e9+1000000;
int n,tree1[MAX],tree2[MAX],lazy[MAX],arr[200009];

void build(int s,int e,int b)
{

    if(s==e)
    {
        tree1[b]=arr[s];
        return;
    }

    int mid=(s+e)>>1;

    build(s,mid,b*2);
    build(mid+1,e,b*2+1);

    tree1[b]=min(tree1[b*2],tree1[b*2+1]);
}

int querymin(int a,int b,int s=0,int e=n-1,int p=1)
{

    if(s>b||e<a)
      return inf;

    if(s>=a&&e<=b)
    {
        return tree1[p];
    }

    int mid=(s+e)>>1;

   return min(querymin(a,b,s,mid,p*2),querymin(a,b,mid+1,e,p*2+1));

}
void apply(int s,int mid,int e,int p)
{
    if(!lazy[p])
        return;

    int lf=p*2;
    int rg=lf+1;

    lazy[lf]=max(lazy[lf],lazy[p]);

    lazy[rg]=max(lazy[rg],lazy[p]);
    tree2[lf]=lazy[lf];
    tree2[rg]=lazy[rg];

    lazy[p]=0;

}

void update(int s,int e,int a,int b,int p,int val)
{
    if(s>b||e<a)
      return ;

    if(s>=a&&e<=b)
    {

        if(val>tree2[p])
        {
            tree2[p]=val;
            lazy[p]=val;
        }

        return ;
    }

    int mid=(s+e)>>1;
     apply(s,mid,e,p);

     update(s,mid,a,b,p*2,val);
     update(mid+1,e,a,b,p*2+1,val);
}

int query(int s,int e,int a,int b,int p)
{

    if(s>=a&&e<=b)
    {
        return tree2[p];
    }

    int mid=(s+e)>>1;
     apply(s,mid,e,p);

    if(a<=mid)
     return query(s,mid,a,b,p*2);
    else if(a>mid)
     return query(mid+1,e,a,b,p*2+1);

}
bool ok(int l,int r,int val)
{
    if(querymin(l,r)==val)
        return 1;
    return 0;
}
int BS(int val,int id)
{

   int l=id; int h=n-1; int ans1;

   while(l<=h)
   {
       int mid=(l+h)/2;

       if(ok(id,mid,val))
        l=mid+1,ans1=mid;
        else
         h=mid-1;
   }

    l=0;  h=id; int ans2;

   while(l<=h)
   {
       int mid=(l+h)/2;

       if(ok(mid,id,val))
        h=mid-1,ans2=mid;
        else
         l=mid+1;
   }

  return ans1-ans2+1;
}

int main()
{
    scanf("%d",&n);

   for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);

   build(0,n-1,1);

   for(int i=0;i<n;i++)
   {

       int val=arr[i];

      int siz= BS(val,i);

       update(1,n,1,siz,1,val);
   }

   for(int i=1;i<=n;i++)
        printf("%d ",query(1,n,i,i,1));
}


// ICPC champion is here
#include <bits/stdc++.h>
#include<iostream>
#include<map>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<long double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int MAX=524288,inf=1e9+1000000;
int n,tree1[MAX],tree2[MAX],lazy[MAX],arr[200009];

void build(int s,int e,int b)
{

    if(s==e)
    {
        tree1[b]=arr[s];
        return;
    }

    int mid=(s+e)>>1;

    build(s,mid,b<<1);
    build(mid+1,e,(b<<1)+1);

    tree1[b]=min(tree1[b<<1],tree1[(b<<1)+1]);
}

int querymin(int a,int b,int s=0,int e=n-1,int p=1)
{

    if(s>b||e<a)
      return inf;

    if(s>=a&&e<=b)
    {
        return tree1[p];
    }

    int mid=(s+e)>>1;

   return min(querymin(a,b,s,mid,p<<1),querymin(a,b,mid+1,e,(p<<1)+1));

}
void apply(int s,int mid,int e,int p)
{
    if(!lazy[p])
        return;

    int lf=p<<1;
    int rg=lf+1;

    lazy[lf]=max(lazy[lf],lazy[p]);

    lazy[rg]=max(lazy[rg],lazy[p]);
    tree2[lf]=lazy[lf];
    tree2[rg]=lazy[rg];

    lazy[p]=0;

}

void update(int s,int e,int a,int b,int p,int val)
{
    if(s>b||e<a)
      return ;

    if(s>=a&&e<=b)
    {

        if(val>tree2[p])
        {
            tree2[p]=val;
            lazy[p]=val;
        }

        return ;
    }

    int mid=(s+e)>>1;
     apply(s,mid,e,p);

     update(s,mid,a,b,p<<1,val);
     update(mid+1,e,a,b,(p<<1)+1,val);
}

int query(int s,int e,int a,int b,int p)
{

    if(s>=a&&e<=b)
    {
        return tree2[p];
    }

    int mid=(s+e)>>1;
     apply(s,mid,e,p);

    if(a<=mid)
     return query(s,mid,a,b,p<<1);
    else if(a>mid)
     return query(mid+1,e,a,b,(p<<1)+1);

}
bool ok(int l,int r,int val)
{
    if(querymin(l,r)==val)
        return 1;
    return 0;
}
int BS(int val,int id)
{

   int l=id; int h=n-1; int ans1;

   while(l<=h)
   {
       int mid=(l+h)>>1;

       if(ok(id,mid,val))
        l=mid+1,ans1=mid;
        else
         h=mid-1;
   }

    l=0;  h=id; int ans2;

   while(l<=h)
   {
       int mid=(l+h)>>1;

       if(ok(mid,id,val))
        h=mid-1,ans2=mid;
        else
         l=mid+1;
   }

  return ans1-ans2+1;
}

int main()
{
    M();

    scanf("%d",&n);

   for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);

   build(0,n-1,1);

   int val,siz;
   for(int i=0;i<n;i++)
   {

       val=arr[i];

       siz= BS(val,i);

       update(1,n,1,siz,1,val);
   }

   for(int i=1;i<=n;i++)
        printf("%d ",query(1,n,i,i,1));
}


// ICPC champion is here
#include <bits/stdc++.h>
#include<iostream>
#include<map>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<long double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int MAX=524288,inf=1e9+1000000;
int n,tree1[MAX],tree2[MAX],lazy[MAX],arr[200009];

void build(int s,int e,int b)
{

    if(s==e)
    {
        tree1[b]=arr[s];
        return;
    }

    int mid=(s+e)>>1;

    build(s,mid,b*2);
    build(mid+1,e,b*2+1);

    tree1[b]=min(tree1[b*2],tree1[b*2+1]);
}

int querymin(int a,int b,int s=0,int e=n-1,int p=1)
{

    if(s>b||e<a)
      return inf;

    if(s>=a&&e<=b)
    {
        return tree1[p];
    }

    int mid=(s+e)>>1;

   return min(querymin(a,b,s,mid,p*2),querymin(a,b,mid+1,e,p*2+1));

}
void apply(int s,int mid,int e,int p)
{
    if(!lazy[p])
        return;

    int lf=p*2;
    int rg=lf+1;

    lazy[lf]=max(lazy[lf],lazy[p]);

    lazy[rg]=max(lazy[rg],lazy[p]);
    tree2[lf]=lazy[lf];
    tree2[rg]=lazy[rg];

    lazy[p]=0;

}

void update(int s,int e,int a,int b,int p,int val)
{
    if(s>b||e<a)
      return ;

    if(s>=a&&e<=b)
    {

        if(val>tree2[p])
        {
            tree2[p]=val;
            lazy[p]=val;
        }

        return ;
    }

    int mid=(s+e)>>1;
     apply(s,mid,e,p);

     update(s,mid,a,b,p*2,val);
     update(mid+1,e,a,b,p*2+1,val);
}

int query(int s,int e,int a,int b,int p)
{

    if(s>=a&&e<=b)
    {
        return tree2[p];
    }

    int mid=(s+e)>>1;
     apply(s,mid,e,p);

    if(a<=mid)
     return query(s,mid,a,b,p*2);
    else if(a>mid)
     return query(mid+1,e,a,b,p*2+1);

}
bool ok(int l,int r,int val)
{
    if(querymin(l,r)==val)
        return 1;
    return 0;
}
int BS(int val,int id)
{

   int l=id; int h=n-1; int ans1;

   while(l<=h)
   {
       int mid=(l+h)/2;

       if(ok(id,mid,val))
        l=mid+1,ans1=mid;
        else
         h=mid-1;
   }

    l=0;  h=id; int ans2;

   while(l<=h)
   {
       int mid=(l+h)/2;

       if(ok(mid,id,val))
        h=mid-1,ans2=mid;
        else
         l=mid+1;
   }

  return ans1-ans2+1;
}

int main()
{
   M();
    scanf("%d",&n);

   for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);

   build(0,n-1,1);

   for(int i=0;i<n;i++)
   {

       int val=arr[i];

      int siz= BS(val,i);

       update(1,n,1,siz,1,val);
   }

   for(int i=1;i<=n;i++)
        printf("%d ",query(1,n,i,i,1));
}


// ICPC champion is here
#include <bits/stdc++.h>
#include<iostream>
#include<map>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<long double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int MAX=524288,inf=1e9+1000000;
int n,tree1[MAX],tree2[MAX],lazy[MAX],arr[200009];

void build(int s,int e,int b)
{

    if(s==e)
    {
        tree1[b]=arr[s];
        return;
    }

    int mid=(s+e)>>1;

    build(s,mid,b*2);
    build(mid+1,e,b*2+1);

    tree1[b]=min(tree1[b*2],tree1[b*2+1]);
}

int querymin(int a,int b,int s=0,int e=n-1,int p=1)
{

    if(s>b||e<a)
      return inf;

    if(s>=a&&e<=b)
    {
        return tree1[p];
    }

    int mid=(s+e)>>1;

   return min(querymin(a,b,s,mid,p*2),querymin(a,b,mid+1,e,p*2+1));

}
void apply(int s,int mid,int e,int p)
{
    if(!lazy[p])
        return;

    int lf=p*2;
    int rg=lf+1;

    lazy[lf]=max(lazy[lf],lazy[p]);

    lazy[rg]=max(lazy[rg],lazy[p]);
    tree2[lf]=lazy[lf];
    tree2[rg]=lazy[rg];

    lazy[p]=0;

}

void update(int s,int e,int a,int b,int p,int val)
{
    if(s>b||e<a)
      return ;

    if(s>=a&&e<=b)
    {

        if(val>tree2[p])
        {
            tree2[p]=val;
            lazy[p]=val;
        }

        return ;
    }

    int mid=(s+e)>>1;
     apply(s,mid,e,p);

     update(s,mid,a,b,p*2,val);
     update(mid+1,e,a,b,p*2+1,val);
}

int query(int s,int e,int a,int b,int p)
{
    if(s>b||e<a)
      return inf;

    if(s>=a&&e<=b)
    {
        return tree2[p];
    }

    int mid=(s+e)>>1;
    apply(s,mid,e,p);

   return min(query(s,mid,a,b,p*2),query(mid+1,e,a,b,p*2+1));

}
bool ok(int l,int r,int val)
{
    if(querymin(l,r)==val)
        return 1;
    return 0;
}
int BS(int val,int id)
{

   int l=id; int h=n-1; int ans1;

   while(l<=h)
   {
       int mid=(l+h)/2;
      // cout<<mid<<endl;
       if(ok(id,mid,val))
        l=mid+1,ans1=mid;//,cout<<mid<<endl;
        else
         h=mid-1;
   }

    l=0;  h=id; int ans2;

   while(l<=h)
   {
       int mid=(l+h)/2;

       if(ok(mid,id,val))
        h=mid-1,ans2=mid;
        else
         l=mid+1;
   }
//cout<<ans1<<" "<<ans2<<endl;
  return ans1-ans2+1;
}

int main()
{
   M();
    cin>>n;

   for(int i=0;i<n;i++)
    cin>>arr[i];

   build(0,n-1,1);

   for(int i=0;i<n;i++)
   {

       int val=arr[i];

      int siz= BS(val,i);
    //cout<<siz<<endl<<endl;
       update(1,n,1,siz,1,val);
   }
  // cout<<querymin(1,1)<<endl;

   for(int i=1;i<=n;i++)
        cout<<query(1,n,i,i,1)<<" ";
}


// ICPC champion is here
#include <bits/stdc++.h>
#include<iostream>
#include<map>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<long double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int MAX=524288,inf=1e9+1000000;
int n,tree[MAX],arr[200009],ans[200009];

void build(int s,int e,int b)
{

    if(s==e)
    {
        tree[b]=arr[s];
        return;
    }

    int mid=(s+e)>>1;

    build(s,mid,b<<1);
    build(mid+1,e,(b<<1)+1);

    tree[b]=min(tree[b<<1],tree[(b<<1)+1]);
}

int querymin(int a,int b,int s=0,int e=n-1,int p=1)
{

    if(s>b||e<a)
      return inf;

    if(s>=a&&e<=b)
    {
        return tree[p];
    }

    int mid=(s+e)>>1;
   return min(querymin(a,b,s,mid,p<<1),querymin(a,b,mid+1,e,(p<<1)+1));

}

int BS(int val,int id)
{

   int l=id; int h=n-1; int ans1;

   while(l<=h)
   {
       int mid=(l+h)>>1;

       if(querymin(id,mid)==val)
        l=mid+1,ans1=mid;
        else
         h=mid-1;
   }

    l=0;  h=id; int ans2;

   while(l<=h)
   {
       int mid=(l+h)>>1;

       if(querymin(mid,id)==val)
        h=mid-1,ans2=mid;
        else
         l=mid+1;
   }

  return ans1-ans2+1;
}

int main()
{
    M();

    scanf("%d",&n);

   for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);

   build(0,n-1,1);

   int val,siz;
   for(int i=0;i<n;i++)
   {

       val=arr[i];

       siz= BS(val,i);

       ans[siz]=max(ans[siz],val);
   }

   for(int i=n;i>=1;i--)
    ans[i-1]=max(ans[i],ans[i-1]);

   for(int i=1;i<=n;i++)
    printf("%d ",ans[i]);

}


// ICPC champion is here
#include <bits/stdc++.h>
#include<iostream>
#include<map>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<long double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int MAX=524288,inf=1e9+1000000;
int n,a[MAX][19],arr[200009],ans[200009];

int minquery(int l,int r)
{
    int siz=r-l+1;
    int mx=log2(siz);

    if(arr[a[l][mx]]<=arr[a[r-(1<<(mx))+1][mx]])
        return arr[a[l][mx]];

    return arr[a[r-(1<<(mx))+1][mx]];
}

bool ok(int l,int r,int val)
{
    int vv=minquery(l,r);

    if(vv==val)
        return 1;
    return 0;
}
int BS(int val,int id)
{

   int l=id; int h=n-1; int ans1;

   while(l<=h)
   {
       int mid=(l+h)>>1;

       if(ok(id,mid,val))
        l=mid+1,ans1=mid;
        else
         h=mid-1;
   }

    l=0;  h=id; int ans2;

   while(l<=h)
   {
       int mid=(l+h)>>1;

       if(ok(mid,id,val))
        h=mid-1,ans2=mid;
        else
         l=mid+1;
   }

  return ans1-ans2+1;
}

void ST()
{
    for(int i=0;i<n;i++)
        a[i][0]=i;

    for(int j=1;(1<<j)<=n;j++)
    {
        for(int i=0;(i+(1<<j)-1)<n;i++)
        {
            if(arr[a[i][j-1]]<arr[a[i+(1<<(j-1))][j-1]])
            a[i][j]=a[i][j-1];
            else
               a[i][j]= a[i+(1<<(j-1))][j-1];

        }

    }

}

int main()
{
    M();

    scanf("%d",&n);

   for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);

   ST();

   int val,siz;
   for(int i=0;i<n;i++)
   {

       val=arr[i];

       siz= BS(val,i);

       ans[siz]=max(ans[siz],val);
   }

   for(int i=n;i>=1;i--)
    ans[i-1]=max(ans[i],ans[i-1]);

   for(int i=1;i<=n;i++)
    printf("%d ",ans[i]);

}


// ICPC champion is here
#include <bits/stdc++.h>
#include<iostream>
#include<map>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<long double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int MAX=524288,inf=1e9+1000000;
int n,tree1[MAX],tree2[MAX],lazy[MAX],arr[200009];

void build(int s,int e,int b)
{

    if(s==e)
    {
        tree1[b]=arr[s];
        return;
    }

    int mid=(s+e)>>1;

    build(s,mid,b*2);
    build(mid+1,e,b*2+1);

    tree1[b]=min(tree1[b*2],tree1[b*2+1]);
}

int querymin(int a,int b,int s=0,int e=n-1,int p=1)
{

    if(s>b||e<a)
      return inf;

    if(s>=a&&e<=b)
    {
        return tree1[p];
    }

    int mid=(s+e)>>1;

   return min(querymin(a,b,s,mid,p*2),querymin(a,b,mid+1,e,p*2+1));

}
void apply(int s,int mid,int e,int p)
{
    if(!lazy[p])
        return;

    int lf=p*2;
    int rg=lf+1;

    lazy[lf]=max(lazy[lf],lazy[p]);

    lazy[rg]=max(lazy[rg],lazy[p]);
    tree2[lf]=lazy[lf];
    tree2[rg]=lazy[rg];

    lazy[p]=0;

}

void update(int s,int e,int a,int b,int p,int val)
{
    if(s>b||e<a)
      return ;

    if(s>=a&&e<=b)
    {

        if(val>tree2[p])
        {
            tree2[p]=val;
            lazy[p]=val;
        }

        return ;
    }

    int mid=(s+e)>>1;
     apply(s,mid,e,p);

     update(s,mid,a,b,p*2,val);
     update(mid+1,e,a,b,p*2+1,val);
}

int query(int s,int e,int a,int b,int p)
{

    if(s>=a&&e<=b)
    {
        return tree2[p];
    }

    int mid=(s+e)>>1;
     apply(s,mid,e,p);

    if(a<=mid)
     return query(s,mid,a,b,p*2);
    else if(a>mid)
     return query(mid+1,e,a,b,p*2+1);

}
bool ok(int l,int r,int val)
{
    if(querymin(l,r)==val)
        return 1;
    return 0;
}
int BS(int val,int id)
{

   int l=id; int h=n-1; int ans1;

   while(l<=h)
   {
       int mid=(l+h)/2;

       if(ok(id,mid,val))
        l=mid+1,ans1=mid;
        else
         h=mid-1;
   }

    l=0;  h=id; int ans2;

   while(l<=h)
   {
       int mid=(l+h)/2;

       if(ok(mid,id,val))
        h=mid-1,ans2=mid;
        else
         l=mid+1;
   }

  return ans1-ans2+1;
}

int main()
{
    freopen("in.in", "r", stdin);
    freopen("out.out", "w", stdout);

    scanf("%d",&n);

   for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);

   build(0,n-1,1);

   for(int i=0;i<n;i++)
   {

       int val=arr[i];

      int siz= BS(val,i);

       update(1,n,1,siz,1,val);
   }

   for(int i=1;i<=n;i++)
        printf("%d ",query(1,n,i,i,1));
}


// ICPC champion is here
#include <bits/stdc++.h>
#include<iostream>
#include<map>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<long double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int MAX=524288,inf=1e9+1000000;
int n,tree1[MAX],tree2[MAX],lazy[MAX],arr[200009],ans[200009];

void build(int s,int e,int b)
{

    if(s==e)
    {
        tree1[b]=arr[s];
        return;
    }

    int mid=(s+e)>>1;

    build(s,mid,b<<1);
    build(mid+1,e,(b<<1)+1);

    tree1[b]=min(tree1[b<<1],tree1[(b<<1)+1]);
}

int querymin(int a,int b,int s=0,int e=n-1,int p=1)
{

    if(s>b||e<a)
      return inf;

    if(s>=a&&e<=b)
    {
        return tree1[p];
    }

    int mid=(s+e)>>1;

   return min(querymin(a,b,s,mid,p<<1),querymin(a,b,mid+1,e,(p<<1)+1));

}
void apply(int s,int mid,int e,int p)
{
    if(!lazy[p])
        return;

    int lf=p<<1;
    int rg=lf+1;

    lazy[lf]=max(lazy[lf],lazy[p]);

    lazy[rg]=max(lazy[rg],lazy[p]);
    tree2[lf]=lazy[lf];
    tree2[rg]=lazy[rg];

    lazy[p]=0;

}

void update(int s,int e,int a,int b,int p,int val)
{
    if(s>b||e<a)
      return ;

    if(s>=a&&e<=b)
    {

        if(val>tree2[p])
        {
            tree2[p]=val;
            lazy[p]=val;
        }

        return ;
    }

    int mid=(s+e)>>1;
     apply(s,mid,e,p);

     update(s,mid,a,b,p<<1,val);
     update(mid+1,e,a,b,(p<<1)+1,val);
}

int query(int s,int e,int a,int b,int p)
{

    if(s>=a&&e<=b)
    {
        return tree2[p];
    }

    int mid=(s+e)>>1;
     apply(s,mid,e,p);

    if(a<=mid)
     return query(s,mid,a,b,p<<1);
    else if(a>mid)
     return query(mid+1,e,a,b,(p<<1)+1);

}
bool ok(int l,int r,int val)
{
    if(querymin(l,r)==val)
        return 1;
    return 0;
}
int BS(int val,int id)
{

   int l=id; int h=n-1; int ans1;

   while(l<=h)
   {
       int mid=(l+h)>>1;

       if(ok(id,mid,val))
        l=mid+1,ans1=mid;
        else
         h=mid-1;
   }

    l=0;  h=id; int ans2;

   while(l<=h)
   {
       int mid=(l+h)>>1;

       if(ok(mid,id,val))
        h=mid-1,ans2=mid;
        else
         l=mid+1;
   }

  return ans1-ans2+1;
}

int main()
{
    M();

    scanf("%d",&n);

   for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);

   build(0,n-1,1);

   int val,siz;
   for(int i=0;i<n;i++)
   {

       val=arr[i];

       siz= BS(val,i);

       //update(1,n,1,siz,1,val);

       ans[siz]=max(ans[siz],val);
   }

   for(int i=n;i>=1;i--)
    ans[i-1]=max(ans[i],ans[i-1]);

   for(int i=1;i<=n;i++)
    cout<<ans[i]<<" ";

}


// ICPC champion is here
#include <bits/stdc++.h>
#include<iostream>
#include<map>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<long double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int MAX=524288,inf=1e9+1000000;
int n,arr[200009],ans[200009];
pair<int,int> tree[MAX];

void build(int s,int e,int b)
{

    if(s==e)
    {
        tree[b]=mp(arr[s],s);
        return;
    }

    int mid=(s+e)>>1;

    build(s,mid,b<<1);
    build(mid+1,e,(b<<1)+1);

    tree[b]=min(tree[b<<1],tree[(b<<1)+1]);
}

pair<int,int> querymin(int a,int b,int s=0,int e=n-1,int p=1)
{

    if(s>b||e<a)
      return mp(inf,0);

    if(s>=a&&e<=b)
    {
        return tree[p];
    }

    int mid=(s+e)>>1;
   return min(querymin(a,b,s,mid,p<<1),querymin(a,b,mid+1,e,(p<<1)+1));

}

void solve(int l,int r)
{

   if(r>n||l<0||r<l)
    return;

   pair<int,int> c=querymin(l,r);

   ans[r-l+1]=max(ans[r-l+1],c.first);

   solve(c.second+1,r);
   solve(l,c.second-1);

}

int main()
{
    M();

    scanf("%d",&n);

   for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);

    build(0,n-1,1);
   solve(0,n-1);

   for(int i=n;i>=1;i--)
    ans[i-1]=max(ans[i],ans[i-1]);

   for(int i=1;i<=n;i++)
    printf("%d ",ans[i]);

}


// ICPC champion is here
#include <bits/stdc++.h>
#include<iostream>
#include<map>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<long double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int MAX=524288,inf=1e9+1000000;
int n,tree1[MAX],tree2[MAX],lazy[MAX],arr[200009],ans[200009];

void build(int s,int e,int b)
{

    if(s==e)
    {
        tree1[b]=arr[s];
        return;
    }

    int mid=(s+e)>>1;

    build(s,mid,b<<1);
    build(mid+1,e,(b<<1)+1);

    tree1[b]=min(tree1[b<<1],tree1[(b<<1)+1]);
}

int querymin(int a,int b,int s=0,int e=n-1,int p=1)
{

    if(s>b||e<a)
      return inf;

    if(s>=a&&e<=b)
    {
        return tree1[p];
    }

    int mid=(s+e)>>1;

   return min(querymin(a,b,s,mid,p<<1),querymin(a,b,mid+1,e,(p<<1)+1));

}
void apply(int s,int mid,int e,int p)
{
    if(!lazy[p])
        return;

    int lf=p<<1;
    int rg=lf+1;

    lazy[lf]=max(lazy[lf],lazy[p]);

    lazy[rg]=max(lazy[rg],lazy[p]);
    tree2[lf]=lazy[lf];
    tree2[rg]=lazy[rg];

    lazy[p]=0;

}

void update(int s,int e,int a,int b,int p,int val)
{
    if(s>b||e<a)
      return ;

    if(s>=a&&e<=b)
    {

        if(val>tree2[p])
        {
            tree2[p]=val;
            lazy[p]=val;
        }

        return ;
    }

    int mid=(s+e)>>1;
     apply(s,mid,e,p);

     update(s,mid,a,b,p<<1,val);
     update(mid+1,e,a,b,(p<<1)+1,val);
}

int query(int s,int e,int a,int b,int p)
{

    if(s>=a&&e<=b)
    {
        return tree2[p];
    }

    int mid=(s+e)>>1;
     apply(s,mid,e,p);

    if(a<=mid)
     return query(s,mid,a,b,p<<1);
    else if(a>mid)
     return query(mid+1,e,a,b,(p<<1)+1);

}
bool ok(int l,int r,int val)
{
    if(querymin(l,r)==val)
        return 1;
    return 0;
}
int BS(int val,int id)
{

   int l=id; int h=n-1; int ans1;

   while(l<=h)
   {
       int mid=(l+h)>>1;

       if(ok(id,mid,val))
        l=mid+1,ans1=mid;
        else
         h=mid-1;
   }

    l=0;  h=id; int ans2;

   while(l<=h)
   {
       int mid=(l+h)>>1;

       if(ok(mid,id,val))
        h=mid-1,ans2=mid;
        else
         l=mid+1;
   }

  return ans1-ans2+1;
}

int main()
{
    M();

    scanf("%d",&n);

   for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);

   build(0,n-1,1);

   int val,siz;
   for(int i=0;i<n;i++)
   {

       val=arr[i];

       siz= BS(val,i);

       //update(1,n,1,siz,1,val);

       ans[siz]=max(ans[siz],val);
   }

   for(int i=n;i>=1;i--)
    ans[i-1]=max(ans[i],ans[i-1]);

   for(int i=1;i<=n;i++)
    printf("%d ",ans[i]);

}


// ICPC champion is here
#include <bits/stdc++.h>
#include<iostream>
#include<map>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<long double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int MAX=524288,inf=1e9+1000000;
int n,arr[200009],ans[200009];
stack< pair<int,int> >st;

int main()
{
    M();

    scanf("%d",&n);

   for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);
   arr[n]=0;
   for(int i=0;i<=n;i++)
   {
       int pos=i;

       while(sz(st)!=0&&st.top().first>arr[i])
       {
           pos=st.top().second;
          int val=st.top().first;
           st.pop();
           ans[i-pos]=max(val,ans[i-pos]);
       }

       st.push(mp(arr[i],pos));
   }

   for(int i=n;i>=1;i--)
    ans[i-1]=max(ans[i],ans[i-1]);

   for(int i=1;i<=n;i++)
    printf("%d ",ans[i]);

}


// ICPC champion is here
#include <bits/stdc++.h>
#include<iostream>
#include<map>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<long double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int MAX=524288,inf=1e9+1000000;
int n,tree1[MAX],tree2[MAX],lazy[MAX],arr[200009];

void build(int s,int e,int b)
{

    if(s==e)
    {
        tree1[b]=arr[s];
        return;
    }

    int mid=(s+e)>>1;

    build(s,mid,b*2);
    build(mid+1,e,b*2+1);

    tree1[b]=min(tree1[b*2],tree1[b*2+1]);
}

int querymin(int a,int b,int s=0,int e=n-1,int p=1)
{

    if(s>b||e<a)
      return inf;

    if(s>=a&&e<=b)
    {
        return tree1[p];
    }

    int mid=(s+e)>>1;

   return min(querymin(a,b,s,mid,p*2),querymin(a,b,mid+1,e,p*2+1));

}
void apply(int s,int mid,int e,int p)
{
    if(!lazy[p])
        return;

    int lf=p*2;
    int rg=lf+1;

    lazy[lf]=max(lazy[lf],lazy[p]);

    lazy[rg]=max(lazy[rg],lazy[p]);
    tree2[lf]=lazy[lf];
    tree2[rg]=lazy[rg];

    lazy[p]=0;

}

void update(int s,int e,int a,int b,int p,int val)
{
    if(s>b||e<a)
      return ;

    if(s>=a&&e<=b)
    {

        if(val>tree2[p])
        {
            tree2[p]=val;
            lazy[p]=val;
        }

        return ;
    }

    int mid=(s+e)>>1;
     apply(s,mid,e,p);

     update(s,mid,a,b,p*2,val);
     update(mid+1,e,a,b,p*2+1,val);
}

int query(int s,int e,int a,int b,int p)
{

    if(s>=a&&e<=b)
    {
        return tree2[p];
    }

    int mid=(s+e)>>1;
     apply(s,mid,e,p);

    if(a<=mid)
     return query(s,mid,a,b,p*2);
    else if(a>mid)
     return query(mid+1,e,a,b,p*2+1);

}
bool ok(int l,int r,int val)
{
    if(querymin(l,r)==val)
        return 1;
    return 0;
}
int BS(int val,int id)
{

   int l=id; int h=n-1; int ans1;

   while(l<=h)
   {
       int mid=(l+h)/2;

       if(ok(id,mid,val))
        l=mid+1,ans1=mid;
        else
         h=mid-1;
   }

    l=0;  h=id; int ans2;

   while(l<=h)
   {
       int mid=(l+h)/2;

       if(ok(mid,id,val))
        h=mid-1,ans2=mid;
        else
         l=mid+1;
   }

  return ans1-ans2+1;
}

int main()
{
    freopen("standard input.in", "r", stdin);
    freopen("standard output.out", "w", stdout);

    scanf("%d",&n);

   for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);

   build(0,n-1,1);

   for(int i=0;i<n;i++)
   {

       int val=arr[i];

      int siz= BS(val,i);

       update(1,n,1,siz,1,val);
   }

   for(int i=1;i<=n;i++)
        printf("%d ",query(1,n,i,i,1));
}


// ICPC champion is here
#include <bits/stdc++.h>
#include<iostream>
#include<map>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<long double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int MAX=524288,inf=1e9+1000000;
int n,tree1[MAX],tree2[MAX],lazy[MAX],arr[200009];

void build(int s,int e,int b)
{

    if(s==e)
    {
        tree1[b]=arr[s];
        return;
    }

    int mid=(s+e)>>1;

    build(s,mid,b<<1);
    build(mid+1,e,(b<<1)+1);

    tree1[b]=min(tree1[b<<1],tree1[(b<<1)+1]);
}

int querymin(int a,int b,int s=0,int e=n-1,int p=1)
{

    if(s>b||e<a)
      return inf;

    if(s>=a&&e<=b)
    {
        return tree1[p];
    }

    int mid=(s+e)>>1;

   return min(querymin(a,b,s,mid,p<<1),querymin(a,b,mid+1,e,(p<<1)+1);

}
void apply(int s,int mid,int e,int p)
{
    if(!lazy[p])
        return;

    int lf=p<<1;
    int rg=lf+1;

    lazy[lf]=max(lazy[lf],lazy[p]);

    lazy[rg]=max(lazy[rg],lazy[p]);
    tree2[lf]=lazy[lf];
    tree2[rg]=lazy[rg];

    lazy[p]=0;

}

void update(int s,int e,int a,int b,int p,int val)
{
    if(s>b||e<a)
      return ;

    if(s>=a&&e<=b)
    {

        if(val>tree2[p])
        {
            tree2[p]=val;
            lazy[p]=val;
        }

        return ;
    }

    int mid=(s+e)>>1;
     apply(s,mid,e,p);

     update(s,mid,a,b,p<<1,val);
     update(mid+1,e,a,b,(p<<1)+1,val);
}

int query(int s,int e,int a,int b,int p)
{

    if(s>=a&&e<=b)
    {
        return tree2[p];
    }

    int mid=(s+e)>>1;
     apply(s,mid,e,p);

    if(a<=mid)
     return query(s,mid,a,b,p<<1);
    else if(a>mid)
     return query(mid+1,e,a,b,(p<<1)+1);

}
bool ok(int l,int r,int val)
{
    if(querymin(l,r)==val)
        return 1;
    return 0;
}
int BS(int val,int id)
{

   int l=id; int h=n-1; int ans1;

   while(l<=h)
   {
       int mid=(l+h)>>1;

       if(ok(id,mid,val))
        l=mid+1,ans1=mid;
        else
         h=mid-1;
   }

    l=0;  h=id; int ans2;

   while(l<=h)
   {
       int mid=(l+h)>>1;

       if(ok(mid,id,val))
        h=mid-1,ans2=mid;
        else
         l=mid+1;
   }

  return ans1-ans2+1;
}

int main()
{
    M();

    scanf("%d",&n);

   for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);

   build(0,n-1,1);

   int val,siz;
   for(int i=0;i<n;i++)
   {

       val=arr[i];

       siz= BS(val,i);

       update(1,n,1,siz,1,val);
   }

   for(int i=1;i<=n;i++)
        printf("%d ",query(1,n,i,i,1));
}


#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <limits>
#include <math.h>
#include <stdio.h>
#include <string.h>

#define MOD 1000000007
#define EPS ((long double)1e-12)
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz(x) ((long long)(x).size())
#define endl '\n'

#define DUMP_NAME(name,a) cout << "#dump " << (name) << " = " << (a) << "  "
#define dump(a) DUMP_NAME(#a, (a))

#define FOREACH(it,x) for(__typeof__((x).begin()) it = (x).begin();it!=(x).end();++it)
#define FOR(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define ROF(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);--i)

const ld PI = 3.141592653589793238L;
const ll N = 400005;

using namespace std;

/**************************************************************************************************/

map<ll,ll> id;
ll seg[N] , L[N] , R[N];
ll n , nn;

void upd_1(ll i,ll val){
    i += nn - 1;
    seg[i] = val;
    while(i != 1) i /= 2 , seg[i] = max(seg[i * 2] , seg[i * 2 + 1]);
}

ll que_1(ll l,ll r,ll i = 1,ll start = 1,ll en = nn){
    if(start > r || en < l || l > r) return 0;
    if(l <= start && en <= r) return seg[i];

    ll mid = (start + en) / 2;
    return max(que_1(l,r,i << 1,start,mid) , que_1(l,r,i << 1 | 1,mid+1,en));
}

void upd_2(ll i,ll val){
    i += nn - 1;
    seg[i] = val;
    while(i != 1) i >>= 1 , seg[i] = min(seg[i << 1] , seg[(i << 1) | 1]);
}

ll que_2(ll l,ll r,ll i = 1,ll start = 1,ll en = nn){
    if(start > r || en < l || l > r) return n + 1;
    if(l <= start && en <= r) return seg[i];

    ll mid = (start + en) / 2;
    return min(que_2(l,r,i << 1,start,mid) , que_2(l,r,i << 1 | 1,mid+1,en));
}

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin >> n;

    set<ll>s;
    ll t[n+1];
    FOR(i,1,n) cin >> t[i] , s.insert(t[i]);
    nn = pow(2,ceil(log2(sz(s))));

    ll tmp = 0;
    FOREACH(it,s) id[*it] = ++tmp;

    FOR(i,1,2*nn-1) seg[i] = 0;
    FOR(i,1,n) L[i] = que_1(1,id[t[i]]-1) , upd_1(id[t[i]],i);

    FOR(i,1,2*nn-1) seg[i] = n + 1;
    ROF(i,n,1) R[i] = que_2(1,id[t[i]]-1) , upd_2(id[t[i]],i);

    ll ans[n+1];
    FOR(i,1,n) ans[i] = 0;
    FOR(i,1,n) ans[R[i] - L[i] - 1] = max(ans[R[i] - L[i] - 1] , t[i]);

    ll mx = 0;
    ROF(i,n,1) ans[i] = max(ans[i] , mx) , mx = max(mx , ans[i]);

    FOR(i,1,n) cout << ans[i] << ((i == n) ? "\n" : " ");

    return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <limits>
#include <math.h>
#include <stdio.h>
#include <string.h>

#define MOD 1000000007
#define EPS ((long double)1e-12)
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz(x) ((long long)(x).size())
#define endl '\n'

#define DUMP_NAME(name,a) cout << "#dump " << (name) << " = " << (a) << "  "
#define dump(a) DUMP_NAME(#a, (a))

#define FOREACH(it,x) for(__typeof__((x).begin()) it = (x).begin();it!=(x).end();++it)
#define FOR(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define ROF(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);--i)

const ld PI = 3.141592653589793238L;
const ll N = 1000005;

using namespace std;

/**************************************************************************************************/

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ll n; cin >> n;

    ll t[n+1];
    FOR(i,1,n) cin >> t[i];

    ll L[n+1] , R[n+1];
    stack<ll>st;
    FOR(i,1,n){
        while(!st.empty() && t[st.top()] >= t[i]) st.pop();
        if(st.empty()) L[i] = 0;
        else L[i] = st.top();

        st.push(i);
    }

    while(!st.empty()) st.pop();
    ROF(i,n,1){
        while(!st.empty() && t[st.top()] >= t[i]) st.pop();
        if(st.empty()) R[i] = n + 1;
        else R[i] = st.top();

        st.push(i);
    }

    ll ans[n+1];
    FOR(i,1,n) ans[i] = 0;
    FOR(i,1,n) ans[R[i] - L[i] - 1] = max(ans[R[i] - L[i] - 1] , t[i]);

    ll mx = 0;
    ROF(i,n,1) ans[i] = max(ans[i] , mx) , mx = max(mx , ans[i]);

    FOR(i,1,n) cout << ans[i] << ((i == n) ? "\n" : " ");

    return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <limits>
#include <math.h>
#include <stdio.h>
#include <string.h>

#define MOD 1000000007
#define EPS ((long double)1e-12)
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz(x) ((long long)(x).size())
#define endl '\n'

#define DUMP_NAME(name,a) cout << "#dump " << (name) << " = " << (a) << "  "
#define dump(a) DUMP_NAME(#a, (a))

#define FOREACH(it,x) for(__typeof__((x).begin()) it = (x).begin();it!=(x).end();++it)
#define FOR(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define ROF(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);--i)

const ld PI = 3.141592653589793238L;
const ll N = 1000005;

using namespace std;

/**************************************************************************************************/

map<ll,ll> id;
ll seg[N] , L[N] , R[N];
ll n , nn;

void upd_1(ll i,ll val){
    i += nn - 1;
    seg[i] = val;
    while(i != 1) i /= 2 , seg[i] = max(seg[i * 2] , seg[i * 2 + 1]);
}

ll que_1(ll l,ll r,ll i = 1,ll start = 1,ll en = nn){
    if(start > r || en < l || l > r) return 0;
    if(l <= start && en <= r) return seg[i];

    ll mid = (start + en) / 2;
    return max(que_1(l,r,i << 1,start,mid) , que_1(l,r,i << 1 | 1,mid+1,en));
}

void upd_2(ll i,ll val){
    i += nn - 1;
    seg[i] = val;
    while(i != 1) i >>= 1 , seg[i] = min(seg[i << 1] , seg[(i << 1) | 1]);
}

ll que_2(ll l,ll r,ll i = 1,ll start = 1,ll en = nn){
    if(start > r || en < l || l > r) return n + 1;
    if(l <= start && en <= r) return seg[i];

    ll mid = (start + en) / 2;
    return min(que_2(l,r,i << 1,start,mid) , que_2(l,r,i << 1 | 1,mid+1,en));
}

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin >> n;

    set<ll>s;
    ll t[n+1];
    FOR(i,1,n) cin >> t[i] , s.insert(t[i]);
    nn = pow(2,ceil(log2(sz(s))));

    ll tmp = 0;
    FOREACH(it,s) id[*it] = ++tmp;

    FOR(i,1,2*nn-1) seg[i] = 0;
    FOR(i,1,n) L[i] = que_1(1,id[t[i]]-1) , upd_1(id[t[i]],i);

    FOR(i,1,2*nn-1) seg[i] = n + 1;
    ROF(i,n,1) R[i] = que_2(1,id[t[i]]-1) , upd_2(id[t[i]],i);

    ll ans[n+1];
    FOR(i,1,n) ans[i] = 0;
    FOR(i,1,n) ans[R[i] - L[i] - 1] = max(ans[R[i] - L[i] - 1] , t[i]);

    ll mx = 0;
    ROF(i,n,1) ans[i] = max(ans[i] , mx) , mx = max(mx , ans[i]);

    FOR(i,1,n) cout << ans[i] << ((i == n) ? "\n" : " ");

    return 0;
}


/*input
10
1 2 3 4 5 4 3 2 1 6
*/
#include <bits/stdc++.h>
using namespace std;

const int N = 1000005;

int l[N + 2], r[N + 2], a[N + 2];
stack<int> st;
int ans[N + 2];

signed main () {
	int n;
	cin >> n;

	fill(l, l + N, 0);
	fill(r, r + N, n + 1);

	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
	}

	for(int i = 1; i <= n; i ++){
        while(!st.empty() && a[st.top()] >= a[i]){
            st.pop();
        }
        if(!st.empty()){
            l[i] = st.top();
        }
        st.push(i);
    }

    while (!st.empty()) st.pop();

    for(int i = n; i >= 1; i --){
        while(!st.empty() && a[st.top()] >= a[i]){
            st.pop();
        }
        if(!st.empty()){
            r[i] = st.top();
        }
        st.push(i);
    }

    for (int i = 1; i <= n; i ++) {
    	ans[r[i] - l[i] - 1] = max(ans[r[i] - l[i] - 1], a[i]);
    }

    for (int i = n; i >= 1; i --) {
    	ans[i] = max(ans[i], ans[i + 1]);
    }

    for (int i = 1; i <= n; i ++) {
    	cout << ans[i] << ' ';
    }
}


/* dsingh_24 */
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define pll        pair<ll ,ll>
#define vll          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define N  100005
ll rt[200005],lt[200005],ans[200005];
int main()
{
    ios
    ll n,i,j,mx=0;
    cin>>n;
    ll a[n+1];
    for(i=0;i<n;i++){cin>>a[i];mx=max(mx,a[i]);}
    for(i=0;i<n;i++)rt[i]=n,lt[i]=-1;
    stack<ll>s,s1;
    for(i=0;i<n;i++)
    {
      while(!s.empty()&&a[s.top()]>=a[i])s.pop();
      if(!s.empty())lt[i]=s.top();
      s.push(i);
    }
    for(i=n-1;i>=0;i--)
    {
      while(!s.empty()&&a[s.top()]>=a[i])s.pop();
      if(!s.empty())rt[i]=s.top();
      s.push(i);
    }
    for(i=0;i<n;i++)
    {
      ans[rt[i]-lt[i]-1]=max(a[i],ans[rt[i]-lt[i]-1]);
    }
    ans[1]=mx;
    for(i=n-1;i>=1;i--)ans[i]=max(ans[i],ans[i+1]);
    for(i=1;i<=n;i++)cout<<ans[i]<<" ";
}


/* dsingh_24 */
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define pll        pair<ll ,ll>
#define vll          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define N  100005
ll rt[200005],lt[200005],ans[200005];
int main()
{
    ios
    ll n,i,j,mx=0;
    cin>>n;
    ll a[n+1];
    for(i=0;i<n;i++){cin>>a[i];mx=max(mx,a[i]);}
    for(i=0;i<n;i++)rt[i]=n,lt[i]=-1;
    stack<ll>s,s1;
    for(i=0;i<n;i++)
    {
      while(!s.empty()&&a[s.top()]>=a[i])s.pop();
      if(!s.empty())lt[i]=s.top();
      s.push(i);
    }
    for(i=n-1;i>=0;i--)
    {
      while(!s.empty()&&a[s.top()]>=a[i])s.pop();
      if(!s.empty())rt[i]=s.top();
      s.push(i);
    }
    for(i=0;i<n;i++)
    {
      ans[rt[i]-lt[i]-1]=a[i];
    }
    ans[1]=mx;
    for(i=n;i>=1;i--)if(ans[i]==0)ans[i]=ans[i+1];
    for(i=1;i<=n;i++)cout<<ans[i]<<" ";
}


/* dsingh_24 */
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define pll        pair<ll ,ll>
#define vll          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define N  100005
ll rt[200005],lt[200005],ans[200005];
int main()
{
    ios
    ll n,i,j,mx=0;
    cin>>n;
    ll a[n+1];
    for(i=0;i<n;i++){cin>>a[i];mx=max(mx,a[i]);}
    for(i=0;i<n;i++)rt[i]=n,lt[i]=-1;
    stack<ll>s,s1;
    for(i=0;i<n;i++)
    {
      while(!s.empty()&&a[s.top()]>=a[i])s.pop();
      if(!s.empty())lt[i]=s.top();
      s.push(i);
    }
    for(i=n-1;i>=0;i--)
    {
      while(!s.empty()&&a[s.top()]>=a[i])s.pop();
      if(!s.empty())rt[i]=s.top();
      s.push(i);
    }
    for(i=0;i<n;i++)
    {
      ans[rt[i]-lt[i]-1]=max(a[i],ans[rt[i]-lt[i]-1]);
    }
    ans[1]=mx;
    for(i=n;i>=1;i--)if(ans[i]==0)ans[i]=ans[i+1];
    for(i=1;i<=n;i++)cout<<ans[i]<<" ";
}


/* dsingh_24 */
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define pll        pair<ll ,ll>
#define vll          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define N  100005
ll rt[200005],lt[200005],ans[200005];
int main()
{
    ios
    ll n,i,j,mx=0;
    cin>>n;
    ll a[n+1];
    for(i=0;i<n;i++){cin>>a[i];mx=max(mx,a[i]);}
    for(i=0;i<n;i++)rt[i]=n,lt[i]=-1;
    stack<ll>s,s1;
    for(i=0;i<n;i++)
    {
      while(!s.empty()&&a[s.top()]>=a[i])s.pop();
      if(!s.empty())lt[i]=s.top();
      s.push(i);
    }
    while(!s.empty())s.pop();
    for(i=n-1;i>=0;i--)
    {
      while(!s.empty()&&a[s.top()]>=a[i])s.pop();
      if(!s.empty())rt[i]=s.top();
      s.push(i);
    }
    for(i=0;i<n;i++)
    {
      ans[rt[i]-lt[i]-1]=max(a[i],ans[rt[i]-lt[i]-1]);
    }
    for(i=n-1;i>=1;i--)ans[i]=max(ans[i],ans[i+1]);
    for(i=1;i<=n;i++)cout<<ans[i]<<" ";
}


#include <bits/stdc++.h>
#define my_max(a, b) (a > b ? a : b)
#define my_min(a, b) (a < b ? a : b)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rep(i, s, t) for(int i = (int)(s); i <= (int)(t); i++)
#define rev(i, t, s) for(int i = (int)(t); i >= (int)(s); i--)
#define lson rt << 1
#define rson rt << 1 | 1
#define sz(x) (int)(x).size()

typedef long long ll;
typedef long double lb;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
ll gcd(ll x, ll y){ return y % x == 0 ? x : gcd(y % x, x); }
template<class T>T my_abs(T a){ if(a < 0) a = -a; return a; }

const int maxn = 2e5 + 7;
int a[maxn], l[maxn], r[maxn], n, ans[maxn];
int main(){
#ifndef ONLINE_JUDGE
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
    scanf("%d", &n);
    rep(i, 1, n) scanf("%d", a + i);
    std::stack<int> s;
    rep(i, 1, n){
        while(s.size() && a[s.top()] >= a[i]) s.pop();
        if(s.size()) l[i] = s.top() + 1;
        else l[i] = 1;
        s.push(i);
    }
    while(s.size()) s.pop();
    rev(i, n, 1){
        while(s.size() && a[s.top()] >= a[i]) s.pop();
        if(s.size()) r[i] = s.top() - 1;
        else r[i] = n;
        s.push(i);
    }
    rep(i, 1, n){
        int c = r[i] - l[i] + 1;
        //printf("%d %d\n", l[i], r[i]);
        rep(j, 1, c) ans[j] = my_max(ans[j], a[i]);
    }
    rep(i, 1, n) printf("%d%c", ans[i], i == n ? '\n' : ' ');
    return 0;
}