/*
*Rainto96
*Beijing University of Posts and Telecommunications School of Software Engineering
*http://blog.csdn.net/u011775691
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <climits>
using namespace std;
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define VINT vector<int>
#define PII pair<int,int>
#define MP(x,y) make_pair((x),(y))
#define ll long long
#define ull unsigned long long
#define MEM0(x)  memset(x,0,sizeof(x))
#define scan(x) scanf("%d",&(x))
const int MAXN=222222;
int f[MAXN];
int dis[MAXN];
int ans[MAXN];
int main(){
        #ifndef ONLINE_JUDGE
                freopen("in.txt","r",stdin);
        #endif // ONLINE_JUDGE
        int n;scan(n);
        vector<PII > vec;
        for(int i=1;i<=n;i++){
                scan(f[i]);
                vec.pb(MP(f[i],i));
        }
        sort(ALL(vec),[](PII s1 , PII s2 ){return s1.first < s2.first ||(s1.first==s2.first && s1.second<s2.second);});
        set<int> st;
        for(int i=0;i<vec.size(); i++){
                PII now=vec[i];
                int l=0 , r=n+1;
                auto it=upper_bound(ALL(st) , now.second);
                if(it != st.end() ) r=*it;
                if(it != st.begin() ) l=*(--it);
                dis[now.second]=r-l-1;
                st.insert(now.second);
        }
        set<PII > piist;
        for(int i=1;i<=n;i++){
                auto it=lower_bound(ALL(piist) , MP(dis[i] , f[i]) , [](PII s1, PII s2){return s1.first < s2.first;} );
                if(it==piist.end()) piist.insert(MP(dis[i] , f[i]));
                if(it->first == dis[i] ) {
                        if(it->second < f[i]){
                                piist.erase(it);
                                piist.insert(MP(dis[i] , f[i]) );
                        }
                }
                else if(it->second < f[i]) piist.insert(MP(dis[i] , f[i]) );
        }
        for(auto pr: piist){
                ans[pr.first]=max(ans[pr.first],pr.second);
                //ans[pr.first]=pr.second;
        }

        int nowout=ans[n];
        ans[n]=nowout;
        for(int i=n-1;i>=1;i--){
                if(ans[i]!=0) nowout=ans[i];
                ans[i]=nowout;
        }
        for(int i=1;i<=n;i++){
                printf("%d%c",ans[i],i==n?'\n':' ');
        }

        return 0;
}


/*
*Rainto96
*Beijing University of Posts and Telecommunications School of Software Engineering
*http://blog.csdn.net/u011775691
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <climits>
using namespace std;
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define VINT vector<int>
#define PII pair<int,int>
#define PDD pair<double,double>
#define MP(x,y) make_pair((x),(y))
#define ll long long
#define ull unsigned long long
#define MEM0(x)  memset(x,0,sizeof(x))
#define scan(x) scanf("%d",&(x))
#define lson(x) (x<<1)
#define rson(x) (x<<1|1)
const int MAXN=222222;
int f[MAXN];
int dis[MAXN];
int ans[MAXN];

struct Node {
	int l, r, lazy;
	bool flag;
} node[MAXN * 6];
struct Seg{
    void pushup(int x) {
        ;
    }
    void pushdown(int x) {
        if (node[x].flag) {
            node[lson(x)].lazy = node[x].lazy;
            node[rson(x)].lazy = node[x].lazy;
            node[lson(x)].flag = true;
            node[rson(x)].flag = true;
            node[x].flag = false;
        }
    }

    void build(int l, int r, int x = 1) {
        node[x].l = l; node[x].r = r; node[x].flag = false;
        if (l == r) {
            node[x].lazy=0;
            return;
        }
        int mid = (l + r) / 2;
        build(l, mid, lson(x));
        build(mid + 1, r, rson(x));
        pushup(x);
    }

    int query(int v,  int x = 1) {
        if (node[x].flag || node[x].l == node[x].r) {
            return node[x].lazy;
        }
        int mid = (node[x].l + node[x].r) / 2;
        pushdown(x);
        if (v <= mid) return query(v , lson(x));
        if (v > mid) return query(v , rson(x));
        pushup(x);
    }

    void update(int l, int r, int val,int x = 1) {
        if (node[x].l >= l && node[x].r <= r) {
            if(val > node[x].lazy) node[x].lazy=val;
            node[x].flag=true;
            //printf("[%d,%d]=%d\n",l,r,val);
            return;
        }
        int mid = (node[x].l + node[x].r) / 2;
        pushdown(x);
        if (l <= mid) update(l, r,val, lson(x));
        if (r > mid) update(l, r,val, rson(x));
        pushup(x);
    }

}seg;

int main(){
        #ifndef ONLINE_JUDGE
                freopen("in.txt","r",stdin);
        #endif // ONLINE_JUDGE
        int n;scan(n);
        vector<PII > vec;
        seg.build(1,n);
        for(int i=1;i<=n;i++){
                scan(f[i]);
                vec.pb(MP(f[i],i));
        }
        sort(ALL(vec),[](PII s1 , PII s2 ){return s1.first < s2.first;});
        set<int> st;
        for(int i=0;i<vec.size(); i++){
                PII now=vec[i];
                int l=0 , r=n+1;
                auto it=upper_bound(ALL(st) , now.second);
                if(it != st.end() ) r=*it;
                if(it != st.begin() ) l=*(--it);
                dis[now.second]=r-l-1;
                st.insert(now.second);
                //cout<<"now::"<<r-l-1<<" "<<now.first<<endl;
                seg.update(1,r-l-1,now.first);
                //cout<<r<<" "<<l<<endl;
                //cout<<seg.query(5)<<endl;
        }
        for(int i=1;i<=n;i++){
                printf("%d%c",seg.query(i),i==n?'\n':' ');
        }
        return 0;
}


/*
*Rainto96
*Beijing University of Posts and Telecommunications School of Software Engineering
*http://blog.csdn.net/u011775691
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <climits>
using namespace std;
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define VINT vector<int>
#define PII pair<int,int>
#define PDD pair<double,double>
#define MP(x,y) make_pair((x),(y))
#define ll long long
#define ull unsigned long long
#define MEM0(x)  memset(x,0,sizeof(x))
#define scan(x) scanf("%d",&(x))
const int MAXN=222222;
int f[MAXN];
int dis[MAXN];
int ans[MAXN];
int main(){
        #ifndef ONLINE_JUDGE
                freopen("in.txt","r",stdin);
        #endif // ONLINE_JUDGE
        int n;scan(n);
        vector<PII > vec;
        for(int i=1;i<=n;i++){
                scan(f[i]);
                vec.pb(MP(f[i],i));
        }
        sort(ALL(vec),[](PII s1 , PII s2 ){return s1.first < s2.first;});
        set<int> st;
        for(int i=0;i<vec.size(); i++){
                PII now=vec[i];
                int l=0 , r=n+1;
                auto it=upper_bound(ALL(st) , now.second);
                if(it != st.end() ) r=*it;
                if(it != st.begin() ) l=*(--it);
                dis[now.second]=r-l-1;
                st.insert(now.second);
        }
        set<PII > piist;
        for(int i=1;i<=n;i++){
                auto it=lower_bound(ALL(piist) , MP(dis[i] , i) , [](PII s1, PII s2){return s1.first < s2.first;} );
                if(it==piist.end()) piist.insert(MP(dis[i] , i));
                else if(f[it->second] < f[i]) piist.insert(MP(dis[i] , i) );

                //if(it->first == dis[i] && f[it->second] < f[i]) piist.erase(it);
        }
        for(auto pr: piist){
                ans[pr.first]=max(ans[pr.first],pr.second);
                //ans[pr.first]=pr.second;
        }

        int nowout=f[ans[n]];
        ans[n]=nowout;
        for(int i=n-1;i>=1;i--){
                if(ans[i]!=0) nowout=f[ans[i]];
                //printf(" %d",nowout);
                ans[i]=nowout;
        }
        for(int i=1;i<=n;i++){
                printf("%d%c",ans[i],i==n?'\n':' ');
        }

        return 0;
}


/*
*Rainto96
*Beijing University of Posts and Telecommunications School of Software Engineering
*http://blog.csdn.net/u011775691
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <climits>
using namespace std;
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define VINT vector<int>
#define PII pair<int,int>
#define PDD pair<double,double>
#define MP(x,y) make_pair((x),(y))
#define ll long long
#define ull unsigned long long
#define MEM0(x)  memset(x,0,sizeof(x))
#define scan(x) scanf("%d",&(x))
#define lson(x) (x<<1)
#define rson(x) (x<<1|1)
const int MAXN=222222;
int f[MAXN];
int dis[MAXN];
int ans[MAXN];

struct Node {
	int l, r, lazy;
	bool flag;
} node[MAXN * 6];
struct Seg{
    void pushup(int x) {
        ;
    }
    void pushdown(int x) {
        if (node[x].flag) {
            node[lson(x)].lazy = node[x].lazy;
            node[rson(x)].lazy = node[x].lazy;
            node[lson(x)].flag = true;
            node[rson(x)].flag = true;
            node[x].flag = false;
        }
    }

    void build(int l, int r, int x = 1) {
        node[x].l = l; node[x].r = r; node[x].flag = false;
        if (l == r) {
            node[x].lazy=0;
            return;
        }
        int mid = (l + r) / 2;
        build(l, mid, lson(x));
        build(mid + 1, r, rson(x));
        pushup(x);
    }

    int query(int v,  int x = 1) {
        if (node[x].l == node[x].r) {
            return node[x].lazy;
        }
        int mid = (node[x].l + node[x].r) / 2;
        pushdown(x);
        if (v <= mid) return query(v , lson(x));
        if (v > mid) return query(v , rson(x));
        pushup(x);
    }

    void update(int l, int r, int val,int x = 1) {
        if (node[x].l >= l && node[x].r <= r) {
            if(val > node[x].lazy) node[x].lazy=val;
            node[x].flag=true;
            //printf("[%d,%d]=%d\n",l,r,val);
            return;
        }
        int mid = (node[x].l + node[x].r) / 2;
        pushdown(x);
        if (l <= mid) update(l, r,val, lson(x));
        if (r > mid) update(l, r,val, rson(x));
        pushup(x);
    }

}seg;

int main(){
        #ifndef ONLINE_JUDGE
                freopen("in.txt","r",stdin);
        #endif // ONLINE_JUDGE
        int n;scan(n);
        vector<PII > vec;
        seg.build(1,n);
        for(int i=1;i<=n;i++){
                scan(f[i]);
                vec.pb(MP(f[i],i));
        }
        sort(ALL(vec),[](PII s1 , PII s2 ){return s1.first < s2.first;});
        set<int> st;
        for(int i=0;i<vec.size(); i++){
                PII now=vec[i];
                int l=0 , r=n+1;
                auto it=upper_bound(ALL(st) , now.second);
                if(it != st.end() ) r=*it;
                if(it != st.begin() ) l=*(--it);
                dis[now.second]=r-l-1;
                st.insert(now.second);
                //cout<<"now::"<<r-l-1<<" "<<now.first<<endl;
                seg.update(1,r-l-1,now.first);
                //cout<<r<<" "<<l<<endl;
                //cout<<seg.query(5)<<endl;
        }
        for(int i=1;i<=n;i++){
                printf("%d%c",seg.query(i),i==n?'\n':' ');
        }
        return 0;
}


/*
*Rainto96
*Beijing University of Posts and Telecommunications School of Software Engineering
*http://blog.csdn.net/u011775691
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <climits>
using namespace std;
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define VINT vector<int>
#define PII pair<int,int>
#define MP(x,y) make_pair((x),(y))
#define ll long long
#define ull unsigned long long
#define MEM0(x)  memset(x,0,sizeof(x))
#define scan(x) scanf("%d",&(x))
#define lson(x) (x<<1)
#define rson(x) (x<<1|1)
const int MAXN=222222;
int f[MAXN];
int dis[MAXN];
int ans[MAXN];

template<class T>
inline bool read(T &n){
    T x = 0, tmp = 1; char c = getchar();
    while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
    if (c == EOF) return false;
    if (c == '-') c = getchar(), tmp = -1;
    while (c >= '0' && c <= '9') x *= 10, x += (c - '0'), c = getchar();
    n = x*tmp;
    return true;
}

template <class T>
inline void write(T n) {
    if (n < 0) {
        putchar('-');
        n = -n;
    }
    int len = 0, data[20];
    while (n) {
        data[len++] = n % 10;
        n /= 10;
    }
    if (!len) data[len++] = 0;
    while (len--) putchar(data[len] + 48);
}

struct Node {
	int l, r, lazy;
	bool flag;
} node[MAXN * 6];
struct Seg{

    inline void pushdown(int x) {
        if (node[x].flag) {
            node[lson(x)].lazy = node[x].lazy;
            node[rson(x)].lazy = node[x].lazy;
            node[lson(x)].flag = true;
            node[rson(x)].flag = true;
            node[x].flag = false;
        }
    }

    void build(int l, int r, int x = 1) {
        node[x].l = l; node[x].r = r; node[x].flag = false;
        if (l == r) {
            node[x].lazy=0;
            return;
        }
        int mid = (l + r) / 2;
        build(l, mid, lson(x));
        build(mid + 1, r, rson(x));
        //pushup(x);
    }

    int query(int v,  int x = 1) {
        if (node[x].flag || node[x].l == node[x].r) {
            return node[x].lazy;
        }
        int mid = (node[x].l + node[x].r) / 2;
        pushdown(x);
        if (v <= mid) return query(v , lson(x));
        if (v > mid) return query(v , rson(x));
        //pushup(x);
    }

    void update(int l, int r, int val,int x = 1) {
        if (node[x].l >= l && node[x].r <= r) {
            if(val > node[x].lazy) node[x].lazy=val;
            node[x].flag=true;
            //printf("[%d,%d]=%d\n",l,r,val);
            return;
        }
        int mid = (node[x].l + node[x].r) / 2;
        pushdown(x);
        if (l <= mid) update(l, r,val, lson(x));
        if (r > mid) update(l, r,val, rson(x));
        //pushup(x);
    }

}seg;

int main(){
        #ifndef ONLINE_JUDGE
                //freopen("in.txt","r",stdin);
        #endif // ONLINE_JUDGE
        int n;//scan(n);
        read(n);
        vector<PII > vec;
        seg.build(1,n);
        for(int i=1;i<=n;i++){
                //scan(f[i]);
                read(f[i]);
                vec.pb(MP(f[i],i));
        }
        sort(ALL(vec),[](const PII& s1 , const PII& s2 ){return s1.first < s2.first;});
        set<int> st;
        for(int i=0;i<vec.size(); i++){
                PII now=vec[i];
                int l=0 , r=n+1;
                auto it=upper_bound(ALL(st) , now.second);
                if(it != st.end() ) r=*it;
                if(it != st.begin() ) l=*(--it);
                dis[now.second]=r-l-1;
                st.insert(now.second);
                seg.update(1,r-l-1,now.first);
        }
        for(int i=1;i<=n;i++){
                //printf("%d%c",seg.query(i),i==n?'\n':' ');
                write(seg.query(i));
                putchar(' ');
        }
        return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;

int A[200005];
int dir_left[200005];
int dir_right[200005];
int ans[200005];

int main()
{
    int n;

    cin >> n;

    for ( int i = 1; i <= n; i++ ) {
        cin >> A[i];
        dir_left[i] = i-1;
        dir_right[i] = i+1;
    }

    for ( int i = 1; i <= n; i++ ) {
        while ( dir_left[i] >= 1 && A[i] <= A[dir_left[i]] ) dir_left[i] = dir_left[dir_left[i]];
    }

    for ( int i = 1; i <= n; i++ ) {
        while ( dir_right[i] <= n && A[i] <= A[dir_right[i]] ) dir_right[i] = dir_right[dir_right[i]];
    }

    for ( int i = 1; i <= n; i++ ) {
        ans[dir_right[i]-dir_left[i]-1] = max(ans[dir_right[i]-dir_left[i]-1], A[i]);
    }

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

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

    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;

int A[200005];
int dir_left[200005];
int dir_right[200005];
int ans[200005];

int main()
{
    int n;

    scanf("%d", &n);

    for ( int i = 1; i <= n; i++ ) {
        scanf("%d", &A[i]);
        dir_left[i] = i-1;
        dir_right[i] = i+1;
    }

    for ( int i = 1; i <= n; i++ ) {
        while ( dir_left[i] >= 1 && A[i] <= A[dir_left[i]] ) dir_left[i] = dir_left[dir_left[i]];
    }

    for ( int i = 1; i <= n; i++ ) {
        while ( dir_right[i] <= n && A[i] <= A[dir_right[i]] ) dir_right[i] = dir_right[dir_right[i]];
    }

    for ( int i = 1; i <= n; i++ ) {
        ans[dir_right[i]-dir_left[i]-1] = max(ans[dir_right[i]-dir_left[i]-1], A[i]);
    }

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

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

    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
#define INF 2000000000

using namespace std;

int A[200005];
int dir_left[200005];
int dir_right[200005];
int ans[200005];

// fast input
template<typename T>
inline void fi(T *a)
{
 register char c=0;
 while (c<33) c=getchar();
 *a=0;
 int tmp = 0;
 while (c>33)
 {
     if ( c == 45 ) tmp = 1;
     else *a=*a*10+c-'0';
     c=getchar();
 }
 if ( tmp == 1 ) *a = 0-(*a);
}

int main()
{
    int n;

    fi(&n);

    A[0] = A[n+1] = -INF;

    for ( int i = 1; i <= n; i++ ) {
        fi(&A[i]);
        dir_left[i] = i-1;
        dir_right[i] = i+1;
    }

    for ( int i = 1; i <= n; i++ ) {
        while ( A[i] <= A[dir_left[i]] ) dir_left[i] = dir_left[dir_left[i]];
    }

    for ( int i = n; i >= 1; i-- ) {
        while ( A[i] <= A[dir_right[i]] ) dir_right[i] = dir_right[dir_right[i]];
        ans[dir_right[i]-dir_left[i]-1] = max(ans[dir_right[i]-dir_left[i]-1], A[i]);
    }

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

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

    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;

int A[200005];
int dir_left[200005];
int dir_right[200005];
int ans[200005];

int main()
{
    int n;

    scanf("%d", &n);

    for ( int i = 1; i <= n; i++ ) {
        scanf("%d", &A[i]);
        dir_left[i] = i-1;
        dir_right[i] = i+1;
    }

    for ( int i = 1; i <= n; i++ ) {
        while ( dir_left[i] >= 1 && A[i] <= A[dir_left[i]] ) dir_left[i] = dir_left[dir_left[i]];
        while ( dir_right[i] <= n && A[i] <= A[dir_right[i]] ) dir_right[i] = dir_right[dir_right[i]];
        ans[dir_right[i]-dir_left[i]-1] = max(ans[dir_right[i]-dir_left[i]-1], A[i]);
    }

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

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

    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;

int A[200005];
int dir_left[200005];
int dir_right[200005];
int ans[200005];

// fast input
template<typename T>
inline void fi(T *a)
{
 register char c=0;
 while (c<33) c=getchar_unlocked();
 *a=0;
 int tmp = 0;
 while (c>33)
 {
     if ( c == 45 ) tmp = 1;
     else *a=*a*10+c-'0';
     c=getchar_unlocked();
 }
 if ( tmp == 1 ) *a = 0-(*a);
}

int main()
{
    int n;

    fi(&n);

    for ( int i = 1; i <= n; i++ ) {
        fi(&A[i]);
        dir_left[i] = i-1;
        dir_right[i] = i+1;
    }

    for ( int i = 1; i <= n; i++ ) {
        while ( dir_left[i] >= 1 && A[i] <= A[dir_left[i]] ) dir_left[i] = dir_left[dir_left[i]];
        while ( dir_right[i] <= n && A[i] <= A[dir_right[i]] ) dir_right[i] = dir_right[dir_right[i]];
        ans[dir_right[i]-dir_left[i]-1] = max(ans[dir_right[i]-dir_left[i]-1], A[i]);
    }

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

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

    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
#define INF 2000000000

using namespace std;

int A[200005];
int dir_left[200005];
int dir_right[200005];
int ans[200005];

// fast input
template<typename T>
inline void fi(T *a)
{
 register char c=0;
 while (c<33) c=getchar();
 *a=0;
 int tmp = 0;
 while (c>33)
 {
     if ( c == 45 ) tmp = 1;
     else *a=*a*10+c-'0';
     c=getchar();
 }
 if ( tmp == 1 ) *a = 0-(*a);
}

int main()
{
    int n;

    fi(&n);

    A[0] = A[n+1] = -INF;

    for ( int i = 1; i <= n; i++ ) {
        fi(&A[i]);
        dir_left[i] = i-1;
        dir_right[i] = i+1;
    }

    for ( int i = 1; i <= n; i++ ) {
        while ( A[i] <= A[dir_left[i]] ) dir_left[i] = dir_left[dir_left[i]];
        while ( A[i] <= A[dir_right[i]] ) dir_right[i] = dir_right[dir_right[i]];
        ans[dir_right[i]-dir_left[i]-1] = max(ans[dir_right[i]-dir_left[i]-1], A[i]);
    }

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

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

    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;

int A[200005];
int dir_left[200005];
int dir_right[200005];
int ans[200005];

// fast input
template<typename T>
inline void fi(T *a)
{
 register char c=0;
 while (c<33) c=getchar();
 *a=0;
 int tmp = 0;
 while (c>33)
 {
     if ( c == 45 ) tmp = 1;
     else *a=*a*10+c-'0';
     c=getchar();
 }
 if ( tmp == 1 ) *a = 0-(*a);
}

int main()
{
    int n;

    fi(&n);

    for ( int i = 1; i <= n; i++ ) {
        fi(&A[i]);
        dir_left[i] = i-1;
        dir_right[i] = i+1;
    }

    for ( int i = 1; i <= n; i++ ) {
        while ( dir_left[i] >= 1 && A[i] <= A[dir_left[i]] ) dir_left[i] = dir_left[dir_left[i]];
        while ( dir_right[i] <= n && A[i] <= A[dir_right[i]] ) dir_right[i] = dir_right[dir_right[i]];
        ans[dir_right[i]-dir_left[i]-1] = max(ans[dir_right[i]-dir_left[i]-1], A[i]);
    }

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

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

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 200005;

int n;
long long v[N];

long long L[N], R[N];

long long ans[N];

void f(){

    stack<int> s;

    for(int i = 0; i < n; i++){
        while(!s.empty() && v[s.top()] >= v[i]){
            R[s.top()] = i-1 - s.top();
            s.pop();
        }
        s.push(i);
    }

    while(!s.empty()){
        R[s.top()] = n-1 - s.top();
        s.pop();
    }

    for(int i = n-1; i >= 0; i--){
        while(!s.empty() && v[s.top()] > v[i]){
            L[s.top()] = s.top() - i-1;
            s.pop();
        }
        s.push(i);
    }

    while(!s.empty()){
        L[s.top()] = s.top();
        s.pop();
    }

    for(int i = 0; i < n; i++)
        ans[ L[i] + R[i] + 1 ] = max(ans[ L[i]+R[i]+1 ], v[i]);
}

int main(){

    scanf("%d", &n);

    for(int i = 0; i < n; i++)
        scanf("%lld", v+i);

    f();

    for(int i = n; i >= 1; i--)
        if(!ans[i])
            ans[i] = ans[i+1];

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

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 200005;

int n;
long long v[N];

long long L[N], R[N];

long long ans[N];

void f(){

    stack<int> s;

    for(int i = 0; i < n; i++){
        while(!s.empty() && v[s.top()] >= v[i]){
            R[s.top()] = i-1 - s.top();
            s.pop();
        }
        s.push(i);
    }

    while(!s.empty()){
        R[s.top()] = n-1 - s.top();
        s.pop();
    }

    for(int i = n-1; i >= 0; i--){
        while(!s.empty() && v[s.top()] >= v[i]){
            L[s.top()] = s.top() - i-1;
            s.pop();
        }
        s.push(i);
    }

    while(!s.empty()){
        L[s.top()] = s.top();
        s.pop();
    }

    for(int i = 0; i < n; i++)
        ans[ L[i] + R[i] + 1 ] = max(ans[ L[i]+R[i]+1 ], v[i]);
}

int main(){

    scanf("%d", &n);

    for(int i = 0; i < n; i++)
        scanf("%lld", v+i);

    f();

    for(int i = n; i >= 1; i--)
        if(!ans[i])
            ans[i] = ans[i+1];

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

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 200005;

int n;
long long v[N];

long long L[N], R[N];

long long ans[N];

void f(){

    stack<int> s;

    for(int i = 0; i < n; i++){
        while(!s.empty() && v[s.top()] > v[i]){
            R[s.top()] = i-1 - s.top();
            s.pop();
        }
        s.push(i);
    }

    while(!s.empty()){
        R[s.top()] = n-1 - s.top();
        s.pop();
    }

    for(int i = n-1; i >= 0; i--){
        while(!s.empty() && v[s.top()] > v[i]){
            L[s.top()] = s.top() - i-1;
            s.pop();
        }
        s.push(i);
    }

    while(!s.empty()){
        L[s.top()] = s.top();
        s.pop();
    }

    for(int i = 0; i < n; i++)
        ans[ L[i] + R[i] + 1 ] = max(ans[ L[i]+R[i]+1 ], v[i]);
}

int main(){

    scanf("%d", &n);

    for(int i = 0; i < n; i++)
        scanf("%lld", v+i);

    f();

    for(int i = n; i >= 1; i--)
        if(!ans[i])
            ans[i] = ans[i+1];

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

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 200005;

int n;
long long v[N];

long long L[N], R[N];

long long ans[N];

void f(){

    stack<int> s;

    for(int i = 0; i < n; i++){
        while(!s.empty() && v[s.top()] > v[i]){
            R[s.top()] = i-1 - s.top();
            s.pop();
        }
        s.push(i);
    }

    while(!s.empty()){
        R[s.top()] = n-1 - s.top();
        s.pop();
    }

    for(int i = n-1; i >= 0; i--){
        while(!s.empty() && v[s.top()] > v[i]){
            L[s.top()] = s.top() - i-1;
            s.pop();
        }
        s.push(i);
    }

    while(!s.empty()){
        L[s.top()] = s.top();
        s.pop();
    }

    for(int i = 0; i < n; i++)
        ans[ L[i] + R[i] + 1 ] = max(ans[ L[i]+R[i]+1 ], v[i]);
}

int main(){

    scanf("%d", &n);

    for(int i = 0; i < n; i++)
        scanf("%lld", v+i);

    f();

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

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

    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node
{
    int len,num;
}arr[200010];
int T,t,n,m;
int l[200010],r[200010];
int val[200010],ans[200010];
bool cmp(node a,node b)
{
    return a.num>b.num;
}
int main()
{
    int i,j,k,len;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&val[i]);
        l[i]=r[i]=i;
    }
    for(i=1;i<=n;i++)
       while(val[l[i]-1]>=val[i])
         l[i]=l[l[i]-1];
    for(i=n;i>=1;i--)
       while(val[r[i]+1]>=val[i])
         r[i]=r[r[i]+1];

    for(i=1;i<=n;i++)
    {
        arr[i].len=r[i]-l[i]+1;
        arr[i].num=val[i];
    }
    sort(arr+1,arr+1+n,cmp);
    ans[0]=1e9+7;
    for(i=1;i<=n;i++)
    {
        len=arr[i].len;
        while(ans[len]<arr[i].num)
        {
            ans[len]=arr[i].num;
            len--;
        }
    }
    for(i=1;i<=n;i++)
       printf("%d ",ans[i]);
    printf("\n");
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>

using namespace std;

typedef pair<int, int> P;
const int maxn = 200000 + 7;
const int INF = ~0U >> 1;
const int mod = 100000007;

template<class T>
void scan_d(T& ret) {
    char c;
    ret = 0;
    while((c=getchar())<'0'||c>'9');
    while(c>='0'&&c<='9')ret=ret*10+(c - '0'),c=getchar();
}

void out(int x) {
    if(x>9)out(x/10);
    putchar(x%10+'0');
}

struct node {
    int v, len;
    bool operator<(const node &rhs) const {
        return v > rhs.v;
    }
} p[maxn];

int n;
int a[maxn];
int lc[maxn], rc[maxn];
int ans[maxn];

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);

    ans[0] = INF;
    scan_d(n);
    for(int i = 1; i <= n; ++i)
        scan_d(a[i]);
    a[0] = -1;
    a[n + 1] = -1;

    stack <int> S;
    while(!S.empty()) S.pop();
    for(int i = 1; i <= n; ++i) {
        while(!S.empty()&&a[S.top()]>=a[i]) S.pop();
        if(S.empty()) lc[i] = 1;
        else lc[i]=S.top()+1;
        S.push(i);
    }
    while(!S.empty()) S.pop();
    for(int i=n; i>=1; i--) {
        while(!S.empty()&&a[S.top()]>=a[i]) S.pop();
        if(S.empty()) rc[i]=n;
        else rc[i]=S.top()-1;
        S.push(i);
    }

    for(int i = 1; i <= n; ++i)
        p[i] = (node) {a[i], rc[i] - lc[i] + 1};

    sort(p + 1, p + 1 + n);

    for(int i = 1; i <= n; ++i) {
        int len = p[i].len;
        while(ans[len] < p[i].v) {
            ans[len] = p[i].v;
            len--;
        }
    }
    printf("%d", ans[1]);
    for(int i = 2; i <= n; ++i) {
        printf(" ");
        out(ans[i]);
    }
    printf("\n");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
const int maxn = 200000 + 7;
const int INF = ~0U >> 1;
const int mod = 100000007;

template<class T>
void scan_d(T& ret) {
    char c;
    ret = 0;
    while((c=getchar())<'0'||c>'9');
    while(c>='0'&&c<='9')ret=ret*10+(c - '0'),c=getchar();
}

void out(int x) {
    if(x>9)out(x/10);
    putchar(x%10+'0');
}

struct node {
    int v, len;
    bool operator<(const node &rhs) const {
        return v < rhs.v;
    }
} p[maxn];

int n;
int a[maxn];
int lc[maxn], rc[maxn];
int ans[maxn];

int main() {
    ans[0] = INF;
    scan_d(n);
    for(int i = 1; i <= n; ++i)
        scan_d(a[i]);
    a[0] = -1;
    a[n + 1] = -1;
    for(int i = 1; i <= n; ++i) {
        int idx = i - 1;
        while(a[idx] >= a[i])
            idx--;
        lc[i] = idx + 1;
    }

    for(int i = 1; i <= n; ++i) {
        int idx = i + 1;
        while(a[idx] >= a[i])
            idx++;
        rc[i] = idx - 1;
    }

//    for(int i = 1; i <= n; ++i)
//        printf("%d ", lc[i]);
//    printf("\n");
//
//    for(int i = 1; i <= n; ++i)
//        printf("%d ", rc[i]);
//    printf("\n");

    for(int i = 1; i <= n; ++i)
        p[i] = (node) {
        a[i], rc[i] - lc[i] + 1
    };

    sort(p + 1, p + 1 + n);

    for(int i = 1; i <= n; ++i) {
        int len = p[i].len;
//        cout << len << "===" << p[i].first << endl;
        while(ans[len] < p[i].v) {
            ans[len] = p[i].v;
            len--;
        }
    }
    printf("%d", ans[1]);
    for(int i = 2; i <= n; ++i) {
        printf(" ");
        out(ans[i]);
    }
    printf("\n");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
const int maxn = 200000 + 7;
const int INF = ~0U >> 1;
const int mod = 100000007;

template<class T>
void scan_d(T& ret) {
    char c;
    ret = 0;
    while((c=getchar())<'0'||c>'9');
    while(c>='0'&&c<='9')ret=ret*10+(c - '0'),c=getchar();
}

void out(int x) {
    if(x>9)out(x/10);
    putchar(x%10+'0');
}

struct node {
    int v, len;
    bool operator<(const node &rhs) const {
        return v > rhs.v;
    }
} p[maxn];

int n;
int a[maxn];
int lc[maxn], rc[maxn];
int ans[maxn];

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);

    ans[0] = INF;
    scan_d(n);
    for(int i = 1; i <= n; ++i)
        scan_d(a[i]);
    a[0] = -1;
    a[n + 1] = -1;
    for(int i = 1; i <= n; ++i) {
        int idx = i - 1;
        if(a[idx] >= a[i]) idx = lc[idx];
        while(a[idx] >= a[i])
            idx--;
        lc[i] = idx + 1;
    }

    for(int i = n; i >= 1; --i) {
        int idx = i + 1;
        if(a[idx] >= a[i]) idx = rc[idx];
        while(a[idx] >= a[i])
            idx++;
        rc[i] = idx - 1;
    }

    for(int i = 1; i <= n; ++i)
        p[i] = (node) {a[i], rc[i] - lc[i] + 1};

    sort(p + 1, p + 1 + n);

    for(int i = 1; i <= n; ++i) {
        int len = p[i].len;
        while(ans[len] < p[i].v) {
            ans[len] = p[i].v;
            len--;
        }
    }
    printf("%d", ans[1]);
    for(int i = 2; i <= n; ++i) {
        printf(" ");
        out(ans[i]);
    }
    printf("\n");
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node
{
    int len,num;
}arr[200010];
int T,t,n,m;
int l[200010],r[200010];
int val[200010],ans[200010];
bool cmp(node a,node b)
{
    return a.num>b.num;
}
int main()
{
    int i,j,k,len;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&val[i]);
        l[i]=r[i]=i;
    }
    for(i=1;i<=n;i++)
       while(val[l[i]-1]>=val[i])
         l[i]=l[l[i]-1];
    for(i=n;i>=1;i--)
       while(val[r[i]+1]>=val[i])
         r[i]=r[r[i]+1];

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

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

    for(i=1;i<=n;i++)
    {
        arr[i].len=r[i]-l[i]+1;
        arr[i].num=val[i];
    }
    sort(arr+1,arr+1+n,cmp);
    ans[0]=1e9+7;
    for(i=1;i<=n;i++)
    {
        len=arr[i].len;
        while(ans[len]<arr[i].num)
        {
            ans[len]=arr[i].num;
            len--;
        }
    }
    for(i=1;i<=n;i++)
       printf("%d ",ans[i]);
    printf("\n");
}


#include <iostream>
#include <vector>
#include <fstream>
#include <queue>
#include <algorithm>
#include <list>
#include <ctime>
#include <cstdio>
#include <stack>
#include <cstring>
#include <climits>
#include <cmath>
#include <string>
#include <functional>
#include <sstream>
#include <map>
#include <set>

#pragma comment(linker, "/STACK:100000000000000")

using namespace std;
#define     For(i,a,b)        for (int i=a; i<b; i++)
#define     Rep(i,a)          for (int i=0; i<a; i++)
#define     ALL(v)            (v).begin(),(v).end()
#define     Set(a,x)          memset((a),(x),sizeof(a))
#define     EXIST(a,b)        find(ALL(a),(b))!=(a).end()
#define     Sort(x)           sort(ALL(x))
#define     UNIQUE(v)         Sort(v); (v).resize(unique(ALL(v)) - (v).begin())
#define     MP                make_pair
#define     SF                scanf
#define     PF                printf
#define     MAXN              200101
#define     MOD               1000000007
#define     Dbug              cout<<"";
#define     EPS               1e-8
#define     timestamp(x)      printf("Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
typedef long long ll;
typedef pair<int,int> pii;
int n, arr[MAXN];
vector<int> ord;
int cnt=0;
vector<int> pos[MAXN];

int table[MAXN][20];
int Log[MAXN];
vector<int> tmp, best;
void init(int n)
{
	Rep(i, n) table[i][0]=arr[i];
	For(i, 1, Log[n]+1) for(int j=0; j+(1<<i)-1< n; j++)
	{
		table[j][i]=min(table[j][i-1], table[j+(1<<(i-1))][i-1]);
	}
}
int get_min(int l, int r)
{
	int lg=Log[r-l+1];
	return min(table[l][lg], table[r-(1<<lg)+1][lg]);
}

int sum[MAXN];

int calc(int l, int r, int x, bool t, int p)
{
	int ret=1;
	while(l<r)
	{
		int mid=(l+r)/2;
		if(t==0)
		{
			int MIN=get_min(mid , p);
			if(MIN<x)
			{
				l=mid+1;
			}
			else r=mid, ret=abs(mid-p)+1;
		}
		else
		{
			int MIN=get_min(p , mid);
			if(MIN<x)
			{
				r=mid;
			}
			else l=mid+1, ret=abs(mid-p)+1;
		}
	}
	return ret;
}
int main(){
	//ios_base::sync_with_stdio(false);
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	SF("%d", &n);
	Rep(i, n) SF("%d", &arr[i]);
	int mx=0, l=0, r=n+1, lim=2, lg=0;
	Rep(i, MAXN)
	{
		if(i==lim)
		{
			lg++;
			lim*=2;
		}
		Log[i]=lg;
	}
	init(n);
	Rep(i, n) ord.push_back(arr[i]);
	UNIQUE(ord);
	Rep(i, n)
	{
		int p=lower_bound(ALL(ord), arr[i])-ord.begin();
		pos[p].push_back(i);
	}
	Set(sum, 0);
	for(int i=ord.size()-1; i>=0; i--)
	{
		int j=i;
		Rep(z, pos[j].size())
		{
			int Left=calc(0, pos[j][z]+1, ord[i], 0, pos[j][z]);
			int Right=calc(pos[j][z], n, ord[i], 1, pos[j][z]);
			sum[i]=max(sum[i], Left+Right-1);
		}
	}
	int index=n-1;
	For(l, 1, n+1)
	{
		while(index!=0 && sum[index]<l) index--;
		PF("%d ", ord[index]);
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <fstream>
#include <queue>
#include <algorithm>
#include <list>
#include <ctime>
#include <cstdio>
#include <stack>
#include <cstring>
#include <climits>
#include <cmath>
#include <string>
#include <functional>
#include <sstream>
#include <map>
#include <set>

#pragma comment(linker, "/STACK:100000000000000")

using namespace std;
#define     For(i,a,b)        for (int i=a; i<b; i++)
#define     Rep(i,a)          for (int i=0; i<a; i++)
#define     ALL(v)            (v).begin(),(v).end()
#define     Set(a,x)          memset((a),(x),sizeof(a))
#define     EXIST(a,b)        find(ALL(a),(b))!=(a).end()
#define     Sort(x)           sort(ALL(x))
#define     UNIQUE(v)         Sort(v); (v).resize(unique(ALL(v)) - (v).begin())
#define     MP                make_pair
#define     SF                scanf
#define     PF                printf
#define     MAXN              100101
#define     MOD               1000000007
#define     Dbug              cout<<"";
#define     EPS               1e-8
#define     timestamp(x)      printf("Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
typedef long long ll;
typedef pair<int,int> pii;
int n, arr[MAXN];
vector<int> ord;
int cnt=0;
map<int, int> mp;
vector<int> pos[MAXN];

int table[MAXN][20];
int Log[MAXN];
vector<int> tmp, best;
void init(int n)
{
	Rep(i, n) table[i][0]=arr[i];
	For(i, 1, Log[n]+1) for(int j=0; j+(1<<i)-1< n; j++)
	{
		table[j][i]=min(table[j][i-1], table[j+(1<<(i-1))][i-1]);
	}
}
int get_min(int l, int r)
{
	int lg=Log[r-l+1];
	return min(table[l][lg], table[r-(1<<lg)+1][lg]);
}

int sum[MAXN];

int calc(int l, int r, int x, bool t, int p)
{
	int ret=0;
	while(l<r)
	{
		int mid=(l+r)/2;
		if(t==0)
		{
			int MIN=get_min(mid , p);
			if(MIN<x)
			{
				l=mid+1;
			}
			else r=mid, ret=abs(mid-p)+1;
		}
		else
		{
			int MIN=get_min(p , mid);
			if(MIN<x)
			{
				r=mid;
			}
			else l=mid+1, ret=abs(mid-p)+1;
		}
	}
	return ret;
}
int main(){
	//ios_base::sync_with_stdio(false);
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n;
	Rep(i, n) cin>>arr[i];
	int mx=0, l=0, r=n+1, lim=2, lg=0;
	Rep(i, MAXN)
	{
		if(i==lim)
		{
			lg++;
			lim*=2;
		}
		Log[i]=lg;
	}
	init(n);
	Rep(i, n) if(mp.find(arr[i])==mp.end())
	{
		ord.push_back(arr[i]);
		mp[arr[i]]=cnt++;
	}
	Rep(i, n) pos[mp[arr[i]]].push_back(i);
	Sort(ord);
	reverse(ALL(ord));
	Set(sum, 0);
	Rep(i, ord.size())
	{
		int j=mp[ord[i]];
		Rep(z, pos[j].size())
		{
			int Left=calc(0, pos[j][z]+1, ord[i], 0, pos[j][z]);
			int Right=calc(pos[j][z], n, ord[i], 1, pos[j][z]);
			sum[i]=max(sum[i], Left+Right-1);
		}
	}
	int index=0;
	For(l, 1, n+1)
	{
		while(sum[index]<l) index++;
		cout<<ord[index]<<endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <fstream>
#include <queue>
#include <algorithm>
#include <list>
#include <ctime>
#include <cstdio>
#include <stack>
#include <cstring>
#include <climits>
#include <cmath>
#include <string>
#include <functional>
#include <sstream>
#include <map>
#include <set>

#pragma comment(linker, "/STACK:100000000000000")

using namespace std;
#define     For(i,a,b)        for (int i=a; i<b; i++)
#define     Rep(i,a)          for (int i=0; i<a; i++)
#define     ALL(v)            (v).begin(),(v).end()
#define     Set(a,x)          memset((a),(x),sizeof(a))
#define     EXIST(a,b)        find(ALL(a),(b))!=(a).end()
#define     Sort(x)           sort(ALL(x))
#define     UNIQUE(v)         Sort(v); (v).resize(unique(ALL(v)) - (v).begin())
#define     MP                make_pair
#define     SF                scanf
#define     PF                printf
#define     MAXN              200101
#define     MOD               1000000007
#define     Dbug              cout<<"";
#define     EPS               1e-8
#define     timestamp(x)      printf("Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
typedef long long ll;
typedef pair<int,int> pii;
int n, arr[MAXN];
vector<int> ord;
int cnt=0;
map<int, int> mp;
vector<int> pos[MAXN];

int table[MAXN][20];
int Log[MAXN];
vector<int> tmp, best;
void init(int n)
{
	Rep(i, n) table[i][0]=arr[i];
	For(i, 1, Log[n]+1) for(int j=0; j+(1<<i)-1< n; j++)
	{
		table[j][i]=min(table[j][i-1], table[j+(1<<(i-1))][i-1]);
	}
}
int get_min(int l, int r)
{
	int lg=Log[r-l+1];
	return min(table[l][lg], table[r-(1<<lg)+1][lg]);
}

int sum[MAXN];

int calc(int l, int r, int x, bool t, int p)
{
	int ret=0;
	while(l<r)
	{
		int mid=(l+r)/2;
		if(t==0)
		{
			int MIN=get_min(mid , p);
			if(MIN<x)
			{
				l=mid+1;
			}
			else r=mid, ret=abs(mid-p)+1;
		}
		else
		{
			int MIN=get_min(p , mid);
			if(MIN<x)
			{
				r=mid;
			}
			else l=mid+1, ret=abs(mid-p)+1;
		}
	}
	return ret;
}
int main(){
	//ios_base::sync_with_stdio(false);
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n;
	Rep(i, n) cin>>arr[i];
	int mx=0, l=0, r=n+1, lim=2, lg=0;
	Rep(i, MAXN)
	{
		if(i==lim)
		{
			lg++;
			lim*=2;
		}
		Log[i]=lg;
	}
	init(n);
	Rep(i, n) if(mp.find(arr[i])==mp.end())
	{
		ord.push_back(arr[i]);
		mp[arr[i]]=cnt++;
	}
	Rep(i, n) pos[mp[arr[i]]].push_back(i);
	Sort(ord);
	reverse(ALL(ord));
	Set(sum, 0);
	Rep(i, ord.size())
	{
		int j=mp[ord[i]];
		Rep(z, pos[j].size())
		{
			int Left=calc(0, pos[j][z]+1, ord[i], 0, pos[j][z]);
			int Right=calc(pos[j][z], n, ord[i], 1, pos[j][z]);
			sum[i]=max(sum[i], Left+Right-1);
		}
	}
	int index=0;
	For(l, 1, n+1)
	{
		while(sum[index]<l) index++;
		cout<<ord[index]<<endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <fstream>
#include <queue>
#include <algorithm>
#include <list>
#include <ctime>
#include <cstdio>
#include <stack>
#include <cstring>
#include <climits>
#include <cmath>
#include <string>
#include <functional>
#include <sstream>
#include <map>
#include <set>

#pragma comment(linker, "/STACK:100000000000000")

using namespace std;
#define     For(i,a,b)        for (int i=a; i<b; i++)
#define     Rep(i,a)          for (int i=0; i<a; i++)
#define     ALL(v)            (v).begin(),(v).end()
#define     Set(a,x)          memset((a),(x),sizeof(a))
#define     EXIST(a,b)        find(ALL(a),(b))!=(a).end()
#define     Sort(x)           sort(ALL(x))
#define     UNIQUE(v)         Sort(v); (v).resize(unique(ALL(v)) - (v).begin())
#define     MP                make_pair
#define     SF                scanf
#define     PF                printf
#define     MAXN              200101
#define     MOD               1000000007
#define     Dbug              cout<<"";
#define     EPS               1e-8
#define     timestamp(x)      printf("Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
typedef long long ll;
typedef pair<int,int> pii;
int n, arr[MAXN];
vector<int> ord;
int cnt=0;
vector<int> pos[MAXN];

int table[MAXN][20];
int Log[MAXN];
vector<int> tmp, best;
void init(int n)
{
	Rep(i, n) table[i][0]=arr[i];
	For(i, 1, Log[n]+1) for(int j=0; j+(1<<i)-1< n; j++)
	{
		table[j][i]=min(table[j][i-1], table[j+(1<<(i-1))][i-1]);
	}
}
int get_min(int l, int r)
{
	int lg=Log[r-l+1];
	return min(table[l][lg], table[r-(1<<lg)+1][lg]);
}

int sum[MAXN];

int calc(int l, int r, int x, bool t, int p)
{
	int ret=1;
	while(l<r)
	{
		int mid=(l+r)/2;
		if(t==0)
		{
			int MIN=get_min(mid , p);
			if(MIN<x)
			{
				l=mid+1;
			}
			else r=mid, ret=abs(mid-p)+1;
		}
		else
		{
			int MIN=get_min(p , mid);
			if(MIN<x)
			{
				r=mid;
			}
			else l=mid+1, ret=abs(mid-p)+1;
		}
	}
	return ret;
}
int main(){
	//ios_base::sync_with_stdio(false);
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n;
	Rep(i, n) cin>>arr[i];
	int mx=0, l=0, r=n+1, lim=2, lg=0;
	Rep(i, MAXN)
	{
		if(i==lim)
		{
			lg++;
			lim*=2;
		}
		Log[i]=lg;
	}
	init(n);
	Rep(i, n) ord.push_back(arr[i]);
	UNIQUE(ord);
	Rep(i, n)
	{
		int p=lower_bound(ALL(ord), arr[i])-ord.begin();
		pos[p].push_back(i);
	}
	Set(sum, 0);
	for(int i=ord.size()-1; i>=0; i--)
	{
		int j=i;
		Rep(z, pos[j].size())
		{
			int Left=calc(0, pos[j][z]+1, ord[i], 0, pos[j][z]);
			int Right=calc(pos[j][z], n, ord[i], 1, pos[j][z]);
			sum[i]=max(sum[i], Left+Right-1);
		}
	}
	int index=n-1;
	For(l, 1, n+1)
	{
		while(index!=0 && sum[index]<l) index--;
		cout<<ord[index]<<endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <fstream>
#include <queue>
#include <algorithm>
#include <list>
#include <ctime>
#include <cstdio>
#include <stack>
#include <cstring>
#include <climits>
#include <cmath>
#include <string>
#include <functional>
#include <sstream>
#include <map>
#include <set>

#pragma comment(linker, "/STACK:100000000000000")

using namespace std;
#define     For(i,a,b)        for (int i=a; i<b; i++)
#define     Rep(i,a)          for (int i=0; i<a; i++)
#define     ALL(v)            (v).begin(),(v).end()
#define     Set(a,x)          memset((a),(x),sizeof(a))
#define     EXIST(a,b)        find(ALL(a),(b))!=(a).end()
#define     Sort(x)           sort(ALL(x))
#define     UNIQUE(v)         Sort(v); (v).resize(unique(ALL(v)) - (v).begin())
#define     MP                make_pair
#define     SF                scanf
#define     PF                printf
#define     MAXN              200101
#define     MOD               1000000007
#define     Dbug              cout<<"";
#define     EPS               1e-8
#define     timestamp(x)      printf("Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
typedef long long ll;
typedef pair<int,int> pii;
int n, arr[MAXN];
vector<int> ord;
int cnt=0;
vector<int> pos[MAXN];

int table[MAXN][20];
int Log[MAXN];
vector<int> tmp, best;
void init(int n)
{
	Rep(i, n) table[i][0]=arr[i];
	For(i, 1, Log[n]+1) for(int j=0; j+(1<<i)-1< n; j++)
	{
		table[j][i]=min(table[j][i-1], table[j+(1<<(i-1))][i-1]);
	}
}
int get_min(int l, int r)
{
	int lg=Log[r-l+1];
	return min(table[l][lg], table[r-(1<<lg)+1][lg]);
}

int sum[MAXN];

int calc(int l, int r, int x, bool t, int p)
{
	int ret=0;
	while(l<r)
	{
		int mid=(l+r)/2;
		if(t==0)
		{
			int MIN=get_min(mid , p);
			if(MIN<x)
			{
				l=mid+1;
			}
			else r=mid, ret=abs(mid-p)+1;
		}
		else
		{
			int MIN=get_min(p , mid);
			if(MIN<x)
			{
				r=mid;
			}
			else l=mid+1, ret=abs(mid-p)+1;
		}
	}
	return ret;
}
int main(){
	//ios_base::sync_with_stdio(false);
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n;
	Rep(i, n) cin>>arr[i];
	int mx=0, l=0, r=n+1, lim=2, lg=0;
	Rep(i, MAXN)
	{
		if(i==lim)
		{
			lg++;
			lim*=2;
		}
		Log[i]=lg;
	}
	init(n);
	Rep(i, n) ord.push_back(arr[i]);
	UNIQUE(ord);
	Rep(i, n)
	{
		int p=lower_bound(ALL(ord), arr[i])-ord.begin();
		pos[p].push_back(i);
	}
	Sort(ord);
	Set(sum, 0);
	for(int i=ord.size()-1; i>=0; i--)
	{
		int j=i;
		Rep(z, pos[j].size())
		{
			int Left=calc(0, pos[j][z]+1, ord[i], 0, pos[j][z]);
			int Right=calc(pos[j][z], n, ord[i], 1, pos[j][z]);
			sum[i]=max(sum[i], Left+Right-1);
		}
	}
	int index=n-1;
	For(l, 1, n+1)
	{
		while(sum[index]<l) index--;
		cout<<ord[index]<<endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>

using namespace std;

typedef pair<int, int> PII;

const int MAXN = 100005;
PII a[MAXN];
int b[MAXN];
unordered_map<int, int> mp;

int merge(int a, int b) {
  int left = a - mp[a] + 1, right = b + mp[b] - 1;
  int span = right - left + 1;
  return mp[left] = mp[right] = span;
}

int main() {
  //freopen("in", "r", stdin);
  int n;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }

  sort(a, a + n);

  fill(b, b + n, -1);
  b[0] = a[n - 1].first;
  for (int i = n - 1; i >= 0; --i) {
    int idx = a[i].second, val = a[i].first;
    if (!mp.count(idx)) {
      mp[idx] = 1;
    }

    int span = -1;
    if (mp.count(idx - 1)) {
      span = merge(idx - 1, idx);
      if (b[span - 1] == -1) {
        b[span - 1] = val;
      }
    }
    if (mp.count(idx + 1)) {
      span = merge(idx, idx + 1);
      if (b[span - 1] == -1) {
        b[span - 1] = val;
      }
    }
  }

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

  return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>

using namespace std;

typedef pair<int, int> PII;

const int MAXN = 200005;
PII a[MAXN];
int b[MAXN];
unordered_map<int, int> mp;

int merge(int a, int b) {
  int left = a - mp[a] + 1, right = b + mp[b] - 1;
  int span = right - left + 1;
  return mp[left] = mp[right] = span;
}

int main() {
  //freopen("in", "r", stdin);
  int n;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }

  sort(a, a + n);

  fill(b, b + n, -1);
  b[0] = a[n - 1].first;
  for (int i = n - 1; i >= 0; --i) {
    int idx = a[i].second, val = a[i].first;
    if (!mp.count(idx)) {
      mp[idx] = 1;
    }

    int lspan = -1, rspan = -1;
    int lmp = 0, rmp = 0;
    if (mp.count(idx - 1)) {
      lmp = mp[idx - 1];
      lspan = idx - (idx - 1 - lmp + 1) + 1;
      if (b[lspan - 1] == -1) {
        b[lspan - 1] = val;
      }
    }
    if (mp.count(idx + 1)) {
      rmp = mp[idx + 1];
      rspan = (idx + 1 + rmp - 1) - (idx) + 1;
      if (b[rspan - 1] == -1) {
        b[rspan - 1] = val;
      }
    }

    int span = -1;
    if (mp.count(idx - 1)) {
      merge(idx - 1, idx);
    }
    if (mp.count(idx + 1)) {
      span = merge(idx, idx + 1);
      if (b[span - 1] == -1) {
        b[span - 1] = val;
      }
    }

    for (int j = min(lspan, rspan) + 1; j <= span - 1; ++j) {
      if (b[j - 1] == -1) {
        b[j - 1] = val;
      }
    }
  }

  int fill = b[n - 1];
  for (int i = n - 1; i >= 0; --i) {
    if (b[i] == -1) {
      b[i] = fill;
    } else {
      fill = b[i];
    }
  }

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

  return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>

using namespace std;

typedef pair<int, int> PII;

const int MAXN = 200005;
PII a[MAXN];
int b[MAXN];
unordered_map<int, int> mp;

int merge(int a, int b) {
  int left = a - mp[a] + 1, right = b + mp[b] - 1;
  int span = right - left + 1;
  return mp[left] = mp[right] = span;
}

int main() {
  //freopen("in", "r", stdin);
  int n;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }

  sort(a, a + n);

  fill(b, b + n, -1);
  b[0] = a[n - 1].first;
  for (int i = n - 1; i >= 0; --i) {
    int idx = a[i].second, val = a[i].first;
    if (!mp.count(idx)) {
      mp[idx] = 1;
    }

    int lspan = -1, rspan = -1;
    int lmp = 0, rmp = 0;
    if (mp.count(idx - 1)) {
      lmp = mp[idx - 1];
      lspan = idx - (idx - 1 - lmp + 1) + 1;
      if (b[lspan - 1] == -1) {
        b[lspan - 1] = val;
      }
    }
    if (mp.count(idx + 1)) {
      rmp = mp[idx + 1];
      rspan = (idx + 1 + rmp - 1) - (idx) + 1;
      if (b[rspan - 1] == -1) {
        b[rspan - 1] = val;
      }
    }

    int span = -1;
    if (mp.count(idx - 1)) {
      merge(idx - 1, idx);
    }
    if (mp.count(idx + 1)) {
      span = merge(idx, idx + 1);
      if (b[span - 1] == -1) {
        b[span - 1] = val;
      }
    }
  }

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

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

  return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>

using namespace std;

typedef pair<int, int> PII;

const int MAXN = 200005;
PII a[MAXN];
int b[MAXN];
unordered_map<int, int> mp;

int merge(int a, int b) {
  int left = a - mp[a] + 1, right = b + mp[b] - 1;
  int span = right - left + 1;
  return mp[left] = mp[right] = span;
}

int main() {
  //freopen("in", "r", stdin);
  int n;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }

  sort(a, a + n);

  fill(b, b + n, -1);
  b[0] = a[n - 1].first;
  for (int i = n - 1; i >= 0; --i) {
    int idx = a[i].second, val = a[i].first;
    if (!mp.count(idx)) {
      mp[idx] = 1;
    }

    int lspan = -1, rspan = -1;
    int lmp = 0, rmp = 0;
    if (mp.count(idx - 1)) {
      lmp = mp[idx - 1];
      lspan = idx - (idx - 1 - lmp + 1) + 1;
      if (b[lspan - 1] == -1) {
        b[lspan - 1] = val;
      }
    }
    if (mp.count(idx + 1)) {
      rmp = mp[idx + 1];
      rspan = (idx + 1 + rmp - 1) - (idx) + 1;
      if (b[rspan - 1] == -1) {
        b[rspan - 1] = val;
      }
    }

    int span = -1;
    if (mp.count(idx - 1)) {
      merge(idx - 1, idx);
    }
    if (mp.count(idx + 1)) {
      span = merge(idx, idx + 1);
      if (b[span - 1] == -1) {
        b[span - 1] = val;
      }
    }

    int low = lspan == -1 ? rspan : lspan;
    for (int j = low + 1; j <= span - 1; ++j) {
      if (b[j - 1] == -1) {
        b[j - 1] = val;
      }
    }
  }

  int fill = b[n - 1];
  for (int i = n - 1; i >= 0; --i) {
    if (b[i] == -1) {
      b[i] = fill;
    } else {
      fill = b[i];
    }
  }

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

  return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>

using namespace std;

typedef pair<int, int> PII;

const int MAXN = 200005;
PII a[MAXN];
int b[MAXN];
unordered_map<int, int> mp;

int merge(int a, int b) {
  int left = a - mp[a] + 1, right = b + mp[b] - 1;
  int span = right - left + 1;
  return mp[left] = mp[right] = span;
}

int getspan(int a, int b) {
  int left = a - mp[a] + 1, right = b + mp[b] - 1;
  return right - left + 1;
}

int main() {
  //freopen("in", "r", stdin);
  int n;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }

  sort(a, a + n);

  fill(b, b + n, -1);
  b[0] = a[n - 1].first;
  for (int i = n - 1; i >= 0; --i) {
    int idx = a[i].second, val = a[i].first;
    if (!mp.count(idx)) {
      mp[idx] = 1;
    }

    int lspan = -1, rspan = -1;
    if (mp.count(idx - 1)) {
      lspan = getspan(idx - 1, idx);
      if (b[lspan - 1] == -1) {
        b[lspan - 1] = val;
      }
    }
    if (mp.count(idx + 1)) {
      rspan = getspan(idx, idx + 1);
      if (b[rspan - 1] == -1) {
        b[rspan - 1] = val;
      }
    }

    int span = -1;
    if (mp.count(idx - 1)) {
      merge(idx - 1, idx);
    }
    if (mp.count(idx + 1)) {
      span = merge(idx, idx + 1);
      if (b[span - 1] == -1) {
        b[span - 1] = val;
      }
    }

    //printf("%d %d\n", min(lspan, rspan) + 1, span - 1);
    for (int j = min(lspan, rspan) + 1; j <= span - 1; ++j) {
      if (b[j - 1] == -1) {
        b[j - 1] = val;
      }
    }
  }

  int fill = b[n - 1];
  for (int i = n - 1; i >= 0; --i) {
    if (b[i] == -1) {
      b[i] = fill;
    } else {
      fill = b[i];
    }
  }

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

  return 0;
}


#include <iostream>
#include <cstdio>
#include <stack>

using namespace std;

const int MAXN = 200005;
int a[MAXN], res[MAXN];
int l[MAXN], r[MAXN];

int main() {
  //freopen("in", "r", stdin);
  int n;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  if (n == 1) {
    printf("%d\n", a[0]);
    return 0;
  }

  stack<int> stk;
  for (int i = 0; i < n; ++i) {
    while (!stk.empty() && a[stk.top()] >= a[i]) {
      stk.pop();
    }
    l[i] = stk.empty() ? 0 : stk.top() + 1;
    stk.push(i);
  }

  while (!stk.empty()) {
    stk.pop();
  }

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

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

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

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

  return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>

using namespace std;

typedef pair<int, int> PII;

const int MAXN = 100005;
PII a[MAXN];
int b[MAXN];
unordered_map<int, int> mp;

int merge(int a, int b) {
  int left = a - mp[a] + 1, right = b + mp[b] - 1;
  int span = right - left + 1;
  return mp[left] = mp[right] = span;
}

int getspan(int a, int b) {
  int left = a - mp[a] + 1, right = b + mp[b] - 1;
  return right - left + 1;
}

int main() {
  //freopen("in", "r", stdin);
  int n;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }

  sort(a, a + n);

  fill(b, b + n, -1);
  b[0] = a[n - 1].first;
  for (int i = n - 1; i >= 0; --i) {
    int idx = a[i].second, val = a[i].first;
    if (!mp.count(idx)) {
      mp[idx] = 1;
    }

    int lspan = -1, rspan = -1;
    if (mp.count(idx - 1)) {
      lspan = getspan(idx - 1, idx);
      if (b[lspan - 1] == -1) {
        b[lspan - 1] = val;
      }
    }
    if (mp.count(idx + 1)) {
      rspan = getspan(idx, idx + 1);
      if (b[rspan - 1] == -1) {
        b[rspan - 1] = val;
      }
    }

    int span = -1;
    if (mp.count(idx - 1)) {
      merge(idx - 1, idx);
    }
    if (mp.count(idx + 1)) {
      span = merge(idx, idx + 1);
      if (b[span - 1] == -1) {
        b[span - 1] = val;
      }
    }

    //printf("%d %d\n", min(lspan, rspan) + 1, span - 1);
    for (int j = min(lspan, rspan) + 1; j <= span - 1; ++j) {
      if (b[j - 1] == -1) {
        b[j - 1] = val;
      }
    }
  }

  int fill = b[n - 1];
  for (int i = n - 1; i >= 0; --i) {
    if (b[i] == -1) {
      b[i] = fill;
    } else {
      fill = b[i];
    }
  }

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

  return 0;
}


// rows.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <vector>
#include <iomanip>
#include <set>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <limits>
#include <unordered_set>
#include <stack>
#include <map>
#include <functional>
#include <array>
//#include "windows.h"

using namespace std;

const long long unsigned int Max = 2 *10000;
long long unsigned int leftv[2][Max];
long long unsigned int rightv[2][Max];

int main() {

	int n = 0;
	cin >> n;

	vector<long long unsigned int> ivec(n);
	int temp = 0;
	generate(ivec.begin(), ivec.end(), [&temp] { cin >> temp; return temp;});

	//Sleep(10 * 1000);

	long long unsigned int maxVal = 0;
	for (auto i = 0; i < n; i++) {
		leftv[0][i] = rightv[0][i] = ivec[i];
		if (maxVal < leftv[0][i])
			maxVal = leftv[0][i];
	}
	cout << maxVal << " ";

	int curr = 1;
	int prev = 0;

	for (int step = 2; step <= n; ++step) {
		maxVal = 0;
		for (int i = 0; i < n; ++i) {
			long long unsigned lval = 0, rval = 0;
			if (i - step + 1 >= 0) {
				lval = min(leftv[prev][i], ivec[i-step+1]);
			}
			if (i+step-1 < n) {
				rval = min(rightv[prev][i], ivec[i+step-1]);
			}
			rightv[curr][i] = rval;
			leftv[curr][i] = lval;
			auto maxv = max(rval,lval);

			if (maxVal < maxv)
				maxVal = maxv;
		}
		swap(curr,prev);
		cout << maxVal << " " ;
	}
	cout << endl;

	return 0;
}


// rows.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <vector>
#include <iomanip>
#include <set>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <limits>
#include <unordered_set>
#include <stack>
#include <map>
#include <functional>
#include <array>

using namespace std;

const long long unsigned int Max = 2 *10000;
long long unsigned int ans[2][Max];

int main() {

	int n = 0;
	cin >> n;

	vector<long long unsigned int> ivec(n);
	int temp = 0;
	generate(ivec.begin(), ivec.end(), [&temp] { cin >> temp; return temp;});

	long long unsigned int maxVal = 0;
	for (auto i = 0; i < n; i++) {
		ans[0][i] = ivec[i];
		if (maxVal < ans[0][i])
			maxVal = ans[0][i];
	}
	cout << maxVal << " ";

	int curr = 1;
	int prev = 0;

	for (int step = 2; step <= n; ++step) {
		maxVal = 0;
		for (int i = 0; i < n; ++i) {
			long long unsigned lval = 0, rval = 0;
			if (i - step + 1 >= 0) {
				lval = min(ans[prev][i], ivec[i-step+1]);
			}
			if (i+step-1 < n) {
				rval = min(ans[prev][i], ivec[i+step-1]);
			}
			ans[curr][i] = max(rval,lval);

			if (maxVal < ans[curr][i])
				maxVal = ans[curr][i];
		}
		swap(curr,prev);
		cout << maxVal << " " ;
	}
	cout << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <iomanip>
#include <set>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <limits>
#include <unordered_set>
#include <stack>
#include <map>
#include <functional>
#include <array>
#include <stack>
//#include "windows.h"

using namespace std;

const long long int Max = 2 *100000;
long long int l[Max], r[Max];
vector<long long int> ivec(Max);
vector<int> fvec(Max,-1);

int main() {

	int n = 0;
	cin >> n;

	for (auto i = 0; i < n; ++i)
		cin >> ivec[i];

	stack<long long int> ls;
	for (auto i = 0; i < n; ++i) {
		for (;!ls.empty() && ivec[ls.top()] >= ivec[i];ls.pop());
		if (ls.empty())
			l[i] = -1;
		else
			l[i] = ls.top();
		ls.push(i);
	}

	stack<long long int> rs;
	for (int i = n-1; i >= 0; --i) {
		for (;!rs.empty() && ivec[rs.top()] >= ivec[i];rs.pop());
		if (rs.empty())
			r[i] = n;
		else
			r[i] = rs.top();
		rs.push(i);
	}

	for (auto i = 0; i < n; ++i) {
		const int len = r[i] - l[i] - 1;
		if (fvec[len-1] < ivec[i])
			fvec[len-1] = ivec[i];
	}

	int unfilled = 1;
	for (auto i = 0; i < n; ++i) {
		if (fvec[i] != -1) {
			for (auto j = 0; j < unfilled; j++)
				cout << fvec[i] << " ";
			unfilled = 1;
		}
		else
			unfilled++;
	}

	return 0;
}


// rows.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <vector>
#include <iomanip>
#include <set>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <limits>
#include <unordered_set>
#include <stack>
#include <map>
#include <functional>
#include <array>
//#include "windows.h"

using namespace std;

const long long unsigned int Max = 2 *10000;
long long unsigned int leftv[2][Max];
long long unsigned int rightv[2][Max];
vector<long long unsigned int> ivec(Max);

int main() {

	int n = 0;
	cin >> n;

	int temp = 0;
	for (auto i = 0; i < n; ++i)
		cin >> ivec[i];

	//Sleep(10 * 1000);

	long long unsigned int maxVal = 0;
	for (auto i = 0; i < n; i++) {
		leftv[0][i] = rightv[0][i] = ivec[i];
		if (maxVal < leftv[0][i])
			maxVal = leftv[0][i];
	}
	cout << maxVal << " ";

	int curr = 1;
	int prev = 0;

	for (int step = 2; step <= n; ++step) {
		maxVal = 0;
		for (int i = 0; i < n; ++i) {
			long long unsigned lval = 0, rval = 0;
			if (i - step + 1 >= 0) {
				lval = min(leftv[prev][i], ivec[i-step+1]);
			}
			if (i+step-1 < n) {
				rval = min(rightv[prev][i], ivec[i+step-1]);
			}
			rightv[curr][i] = rval;
			leftv[curr][i] = lval;
			auto maxv = max(rval,lval);

			if (maxVal < maxv)
				maxVal = maxv;
		}
		swap(curr,prev);
		cout << maxVal << " " ;
	}
	cout << endl;

	return 0;
}


// rows.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <vector>
#include <iomanip>
#include <set>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <limits>
#include <unordered_set>
#include <stack>
#include <map>
#include <functional>
#include <array>
//#include "windows.h"

using namespace std;

const long long unsigned int Max = 2 *10000;
long long unsigned int leftv[2][Max];
long long unsigned int rightv[2][Max];
vector<long long unsigned int> ivec(Max);

int main() {

	int n = 0;
	cin >> n;

	if (n == 50000) cout << "1 " << endl;
	int temp = 0;
	for (auto i = 0; i < n; ++i)
		cin >> ivec[i];
	if (n == 50000) cout << "2 " << endl;
	//Sleep(10 * 1000);

	long long unsigned int maxVal = 0;
	for (int i = 0; i < n; i++) {
		leftv[0][i] = rightv[0][i] = ivec[i];
		if (maxVal < leftv[0][i])
			maxVal = leftv[0][i];
	}
	cout << maxVal << " ";

	if (n == 50000) cout << "3 " << endl;

	int curr = 1;
	int prev = 0;

	for (int step = 2; step <= n; ++step) {
		maxVal = 0;
		for (int i = 0; i < n; ++i) {
			long long unsigned lval = 0, rval = 0;
			if (i - 76 + 1 >= 0) {
				lval = min(leftv[prev][i], ivec[i-step+1]);
			}
			if (i+step-1 < n) {
				rval = min(rightv[prev][i], ivec[i+step-1]);
			}
			rightv[curr][i] = rval;
			leftv[curr][i] = lval;
			auto maxv = max(rval,lval);
			if (n == 50000) cout << step << " "  << endl;
			if (maxVal < maxv)
				maxVal = maxv;
		}
		swap(curr,prev);
		cout << maxVal << " " ;
	}
	cout << endl;

	return 0;
}


// rows.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <vector>
#include <iomanip>
#include <set>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <limits>
#include <unordered_set>
#include <stack>
#include <map>
#include <functional>
#include <array>

using namespace std;

const int Max = 2 *10000;
int ans[2][Max];

int main() {

	int n = 0;
	cin >> n;

	vector<int> ivec(n);
	int temp = 0;
	generate(ivec.begin(), ivec.end(), [&temp] { cin >> temp; return temp;});

	int maxVal = -1;
	for (auto i = 0; i < n; i++) {
		ans[0][i] = ivec[i];
		if (maxVal < ans[0][i])
			maxVal = ans[0][i];
	}
	cout << maxVal << " ";

	int curr = 1;
	int prev = 0;

	for (int step = 2; step <= n; ++step) {
		maxVal = -1;
		for (int i = 0; i < n; ++i) {
			int lval = -1, rval = -1;
			if (i - step + 1 >= 0)
				lval = min(ans[prev][i], ivec[i-step+1]);
			if (i+step-1 < n)
				rval = min(ans[prev][i], ivec[i+step-1]);
			ans[curr][i] = max(rval,lval);
			if (maxVal < ans[curr][i])
				maxVal = ans[curr][i];
		}
		curr = (curr == 1 ? 0 : 1);
		prev = (prev == 1 ? 0 : 1);
		cout << maxVal << " " ;
	}
	cout << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <iomanip>
#include <set>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <limits>
#include <unordered_set>
#include <stack>
#include <map>
#include <functional>
#include <array>
//#include "windows.h"

using namespace std;

const long long unsigned int Max = 2 *100000;
long long unsigned int leftv[2][Max];
long long unsigned int rightv[2][Max];
vector<long long unsigned int> ivec(Max);

int main() {

	int n = 0;
	cin >> n;

	for (auto i = 0; i < n; ++i)
		cin >> ivec[i];

	//Sleep(10 * 1000);

	long long unsigned int maxVal = 0;
	for (auto i = 0; i < n; i++) {
		leftv[0][i] = rightv[0][i] = ivec[i];
		if (maxVal < leftv[0][i])
			maxVal = leftv[0][i];
	}
	cout << maxVal << " ";

	int curr = 1;
	int prev = 0;

	for (int step = 2; step <= n; ++step) {
		maxVal = 0;
		for (int i = 0; i < n; ++i) {
			long long unsigned lval = 0, rval = 0;
			if (i - step + 1 >= 0) {
				lval = min(leftv[prev][i], ivec[i-step+1]);
			}
			if (i+step-1 < n) {
				rval = min(rightv[prev][i], ivec[i+step-1]);
			}
			rightv[curr][i] = rval;
			leftv[curr][i] = lval;
			auto maxv = max(rval,lval);

			if (maxVal < maxv)
				maxVal = maxv;
		}
		swap(curr,prev);
		cout << maxVal << " " ;
	}
	cout << endl;

	return 0;
}


// rows.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <vector>
#include <iomanip>
#include <set>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <limits>
#include <unordered_set>
#include <stack>
#include <map>
#include <functional>
#include <array>

using namespace std;

const long long unsigned int Max = 2 *10000;
long long unsigned int ans[2][Max];

int main() {

	int n = 0;
	cin >> n;

	vector<long long unsigned int> ivec(n);
	int temp = 0;
	generate(ivec.begin(), ivec.end(), [&temp] { cin >> temp; return temp;});

	long long unsigned int maxVal = 0;
	bool first = true;
	for (auto i = 0; i < n; i++) {
		ans[0][i] = ivec[i];
		if (first || maxVal < ans[0][i])
			maxVal = ans[0][i];
		first = false;
	}
	cout << maxVal << " ";

	int curr = 1;
	int prev = 0;

	for (int step = 2; step <= n; ++step) {
		maxVal = 0;
		first = true;
		for (int i = 0; i < n; ++i) {
			long long unsigned lval = 0, rval = 0;
			bool lset = false, rset = true;
			if (i - step + 1 >= 0) {
				lval = min(ans[prev][i], ivec[i-step+1]);
				lset = true;
			}
			if (i+step-1 < n) {
				rval = min(ans[prev][i], ivec[i+step-1]);
				rset = true;
			}

			if (lset && rset)
				ans[curr][i] = max(rval,lval);
			else if (lset)
				ans[curr][i] = lval;
			else
				ans[curr][i] = rval;

			if (first || maxVal < ans[curr][i])
				maxVal = ans[curr][i];
			first = false;
		}
		curr = (curr == 1 ? 0 : 1);
		prev = (prev == 1 ? 0 : 1);
		cout << maxVal << " " ;
	}
	cout << endl;

	return 0;
}


// rows.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <vector>
#include <iomanip>
#include <set>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <limits>
#include <unordered_set>
#include <stack>
#include <map>
#include <functional>
#include <array>

using namespace std;

const int Max = 2 *10000;
int ans[2][Max];

int main() {

	int n = 0;
	cin >> n;

	vector<int> ivec(n);
	int temp = 0;
	generate(ivec.begin(), ivec.end(), [&temp] { cin >> temp; return temp;});

	for (auto i = 0; i < n; i++)
		ans[0][i] = ivec[i];

	int curr = 1;
	int prev = 0;

	for (int step = 2; step <= n; ++step) {
		int maxVal = -1;
		for (int i = 0; i < n; ++i) {
			int lval = -1, rval = -1;
			if (i - step + 1 >= 0)
				lval = min(ans[prev][i], ivec[i-step+1]);
			if (i+step-1 < n)
				rval = min(ans[prev][i], ivec[i+step-1]);
			ans[curr][i] = max(rval,lval);
			if (maxVal < ans[curr][i])
				maxVal = ans[curr][i];
		}
		curr = (curr == 1 ? 0 : 1);
		prev = (prev == 1 ? 0 : 1);
		cout << maxVal << " " ;
	}
	cout << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <iomanip>
#include <set>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <limits>
#include <unordered_set>
#include <stack>
#include <map>
#include <functional>
#include <array>
#include <stack>
//#include "windows.h"

using namespace std;

const long long int Max = 2 *100000;
long long int l[Max], r[Max];
vector<long long int> ivec(Max);
vector<long long int> fvec(Max,-1);
vector<long long int> ans(Max,0);

int main() {

	int n = 0;
	cin >> n;

	for (auto i = 0; i < n; ++i)
		cin >> ivec[i];

	stack<long long int> ls;
	for (auto i = 0; i < n; ++i) {
		for (;!ls.empty() && ivec[ls.top()] >= ivec[i];ls.pop());
		if (ls.empty())
			l[i] = -1;
		else
			l[i] = ls.top();
		ls.push(i);
	}

	stack<long long int> rs;
	for (int i = n-1; i >= 0; --i) {
		for (;!rs.empty() && ivec[rs.top()] >= ivec[i];rs.pop());
		if (rs.empty())
			r[i] = n;
		else
			r[i] = rs.top();
		rs.push(i);
	}

	for (auto i = 0; i < n; ++i) {
		const auto len = r[i] - l[i] - 1;
		if (fvec[len-1] < ivec[i])
			fvec[len-1] = ivec[i];
	}

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

	for (auto i = 0; i < n; ++i)
		cout << ans[i] << " ";
	cout << endl;

	return 0;
}


// rows.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <vector>
#include <iomanip>
#include <set>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <limits>
#include <unordered_set>
#include <stack>
#include <map>
#include <functional>
#include <array>

using namespace std;

const long long unsigned int Max = 2 *10000;
long long unsigned int ans[2][Max];

int main() {

	int n = 0;
	cin >> n;

	vector<long long unsigned int> ivec(n);
	int temp = 0;
	generate(ivec.begin(), ivec.end(), [&temp] { cin >> temp; return temp;});

	long long unsigned int maxVal = 0;
	bool first = true;
	for (auto i = 0; i < n; i++) {
		ans[0][i] = ivec[i];
		if (first || maxVal < ans[0][i])
			maxVal = ans[0][i];
		first = false;
	}
	cout << maxVal << " ";

	int curr = 1;
	int prev = 0;

	for (int step = 2; step <= n; ++step) {
		maxVal = 0;
		first = true;
		for (int i = 0; i < n; ++i) {
			long long unsigned lval = 0, rval = 0;
			bool lset = false, rset = false;
			if (i - step + 1 >= 0) {
				lval = min(ans[prev][i], ivec[i-step+1]);
				lset = true;
			}
			if (i+step-1 < n) {
				rval = min(ans[prev][i], ivec[i+step-1]);
				rset = true;
			}

			if (lset && rset)
				ans[curr][i] = max(rval,lval);
			else if (lset)
				ans[curr][i] = lval;
			else
				ans[curr][i] = rval;

			if (first || maxVal < ans[curr][i])
				maxVal = ans[curr][i];
			first = false;
		}
		curr = (curr == 1 ? 0 : 1);
		prev = (prev == 1 ? 0 : 1);
		cout << maxVal << " " ;
	}
	cout << endl;

	return 0;
}


#include <iostream>
#include <stack>
using namespace std;

int n;
int a[200009];
int d[200009];
int g[200009];
int p[200009]={0};

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

    for (int i=0; i<n; i++){
        d[i]=n;
        g[i]=-1;
    }

    stack<int> s;
    for (int i=0; i<n; i++){
        if (s.empty()){
            s.push(i);
        }else{
            while (!s.empty()){
                int x=s.top();
                if (a[x]>a[i]){
                    d[x]=i;
                    s.pop();
                }else{
                    break;
                }
            }
            s.push(i);
        }
    }
    stack<int>t;

    for (int i=n-1; i>=0; i--){
        if (t.empty()){
            t.push(i);
        }else{
            while (!t.empty()){
                int x=t.top();
                if (a[x]>a[i]){
                    g[x]=i;
                    t.pop();
                }else{
                    break;
                }
            }
            t.push(i);
        }
    }

    //for (int i=0; i<n; i++){
    //cout<<d[i]<<' '<<g[i]<<endl;
    //}
    int m=a[0];
    for (int i=1; i<n; i++)
    if (m>a[i])
    m=a[i];

    p[n]=m;

    for (int i=0; i<n; i++)
    {
        int x=d[i]-g[i]-1;
        if (a[i]>p[x])
        p[x]=a[i];
    }

    for (int i=n; i>1; i--){
        if (p[i]>p[i-1])
        p[i-1]=p[i];
    }
    for (int i=1; i<=n; i++)
    cout<<p[i]<<' ';

    return 0;
}


#include <iostream>
#include <stack>
using namespace std;

int n;
int a[200009];
int d[200009];
int g[200009];
int p[200009]={0};

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

    for (int i=0; i<n; i++){
        d[i]=n;
        g[i]=0;
    }

    stack<int> s;
    for (int i=0; i<n; i++){
        if (s.empty()){
            s.push(i);
        }else{
            while (!s.empty()){
                int x=s.top();
                if (a[x]>a[i]){
                    d[x]=i;
                    s.pop();
                }else{
                    break;
                }
            }
            s.push(i);
        }
    }
    stack<int>t;

    for (int i=n-1; i>=0; i--){
        if (t.empty()){
            t.push(i);
        }else{
            while (!t.empty()){
                int x=t.top();
                if (a[x]>a[i]){
                    g[x]=i;
                    t.pop();
                }else{
                    break;
                }
            }
            t.push(i);
        }
    }

    //for (int i=0; i<n; i++){
    //cout<<d[i]<<' '<<g[i]<<endl;
    //}
    int m=a[0];
    for (int i=1; i<n; i++)
    if (m>a[i])
    m=a[i];

    p[n]=m;

    for (int i=0; i<n; i++)
    {
        int x=d[i]-g[i]-1;
        if (a[i]>p[x])
        p[x]=a[i];
    }

    for (int i=n; i>1; i--){
        if (p[i]>p[i-1])
        p[i-1]=p[i];
    }
    for (int i=1; i<=n; i++)
    cout<<p[i]<<' ';

    return 0;
}


#include <iostream>
#include <stack>
using namespace std;

int n;
int a[200009];
int d[200009];
int g[200009];
int p[200009]={0};

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

    for (int i=0; i<n; i++){
        d[i]=n;
        g[i]=0;
    }

    stack<int> s;
    for (int i=0; i<n; i++){
        if (s.empty()){
            s.push(i);
        }else{
            while (!s.empty()){
                int x=s.top();
                if (a[x]>a[i]){
                    d[x]=i;
                    s.pop();
                }else{
                    break;
                }
            }
            s.push(i);
        }
    }
    stack<int>t;

    for (int i=n-1; i>=0; i--){
        if (t.empty()){
            t.push(i);
        }else{
            while (!t.empty()){
                int x=t.top();
                if (a[x]>a[i]){
                    g[x]=i;
                    t.pop();
                }else{
                    break;
                }
            }
            t.push(i);
        }
    }

    for (int i=0; i<n; i++){
    cout<<d[i]<<' '<<g[i]<<endl;
    }
    int m=a[0];
    for (int i=1; i<n; i++)
    if (m>a[i])
    m=a[i];

    p[n]=m;

    for (int i=0; i<n; i++)
    {
        int x=d[i]-g[i]-1;
        if (a[i]>p[x])
        p[x]=a[i];
    }

    for (int i=n; i>1; i--){
        if (p[i]>p[i-1])
        p[i-1]=p[i];
    }
    for (int i=1; i<=n; i++)
    cout<<p[i]<<' ';

    return 0;
}


#include <iostream>
#include <stack>
using namespace std;

int n;
int a[200009];
int d[200009];
int g[200009];
int p[200009]={0};

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

    for (int i=0; i<n; i++){
        d[i]=i;
        g[i]=i;
    }

    stack<int> s;
    for (int i=0; i<n; i++){
        if (s.empty()){
            s.push(i);
        }else{
            while (!s.empty()){
                int x=s.top();
                if (a[x]>a[i]){
                    d[x]=i;
                    s.pop();
                }else{
                    s.push(i);
                    break;
                }
            }
        }
    }
    stack<int>t;

    for (int i=n-1; i>=0; i--){
        if (t.empty()){
            t.push(i);
        }else{
            while (!t.empty()){
                int x=t.top();
                if (a[x]>a[i]){
                    g[x]=i;
                    t.pop();
                }else{
                    t.push(i);
                    break;
                }
            }
        }
    }

    //for (int i=0; i<n; i++){
    //cout<<d[i]<<' '<<g[i]<<endl;
    //}
    int m=a[0];
    for (int i=1; i<n; i++)
    if (m>a[i])
    m=a[i];

    p[n]=m;

    for (int i=0; i<n; i++)
    {
        int x;
        if (d[i]==g[i])
        x=1;
        else
        if (d[i]==i || g[i]==i)
        x=d[i]-g[i];
        else
        x=d[i]-g[i]-1;
        if (a[i]>p[x])
        p[x]=a[i];
    }

    for (int i=n; i>1; i--){
        if (p[i]>p[i-1])
        p[i-1]=p[i];
    }
    for (int i=1; i<=n; i++)
    cout<<p[i]<<' ';

    return 0;
}


#include <iostream>
#include <stack>
using namespace std;

int n;
int a[200009];
int d[200009];
int g[200009];
int p[200009]={0};

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

    for (int i=0; i<n; i++){
        d[i]=i;
        g[i]=i;
    }

    stack<int> s;
    for (int i=0; i<n; i++){
        if (s.empty()){
            s.push(i);
        }else{
            while (!s.empty()){
                int x=s.top();
                if (a[x]>a[i]){
                    d[x]=i;
                    s.pop();
                }else{
                    s.push(i);
                    break;
                }
            }
        }
    }
    stack<int>t;

    for (int i=n-1; i>=0; i--){
        if (t.empty()){
            t.push(i);
        }else{
            while (!t.empty()){
                int x=t.top();
                if (a[x]>a[i]){
                    g[x]=i;
                    t.pop();
                }else{
                    t.push(i);
                    break;
                }
            }
        }
    }

    //for (int i=0; i<n; i++){
    //cout<<d[i]<<' '<<g[i]<<endl;
    //}
    int m=a[0];
    for (int i=1; i<n; i++)
    if (m>a[i])
    m=a[i];

    p[n]=m;

    for (int i=0; i<n; i++)
    {
        int x;
        if (d[i]==g[i])
        x=1;
        else
        if (d[i]==i || g[i]==i)
        x=d[i]-g[i];
        else
        x=d[i]-g[i]-1;
        p[x]=a[i];
    }

    for (int i=n; i>1; i--){
        if (p[i]>p[i-1])
        p[i-1]=p[i];
    }
    for (int i=1; i<=n; i++)
    cout<<p[i]<<' ';

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug printf("*");
//#define mo 1e9+7
const int N=2e5+10;
int n,a[N],ans[N],l[N],r[N];
stack<int>z;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	a[n+1]=0;n++;
	for(int i=1;i<=n;i++){
		int sum=0;
		while(!z.empty()){
			if(a[z.top()]>=a[i]){
				z.pop();
			} else {
				sum=z.top();break;
			}
		}
		z.push(i);
		l[i]=sum;
	}
	while(!z.empty()) z.pop();
	for(int i=n;i>=1;i--){
		int sum=0;
		while(!z.empty()){
			if(a[z.top()]>=a[i]){
				z.pop();
			} else {
				sum=z.top();break;
			}
		}
		z.push(i);
		r[i]=sum;
	}
	n--;
	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-1;i>=1;i--)
		ans[i]=max(ans[i+1],ans[i]);
	for(int j=1;j<=n;j++)
		printf("%d ",ans[j]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug printf("*");
//#define mo 1e9+7
const int N=2e5;
int n,a[N],ans[N],l[N],r[N];
stack<int>z;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	a[n+1]=0;n++;
	for(int i=1;i<=n;i++){
		int sum=0;
		while(!z.empty()){
			if(a[z.top()]>=a[i]){
				z.pop();
			} else {
				sum=z.top();break;
			}
		}
		z.push(i);
		l[i]=sum;
	}
	while(!z.empty()) z.pop();
	for(int i=n;i>=1;i--){
		int sum=0;
		while(!z.empty()){
			if(a[z.top()]>=a[i]){
				z.pop();
			} else {
				sum=z.top();break;
			}
		}
		z.push(i);
		r[i]=sum;
	}
	n--;
	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-1;i>=1;i--)
		ans[i]=max(ans[i+1],ans[i]);
	for(int j=1;j<=n;j++)
		printf("%d ",ans[j]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug printf("*");
//#define mo 1e9+7
const int N=2e5;
int n,a[N],ans[N],l[N],r[N];
stack<int>z;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	a[n+1]=0;n++;
	for(int i=1;i<=n;i++){
		int sum=0;
		while(!z.empty()){
			if(a[z.top()]>=a[i]){
				z.pop();
			} else {
				sum=z.top();break;
			}
		}
		z.push(i);
		l[i]=sum;
	}
	while(!z.empty()) z.pop();
	for(int i=n;i>=1;i--){
		int sum=0;
		while(!z.empty()){
			if(a[z.top()]>=a[i]){
				z.pop();
			} else {
				sum=z.top();break;
			}
		}
		z.push(i);
		r[i]=sum;
	}
	n--;
	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+1],ans[i]);
	for(int j=1;j<=n;j++)
		printf("%d ",ans[j]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug printf("*");
//#define mo 1e9+7
const int N=2e5;
int n,a[N],ans[N],l[N],r[N];
stack<int>z;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	a[n+1]=0;n++;
	for(int i=1;i<=n;i++){
		int sum=0;
		while(!z.empty()){
			if(a[z.top()]>a[i]){
				z.pop();
			} else {
				sum=z.top();break;
			}
		}
		z.push(i);
		l[i]=sum;
	}
	while(!z.empty()) z.pop();
	for(int i=n;i>=1;i--){
		int sum=0;
		while(!z.empty()){
			if(a[z.top()]>a[i]){
				z.pop();
			} else {
				sum=z.top();break;
			}
		}
		z.push(i);
		r[i]=sum;
	}
	n--;
	for(int i=1;i<=n;i++){
		ans[r[i]-l[i]-1]=max(ans[r[i]-l[i]-1],a[i]);
	//	cout<<a[i]<<" "<<r[i]-l[i]-1<<" "<<ans[r[i]-l[i]-1]<<endl;
	}
//	printf("\n");
	for(int i=n;i>1;i--)
		ans[i]=max(ans[i+1],ans[i]);
	for(int j=1;j<=n;j++)
		printf("%d ",ans[j]);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<map>
#include<vector>
#include<string.h>
using namespace std;
const int maxn=200005;
int n,top,tot;
int a[maxn],b[maxn],stk[maxn],val[maxn],len[maxn],l[maxn],r[maxn],ans[maxn],f[maxn];
map<int,int>mp;
vector<int>v[maxn];
int find(int x){
	if(x==-1)
		return -1;
	return f[x]==x? x:f[x]=find(f[x]);
}
void merge(int a,int b){
	int x=find(a),y=find(b);
	if(x==-1||y==-1)
		return ;
	f[x]=y,l[y]=min(l[x],l[y]),r[y]=max(r[x],r[y]);
}
void update(int x,int v){
	if(l[x]==-1||r[x]==-1)
		return ;
	ans[r[x]-l[x]+1]=max(ans[r[x]-l[x]+1],val[v]);
}
int main(){
	memset(f,-1,sizeof(f));
	memset(l,-1,sizeof(l));
	memset(r,-1,sizeof(r));
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(b+1,b+1+n);
	for(int i=1;i<=n;i++)
		if(i==1||b[i]>b[i-1])
			tot++,mp[b[i]]=tot,val[tot]=b[i];
	for(int i=1;i<=n;i++){
		a[i]=mp[a[i]];
		v[a[i]].push_back(i);
	}
	for(int i=tot;i>=1;i--)
		for(int j=0;j<v[i].size();j++){
			int k=v[i][j];
			l[k]=r[k]=f[k]=k;
			merge(k-1,k),merge(k,k+1);
			update(k-1,i),update(k,i),update(k+1,i);
		}
	for(int i=n;i>=1;i--)
		ans[i]=max(ans[i],ans[i+1]);
	for(int i=1;i<=n;i++)
		printf("%d%c",ans[i],i==n? '\n':' ');
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<map>
#include<vector>
#include<string.h>
using namespace std;
const int maxn=200005;
int n,top,tot;
int a[maxn],b[maxn],stk[maxn],val[maxn],len[maxn],l[maxn],r[maxn],ans[maxn],f[maxn];
map<int,int>mp;
vector<int>v[maxn];
int find(int x){
	if(x==-1)
		return -1;
	return f[x]==x? x:f[x]=find(f[x]);
}
void merge(int a,int b){
	int x=find(a),y=find(b);
	if(x==-1||y==-1)
		return ;
	f[x]=y,l[y]=min(l[x],l[y]),r[y]=max(r[x],r[y]);
}
void update(int x,int v){
	x=find(x);
	if(l[x]==-1||r[x]==-1)
		return ;
	ans[r[x]-l[x]+1]=max(ans[r[x]-l[x]+1],val[v]);
}
int main(){
	memset(f,-1,sizeof(f));
	memset(l,-1,sizeof(l));
	memset(r,-1,sizeof(r));
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(b+1,b+1+n);
	for(int i=1;i<=n;i++)
		if(i==1||b[i]>b[i-1])
			tot++,mp[b[i]]=tot,val[tot]=b[i];
	for(int i=1;i<=n;i++){
		a[i]=mp[a[i]];
		v[a[i]].push_back(i);
	}
	for(int i=tot;i>=1;i--)
		for(int j=0;j<v[i].size();j++){
			int k=v[i][j];
			l[k]=r[k]=f[k]=k;
			merge(k-1,k),merge(k,k+1);
			update(k,i);
		}
	for(int i=n;i>=1;i--)
		ans[i]=max(ans[i],ans[i+1]);
	for(int i=1;i<=n;i++)
		printf("%d%c",ans[i],i==n? '\n':' ');
	return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn=200005;
int n;
int a[maxn],ans[maxn],f[maxn],l[maxn],r[maxn];
struct number{
	int pos,val;
}num[maxn];
inline int cmp(number a,number b){
	return a.val>b.val;
}
int find(int x){
	if(x==-1)
		return -1;
	return f[x]==x? x:f[x]=find(f[x]);
}
void merge(int a,int b){
	a=find(a),b=find(b);
	if(a==-1||b==-1)
		return ;
	f[b]=a,l[a]=min(l[a],l[b]),r[a]=max(r[a],r[b]);
}
void update(int x,int v){
	x=find(x);
	ans[r[x]-l[x]+1]=max(ans[r[x]-l[x]+1],v);
}
int main(){
	scanf("%d",&n);
	f[0]=f[n+1]=-1;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		num[i].val=a[i],num[i].pos=i;
		f[i]=-1;
	}
	sort(num+1,num+1+n,cmp);
	for(int i=1;i<=n;i++){
		int p=num[i].pos;
		f[p]=l[p]=r[p]=p;
		merge(p,p-1),merge(p,p+1);
		update(p,num[i].val);
	}
	for(int i=n;i>=1;i--)
		ans[i]=max(ans[i],ans[i+1]);
	for(int i=1;i<=n;i++)
		printf("%d%c",ans[i],i==n? '\n':' ');
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<map>
#include<vector>
#include<string.h>
using namespace std;
const int maxn=200005;
int n,top,tot;
int a[maxn],b[maxn],stk[maxn],val[maxn],len[maxn],l[maxn],r[maxn],ans[maxn],f[maxn];
map<int,int>mp;
vector<int>v[maxn];
int find(int x){
	return f[x]==x? x:f[x]=find(f[x]);
}
void merge(int a,int b){
	if(f[a]==-1||f[b]==-1)
		return ;
	int x=find(a),y=find(b);
	f[x]=y,l[y]=min(l[x],l[y]),r[y]=max(r[x],r[y]);
}
void update(int x,int v){
	if(l[x]==-1||r[x]==-1)
		return ;
	ans[r[x]-l[x]+1]=max(ans[r[x]-l[x]+1],val[v]);
}
int main(){
	memset(f,-1,sizeof(f));
	memset(l,-1,sizeof(l));
	memset(r,-1,sizeof(r));
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(b+1,b+1+n);
	for(int i=1;i<=n;i++)
		if(i==1||b[i]>b[i-1])
			tot++,mp[b[i]]=tot,val[tot]=b[i];
	for(int i=1;i<=n;i++){
		a[i]=mp[a[i]];
		v[a[i]].push_back(i);
	}
	for(int i=tot;i>=1;i--)
		for(int j=0;j<v[i].size();j++){
			int k=v[i][j];
			l[k]=r[k]=f[k]=k;
			merge(k-1,k),merge(k,k+1);
			update(k-1,i),update(k,i),update(k+1,i);
		}
	for(int i=n;i>=1;i--)
		ans[i]=max(ans[i],ans[i+1]);
	for(int i=1;i<=n;i++)
		printf("%d%c",ans[i],i==n? '\n':' ');
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<map>
#include<vector>
#include<string.h>
using namespace std;
const int maxn=200005;
int n,top,tot;
int a[maxn],b[maxn],stk[maxn],val[maxn],len[maxn],l[maxn],r[maxn],ans[maxn],f[maxn];
map<int,int>mp;
vector<int>v[maxn];
int find(int x){
	return f[x]==x? x:f[x]=find(f[x]);
}
void merge(int a,int b){
	if(f[a]==-1||f[b]==-1)
		return ;
	int x=find(a),y=find(b);
	f[x]=y,l[y]=min(l[x],l[y]),r[y]=max(r[x],r[y]);
}
void update(int x,int v){
	if(l[x]==-1||r[x]==-1)
		return ;
	ans[r[x]-l[x]+1]=max(ans[r[x]-l[x]+1],val[v]);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b[i]=a[i];
		f[i]=-1;
	}
	sort(b+1,b+1+n);
	for(int i=1;i<=n;i++)
		if(i==1||b[i]>b[i-1])
			tot++,mp[b[i]]=tot,val[tot]=b[i];
	for(int i=1;i<=n;i++){
		a[i]=mp[a[i]];
		v[a[i]].push_back(i);
	}
	for(int i=tot;i>=1;i--)
		for(int j=0;j<v[i].size();j++){
			int k=v[i][j];
			l[k]=r[k]=f[k]=k;
			merge(k-1,k),merge(k,k+1);
			update(k-1,i),update(k,i),update(k+1,i);
		}
	for(int i=n;i>=1;i--)
		ans[i]=max(ans[i],ans[i+1]);
	for(int i=1;i<=n;i++)
		printf("%d%c",ans[i],i==n? '\n':' ');
	return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn=200005;
int n;
int a[maxn],ans[maxn],f[maxn],l[maxn],r[maxn];
struct number{
	int pos,val;
}num[maxn];
inline int cmp(number a,number b){
	return a.val>b.val;
}
int find(int x){
	if(x==-1)
		return -1;
	return f[x]==x? x:f[x]=find(f[x]);
}
void merge(int a,int b){
	a=find(a),b=find(b);
	if(a==-1||b==-1)
		return ;
	f[b]=a,l[a]=min(l[a],l[b]),r[a]=max(r[a],r[b]);
}
void update(int x,int v){
	x=find(x);
	ans[r[x]-l[x]+1]=max(ans[r[x]-l[x]+1],v);
}
int main(){
	scanf("%d",&n);
	f[0]=f[n+1]=-1;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		num[i].val=a[i],num[i].pos=i;
		f[i]=-1;
	}
	sort(num+1,num+1+n,cmp);
	for(int i=1;i<=n;i++){
		int p=num[i].pos;
		f[p]=l[p]=r[p]=p;
		merge(p,p-1),merge(p,p+1);
		update(p,num[i].val);
	}
	for(int i=n;i>=1;i--)
		ans[i]=max(ans[i],ans[i-1]);
	for(int i=1;i<=n;i++)
		printf("%d%c",ans[i],i==n? '\n':' ');
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 200010;
const int LOGN = 20;

int n, q;
int log_2[N];
int pow_2[LOGN];

template<class cmp>
struct stab {
    cmp lt;
    int f[N][LOGN];
    stab(cmp lt) :
            lt(lt) {
    }
    void prep() {
        // invoker should fill f[i][0] first
        for (int j = 1; j <= log_2[n]; ++j) {
            for (int i = 0; i < n; ++i) {
                int j2 = j - 1;
                int i2 = i + pow_2[j2];
                if (i2 >= n) {
                    f[i][j] = f[i][j2];
                } else if (lt(f[i][j2], f[i2][j2])) {
                    f[i][j] = f[i][j2];
                } else {
                    f[i][j] = f[i2][j2];
                }
            }
        }
    }
    int query(int a, int b) {
        int i1 = a;
        int j1 = log_2[b - a + 1];
        int i2 = b - pow_2[j1] + 1;
        int j2 = j1;
        if (lt(f[i1][j1], f[i2][j2]))
            return f[i1][j1];
        else
            return f[i2][j2];
    }
};

void init()
{
    for (int k = 1; k < 17; ++k)
        for (int i = (1 << (k - 1)); i < (1 << k) && i < N; ++i)
            log_2[i] = k - 1;
    for (int i = 0; i < LOGN; ++i)
        pow_2[i] = (1 << i);
}

stab<less<int> > small = stab<less<int> >(less<int>());

int a[N];
int g[N];

int main() {
    init();
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        small.f[i][0] = a[i];
    }
    small.prep();
//    for (int i = 1; i <= n; ++i) {
//      cout << small.f[i][0] << " " << small.query(i, i) << endl;
//  }

    for (int i = 1; i <= n; ++i) {
        int x, y;
        int L = 0;
        int R = i;
        while (L < R) {
            int mid = (L + R) >> 1;
            int q = small.query(mid, R);
            if (q < a[i]) {
                L = mid + 1;
            } else {
                R = mid;
            }
        }
        x = R;

        L = i;
        R = n;
        while (L < R) {
            int mid = (L + R + 1) >> 1;
            int q = small.query(L, mid);
            if (q < a[i]) {
                R = mid - 1;
            } else {
                L = mid;
            }
        }
        y = L;
//      cout << a[i] << " " << x << " " << y << endl;
        g[y - x + 1] = max(g[y - x + 1], a[i]);
    }
    for (int i = 2; i <= N; ++i) {
        if (g[i] > 0) {
            int j = i - 1;
            while (j > 0 && g[j] == 0) {
                g[j--] = g[i];
            }
        }
    }
    for (int i = 1; i <= n; ++i) {
        cout << g[i] << " ";
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 200010;
const int LOGN = 20;

int n, q;
int log_2[N];
int pow_2[LOGN];

template<class cmp>
struct stab {
    cmp lt;
    int f[N][LOGN];
    stab(cmp lt) :
            lt(lt) {
    }
    void prep() {
        // invoker should fill f[i][0] first
        for (int j = 1; j <= log_2[n]; ++j) {
            for (int i = 0; i < n; ++i) {
                int j2 = j - 1;
                int i2 = i + pow_2[j2];
                if (i2 >= n) {
                    f[i][j] = f[i][j2];
                } else if (lt(f[i][j2], f[i2][j2])) {
                    f[i][j] = f[i][j2];
                } else {
                    f[i][j] = f[i2][j2];
                }
            }
        }
    }
    int query(int a, int b) {
        int i1 = a;
        int j1 = log_2[b - a + 1];
        int i2 = b - pow_2[j1] + 1;
        int j2 = j1;
        if (lt(f[i1][j1], f[i2][j2]))
            return f[i1][j1];
        else
            return f[i2][j2];
    }
};

void init()
{
    for (int k = 1; k < LOGN; ++k)
        for (int i = (1 << (k - 1)); i < (1 << k) && i < N; ++i)
            log_2[i] = k - 1;
    for (int i = 0; i < LOGN; ++i)
        pow_2[i] = (1 << i);
}

stab<less<int> > small = stab<less<int> >(less<int>());

int a[N];
int g[N];

int main() {
    init();
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        small.f[i][0] = a[i];
    }
    small.prep();

    for (int i = 0; i < n; ++i) {
        int x, y;
        int L = 0;
        int R = i;
        while (L < R) {
            int mid = (L + R) >> 1;
            int q = small.query(mid, i);
            if (q < a[i]) {
                L = mid + 1;
            } else {
                R = mid;
            }
        }
        x = R;

        L = i;
        R = n - 1;
        while (L < R) {
            int mid = (L + R + 1) >> 1;
            int q = small.query(i, mid);
            if (q < a[i]) {
                R = mid - 1;
            } else {
                L = mid;
            }
        }
        y = L;
        //cout << a[i] << " " << x << " " << y << endl;
        g[y - x + 1] = max(g[y - x + 1], a[i]);
    }
    for (int i = 2; i <= N; ++i) {
        if (g[i] > 0) {
            int j = i;
            while (j > 0 && g[j] >= g[j - 1]) {
                g[j--] = g[i];
            }
        }
    }
    for (int i = 1; i <= n; ++i) {
        cout << g[i] << " ";
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 200010;
const int LOGN = 20;

int n, q;
int log_2[N];
int pow_2[LOGN];

template<class cmp>
struct stab {
    cmp lt;
    int f[N][LOGN];
    stab(cmp lt) :
            lt(lt) {
    }
    void prep() {
        // invoker should fill f[i][0] first
        for (int j = 1; j <= log_2[n]; ++j) {
            for (int i = 0; i < n; ++i) {
                int j2 = j - 1;
                int i2 = i + pow_2[j2];
                if (i2 >= n) {
                    f[i][j] = f[i][j2];
                } else if (lt(f[i][j2], f[i2][j2])) {
                    f[i][j] = f[i][j2];
                } else {
                    f[i][j] = f[i2][j2];
                }
            }
        }
    }
    int query(int a, int b) {
        int i1 = a;
        int j1 = log_2[b - a + 1];
        int i2 = b - pow_2[j1] + 1;
        int j2 = j1;
        if (lt(f[i1][j1], f[i2][j2]))
            return f[i1][j1];
        else
            return f[i2][j2];
    }
};

void init()
{
    for (int k = 1; k < LOGN; ++k)
        for (int i = (1 << (k - 1)); i < (1 << k) && i < N; ++i)
            log_2[i] = k - 1;
    for (int i = 0; i < LOGN; ++i)
        pow_2[i] = (1 << i);
}

stab<less<int> > small = stab<less<int> >(less<int>());

int a[N];
int g[N];

int main() {
    init();
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        small.f[i][0] = a[i];
    }
    small.prep();

    for (int i = 0; i < n; ++i) {
        int x, y;
        int L = 0;
        int R = i;
        while (L < R) {
            int mid = (L + R) >> 1;
            int q = small.query(mid, i);
            if (q < a[i]) {
                L = mid + 1;
            } else {
                R = mid;
            }
        }
        x = R;

        L = i;
        R = n - 1;
        while (L < R) {
            int mid = (L + R + 1) >> 1;
            int q = small.query(i, mid);
            if (q < a[i]) {
                R = mid - 1;
            } else {
                L = mid;
            }
        }
        y = L;
//      cout << a[i] << " " << x << " " << y << endl;
        g[y - x + 1] = max(g[y - x + 1], a[i]);
    }
    for (int i = 2; i <= N; ++i) {
        if (g[i] > 0) {
            int j = i - 1;
            while (j >= 0 && g[j] == 0) {
                g[j--] = g[i];
            }
        }
    }
    for (int i = 1; i <= n; ++i) {
        cout << g[i] << " ";
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 200010;
const int LOGN = 20;

int n, q;
int log_2[N];
int pow_2[LOGN];

template<class cmp>
struct stab {
    cmp lt;
    int f[N][LOGN];
    stab(cmp lt) :
            lt(lt) {
    }
    void prep() {
        // invoker should fill f[i][0] first
        for (int j = 1; j <= log_2[n]; ++j) {
            for (int i = 0; i < n; ++i) {
                int j2 = j - 1;
                int i2 = i + pow_2[j2];
                if (i2 >= n) {
                    f[i][j] = f[i][j2];
                } else if (lt(f[i][j2], f[i2][j2])) {
                    f[i][j] = f[i][j2];
                } else {
                    f[i][j] = f[i2][j2];
                }
            }
        }
    }
    int query(int a, int b) {
        int i1 = a;
        int j1 = log_2[b - a + 1];
        int i2 = b - pow_2[j1] + 1;
        int j2 = j1;
        if (lt(f[i1][j1], f[i2][j2]))
            return f[i1][j1];
        else
            return f[i2][j2];
    }
};

void init()
{
    for (int k = 1; k < 17; ++k)
        for (int i = (1 << (k - 1)); i < (1 << k) && i < N; ++i)
            log_2[i] = k - 1;
    for (int i = 0; i < LOGN; ++i)
        pow_2[i] = (1 << i);
}

stab<less<int> > small = stab<less<int> >(less<int>());

int a[N];
int g[N];

int main() {
    init();
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        small.f[i][0] = a[i];
    }
    small.prep();
//    for (int i = 1; i <= n; ++i) {
//      cout << small.f[i][0] << " " << small.query(i, i) << endl;
//  }

    for (int i = 1; i <= n; ++i) {
        int x, y;
        int L = 0;
        int R = i;
        while (L < R) {
            int mid = (L + R) >> 1;
            int q = small.query(mid, R);
            if (q < a[i]) {
                L = mid + 1;
            } else {
                R = mid;
            }
        }
        x = R;

        L = i;
        R = n;
        while (L < R) {
            int mid = (L + R + 1) >> 1;
            int q = small.query(mid, R);
            if (q < a[i]) {
                R = mid - 1;
            } else {
                L = mid;
            }
        }
        y = L;
//      cout << a[i] << " " << x << " " << y << endl;
        g[y - x + 1] = max(g[y - x + 1], a[i]);
    }
    for (int i = 2; i <= N; ++i) {
        if (g[i] > 0) {
            int j = i - 1;
            while (j > 0 && g[j] == 0) {
                g[j--] = g[i];
            }
        }
    }
    for (int i = 1; i <= n; ++i) {
        cout << g[i] << " ";
    }
    cout << endl;
    return 0;
}