#include <bits/stdc++.h>
using namespace std;
#define DB(v) cerr << #v << ' ' << v << endl
#define forn(i,n) for(int i = 0;i < n;++i)
#define forup(i,a,b) for(int i = a;i <= b;++i)
void print_all(vector <int> &v){
    cout << "{ ";
    for(auto x:v){cout << x + 1<< ", ";} cout << "}";
}

static const int INF = 1e9 * 2,N = 1e5 * 2 + 9;

int n;
vector <int> bear (N);

bool compare(int a,int b)
{
    return bear[a] > bear[b];
}

namespace DSU
{
    vector <int> parent (N);
    vector <int> sz(N,1);
    void init(){
        forn(i,n)
            parent[i] = i;
    }
    int find_set(int a){
        if(a == parent[a]){return a;}
        return parent[a] = find_set(parent[a]);
    }
    int find_size(int v)
    {
        if(v == parent[v]){return sz[v];}
        return sz[v] = find_size(parent[v]);
    }
    void union_sets(int a,int b)
    {
        a = find_set(a);
        b = find_set(b);
        if(a == b){return;}
        if(sz[a] < sz[b]){swap(a,b);}
        parent[b] = a;
        sz[a] += sz[b];
    }
}

int main()
{
    //freopen("input.txt","r",stdin);
    cin >> n;
    vector <int> pos (n);
    forn(i,n){
        cin >> bear[i];
        pos[i] = i;
    }
    sort(pos.begin(),pos.end(),&compare);
    DSU::init();
    vector <bool> have(n);
    fill(have.begin(),have.end(),false);
    vector <int> ans(n + 1);
    fill(ans.begin(),ans.end(),-INF);
    int sz_now;
    for(auto current:pos){
        if(current > 0 && have[current - 1]){
            DSU::union_sets(current,current - 1);
        }
        if(current < n && have[current + 1]){
            DSU::union_sets(current,current + 1);
        }
        have[current] = true;
        sz_now = DSU::find_size(current);
        ans[sz_now] = max(ans[sz_now] , bear[current]);
    }
    for(int i = n-1;i >= 0;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>
using namespace std;
#define DB(v) cerr << #v << ' ' << v << endl
#define forn(i,n) for(int i = 0;i < n;++i)
#define forup(i,a,b) for(int i = a;i <= b;++i)
void print_all(vector <int> &v){
    cout << "{ ";
    for(auto x:v){cout << x + 1<< ", ";} cout << "}";
}

static const int INF = 1e9 * 2,N = 1e5 * 2 + 9;

int n;
vector <int> bear (N);

bool compare(int a,int b)
{
    return bear[a] > bear[b];
}

namespace DSU
{
    vector <int> parent (N);
    vector <int> sz(N,1);
    void init(){
        forn(i,n)
            parent[i] = i;
    }
    int find_set(int a){
        if(a == parent[a]){return a;}
        return parent[a] = find_set(parent[a]);
    }
    int find_size(int v)
    {
        if(v == parent[v]){return sz[v];}
        return sz[v] = find_size(parent[v]);
    }
    void union_sets(int a,int b)
    {
        a = find_set(a);
        b = find_set(b);
        if(a == b){return;}
        if(sz[a] < sz[b]){swap(a,b);}
        parent[b] = a;
        sz[a] += sz[b];
    }
}

int main()
{
    //freopen("input.txt","r",stdin);
    cin >> n;
    vector <int> pos (n);
    forn(i,n){
        cin >> bear[i];
        pos[i] = i;
    }
    sort(pos.begin(),pos.end(),&compare);
    DSU::init();
    vector <bool> have(n);
    fill(have.begin(),have.end(),false);
    vector <int> ans(n);
    fill(ans.begin(),ans.end(),-INF);
    int sz_now;
    for(auto current:pos){
        if(current > 0 && have[current - 1]){
            DSU::union_sets(current,current - 1);
        }
        if(current < n && have[current + 1]){
            DSU::union_sets(current,current + 1);
        }
        have[current] = true;
        sz_now = DSU::find_size(current);
        ans[sz_now - 1] = max(ans[sz_now - 1],bear[current]);
    }
    for(int i = n-2;i >= 0;i--)
        ans[i] = max(ans[i],ans[i+1]);
    for(auto to:ans)
        cout << to << ' ';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define DB(v) cerr << #v << ' ' << v << endl
#define forn(i,n) for(int i = 0;i < n;++i)
#define forup(i,a,b) for(int i = a;i <= b;++i)
void print_all(vector <int> &v){
    cout << "{ ";
    for(auto x:v){cout << x + 1<< ", ";} cout << "}";
}

static const int INF = 1e9 * 2,N = 1e5 * 2 + 9;

int n;
vector <int> bear (N);

bool compare(int a,int b)
{
    return bear[a] > bear[b];
}

namespace DSU
{
    vector <int> parent (N);
    vector <int> sz(N,1);
    void init(){
        forn(i,n) parent[i] = i;
    }
    int find_set(int v){
        if(v == parent[v]){return v;}
        return parent[v] = find_set(parent[v]);
    }
    int find_size(int v){
        if(v == parent[v]){return sz[v];}
        return sz[v] = sz[find_set(v)];
    }
    void union_sets(int a,int b)
    {
        a = find_set(a);
        b = find_set(b);
        if(a == b){return;}
        if(sz[a] < sz[b]){swap(a,b);}
        parent[b] = a;
        sz[a] += sz[b];
    }
}
int main()
{
    //freopen("input.txt","r",stdin);
    cin >> n;
    vector <int> pos (n);
    forn(i,n){
        cin >> bear[i];
        pos[i] = i;
    }
    sort(pos.begin(),pos.end(),&compare);
    DSU::init();
    vector <bool> have(n,false);
    vector <int> ans(n + 1,-INF);
    int sz_now;
    for(auto current:pos){
        if(current > 0 && have[current - 1])
            DSU::union_sets(current,current - 1);

        if(current < n && have[current + 1])
            DSU::union_sets(current,current + 1);

        have[current] = true;
        sz_now = DSU::find_size(current);
        ans[sz_now] = max(ans[sz_now] , bear[current]);
    }
    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>
using namespace std;
#define DB(v) cerr << #v << ' ' << v << endl
#define forn(i,n) for(int i = 0;i < n;++i)
#define forup(i,a,b) for(int i = a;i <= b;++i)
void print_all(vector <int> &v){
    cout << "{ ";
    for(auto x:v){cout << x + 1<< ", ";} cout << "}";
}

static const int INF = 1e9 * 2,N = 1e5 * 2 + 9;

int n;
vector <int> bear (N);

bool compare(int a,int b)
{
    return bear[a] > bear[b];
}

namespace DSU
{
    vector <int> parent (N);
    vector <int> sz(N,1);
    void init(){
        forn(i,n) parent[i] = i;
    }
    int find_set(int v){
        if(v == parent[v]){return v;}
        return parent[v] = find_set(parent[v]);
    }
    int find_size(int v){
        if(v == parent[v]){return sz[v];}
        return sz[v] = sz[find_set(v)];
    }
    void union_sets(int a,int b)
    {
        a = find_set(a);
        b = find_set(b);
        if(a == b){return;}
        if(sz[a] < sz[b]){swap(a,b);}
        parent[b] = a;
        sz[a] += sz[b];
    }
}
int main()
{
    //freopen("input.txt","r",stdin);
    cin >> n;
    vector <int> pos (n);
    forn(i,n){
        cin >> bear[i];
        pos[i] = i;
    }
    sort(pos.begin(),pos.end(),&compare);
    DSU::init();
    vector <bool> have(n,false);
    vector <int> ans(n + 1,-INF);
    int sz_now;
    for(auto current:pos){
        if(current > 0 && have[current - 1])
            DSU::union_sets(current,current - 1);

        if(current < n && have[current + 1])
            DSU::union_sets(current,current + 1);

        have[current] = true;
        sz_now = DSU::find_size(current);
        ans[sz_now] = max(ans[sz_now] , bear[current]);
    }
    for(int i = n-1;i >= 0;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>
using namespace std;
#define DB(v) cerr << #v << ' ' << v << endl
#define forn(i,n) for(int i = 0;i < n;++i)
#define forup(i,a,b) for(int i = a;i <= b;++i)
void print_all(vector <int> &v){
    cout << "{ ";
    for(auto x:v){cout << x + 1<< ", ";} cout << "}";
}

static const int INF = 1e9 * 2,N = 1e5 * 2 + 9;

int n;
vector <int> bear (N);

bool compare(int a,int b)
{
    return bear[a] > bear[b];
}

namespace DSU
{
    vector <int> parent (N);
    vector <int> sz(N,1);
    void init(){
        forn(i,n) parent[i] = i;
    }
    int find_set(int v){
        if(v == parent[v]){return v;}
        return parent[v] = find_set(parent[v]);
    }
    int find_size(int v){
        if(v == parent[v]){return sz[v];}
        return sz[v] = sz[find_set(v)];
    }
    void union_sets(int a,int b)
    {
        a = find_set(a);
        b = find_set(b);
        if(a == b){return;}
        if(sz[a] < sz[b]){swap(a,b);}
        parent[b] = a;
        sz[a] += sz[b];
    }
}
int main()
{
    //freopen("input.txt","r",stdin);
    cin >> n;
    vector <int> pos (n);
    forn(i,n){
        cin >> bear[i];
        pos[i] = i;
    }
    sort(pos.begin(),pos.end(),&compare);
    DSU::init();
    vector <bool> have(n,false);
    vector <int> ans(n + 1,-INF);
    int sz_now;
    for(auto current:pos){
        if(current > 0 && have[current - 1])
            DSU::union_sets(current,current - 1);

        if(current < (n-1) && have[current + 1])
            DSU::union_sets(current,current + 1);

        have[current] = true;
        sz_now = DSU::find_size(current);
        ans[sz_now] = max(ans[sz_now] , bear[current]);
    }
    for(int i = n-1;i >= 0;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>
using namespace std;
#define DB(v) cerr << #v << ' ' << v << endl
#define forn(i,n) for(int i = 0;i < n;++i)
#define forup(i,a,b) for(int i = a;i <= b;++i)
void print_all(vector <int> &v){
    cout << "{ ";
    for(auto x:v){cout << x + 1<< ", ";} cout << "}";
}

static const int INF = 1e9 * 2,N = 1e5 * 2 + 9;

int n;
vector <int> bear (N);

bool compare(int a,int b)
{
    return bear[a] > bear[b];
}

namespace DSU
{
    vector <int> parent (N);
    vector <int> sz(N,1);
    void init(){
        forn(i,n)
            parent[i] = i;
    }
    int find_set(int a){
        if(a == parent[a]){return a;}
        return parent[a] = find_set(parent[a]);
    }
    int find_size(int v)
    {
        if(v == parent[v]){return sz[v];}
        return sz[v] = find_size(parent[v]);
    }
    void union_sets(int a,int b)
    {
        a = find_set(a);
        b = find_set(b);
        if(a == b){return;}
        if(sz[a] < sz[b]){swap(a,b);}
        parent[b] = a;
        sz[a] += sz[b];
    }
}

int main()
{
    //freopen("input.txt","r",stdin);
    cin >> n;
    vector <int> pos (n);
    forn(i,n){
        cin >> bear[i];
        pos[i] = i;
    }
    sort(pos.begin(),pos.end(),&compare);
    DSU::init();
    vector <bool> have(n);
    fill(have.begin(),have.end(),false);
    vector <int> ans(n + 1);
    fill(ans.begin(),ans.end(),-INF);
    int sz_now;
    for(auto current:pos){
        if(current > 0 && have[current - 1]){
            DSU::union_sets(current,current - 1);
        }
        if(current < n && have[current + 1]){
            DSU::union_sets(current,current + 1);
        }
        have[current] = true;
        sz_now = DSU::find_size(current);
        ans[sz_now] = max(ans[sz_now] , bear[current]);
    }
    for(int i = n-1;i >= 0;i--)
        ans[i] = max(ans[i],ans[i+1]);
    for(auto to:ans)
        cout << to << ' ';
    return 0;
}


#include <cstdint>
#include <cstdio>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cassert>
#include <stack>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long Long;
typedef pair<int,int> PII;

#define MAXN 200010
#define MINV -2000000000
int V[MAXN], A[MAXN], ANS[MAXN], N;
int L[MAXN], R[MAXN], S[MAXN];
int sS;
void ansv(int A[MAXN]){
	fill(A,A+N, -1);
	sS = 0;
	for (int i = 0; i < N; ++i) {
		while(sS && V[S[sS-1]] >= V[i]){
			sS--;
		}
		A[i] = sS == 0 ? -1 : S[sS-1];
		S[sS] = i;
		sS++;
	}
}
int main()
{
	scanf("%d", &N);
	fill(ANS,ANS+N,MINV);
	for (int i = 0; i < N; ++i) {
		scanf("%d", &V[i]);
	}
	ansv(L);
	reverse(V,V+N);
	ansv(R);
	reverse(R,R+N);
	reverse(V,V+N);
	for(int i = 0; i < N; ++i){
		if(R[i] == -1)R[i] = N;
		else          R[i] = N-1-R[i];
	}
	for(int i = 0; i < N; ++i){
		int k = R[i] - L[i] - 1;
		ANS[ k ] = max(ANS[k], V[i]);
	}
	for (int i = N-1; i >= 1; --i) {
		if(ANS[i] == MINV)ANS[i] = ANS[i+1];
		ANS[i] = max(ANS[i+1],ANS[i]);
	}
	for (int i = 1; i <= N; ++i) {
		printf("%d ", ANS[i]);
	}
	puts("");

	return 0;
}
/*
4
4 2
1 1
1 1
2 1 2
1 2
4 6
2 1 2
2 1 3
2 2 4
4 3 4 5 6
3 2
1 1
2 1 2
2 1 2
2 2
1 2
1 2

 */


#include <cstdint>
#include <cstdio>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cassert>
#include <stack>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long Long;
typedef pair<int,int> PII;

VI ansv(VI V){
	int N = V.size();
	stack<PII> STK;
	VI A(N, -1);
	for (int i = 0; i < N; ++i) {
		while(STK.size() && STK.top().first >= V[i]){
			STK.pop();
		}
		A[i] = STK.size() == 0 ? -1 : STK.top().second;
		STK.push(PII(V[i],i));
	}
	return A;
}
#define MINV -2000000000
void update(VI &ANS, VI &V){
	int N = V.size();
	VI A = ansv(V);
	for (int i = 0; i < N; ++i) {
		int p = A[i];
		ANS[i-p] = max(ANS[i-p], V[i]);
	}

}
int main()
{
	int N;
	scanf("%d", &N);
	VI V(N);
	for (int i = 0; i < N; ++i) {
		scanf("%d", &V[i]);
	}
	VI ANS(N+1,MINV);
	VI L = ansv(V);
	reverse(V.begin(),V.end());
	VI R = ansv(V);
	reverse(R.begin(),R.end());
	reverse(V.begin(),V.end());
	for(int i = 0; i < N; ++i){
		if(R[i] == -1)R[i] = N;
		else          R[i] = N-1-R[i];
	}
	for(int i = 0; i < N; ++i){
		int k = R[i] - L[i] - 1;
		ANS[ k ] = max(ANS[k], V[i]);
	}
	for (int i = N-1; i >= 1; --i) {
		if(ANS[i] == MINV)ANS[i] = ANS[i+1];
		ANS[i] = max(ANS[i+1],ANS[i]);
	}
	for (int i = 1; i <= N; ++i) {
		printf("%d ", ANS[i]);
	}
	puts("");

	return 0;
}
/*
4
4 2
1 1
1 1
2 1 2
1 2
4 6
2 1 2
2 1 3
2 2 4
4 3 4 5 6
3 2
1 1
2 1 2
2 1 2
2 2
1 2
1 2

 */


#include <cstdint>
#include <cstdio>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cassert>
#include <stack>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long Long;
typedef pair<int,int> PII;

VI ansv(VI V){
	int N = V.size();
	stack<PII> STK;
	VI A(N, -1);
	for (int i = 0; i < N; ++i) {
		while(STK.size() && STK.top().first >= V[i]){
			STK.pop();
		}
		A[i] = STK.size() == 0 ? -1 : STK.top().second;
		STK.push(PII(V[i],i));
	}
	return A;
}
#define MINV -2000000000
void update(VI &ANS, VI &V){
	int N = V.size();
	VI A = ansv(V);
	for (int i = 0; i < N; ++i) {
		int p = A[i];
		ANS[i-p] = max(ANS[i-p], V[i]);
	}

}
int main()
{
	int N;
	cin >> N;
	VI V(N);
	for (int i = 0; i < N; ++i) {
		cin >> V[i];
	}
	VI ANS(N+1,MINV);
	VI L = ansv(V);
	reverse(V.begin(),V.end());
	VI R = ansv(V);
	reverse(R.begin(),R.end());
	reverse(V.begin(),V.end());
	for(int i = 0; i < N; ++i){
		if(R[i] == -1)R[i] = N;
		else          R[i] = N-1-R[i];
	}
	for(int i = 0; i < N; ++i){
		int k = R[i] - L[i] - 1;
		ANS[ k ] = max(ANS[k], V[i]);
	}
	for (int i = N-1; i >= 1; --i) {
		if(ANS[i] == MINV)ANS[i] = ANS[i+1];
		ANS[i] = max(ANS[i+1],ANS[i]);
	}
	for (int i = 1; i <= N; ++i) {
		cout << ANS[i] << " ";
	}
	cout << endl;

	return 0;
}
/*
4
4 2
1 1
1 1
2 1 2
1 2
4 6
2 1 2
2 1 3
2 2 4
4 3 4 5 6
3 2
1 1
2 1 2
2 1 2
2 2
1 2
1 2

 */


#include <cstdint>
#include <cstdio>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cassert>
#include <stack>
using namespace std;

int n,L[200010],R[200010],anw[200010];
pair <int,int> dq [200010];

void create ()
{
	stack <pair<int,int> > ns;
	ns.push(make_pair(-1,-1));
	for (int i = 0; i < n; i++)
	{
		while (ns.top().first >= dq[i].first) ns.pop();
		L[i] = ns.top().second+1;
		ns.push(make_pair(dq[i].first,i));
	}
	while (!ns.empty()) ns.pop();
	ns.push(make_pair(-1,n));
	for (int i = n-1; i >= 0; i--)
	{
		while (ns.top().first >= dq[i].first) ns.pop();
		R[i] = ns.top().second-1;
		ns.push(make_pair(dq[i].first,i));
	}
}

int main()
{
    scanf("%d",&n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d",&dq[i].first);
        dq[i].second = i;
    }
    create();
    const int MINV = -2000000000;
    fill(anw,anw+n, MINV);
    for (int i = 0; i < n; i++){
    	int k = R[dq[i].second]-L[dq[i].second]+1;
    	anw[k] = max(anw[k], dq[i].first);
    }
    for(int i = n-1; i >= 1; --i){
    	if(anw[i] == MINV)
    		anw[i] = anw[i+1];
    	else
    		anw[i] = max(anw[i],anw[i+1]);
    }
    for (int i = 1; i <= n; i++)
    {
    	if (i != 0) printf(" ");
    	printf("%d",anw[i]);
    }
    printf("\n");
}


#include <cstdint>
#include <cstdio>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cassert>
#include <stack>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long Long;
typedef pair<int,int> PII;
#define MAXN 200010
#define MINV -2000000000
int V[MAXN], A[MAXN], ANS[MAXN], N;
int L[MAXN], R[MAXN];
void ansv(int A[MAXN]){
	stack<PII> STK;
	fill(A,A+N, -1);
	for (int i = 0; i < N; ++i) {
		while(STK.size() && STK.top().first >= V[i]){
			STK.pop();
		}
		A[i] = STK.size() == 0 ? -1 : STK.top().second;
		STK.push(PII(V[i],i));
	}
}
int main()
{
	scanf("%d", &N);
	fill(ANS,ANS+N,MINV);
	for (int i = 0; i < N; ++i) {
		scanf("%d", &V[i]);
	}
	ansv(L);
	reverse(V,V+N);
	ansv(R);
	reverse(R,R+N);
	reverse(V,V+N);
	for(int i = 0; i < N; ++i){
		if(R[i] == -1)R[i] = N;
		else          R[i] = N-1-R[i];
	}
	for(int i = 0; i < N; ++i){
		int k = R[i] - L[i] - 1;
		ANS[ k ] = max(ANS[k], V[i]);
	}
	for (int i = N-1; i >= 1; --i) {
		if(ANS[i] == MINV)ANS[i] = ANS[i+1];
		ANS[i] = max(ANS[i+1],ANS[i]);
	}
	for (int i = 1; i <= N; ++i) {
		printf("%d ", ANS[i]);
	}
	puts("");

	return 0;
}
/*
4
4 2
1 1
1 1
2 1 2
1 2
4 6
2 1 2
2 1 3
2 2 4
4 3 4 5 6
3 2
1 1
2 1 2
2 1 2
2 2
1 2
1 2

 */


#include <cstdint>
#include <cstdio>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cassert>
#include <stack>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long Long;
typedef pair<int,int> PII;

int V[100010], A[100010], ANS[100010], N;
int L[100010], R[100010];
void ansv(int A[100010]){
	stack<PII> STK;
	fill(A,A+N, -1);
	for (int i = 0; i < N; ++i) {
		while(STK.size() && STK.top().first >= V[i]){
			STK.pop();
		}
		A[i] = STK.size() == 0 ? -1 : STK.top().second;
		STK.push(PII(V[i],i));
	}
}
#define MINV -2000000000
int main()
{
	scanf("%d", &N);
	fill(ANS,ANS+N,MINV);
	for (int i = 0; i < N; ++i) {
		scanf("%d", &V[i]);
	}
	ansv(L);
	reverse(V,V+N);
	ansv(R);
	reverse(R,R+N);
	reverse(V,V+N);
	for(int i = 0; i < N; ++i){
		if(R[i] == -1)R[i] = N;
		else          R[i] = N-1-R[i];
	}
	for(int i = 0; i < N; ++i){
		int k = R[i] - L[i] - 1;
		ANS[ k ] = max(ANS[k], V[i]);
	}
	for (int i = N-1; i >= 1; --i) {
		if(ANS[i] == MINV)ANS[i] = ANS[i+1];
		ANS[i] = max(ANS[i+1],ANS[i]);
	}
	for (int i = 1; i <= N; ++i) {
		printf("%d ", ANS[i]);
	}
	puts("");

	return 0;
}
/*
4
4 2
1 1
1 1
2 1 2
1 2
4 6
2 1 2
2 1 3
2 2 4
4 3 4 5 6
3 2
1 1
2 1 2
2 1 2
2 2
1 2
1 2

 */


#include <cstdint>
#include <cstdio>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stack>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long Long;
typedef pair<int,int> PII;

VI ansv(VI V){
	int N = V.size();
	stack<PII> STK;
	VI A(N, -1);
	for (int i = 0; i < N; ++i) {
		while(STK.size() && STK.top().first > V[i]){
			STK.pop();
		}
		V[i] = STK.size() == 0 ? -1 : STK.top().second;
		STK.push(PII(V[i],i));
	}
	return V;
}
#define MINV -2000000000
void update(VI &ANS, VI &V){
	int N = V.size();
	VI A = ansv(V);
	for (int i = 0; i < N; ++i) {
		int p = A[i];
		ANS[i-p] = max(ANS[i-p], V[i]);
	}

}
int main()
{
	int N;
	cin >> N;
	VI V(N);
	for (int i = 0; i < N; ++i) {
		cin >> V[i];
	}
	VI ANS(N+1,MINV);
	update(ANS,V);
	reverse(V.begin(),V.end());
	update(ANS,V);
	for (int i = 1; i <= N; ++i) {
		if(ANS[i] == MINV)
			ANS[i] = ANS[i-1];
		else if(i > 1)
			ANS[i] = min(ANS[i-1],ANS[i]);
		cout << ANS[i] << " ";
	}
	cout << endl;

	return 0;
}
/*
4
4 2
1 1
1 1
2 1 2
1 2
4 6
2 1 2
2 1 3
2 2 4
4 3 4 5 6
3 2
1 1
2 1 2
2 1 2
2 2
1 2
1 2

 */


#include <cstdint>
#include <cstdio>
#include <cmath>
#include <vector>
#include <iostream>
#include <stack>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long Long;
typedef pair<int,int> PII;

VI ansv(VI V){
	int N = V.size();
	stack<PII> STK;
	VI A(N, -1);
	for (int i = 0; i < N; ++i) {
		while(STK.size() && STK.top().first > V[i]){
			STK.pop();
		}
		V[i] = STK.size() == 0 ? -1 : STK.top().second;
		STK.push(PII(V[i],i));
	}
	return V;
}
#define MINV -2000000000
void update(VI &ANS, VI &V){
	int N = V.size();
	VI A = ansv(V);
	for (int i = 0; i < N; ++i) {
		int p = A[i];
		ANS[i-p] = max(ANS[i-p], V[i]);
	}

}
int main()
{
	int N;
	cin >> N;
	VI V(N);
	for (int i = 0; i < N; ++i) {
		cin >> V[i];
	}
	VI ANS(N+1,MINV);
	update(ANS,V);
	reverse(V.begin(),V.end());
	update(ANS,V);
	for (int i = 1; i <= N; ++i) {
		if(ANS[i] == MINV)
			ANS[i] = ANS[i-1];
		else if(i > 1)
			ANS[i] = min(ANS[i-1],ANS[i]);
		cout << ANS[i] << " ";
	}
	cout << endl;

	return 0;
}
/*
4
4 2
1 1
1 1
2 1 2
1 2
4 6
2 1 2
2 1 3
2 2 4
4 3 4 5 6
3 2
1 1
2 1 2
2 1 2
2 2
1 2
1 2

 */


#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn = 200005;

int n, a[maxn];
int l[maxn], r[maxn];
int ans[maxn];
int stack[maxn], top = 0;
// l[i], the leftest point that the point i could update

void input()
{
    scanf("%d", &n);
    for (register int i = 1; i <= n; i++) {
        scanf("%d\n", &a[i]);
    }
}

void init()
{
    int len;
    for (register int i = 1; i <= n; i++) {
        if (top == 0 || a[i] > a[stack[top]]) {
            stack[++top] = i;
            l[i] = i;
        } else {
            while (top && a[i] <= a[stack[top]]) {
                top --;
            }
            if (top == 0) l[i] = 1;
            else l[i] = stack[top + 1];
            stack[++top] = i;
        }
    }
    top = 0;
    for (register int i = n; i >= 1; i--) {
        if (top == 0 || a[i] > a[stack[top]]) {
            stack[++top] = i;
            r[i] = i;
        } else {
            while (top && a[i] <= a[stack[top]]) {
                top --;
            }
            if (top == 0) r[i] = n;
            else r[i] = stack[top + 1];
            stack[++top] = i;
        }
    }
    for (register int i = 1; i <= n; i++) {
        len = r[i] - l[i] + 1;
        ans[len] = max(ans[len], a[i]);
    }
    for (register int i = n; i >= 1; i--) {
        ans[i] = max(ans[i], ans[i + 1]);
    }
    for (register int i = 1; i <= n; i++) {
        printf("%d ", ans[i]);
    }
    printf("\n");

}

void solve()
{

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    input();
    init();
    solve();

    #ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout);
    #endif
    return 0;
}


#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn = 200005;

int n, a[maxn];
int l[maxn], r[maxn];
int ans[maxn];
int stack[maxn], top = 0;
// l[i], the leftest point that the point i could update

void input()
{
	scanf("%d", &n);
	for (register int i = 1; i <= n; i++) {
		scanf("%d\n", &a[i]);
	}
}

void init()
{
	int len;
	for (register int i = 1; i <= n; i++) {
		if (top == 0 || a[i] > a[stack[top]]) {
			stack[++top] = i;
			l[i] = i;
		} else {
			while (top && a[i] < a[stack[top]]) {
				top --;
			}
			l[i] = stack[top + 1];
		}
	}
	top = 0;
	for (register int i = n; i >= 1; i--) {
		if (top == 0 || a[i] > a[stack[top]]) {
			stack[++top] = i;
			r[i] = i;
		} else {
			while (top && a[i] < a[stack[top]]) {
				top --;
			}
			r[i] = stack[top + 1];
		}
	}
	for (register int i = 1; i <= n; i++) {
		len = r[i] - l[i] + 1;
		ans[len] = max(ans[len], a[i]);
	}
	for (register int i = 1; i <= n; i++) {
		if (ans[i] == 0) {
			ans[i] = ans[i - 1];
		}
		printf("%d ", ans[i]);
	}
	printf("\n");

}

void solve()
{

}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	input();
	init();
	solve();

	#ifndef ONLINE_JUDGE
	fclose(stdin);
	fclose(stdout);
	#endif
	return 0;
}


#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn = 200005;

int n, a[maxn];
int l[maxn], r[maxn];
int ans[maxn];
int stack[maxn], top = 0;
// l[i], the leftest point that the point i could update

void input()
{
    scanf("%d", &n);
    for (register int i = 1; i <= n; i++) {
        scanf("%d\n", &a[i]);
    }
}

void init()
{
    int len;
    top = 0;
    for (register int i = 1; i <= n; i++) {
        if (top == 0 || a[i] > a[stack[top]]) {
            stack[++top] = i;
            l[i] = i - 1;
        } else {
            while (top && a[i] <= a[stack[top]]) {
                top --;
            }
            if (top) l[i] = stack[top];
            else l[i] = 0;
            stack[++top] = i;
        }
    }
    top = 0;
    for (register int i = n; i >= 1; i--) {
        if (top == 0 || a[i] > a[stack[top]]) {
            stack[++top] = i;
            r[i] = i + 1;
        } else {
            while (top && a[i] <= a[stack[top]]) {
                top --;
            }
            if (top) r[i] = stack[top];
            else r[i] = n + 1;
            stack[++top] = i;
        }
    }
    for (register int i = 1; i <= n; i++) {
        len = r[i] - l[i] - 1;
        ans[len] = max(ans[len], a[i]);
    }
    for (register int i = n; i >= 1; i--) {
        if (!ans[i]) ans[i] = max(ans[i], ans[i + 1]);
    }
    for (register int i = 1; i <= n; i++) {
        printf("%d ", ans[i]);
    }
    printf("\n");

}

void solve()
{

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    input();
    init();
    solve();

    #ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout);
    #endif
    return 0;
}


#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn = 200005;

int n, a[maxn];
int l[maxn], r[maxn];
int ans[maxn];
int stack[maxn], top = 0;
// l[i], the leftest point that the point i could update

void input()
{
    scanf("%d", &n);
    for (register int i = 1; i <= n; i++) {
        scanf("%d\n", &a[i]);
    }
}

void init()
{
    int len;
    top = 0;
    for (register int i = 1; i <= n; i++) {
        if (top == 0 || a[i] > a[stack[top]]) {
            stack[++top] = i;
            l[i] = i - 1;
        } else {
            while (top && a[i] <= a[stack[top]]) {
                top --;
            }
            if (top) l[i] = stack[top];
            else l[i] = 0;
            stack[++top] = i;
        }
    }
    top = 0;
    for (register int i = n; i >= 1; i--) {
        if (top == 0 || a[i] > a[stack[top]]) {
            stack[++top] = i;
            r[i] = i + 1;
        } else {
            while (top && a[i] <= a[stack[top]]) {
                top --;
            }
            if (top) r[i] = stack[top];
            else r[i] = n + 1;
            stack[++top] = i;
        }
    }
    for (register int i = 1; i <= n; i++) {
        len = r[i] - l[i] - 1;
        ans[len] = max(ans[len], a[i]);
    }
    for (register int i = n; i >= 1; i--) {
        ans[i] = max(ans[i], ans[i + 1]);
    }
    for (register int i = 1; i <= n; i++) {
        printf("%d ", ans[i]);
    }
    printf("\n");

}

void solve()
{

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    input();
    init();
    solve();

    #ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout);
    #endif
    return 0;
}


/* ***********************************************
Author        :xdlove
Created Time  :2015年06月03日 星期三 16时10分06秒
File Name     :A.cpp
************************************************ */

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#define lson l,mid,u<<1
#define rson mid+1,r,u<<1|1
#define ls u<<1
#define rs u<<1|1
#define mid ((l + r)>>1)
using namespace std;
typedef long long ll;
const int MAX_V = 2e5 + 5;
int a[MAX_V];
int pre[MAX_V],last[MAX_V];

struct ST
{
    int x,id;
};

struct Line
{
    int x,c;
    bool operator < (const Line &a) const
    {
        return c < a.c;
    }
}p[MAX_V * 3];

stack<ST>st;

int main()
{
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    for(int i = 1; i <= n; i++)
        scanf("%d",&a[i]);
    for(int i = 1; i <= n; i++)
    {
        if(st.size() == 0)
            st.push((ST){a[i],i});
        else
        {
            ST tp = st.top();
            if(a[i] >= tp.x) st.push((ST){a[i],i});
            else
            {
                //cout<<a[i]<<": "<<i<<endl;
                while(st.size() && tp.x >  a[i])
                {
                    pre[tp.id] = i - tp.id;
                    if(st.size()) st.pop();
                    tp = st.top();
                }
                st.push((ST){a[i],i});
            }
        }
    }
    while(st.size())
    {
        ST tp = st.top();
        pre[tp.id] = n - tp.id + 1;
        st.pop();
    }
    //for(int i = 1; i <= n; i++)
    //  printf("%d ",pre[i]);

    for(int i = n; i >= 1; i--)
    {
        if(st.size() == 0)
            st.push((ST){a[i],i});
        else
        {
            ST tp = st.top();
            if(a[i] >= tp.x) st.push((ST){a[i],i});
            else
            {
                //cout<<a[i]<<": "<<i<<endl;
                while(st.size() && tp.x >  a[i])
                {
                    last[tp.id] = tp.id - i;
                    st.pop();
                    if(st.size()) tp = st.top();
                }
                st.push((ST){a[i],i});
            }
        }
    }
    while(st.size())
    {
        ST tp = st.top();
        last[tp.id] = tp.id;
        st.pop();
    }
    //for(int i = 1; i <= n; i++)
        //printf("%d ",last[i]);
    int tot = 0;
    for(int i = 1; i <= n; i++)
    {
        p[tot].x = pre[i] + last[i] - 1;
        p[tot++].c = a[i];
    }
    sort(p,p + tot);
    memset(a,0,sizeof(a));
    int R = 0;
    for(int i = 0; i < tot; i++)
    {
        if(R < p[i].x)
            for(int j = R; j <= p[i].x && j <= n; j++)
                a[j] = p[i].c;
    }
    for(int i = 1; i <= n; i++)
        printf("%d ",a[i]);
    puts("");
    return 0;
}


/* ***********************************************
Author        :xdlove
Created Time  :2015年06月03日 星期三 16时10分06秒
File Name     :A.cpp
************************************************ */

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#define lson l,mid,u<<1
#define rson mid+1,r,u<<1|1
#define ls u<<1
#define rs u<<1|1
#define mid ((l + r)>>1)
using namespace std;
typedef long long ll;
const int MAX_V = 2e5 + 5;
int a[MAX_V];
int pre[MAX_V],last[MAX_V];

struct ST
{
    int x,id;
};

struct Line
{
    int x,c;
    bool operator < (const Line &a) const
    {
        return c < a.c;
    }
}p[MAX_V * 3];

stack<ST>st;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    for(int i = 1; i <= n; i++)
        scanf("%d",&a[i]);
    for(int i = 1; i <= n; i++)
    {
        if(st.size() == 0)
            st.push((ST){a[i],i});
        else
        {
            ST tp = st.top();
            if(a[i] >= tp.x) st.push((ST){a[i],i});
            else
            {
                //cout<<a[i]<<": "<<i<<endl;
                while(st.size() && tp.x >  a[i])
                {
                    pre[tp.id] = i - tp.id;
                    st.pop();
                    if(st.size()) tp = st.top();
                }
                st.push((ST){a[i],i});
            }
        }
    }
    while(st.size())
    {
        ST tp = st.top();
        pre[tp.id] = n - tp.id + 1;
        st.pop();
    }
    //for(int i = 1; i <= n; i++)
    //  printf("%d ",pre[i]);

    for(int i = n; i >= 1; i--)
    {
        if(st.size() == 0)
            st.push((ST){a[i],i});
        else
        {
            ST tp = st.top();
            if(a[i] >= tp.x) st.push((ST){a[i],i});
            else
            {
                //cout<<a[i]<<": "<<i<<endl;
                while(st.size() && tp.x >  a[i])
                {
                    last[tp.id] = tp.id - i;
                    st.pop();
                    if(st.size()) tp = st.top();
                }
                st.push((ST){a[i],i});
            }
        }
    }
    while(st.size())
    {
        ST tp = st.top();
        last[tp.id] = tp.id;
        st.pop();
    }
    //for(int i = 1; i <= n; i++)
        //printf("%d ",last[i]);
//  cout<<"haha"<<endl;
    int tot = 0;
    for(int i = 1; i <= n; i++)
    {
        p[tot].x = pre[i] + last[i] - 1;
        p[tot++].c = a[i];
    }
    sort(p,p + tot);
    memset(a,0,sizeof(a));
    int R = 0;
    for(int i = 0; i < tot; i++)
    {
        if(R < p[i].x)
        {
            for(int j = R; j <= p[i].x && j <= n; j++)
                a[j] = p[i].c;
            R = p[i].x;
        }
    }
    for(int i = 1; i <= n; i++)
        printf("%d ",a[i]);
    puts("");
    return 0;
}


/* ***********************************************
Author        :xdlove
Created Time  :2015年06月03日 星期三 16时10分06秒
File Name     :A.cpp
************************************************ */

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#define lson l,mid,u<<1
#define rson mid+1,r,u<<1|1
#define ls u<<1
#define rs u<<1|1
#define mid ((l + r)>>1)
using namespace std;
typedef long long ll;
const int MAX_V = 2e5 + 5;
int a[MAX_V];
int pre[MAX_V],last[MAX_V];

struct ST
{
    int x,id;
};

struct Line
{
    int x,c;
    bool operator < (const Line &a) const
    {
        return c < a.c;
    }
}p[MAX_V * 3];

stack<ST>st;

int main()
{
   // freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    for(int i = 1; i <= n; i++)
        scanf("%d",&a[i]);
    for(int i = 1; i <= n; i++)
    {
        if(st.size() == 0)
            st.push((ST){a[i],i});
        else
        {
            ST tp = st.top();
            if(a[i] >= tp.x) st.push((ST){a[i],i});
            else
            {
                //cout<<a[i]<<": "<<i<<endl;
                while(st.size() && tp.x >  a[i])
                {
                    pre[tp.id] = i - tp.id;
                    if(st.size()) st.pop();
                    tp = st.top();
                }
                st.push((ST){a[i],i});
            }
        }
    }
    while(st.size())
    {
        ST tp = st.top();
        pre[tp.id] = n - tp.id + 1;
        st.pop();
    }
    //for(int i = 1; i <= n; i++)
    //  printf("%d ",pre[i]);

    for(int i = n; i >= 1; i--)
    {
        if(st.size() == 0)
            st.push((ST){a[i],i});
        else
        {
            ST tp = st.top();
            if(a[i] >= tp.x) st.push((ST){a[i],i});
            else
            {
                //cout<<a[i]<<": "<<i<<endl;
                while(st.size() && tp.x >  a[i])
                {
                    last[tp.id] = tp.id - i;
                    st.pop();
                    if(st.size()) tp = st.top();
                }
                st.push((ST){a[i],i});
            }
        }
    }
    while(st.size())
    {
        ST tp = st.top();
        last[tp.id] = tp.id;
        st.pop();
    }
    //for(int i = 1; i <= n; i++)
        //printf("%d ",last[i]);
    int tot = 0;
    for(int i = 1; i <= n; i++)
    {
        p[tot].x = pre[i] + last[i] - 1;
        p[tot++].c = a[i];
    }
    sort(p,p + tot);
    memset(a,0,sizeof(a));
    int R = 0;
    for(int i = 0; i < tot; i++)
    {
        if(R < p[i].x)
            for(int j = R; j <= p[i].x && j <= n; j++)
                a[j] = p[i].c;
    }
    for(int i = 1; i <= n; i++)
        printf("%d ",a[i]);
    puts("");
    return 0;
}


/* ***********************************************
Author        :xdlove
Created Time  :2015年06月03日 星期三 16时10分06秒
File Name     :A.cpp
************************************************ */

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#define lson l,mid,u<<1
#define rson mid+1,r,u<<1|1
#define ls u<<1
#define rs u<<1|1
#define mid ((l + r)>>1)
using namespace std;
typedef long long ll;
const int MAX_V = 2e5 + 5;
int a[MAX_V];
int pre[MAX_V],last[MAX_V];

struct ST
{
    int x,id;
};

struct Line
{
    int x,c;
    bool operator < (const Line &a) const
    {
        return c > a.c;
    }
}p[MAX_V * 3];

stack<ST>st;

int main()
{
   // freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    for(int i = 1; i <= n; i++)
        scanf("%d",&a[i]);
    for(int i = 1; i <= n; i++)
    {
        if(st.size() == 0)
            st.push((ST){a[i],i});
        else
        {
            ST tp = st.top();
            if(a[i] >= tp.x) st.push((ST){a[i],i});
            else
            {
                //cout<<a[i]<<": "<<i<<endl;
                while(st.size() && tp.x >  a[i])
                {
                    pre[tp.id] = i - tp.id;
                    st.pop();
                    if(st.size()) tp = st.top();
                }
                st.push((ST){a[i],i});
            }
        }
    }
    while(st.size())
    {
        ST tp = st.top();
        pre[tp.id] = n - tp.id + 1;
        st.pop();
    }
    //for(int i = 1; i <= n; i++)
    //  printf("%d ",pre[i]);

    for(int i = n; i >= 1; i--)
    {
        if(st.size() == 0)
            st.push((ST){a[i],i});
        else
        {
            ST tp = st.top();
            if(a[i] >= tp.x) st.push((ST){a[i],i});
            else
            {
                //cout<<a[i]<<": "<<i<<endl;
                while(st.size() && tp.x >  a[i])
                {
                    last[tp.id] = tp.id - i;
                    st.pop();
                    if(st.size()) tp = st.top();
                }
                st.push((ST){a[i],i});
            }
        }
    }
    while(st.size())
    {
        ST tp = st.top();
        last[tp.id] = tp.id;
        st.pop();
    }
    //for(int i = 1; i <= n; i++)
        //printf("%d ",last[i]);
//  cout<<"haha"<<endl;
    int tot = 0;
    for(int i = 1; i <= n; i++)
    {
        p[tot].x = pre[i] + last[i] - 1;
        p[tot++].c = a[i];
    }
    sort(p,p + tot);
    memset(a,0,sizeof(a));
    int R = 0;
    for(int i = 0; i < tot; i++)
    {
        //cout<<p[i].c<<": "<<p[i].x<<endl;
        if(R < p[i].x)
        {
            for(int j = R + 1; j <= p[i].x && j <= n; j++)
                a[j] = p[i].c;
            R = p[i].x;
        }
    }
    for(int i = 1; i <= n; i++)
        printf("%d ",a[i]);
    puts("");
    return 0;
}


/* ***********************************************
Author        :xdlove
Created Time  :2015年06月03日 星期三 16时10分06秒
File Name     :A.cpp
************************************************ */

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#define lson l,mid,u<<1
#define rson mid+1,r,u<<1|1
#define ls u<<1
#define rs u<<1|1
#define mid ((l + r)>>1)
using namespace std;
typedef long long ll;
const int MAX_V = 2e5 + 5;
int a[MAX_V];
int pre[MAX_V],last[MAX_V];

struct ST
{
    int x,id;
};

struct Line
{
    int x,c;
    bool operator < (const Line &a) const
    {
        return c > a.c;
    }
}p[MAX_V * 3];

stack<ST>st;

int main()
{
   // freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    for(int i = 1; i <= n; i++)
        scanf("%d",&a[i]);
    for(int i = 1; i <= n; i++)
    {
        if(st.size() == 0)
            st.push((ST){a[i],i});
        else
        {
            ST tp = st.top();
            if(a[i] >= tp.x) st.push((ST){a[i],i});
            else
            {
                //cout<<a[i]<<": "<<i<<endl;
                while(st.size() && tp.x >  a[i])
                {
                    pre[tp.id] = i - tp.id;
                    st.pop();
                    if(st.size()) tp = st.top();
                }
                st.push((ST){a[i],i});
            }
        }
    }
    while(st.size())
    {
        ST tp = st.top();
        pre[tp.id] = n - tp.id + 1;
        st.pop();
    }
    //for(int i = 1; i <= n; i++)
    //  printf("%d ",pre[i]);

    for(int i = n; i >= 1; i--)
    {
        if(st.size() == 0)
            st.push((ST){a[i],i});
        else
        {
            ST tp = st.top();
            if(a[i] >= tp.x) st.push((ST){a[i],i});
            else
            {
                //cout<<a[i]<<": "<<i<<endl;
                while(st.size() && tp.x >  a[i])
                {
                    last[tp.id] = tp.id - i;
                    st.pop();
                    if(st.size()) tp = st.top();
                }
                st.push((ST){a[i],i});
            }
        }
    }
    while(st.size())
    {
        ST tp = st.top();
        last[tp.id] = tp.id;
        st.pop();
    }
    //for(int i = 1; i <= n; i++)
        //printf("%d ",last[i]);
//  cout<<"haha"<<endl;
    int tot = 0;
    for(int i = 1; i <= n; i++)
    {
        p[tot].x = pre[i] + last[i] - 1;
        p[tot++].c = a[i];
    }
    sort(p,p + tot);
    memset(a,0,sizeof(a));
    int R = 0;
    for(int i = 0; i < tot; i++)
    {
        if(R < p[i].x)
        {
            for(int j = R; j <= p[i].x && j <= n; j++)
                a[j] = p[i].c;
            R = p[i].x;
        }
    }
    for(int i = 1; i <= n; i++)
        printf("%d ",a[i]);
    puts("");
    return 0;
}


/* ***********************************************
Author        :xdlove
Created Time  :2015年06月03日 星期三 16时10分06秒
File Name     :A.cpp
************************************************ */

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#define lson l,mid,u<<1
#define rson mid+1,r,u<<1|1
#define ls u<<1
#define rs u<<1|1
#define mid ((l + r)>>1)
using namespace std;
typedef long long ll;
const int MAX_V = 2e5 + 5;
int a[MAX_V];
int pre[MAX_V],last[MAX_V];

struct ST
{
    int x,id;
};

struct Line
{
    int x,c;
    bool operator < (const Line &a) const
    {
        return c < a.c;
    }
}p[MAX_V * 3];

stack<ST>st;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    for(int i = 1; i <= n; i++)
        scanf("%d",&a[i]);
    for(int i = 1; i <= n; i++)
    {
        if(st.size() == 0)
            st.push((ST){a[i],i});
        else
        {
            ST tp = st.top();
            if(a[i] >= tp.x) st.push((ST){a[i],i});
            else
            {
                //cout<<a[i]<<": "<<i<<endl;
                while(st.size() && tp.x >  a[i])
                {
                    pre[tp.id] = i - tp.id;
                    if(st.size()) st.pop();
                    tp = st.top();
                }
                st.push((ST){a[i],i});
            }
        }
    }
    while(st.size())
    {
        ST tp = st.top();
        pre[tp.id] = n - tp.id + 1;
        st.pop();
    }
    //for(int i = 1; i <= n; i++)
    //  printf("%d ",pre[i]);

    for(int i = n; i >= 1; i--)
    {
        if(st.size() == 0)
            st.push((ST){a[i],i});
        else
        {
            ST tp = st.top();
            if(a[i] >= tp.x) st.push((ST){a[i],i});
            else
            {
                //cout<<a[i]<<": "<<i<<endl;
                while(st.size() && tp.x >  a[i])
                {
                    last[tp.id] = tp.id - i;
                    st.pop();
                    if(st.size()) tp = st.top();
                }
                st.push((ST){a[i],i});
            }
        }
    }
    while(st.size())
    {
        ST tp = st.top();
        last[tp.id] = tp.id;
        st.pop();
    }
    //for(int i = 1; i <= n; i++)
        //printf("%d ",last[i]);
    int tot = 0;
    for(int i = 1; i <= n; i++)
    {
        p[tot].x = pre[i] + last[i] - 1;
        p[tot++].c = a[i];
    }
    sort(p,p + tot);
    memset(a,0,sizeof(a));
    int R = 0;
    for(int i = 0; i < tot; i++)
    {
        if(R < p[i].x)
            for(int j = R; j <= p[i].x; j++)
                a[j] = p[i].c;
    }
    for(int i = 1; i <= n; i++)
        printf("%d ",a[i]);
    puts("");
    return 0;
}


/* ***********************************************
Author        :xdlove
Created Time  :2015年06月03日 星期三 16时10分06秒
File Name     :A.cpp
************************************************ */

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#define lson l,mid,u<<1
#define rson mid+1,r,u<<1|1
#define ls u<<1
#define rs u<<1|1
#define mid ((l + r)>>1)
using namespace std;
typedef long long ll;
const int MAX_V = 2e5 + 5;
int a[MAX_V];
int pre[MAX_V],last[MAX_V];

struct ST
{
    int x,id;
};

struct Line
{
    int x,c;
    bool operator < (const Line &a) const
    {
        return c < a.c;
    }
}p[MAX_V * 3];

stack<ST>st;

int main()
{
  //  freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    for(int i = 1; i <= n; i++)
        scanf("%d",&a[i]);
    for(int i = 1; i <= n; i++)
    {
        if(st.size() == 0)
            st.push((ST){a[i],i});
        else
        {
            ST tp = st.top();
            if(a[i] >= tp.x) st.push((ST){a[i],i});
            else
            {
                //cout<<a[i]<<": "<<i<<endl;
                while(st.size() && tp.x >  a[i])
                {
                    pre[tp.id] = i - tp.id;
                    st.pop();
                    if(st.size()) tp = st.top();
                }
                st.push((ST){a[i],i});
            }
        }
    }
    while(st.size())
    {
        ST tp = st.top();
        pre[tp.id] = n - tp.id + 1;
        st.pop();
    }
    //for(int i = 1; i <= n; i++)
    //  printf("%d ",pre[i]);

    for(int i = n; i >= 1; i--)
    {
        if(st.size() == 0)
            st.push((ST){a[i],i});
        else
        {
            ST tp = st.top();
            if(a[i] >= tp.x) st.push((ST){a[i],i});
            else
            {
                //cout<<a[i]<<": "<<i<<endl;
                while(st.size() && tp.x >  a[i])
                {
                    last[tp.id] = tp.id - i;
                    st.pop();
                    if(st.size()) tp = st.top();
                }
                st.push((ST){a[i],i});
            }
        }
    }
    while(st.size())
    {
        ST tp = st.top();
        last[tp.id] = tp.id;
        st.pop();
    }
    //for(int i = 1; i <= n; i++)
        //printf("%d ",last[i]);
//  cout<<"haha"<<endl;
    int tot = 0;
    for(int i = 1; i <= n; i++)
    {
        p[tot].x = pre[i] + last[i] - 1;
        p[tot++].c = a[i];
    }
    sort(p,p + tot);
    memset(a,0,sizeof(a));
    int R = 0;
    for(int i = 0; i < tot; i++)
    {
        if(R < p[i].x)
            for(int j = R; j <= p[i].x && j <= n; j++)
                a[j] = p[i].c;
    }
    for(int i = 1; i <= n; i++)
        printf("%d ",a[i]);
    puts("");
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <math.h>
#include <cmath>
#include <set>
#include <map>
#include <cassert>
#include <algorithm>
#include <ctime>
#include <iomanip>
#include <queue>

using namespace std;

#define mp make_pair
#define sz size()
#define all(x) x.begin(),x.end()
#define forn(i,n) for (int i = 0; i<int(n); i++)
#define sqr(x) ((x)*(x))
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const int INF = 1e9 + 7;
const ld EPS = 1e-14;
struct set_compare {
    bool operator() (const pair<ll, int> a, const pair<ll, int> b) const{
        return (a.first>b.first || a.first == b.first && a.second > b.second);
    }
};

const int NUM = 200007;
vector<int> a;
vector<int> lv;
vector<int> rv;
ii tmp[NUM];
void set_lv(){
    int it = -1;
    for (int i = 0; i < a.size(); i++){
        if (it == -1){
            lv[i] = 1;
            tmp[++it] = mp(lv[i], a[i]);
        }
        else{
            int cnt = 0;
            while (it >= 0 && tmp[it].S >= a[i]){
                cnt += tmp[it].F;
                it--;
            }
            lv[i] = cnt + 1;
            tmp[++it] = mp(lv[i], a[i]);
        }
    }
}
void set_rv(){
    int it = -1;
    for (int i = a.size()-1; i >= 0; i--){
        if (it == -1){
            rv[i] = 1;
            tmp[++it] = mp(rv[i], a[i]);
        }
        else{
            int cnt = 0;
            while (it >= 0 && tmp[it].S >= a[i]){
                cnt += tmp[it].F;
                it--;
            }
            rv[i] = cnt + 1;
            tmp[++it] = mp(rv[i], a[i]);
        }
    }
}

//#define DEBUG
int main(){
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n;
    cin >> n;
    a.resize(n);
    lv.resize(n);
    rv.resize(n);
    int min_el = INF;
    for (int i = 0; i < n; i++){
        scanf("%d", &a[i]);
        min_el = min(min_el, a[i]);
    }
    set_lv();
    set_rv();

    vector<int> ans(a.size() + 1);
    vector<int> v(a.size());
    for (int i = 0; i < v.size(); i++)
        v[i] = lv[i] + rv[i] - 1;
    for (int i = 0; i < v.size(); i++){
        ans[v[i]] = max(ans[v[i]], a[i]);
    }

    int cur_max = min_el;
    for (int i = a.size(); i > 0; i--){
        ans[i] = max(ans[i], cur_max);
        cur_max = max(cur_max, ans[i]);
    }
    for (int i = 1; i < ans.size(); i++){
        printf("%d ", ans[i]);
    }

#ifdef DEBUG
    cerr << "Time elapsed: " << (ld)clock() / CLOCKS_PER_SEC << " sec." << endl;
#endif
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <math.h>
#include <cmath>
#include <set>
#include <map>
#include <cassert>
#include <algorithm>
#include <ctime>
#include <iomanip>
#include <queue>

using namespace std;

#define mp make_pair
#define sz size()
#define all(x) x.begin(),x.end()
#define forn(i,n) for (int i = 0; i<int(n); i++)
#define sqr(x) ((x)*(x))
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const int INF = 1e9 + 7;
const ld EPS = 1e-14;
struct set_compare {
    bool operator() (const pair<ll, int> a, const pair<ll, int> b) const{
        return (a.first>b.first || a.first == b.first && a.second > b.second);
    }
};

const int NUM = 100007;
vector<int> a;
vector<int> lv;
vector<int> rv;
ii tmp[NUM];
void set_lv(){
    int it = -1;
    for (int i = 0; i < a.size(); i++){
        if (it == -1){
            lv[i] = 1;
            tmp[++it] = mp(lv[i], a[i]);
        }
        else{
            int cnt = 0;
            while (it >= 0 && tmp[it].S >= a[i]){
                cnt += tmp[it].F;
                it--;
            }
            lv[i] = cnt + 1;
            tmp[++it] = mp(lv[i], a[i]);
        }
    }
}
void set_rv(){
    int it = -1;
    for (int i = a.size()-1; i >= 0; i--){
        if (it == -1){
            rv[i] = 1;
            tmp[++it] = mp(rv[i], a[i]);
        }
        else{
            int cnt = 0;
            while (it >= 0 && tmp[it].S >= a[i]){
                cnt += tmp[it].F;
                it--;
            }
            rv[i] = cnt + 1;
            tmp[++it] = mp(rv[i], a[i]);
        }
    }
}

//#define DEBUG
int main(){
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n;
    cin >> n;
    a.resize(n);
    lv.resize(n);
    rv.resize(n);
    int min_el = INF;
    for (int i = 0; i < n; i++){
        scanf("%d", &a[i]);
        min_el = min(min_el, a[i]);
    }
    set_lv();
    set_rv();

    vector<int> ans(a.size() + 1);
    vector<int> v(a.size());
    for (int i = 0; i < v.size(); i++)
        v[i] = lv[i] + rv[i] - 1;
    for (int i = 0; i < v.size(); i++){
        ans[v[i]] = max(ans[v[i]], a[i]);
    }

    int cur_max = min_el;
    for (int i = a.size(); i > 0; i--){
        ans[i] = max(ans[i], cur_max);
        cur_max = max(cur_max, ans[i]);
    }
    for (int i = 1; i < ans.size(); i++){
        printf("%d ", ans[i]);
    }

#ifdef DEBUG
    cerr << "Time elapsed: " << (ld)clock() / CLOCKS_PER_SEC << " sec." << endl;
#endif
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <math.h>
#include <cmath>
#include <set>
#include <map>
#include <cassert>
#include <algorithm>
#include <ctime>
#include <iomanip>
#include <queue>

using namespace std;

#define mp make_pair
#define sz size()
#define all(x) x.begin(),x.end()
#define forn(i,n) for (int i = 0; i<int(n); i++)
#define sqr(x) ((x)*(x))
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const int INF = 1e9 + 7;
const ld EPS = 1e-14;
struct set_compare {
    bool operator() (const pair<ll, int> a, const pair<ll, int> b) const{
        return (a.first>b.first || a.first == b.first && a.second > b.second);
    }
};

const int NUM = 100007;
vector<int> a;
vector<int> lv;
vector<int> rv;
ii tmp[NUM];
void set_lv(){
    int it = -1;
    for (int i = 0; i < a.size(); i++){
        if (it == -1){
            lv[i] = 1;
            tmp[++it] = mp(lv[i], a[i]);
        }
        else{
            int cnt = 0;
            while (it >= 0 && tmp[it].S >= a[i]){
                cnt += tmp[it].F;
                it--;
            }
            lv[i] = cnt + 1;
            tmp[++it] = mp(lv[i], a[i]);
        }
    }
}
void set_rv(){
    int it = -1;
    for (int i = a.size()-1; i >= 0; i--){
        if (it == -1){
            rv[i] = 1;
            tmp[++it] = mp(rv[i], a[i]);
        }
        else{
            int cnt = 0;
            while (it >= 0 && tmp[it].S >= a[i]){
                cnt += tmp[it].F;
                it--;
            }
            rv[i] = cnt + 1;
            tmp[++it] = mp(rv[i], a[i]);
        }
    }
}

//#define DEBUG
int main(){
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n;
    cin >> n;
    a.resize(n);
    lv.resize(n);
    rv.resize(n);
    int min_el;
    for (int i = 0; i < n; i++){
        scanf("%d", &a[i]);
        min_el = min(min_el, a[i]);
    }
    set_lv();
    set_rv();

    vector<int> ans(a.size() + 1);
    vector<int> v(a.size());
    for (int i = 0; i < v.size(); i++)
        v[i] = max(lv[i], rv[i]);
    for (int i = 0; i < v.size(); i++){
        ans[v[i]] = max(ans[v[i]], a[i]);
    }

    int cur_max = min_el;
    for (int i = a.size(); i > 0; i--){
        ans[i] = max(ans[i], cur_max);
        cur_max = max(cur_max, ans[i]);
    }
    for (int i = 1; i < ans.size(); i++){
        printf("%d ", ans[i]);
    }

#ifdef DEBUG
    cerr << "Time elapsed: " << (ld)clock() / CLOCKS_PER_SEC << " sec." << endl;
#endif
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int arr[204800], len[204800], ans[204800];
int l[204800], r[204800];
pair<int, int> w[204800];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("D.in", "r", stdin);
#endif
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
    }
    stack<int> st;
    for (int i = 1; i <= n; i++)
    {
        while (!st.empty() && arr[st.top()] >= arr[i])
            st.pop();
        if (st.empty())
            l[i] = 0;
        else
            l[i] = st.top();
        st.push(i);
    }
    while (!st.empty())
        st.pop();
    for (int i = n; i >= 1; i--)
    {
        while (!st.empty() && arr[st.top()] >= arr[i])
            st.pop();
        if (st.empty())
            r[i] = n + 1;
        else
            r[i] = st.top();
        st.push(i);
    }
    for (int i = 1; i <= n; i++)
    {
        w[i].first = -arr[i];
        w[i].second = r[i] - l[i] - 1;
#ifndef ONLINE_JUDGE
        cout << l[i] << " " << r[i] << endl;
#endif
    }
    sort(w + 1, w + n + 1);
    for (int i = 1; i <= n; i++)
    {
        arr[i] = -w[i].first;
        len[i] = w[i].second;
    }
    ans[0] = 0x3FFFFFFF;
    for (int i = 1; i <= n; i++)
    {
        int np = len[i];
        while (ans[np] < arr[i])
        {
            ans[np] = arr[i];
            np--;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        cout << ans[i] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int arr[204800], len[204800], ans[204800];
int l[204800], r[204800];
pair<int, int> w[204800];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("D.in", "r", stdin);
#endif
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    for (int i = 0; i < n; i++)
    {
        if (!i)
        {
            l[i] = r[i] = i;
            for (int j = i + 1; j < n && arr[j] >= arr[i]; j++)
                r[i] = j;
        }
        else
        {
            if (arr[i] < arr[i - 1])
            {
                l[i] = l[i - 1];
                r[i] = i;
            }
            else if (arr[i] > arr[i - 1])
            {
                l[i] = i;
                r[i] = r[i - 1];
            }
            else
            {
                l[i] = l[i - 1];
                r[i] = r[i - 1];
            }
        }
        w[i].second = r[i] - l[i] + 1;
        w[i].first = -arr[i];
    }
    sort(w, w + n);
    for (int i = 0; i < n; i++)
    {
        arr[i] = -w[i].first;
        len[i] = w[i].second;
    }
    ans[0] = 0x3FFFFFFF;
    for (int i = 1; i <= n; i++)
    {
        int np = len[i - 1];
        while (ans[np] < arr[i - 1])
        {
            ans[np] = arr[i - 1];
            np--;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        cout << ans[i] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int arr[204800], len[204800], ans[204800];
int l[204800], r[204800];
pair<int, int> w[204800];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("D.in", "r", stdin);
#endif
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    for (int j = 1; j < n && arr[j] >= arr[0]; j++)
        r[0] = j;
    w[0].second = r[0] + 1;
    w[0].first = -arr[0];
    for (int i = 1; i < n; i++)
    {
        if (arr[i] < arr[i - 1])
        {
            l[i] = l[i - 1];
            r[i] = i;
            for (int j = i + 1; j < n && arr[j] >= arr[i]; j++)
                r[i] = j;
        }
        else if (arr[i] > arr[i - 1])
        {
            l[i] = i;
            r[i] = i;
            for (int j = i + 1; j < n && arr[j] >= arr[i]; j++)
                r[i] = j;
        }
        else
        {
            l[i] = l[i - 1];
            r[i] = r[i - 1];
        }
        w[i].second = r[i] - l[i] + 1;
        w[i].first = -arr[i];
    }
    sort(w, w + n);
    for (int i = 0; i < n; i++)
    {
        arr[i] = -w[i].first;
        len[i] = w[i].second;
    }
    ans[0] = 0x3FFFFFFF;
    for (int i = 1; i <= n; i++)
    {
        int np = len[i - 1];
        while (ans[np] < arr[i - 1])
        {
            ans[np] = arr[i - 1];
            np--;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        cout << ans[i] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int arr[204800], len[204800], ans[204800];
pair<int, int> w[204800];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("D.in", "r", stdin);
#endif
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    for (int i = 0; i < n; i++)
    {
        int l = 0;
        for (int j = i; j >= 0 && arr[j] >= arr[i]; j--)
            l++;
        for (int j = i + 1; j < n && arr[j] >= arr[i]; j++)
            l++;
        w[i].second = l;
        w[i].first = -arr[i];
    }
    sort(w, w + n);
    for (int i = 0; i < n; i++)
    {
        arr[i] = -w[i].first;
        len[i] = w[i].second;
    }
    ans[0] = 0x3FFFFFFF;
    for (int i = 1; i <= n; i++)
    {
        int l = len[i - 1];
        while (l > 0 && ans[l] < arr[i - 1])
        {
            ans[l] = arr[i - 1];
            l--;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        cout << ans[i] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int arr[204800], len[204800];
pair<int, int> w[204800];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("D.in", "r", stdin);
#endif
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    for (int i = 0; i < n; i++)
    {
        int l = 0;
        for (int j = i; j >= 0 && arr[j] >= arr[i]; j--)
            l++;
        for (int j = i + 1; j < n && arr[j] >= arr[i]; j++)
            l++;
        w[i].first = l;
        w[i].second = -arr[i];
    }
    sort(w, w + n);
    for (int i = 0; i < n; i++)
    {
        arr[i] = -w[i].second;
        len[i] = w[i].first;
    }
    for (int i = 0; i < n; i++)
    {
        int x = lower_bound(len, len + n, i + 1) - len;
        cout << arr[x] << " ";
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <climits>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <algorithm>

#define F(i,a,n) for(int i=(a);i<(n);++i)
#define rof(i,a,b) for(int (i)=(a);(i) > (b); --(i))
#define ll long long
#define pb push_back
#define mp make_pair
#define sqr(x) (x)*(x)
#define debug(x) printf("%s\n",x)
#define all(x) (x).begin(),(x).end()
#define N 200003

using namespace std;
inline int fast_input(void)
{
	char t;
	int x=0;
	int neg=0;
	t=getchar();
	while((t<48 || t>57) && t!='-')
		t=getchar();
	if(t=='-')
		{neg=1; t=getchar();}
    while(t>=48 && t<=57)
    {
        x=(x<<3)+(x<<1)+t-48;
        t=getchar();
    }
	if(neg)
		x=-x;
	return x;
}
int height[N],l[N],r[N],ans[N];
stack<int> s;

/* Given N buildings/bars, find the greatest area formed by
	consecutive buildings/bars.

	SOLUTION:
	 	for every building/bar 'x' find the area
	 	with 'x' as the smallest bar in the rectangle

	 * find the width for which x is the smallest bar
	 * l[x] stores the nearest smallest value on left
	 * r[x] stores the nearest smallest value on right
	 * so in b/w l[x] and r[x] x is the smallest bar
	 * calculate the area;
*/
int main()
{
	int n;
	n = fast_input();
	F(i,0,n)
		height[i] = fast_input();
	fill(l,l+n,-1);
	fill(r,r+n,n);
	F(i,0,n){
		while(!s.empty() && height[s.top()] >= height[i])
			s.pop();
		if(!s.empty())
			l[i] = s.top();
		s.push(i);
	}
	while(!s.empty())
		s.pop();
	rof(i,n-1,-1){
		while(!s.empty() && height[s.top()] >= height[i])
			s.pop();
		if(!s.empty())
			r[i] = s.top();
		s.push(i);
	}
/*	F(i,0,n)
		printf("%d ",l[i]);
	printf("\n");
	F(i,0,n)
		printf("%d ",r[i]);
	printf("\n");
	*/
	F(i,0,n){
		int len = r[i] - l[i] - 1;
		ans[len] = max(ans[len], height[i]);
	}
	rof(i,n,-1)
		ans[i] = max(ans[i], ans[i+1]);

	F(i,1,n+1)
		printf("%d ", ans[i]);
	cout << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <climits>
#include <cassert>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <algorithm>

#define F(i,a,n) for(int i=(a);i<(n);++i)
#define ll long long
#define pb push_back
#define mp make_pair
#define sqr(x) (x)*(x)
#define debug(x) printf("%s\n",x)
#define all(x) (x).begin(),(x).end()
#define N 200003
//#define SQRT 448

using namespace std;
inline ll int fast_input(void)
{
	char t;
	ll int x=0;
	ll int neg=0;
	t=getchar();
	while((t<48 || t>57) && t!='-')
		t=getchar();
	if(t=='-')
		{neg=1; t=getchar();}
    while(t>=48 && t<=57)
    {
        x=(x<<3)+(x<<1)+t-48;
        t=getchar();
    }
	if(neg)
		x=-x;
	return x;
}
int SQRT;
int a[N];
int rmq(int l,int r,int m[]){
	int lblock = l/SQRT;
	int rblock = r/SQRT;
	int mini = INT_MAX;
	if(lblock == rblock){
		F(i,l,r+1){
			mini = min(mini,a[i]);
		}
		return mini;
	}
	else{

		for(int i = lblock*SQRT+l;i<(lblock+1)*SQRT;i++)
			mini = min(mini,a[i]);
		for(int i = lblock+1;i<rblock;i++)
			mini = min(mini,m[i]);
		for(int i = rblock*SQRT;i<r+1;i++)
			mini = min(mini,a[i]);
		return mini;
	}
}
int main(){
	int n;
	scanf("%d",&n);
	SQRT = ceil(sqrt(double(n)));
	//printf("%d\n",SQRT);
	int m[SQRT];
	F(i,0,n)
		scanf("%d",&a[i]);

	for(int i = 0;i<n && i<SQRT; i++){
		int mini  = INT_MAX;
		for(int j = i*SQRT;j<n && j<(i+1)*SQRT;j++){
			mini = min(mini,a[j]);
		}
		m[i] = mini;
	}
	F(x,1,n+1){
		int maxi = 0;
		for(int i = 0;i<n-x+1;i++){
			int l = i,r = i+x-1;
			maxi = max(rmq(l,r,m),maxi);
		}
		printf("%d ",maxi);
	}

	/*F(x,1,n+1){
		int maxi = 0,mini;
		for(int i = 0;i<n-x+1;i++){
			mini = INT_MAX;
			int j = i;
			for(;j<i+x;j++){
				mini = min(mini,a[j]);
			}

			maxi = max(maxi,mini);
		}
		printf("%d ",maxi);
	}
	*/
}


#include <iostream>
#include <cstdio>
#include <climits>
#include <cassert>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <algorithm>

#define F(i,a,n) for(int i=(a);i<(n);++i)
#define ll long long
#define pb push_back
#define mp make_pair
#define sqr(x) (x)*(x)
#define debug(x) printf("%s\n",x)
#define all(x) (x).begin(),(x).end()
#define N 200003
#define SQRT 448

using namespace std;
inline ll int fast_input(void)
{
	char t;
	ll int x=0;
	ll int neg=0;
	t=getchar();
	while((t<48 || t>57) && t!='-')
		t=getchar();
	if(t=='-')
		{neg=1; t=getchar();}
    while(t>=48 && t<=57)
    {
        x=(x<<3)+(x<<1)+t-48;
        t=getchar();
    }
	if(neg)
		x=-x;
	return x;
}
int a[N],m[SQRT];
int rmq(int l,int r){
	int lblock = l/SQRT;
	int rblock = r/SQRT;
	int mini = INT_MAX;
	if(lblock == rblock){
		F(i,l,r+1){
			mini = min(mini,a[i]);
		}
		return mini;
	}
	else{

		for(int i = l;i<(lblock+1)*SQRT;i++)
			mini = min(mini,a[i]);
		for(int i = lblock+1;i<rblock;i++)
			mini = min(mini,m[i]);
		for(int i = rblock*SQRT;i<r+1;i++)
			mini = min(mini,a[i]);
		return mini;
	}
}
int main(){
	int n;
	scanf("%d",&n);
	F(i,0,n)
		scanf("%d",&a[i]);

	for(int i = 0;i<n && i<SQRT; i++){
		int mini  = INT_MAX;
		for(int j = i*SQRT;j<n && j<(i+1)*SQRT;j++){
			mini = min(mini,a[j]);
		}
		m[i] = mini;
	}
	F(x,1,n+1){
		int maxi = 0;
		for(int i = 0;i<n-x+1;i++){
			int l = i,r = i+x-1;
			maxi = max(rmq(l,r),maxi);
		}
		printf("%d ",maxi);
	}

	/*F(x,1,n+1){
		int maxi = 0,mini;
		for(int i = 0;i<n-x+1;i++){
			mini = INT_MAX;
			int j = i;
			for(;j<i+x;j++){
				mini = min(mini,a[j]);
			}

			maxi = max(maxi,mini);
		}
		printf("%d ",maxi);
	}
	*/

}


#include <iostream>
#include <cstdio>
#include <climits>
#include <cassert>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <algorithm>

#define F(i,a,n) for(ll i=(a);i<(n);++i)
#define ll  long long
#define pb push_back
#define mp make_pair
#define sqr(x) (x)*(x)
#define debug(x) printf("%s\n",x)
#define all (x) (x).begin(),(x).end()
#define N 200003
#define SQRT 448

using namespace std;
inline ll  fast_input(void)
{
	char t;
	ll  x=0;
	ll  neg=0;
	t=getchar();
	while((t<48 || t>57) && t!='-')
		t=getchar();
	if(t=='-')
		{neg=1; t=getchar();}
    while(t>=48 && t<=57)
    {
        x=(x<<3)+(x<<1)+t-48;
        t=getchar();
    }
	if(neg)
		x=-x;
	return x;
}
ll a[N],m[SQRT];
ll rmq(ll l,ll r){
	ll lblock = l/SQRT;
	ll rblock = r/SQRT;
	ll mini = LLONG_MAX;
	if(lblock == rblock){
		F(i,l,r+1){
			mini = min(mini,a[i]);
		}
		return mini;
	}
	else{

		for(ll i = lblock*SQRT+l;i<(lblock+1)*SQRT;i++)
			mini = min(mini,a[i]);
		for(ll i = lblock+1;i<rblock;i++)
			mini = min(mini,m[i]);
		for(ll i = rblock*SQRT;i<r+1;i++)
			mini = min(mini,a[i]);
		return mini;
	}
}
int main(){
	ll n;
	n = fast_input();
	//scanf("%lld",&n);
	F(i,0,n)
		a[i] = fast_input();
		//scanf("%lld",&a[i]);

	for(ll i = 0;i<n && i<SQRT; i++){
		ll mini  = LLONG_MAX;
		for(ll j = i*SQRT;j<n && j<(i+1)*SQRT;j++){
			mini = min(mini,a[j]);
		}
		m[i] = mini;
	}
	F(x,1,n+1){
		ll maxi = 0;
		for(ll i = 0;i<n-x+1;i++){
			ll l = i,r = i+x-1;
			maxi = max(rmq(l,r),maxi);
		}
		cout<<maxi<<" ";
		//printf("%lld ",maxi);
	}

	/*F(x,1,n+1){
		ll maxi = 0,mini;
		for(ll i = 0;i<n-x+1;i++){
			mini = INT_MAX;
			ll j = i;
			for(;j<i+x;j++){
				mini = min(mini,a[j]);
			}

			maxi = max(maxi,mini);
		}
		printf("%d ",maxi);
	}
	*/

}


#include <iostream>
#include <cstdio>
#include <climits>
#include <cassert>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <algorithm>

#define F(i,a,n) for(int i=(a);i<(n);++i)
#define ll long long
#define pb push_back
#define mp make_pair
#define sqr(x) (x)*(x)
#define debug(x) printf("%s\n",x)
#define all(x) (x).begin(),(x).end()
#define N 200003
#define MAX_LOG 18

using namespace std;
inline ll int fast_input(void)
{
	char t;
	ll int x=0;
	ll int neg=0;
	t=getchar();
	while((t<48 || t>57) && t!='-')
		t=getchar();
	if(t=='-')
		{neg=1; t=getchar();}
    while(t>=48 && t<=57)
    {
        x=(x<<3)+(x<<1)+t-48;
        t=getchar();
    }
	if(neg)
		x=-x;
	return x;
}
int a[N],m[N][MAX_LOG];

int rmq(int l,int r){
	int x=log(r-l+1)/log(2);
	return min(m[l][x],m[r-(1<<x)+1][x]);
}
int main(){
	int n;
	scanf("%d",&n);
	int maxlog= ceil(log(n)/log(2));
	F(i,0,n)
		scanf("%d",&a[i]);

	for(int j = 0;j<=maxlog;j++){ //col wise filling
		for(int i = 0; i<n;i++){
			if(i+ (1<<j) -1 < n){
				if(j){
					m[i][j]=min(m[i][j-1], m[i+(1<<(j-1))][j-1]);
				}
				else{
					m[i][j] = a[i];
				}
			}
		}
	}
	F(x,1,n+1){
		int maxi = 0;
		for(int i = 0;i<n-x+1;i++){
			int l = i,r = i+x-1;
			maxi = max(rmq(l,r),maxi);
		}
		printf("%d ",maxi);
	}

	/*F(x,1,n+1){
		int maxi = 0,mini;
		for(int i = 0;i<n-x+1;i++){
			mini = INT_MAX;
			int j = i;
			for(;j<i+x;j++){
				mini = min(mini,a[j]);
			}

			maxi = max(maxi,mini);
		}
		printf("%d ",maxi);
	}
	*/

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<cmath>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
#define MAX 1000100
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef unsigned long long ull;
#define INF (1ll<<60)-1
using namespace std;
int n;
struct node{
    int pos,v;
    node(int pos=0,int v=0):pos(pos),v(v){}
};
stack<node> qu;
int a[200100];
int L[200100],R[200100];
int anw[200100];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    qu.push(node(0,0));
    node now;
    for(int i=1;i<=n;i++){
        while(!qu.empty()){
            now=qu.top();
            if(a[i]<now.v){
                R[now.pos]=i-1;
                qu.pop();
            } else {
                qu.push(node(i,a[i]));
                break;
            }
        }
    }
    while(!qu.empty()){
        now=qu.top();
        qu.pop();
        R[now.pos]=n;
    }
    ///for(int i=1;i<=n;i++) cout<<R[i]<<" "; cout<<endl;
    qu.push(node(0,0));
    for(int i=n;i>=1;i--){
        while(!qu.empty()){
            now=qu.top();
            if(a[i]<now.v){
                L[now.pos]=i+1;
                qu.pop();
            } else {
                qu.push(node(i,a[i]));
                break;
            }
        }
    }
    while(!qu.empty()){
        now=qu.top();
        qu.pop();
        L[now.pos]=1;
    }
    ///for(int i=1;i<=n;i++) cout<<L[i]<<" ";cout<<endl;
    for(int i=1;i<=n;i++){
        int len=R[i]-L[i]+1;
        anw[len]=max(anw[len],a[i]);
    }
    for(int i=n;i>=1;i--){
        if(anw[i]<anw[i+1]) anw[i]=anw[i+1];
    }
    for(int i=1;i<=n;i++) cout<<anw[i]<<" ";cout<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<cmath>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
#define MAX 1000100
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef unsigned long long ull;
#define INF (1ll<<60)-1
using namespace std;
int n;
struct node{
    int pos,v;
    node(int pos=0,int v=0):pos(pos),v(v){}
};
stack<node> qu;
int a[200100];
int L[200100],R[200100];
int anw[200100];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    qu.push(node(0,0));
    node now;
    for(int i=1;i<=n;i++){
        while(!qu.empty()){
            now=qu.top();
            if(a[i]<now.v){
                R[now.pos]=i-1;
                qu.pop();
            } else {
                qu.push(node(i,a[i]));
                break;
            }
        }
    }
    while(!qu.empty()){
        now=qu.top();
        qu.pop();
        R[now.pos]=n;
    }
    ///for(int i=1;i<=n;i++) cout<<R[i]<<" "; cout<<endl;
    qu.push(node(0,0));
    for(int i=n;i>=1;i--){
        while(!qu.empty()){
            now=qu.top();
            if(a[i]<now.v){
                L[now.pos]=i+1;
                qu.pop();
            } else {
                qu.push(node(i,a[i]));
                break;
            }
        }
    }
    while(!qu.empty()){
        now=qu.top();
        qu.pop();
        L[now.pos]=1;
    }
    ///for(int i=1;i<=n;i++) cout<<L[i]<<" ";cout<<endl;
    for(int i=1;i<=n;i++){
        int len=R[i]-L[i]+1;
        anw[len]=max(anw[len],a[i]);
    }
    for(int i=n;i>=1;i--){
        if(anw[i]==0) anw[i]=anw[i+1];
    }
    for(int i=1;i<=n;i++) cout<<anw[i]<<" ";cout<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<cmath>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
using namespace std;
struct node {
    int l,r;
} s[500001];
int n;
int a[500001],anw[500001];
int main() {
    scanf("%d",&n);
    for(int i=1; i<=n; i++) {
        scanf("%d",&a[i]);
        s[i].l=0;
        s[i].r=n+1;
    }
    a[0]=0;
    a[n+1]=0;
    mst(anw,0);
    for(int i=1; i<=n; i++) {
        int j=i-1;
        while(a[j]>=a[i])
            j=s[j].l;
        s[i].l=j;
    }
    for(int i=n; i>=1; i--) {
        int j=i+1;
        while(a[j]>=a[i])
            j=s[j].r;
        s[i].r=j;
    }
    for(int i=1; i<=n; i++) {
        int len=s[i].r-s[i].l-1;
        anw[len]=max(anw[len],a[i]);
    }
    for(int i=n; i>=1; i--) {
        if(anw[i+1]>anw[i]) {
            anw[i]=anw[i+1];
        }
    }
    for(int i=1; i<=n; i++) {
        printf("%d ",anw[i]);
    }
    return 0;
}


/**
 *    author:  skmonir
 *    created: 03-May-2018 12:26:16
**/

#include <bits/stdc++.h>

using namespace std;

#define endl                '\n'
#define TN                  typename
#define mod                 1000000007LL
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define mem(x, y)           memset(x, y, sizeof x)
#define FOR(x, l, r)        for (int x = l; x <= r; ++x)
#define ROF(x, l, r)        for (int x = l; x >= r; --x)

template <TN T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> inline void umin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void umax(T &a, T b) {a = a > b ? a : b;}
template <TN T, TN W> inline void Int(T &x, W &y) {Int(x), Int(y);}
template <TN T, TN W, TN Q> inline void Int(T &x, W &y, Q &z) {Int(x, y), Int(z);}

const int N = 2e5 + 7;
const int inf = 1e9 + 7;

int a[N];

struct SegmentTree {
    int t[N << 2][2], f[N << 2];

    void push(int nd, int s, int e) {
        if (f[nd]) {
            umax(t[nd][1], f[nd]);
            if (s != e) umax(f[nd << 1], f[nd]), umax(f[nd << 1 | 1], f[nd]);
            f[nd] = 0;
        }
    }

    void build(int nd, int s, int e) {
        if (s == e) {
            t[nd][0] = a[s];
            return;
        }
        int md = (s + e) >> 1;
        build(nd << 1, s, md);
        build(nd << 1 | 1, md + 1, e);
        t[nd][0] = min(t[nd << 1][0], t[nd << 1 | 1][0]);
    }

    void modify(int nd, int s, int e, int l, int r, int v) {
        push(nd, s, e);
        if (e < l or r < s) return;
        if (s >= l and e <= r) {
            umax(f[nd], v);
            push(nd, s, e);
            return;
        }
        int md = (s + e) >> 1;
        modify(nd << 1, s, md, l, r, v);
        modify(nd << 1 | 1, md + 1, e, l, r, v);
        t[nd][1] = max(t[nd << 1][1], t[nd << 1 | 1][1]);
    }

    int askMin(int nd, int s, int e, int l, int r) {
        if (e < l or r < s) return inf;
        int md = (s + e) >> 1;
        if (s >= l and e <= r) return t[nd][0];
        int c1 = askMin(nd << 1, s, md, l, r);
        int c2 = askMin(nd << 1 | 1, md + 1, e, l, r);
        return min(c1, c2);
    }

    int askMax(int nd, int s, int e, int l, int r) {
        push(nd, s, e);
        if (e < l or r < s) return 0;
        int md = (s + e) >> 1;
        if (s >= l and e <= r) return t[nd][1];
        int c1 = askMax(nd << 1, s, md, l, r);
        int c2 = askMax(nd << 1 | 1, md + 1, e, l, r);
        return max(c1, c2);
    }
} st[2];

int solve() {
    int n; Int(n);
    FOR (i, 1, n) Int(a[i]);

    st[0].build(1, 1, n);

    FOR (i, 1, n) {
        int leftEnd = i, rightEnd = i, l, r;

        l = 1, r = i;
        while (l <= r) {
            int md = l + r >> 1;
            int mn = st[0].askMin(1, 1, n, md, i);
            if (mn == a[i]) leftEnd = md, r = md - 1;
            else l = md + 1;
        }

        l = i, r = n;
        while (l <= r) {
            int md = l + r >> 1;
            int mn = st[0].askMin(1, 1, n, i, md);
            if (mn == a[i]) rightEnd = md, l = md + 1;
            else r = md - 1;
        }

        int len = rightEnd - leftEnd + 1;
        st[1].modify(1, 1, n, 1, len, a[i]);
    }

    FOR (i, 1, n) printf("%d ", st[1].askMax(1, 1, n, i, i));
    printf("\n");

    return 0;
}

int main() {
    int tests = 1, CaseNo = 0; //Int(tests);
    while (tests--) {
        //printf("Case %d: ", ++CaseNo);
        solve();
    }
    return 0;
}


/**
 *    author:  skmonir
 *    created: 03-May-2018 12:26:16
**/

#include <bits/stdc++.h>

using namespace std;

#define endl                '\n'
#define TN                  typename
#define mod                 1000000007LL
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define mem(x, y)           memset(x, y, sizeof x)
#define FOR(x, l, r)        for (int x = l; x <= r; ++x)
#define ROF(x, l, r)        for (int x = l; x >= r; --x)

template <TN T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> inline void umin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void umax(T &a, T b) {a = a > b ? a : b;}
template <TN T, TN W> inline void Int(T &x, W &y) {Int(x), Int(y);}
template <TN T, TN W, TN Q> inline void Int(T &x, W &y, Q &z) {Int(x, y), Int(z);}

const int N = 2e5 + 7;
const int inf = 1e9 + 7;

int res[N];
map <int, vector <int> > idx;

int solve() {
    int n; Int(n);
    FOR (i, 1, n) {
        int ai; Int(ai);
        idx[ai].push_back(i);
    }

    set <int> A = {0, n + 1};
    set <int> D = { - n - 1, 0};

    for (auto u : idx) {
        int mxLen = 0;
        for (int i = 0; i < u.second.size(); ++i) {
            int r = *A.upper_bound(u.second[i]);
            int l = *D.upper_bound(-u.second[i]);
            umax(mxLen, r + l - 1);
        }
        for (int i = 0; i < u.second.size(); ++i) {
            A.insert(u.second[i]);
            D.insert(-u.second[i]);
        }
        umax(res[mxLen], u.first);
    }

    ROF (i, n, 1) umax(res[i], res[i + 1]);

    FOR (i, 1, n) printf("%d ", res[i]);
    printf("\n");

    return 0;
}

int main() {
    int tests = 1, CaseNo = 0; //Int(tests);
    while (tests--) {
        //printf("Case %d: ", ++CaseNo);
        solve();
    }
    return 0;
}


/**
 *    author:  skmonir
 *    created: 03-May-2018 12:26:16
**/

#include <bits/stdc++.h>

using namespace std;

#define endl                '\n'
#define TN                  typename
#define mod                 1000000007LL
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define mem(x, y)           memset(x, y, sizeof x)
#define FOR(x, l, r)        for (int x = l; x <= r; ++x)
#define ROF(x, l, r)        for (int x = l; x >= r; --x)

template <TN T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> inline void umin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void umax(T &a, T b) {a = a > b ? a : b;}
template <TN T, TN W> inline void Int(T &x, W &y) {Int(x), Int(y);}
template <TN T, TN W, TN Q> inline void Int(T &x, W &y, Q &z) {Int(x, y), Int(z);}

const int N = 2e5 + 7;
const int inf = 1e9 + 7;

struct SegmentTree {
    int t[N << 2][2], f[N << 2];

    void push(int nd, int s, int e) {
        if (f[nd]) {
            umax(t[nd][1], f[nd]);
            if (s != e) umax(f[nd << 1], f[nd]), umax(f[nd << 1 | 1], f[nd]);
            f[nd] = 0;
        }
    }

    void modify(int nd, int s, int e, int l, int r, int v) {
        push(nd, s, e);
        if (e < l or r < s) return;
        if (s >= l and e <= r) {
            umax(f[nd], v);
            push(nd, s, e);
            return;
        }
        int md = (s + e) >> 1;
        modify(nd << 1, s, md, l, r, v);
        modify(nd << 1 | 1, md + 1, e, l, r, v);
        t[nd][1] = max(t[nd << 1][1], t[nd << 1 | 1][1]);
    }

    int askMax(int nd, int s, int e, int l, int r) {
        push(nd, s, e);
        if (e < l or r < s) return 0;
        int md = (s + e) >> 1;
        if (s >= l and e <= r) return t[nd][1];
        int c1 = askMax(nd << 1, s, md, l, r);
        int c2 = askMax(nd << 1 | 1, md + 1, e, l, r);
        return max(c1, c2);
    }
} st;

map <int, vector <int> > idx;

int solve() {
    int n; Int(n);
    FOR (i, 1, n) {
        int ai; Int(ai);
        idx[ai].push_back(i);
    }

    set <int> A = {0, n + 1};
    set <int> D = { - n - 1, 0};

    for (auto u : idx) {
        int mxLen = 0;
        for (int i = 0; i < u.second.size(); ++i) {
            int r = *A.upper_bound(u.second[i]);
            int l = *D.upper_bound(-u.second[i]);
            umax(mxLen, r + l - 1);
        }
        for (int i = 0; i < u.second.size(); ++i) {
            A.insert(u.second[i]);
            D.insert(-u.second[i]);
        }
        st.modify(1, 1, n, 1, mxLen, u.first);
    }

    FOR (i, 1, n) printf("%d ", st.askMax(1, 1, n, i, i));
    printf("\n");

    return 0;
}

int main() {
    int tests = 1, CaseNo = 0; //Int(tests);
    while (tests--) {
        //printf("Case %d: ", ++CaseNo);
        solve();
    }
    return 0;
}


/**
 *    author:  skmonir
 *    created: 03-May-2018 12:26:16
**/

#include <bits/stdc++.h>

using namespace std;

#define endl                '\n'
#define TN                  typename
#define mod                 1000000007LL
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define mem(x, y)           memset(x, y, sizeof x)
#define FOR(x, l, r)        for (int x = l; x <= r; ++x)
#define ROF(x, l, r)        for (int x = l; x >= r; --x)

template <TN T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> inline void umin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void umax(T &a, T b) {a = a > b ? a : b;}
template <TN T, TN W> inline void Int(T &x, W &y) {Int(x), Int(y);}
template <TN T, TN W, TN Q> inline void Int(T &x, W &y, Q &z) {Int(x, y), Int(z);}

const int N = 2e5 + 7;
const int inf = 1e9 + 7;

int a[N];

struct SegmentTree {
    int t[N << 2][2], f[N << 2];

    void push(int nd, int s, int e) {
        if (f[nd]) {
            umax(t[nd][1], f[nd]);
            if (s != e) umax(f[nd << 1], f[nd]), umax(f[nd << 1 | 1], f[nd]);
            f[nd] = 0;
        }
    }

    void build(int nd, int s, int e) {
        if (s == e) {
            t[nd][0] = a[s];
            return;
        }
        int md = (s + e) >> 1;
        build(nd << 1, s, md);
        build(nd << 1 | 1, md + 1, e);
        t[nd][0] = min(t[nd << 1][0], t[nd << 1 | 1][0]);
    }

    void modify(int nd, int s, int e, int l, int r, int v) {
        push(nd, s, e);
        if (e < l or r < s) return;
        if (s >= l and e <= r) {
            umax(f[nd], v);
            push(nd, s, e);
            return;
        }
        int md = (s + e) >> 1;
        modify(nd << 1, s, md, l, r, v);
        modify(nd << 1 | 1, md + 1, e, l, r, v);
        t[nd][1] = max(t[nd << 1][1], t[nd << 1 | 1][1]);
    }

    int askMin(int nd, int s, int e, int l, int r) {
        if (e < l or r < s) return inf;
        int md = (s + e) >> 1;
        if (s >= l and e <= r) return t[nd][0];
        long long c1 = askMin(nd << 1, s, md, l, r);
        long long c2 = askMin(nd << 1 | 1, md + 1, e, l, r);
        return min(c1, c2);
    }

    int askMax(int nd, int s, int e, int l, int r) {
        push(nd, s, e);
        if (e < l or r < s) return 0;
        int md = (s + e) >> 1;
        if (s >= l and e <= r) return t[nd][1];
        long long c1 = askMax(nd << 1, s, md, l, r);
        long long c2 = askMax(nd << 1 | 1, md + 1, e, l, r);
        return max(c1, c2);
    }
} st[2];

int solve() {
    int n; Int(n);
    FOR (i, 1, n) Int(a[i]);

    st[0].build(1, 1, n);

    FOR (i, 1, n) {
        int leftEnd = i, rightEnd = i, l, r;

        l = 1, r = i;
        while (l <= r) {
            int md = l + r >> 1;
            int mn = st[0].askMin(1, 1, n, md, i);
            if (mn == a[i]) leftEnd = md, r = md - 1;
            else l = md + 1;
        }

        l = i, r = n;
        while (l <= r) {
            int md = l + r >> 1;
            int mn = st[0].askMin(1, 1, n, i, md);
            if (mn == a[i]) rightEnd = md, l = md + 1;
            else r = md - 1;
        }

        int len = rightEnd - leftEnd + 1;
        st[1].modify(1, 1, n, 1, len, a[i]);
    }

    FOR (i, 1, n) printf("%d ", st[1].askMax(1, 1, n, i, i));
    printf("\n");

    return 0;
}

int main() {
    int tests = 1, CaseNo = 0; //Int(tests);
    while (tests--) {
        //printf("Case %d: ", ++CaseNo);
        solve();
    }
    return 0;
}


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

typedef long long LL;
const int INF = 0x7fffffff;
const int MOD = 1e9 + 7;
const int N = 1e6 + 10;

vector <pair<int, int> > Q;
int fa[N], vis[N], sz[N], ans[N], a[N];

int Find(int x) {
    if(fa[x] == -1) return x;
    else return fa[x] = Find(fa[x]);
}
void Merge(int x, int y, int v) {
    int fx = Find(x), fy = Find(y);
    if(fx != fy) {
        fa[fx] = fy;
        //cout << sz[fx] << " " << sz[fy] << endl;
        sz[fy] += sz[fx];
    }
    ans[sz[fy]] = max(ans[sz[fy]], v);
}
int main() {
#ifdef Tally_Ho
    freopen("in.txt", "r", stdin);
#endif // Tally_Ho
    int n;
    scanf("%d", &n);
    memset(fa, -1, sizeof(fa));
    for(int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        Q.push_back(make_pair(a[i], i));
    }
    sort(Q.begin(), Q.end());
    reverse(Q.begin(), Q.end());
    ans[1] = *max_element(a, a + n);
    for(int i = 0; i < n; i++) {
        int v = Q[i].first, p = Q[i].second;
        vis[p] = 1, sz[p] = 1;
        if(p - 1 >= 0 && vis[p - 1]) Merge(p, p - 1, v);
        if(p + 1 < n && vis[p + 1]) Merge(p, p + 1, v);
    }
    for(int i = 1; i <= n; i++ ) {
        printf("%d ", ans[i]);
    }
    return 0;
}


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

typedef long long LL;
const int INF = 0x7fffffff;
const int MOD = 1e9 + 7;
const int N = 1e6 + 10;

vector <pair<int, int> > Q;
int fa[N], vis[N], sz[N], ans[N], a[N];

int Find(int x) {
    if(fa[x] == -1) return x;
    else return fa[x] = Find(fa[x]);
}
void Merge(int x, int y, int v) {
    int fx = Find(x), fy = Find(y);
    if(fx != fy) {
        fa[fx] = fy;
        //cout << sz[fx] << " " << sz[fy] << endl;
        sz[fy] += sz[fx];
    }
    ans[sz[fy]] = max(ans[sz[fy]], v);
}
int main() {
#ifdef Tally_Ho
    freopen("in.txt", "r", stdin);
#endif // Tally_Ho
    int n;
    scanf("%d", &n);
    memset(fa, -1, sizeof(fa));
    for(int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        Q.push_back(make_pair(a[i], i));
    }
    sort(Q.begin(), Q.end());
    reverse(Q.begin(), Q.end());
    ans[1] = *max_element(a, a + n);
    for(int i = 0; i < n; i++) {
        int v = Q[i].first, p = Q[i].second;
        vis[p] = 1, sz[p] = 1;
        if(p - 1 >= 0 && vis[p - 1]) Merge(p, p - 1, v);
        if(p + 1 < n && vis[p + 1]) Merge(p, p + 1, v);
    }
    for(int i = 1; i <= n; i++ ) {
        if(ans[i] == 0) ans[i] = ans[i - 1];
        printf("%d ", ans[i]);
    }
    return 0;
}


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

typedef long long LL;
const int INF = 0x7fffffff;
const int MOD = 1e9 + 7;
const int N = 1e6 + 10;

vector <pair<int, int> > Q;
int fa[N], vis[N], sz[N], ans[N], a[N];

int Find(int x) {
    if(fa[x] == -1) return x;
    else return fa[x] = Find(fa[x]);
}
void Merge(int x, int y, int v) {
    int fx = Find(x), fy = Find(y);
    if(fx != fy) {
        fa[fx] = fy;
        //cout << sz[fx] << " " << sz[fy] << endl;
        sz[fy] += sz[fx];
    }
    ans[sz[fy]] = max(ans[sz[fy]], v);
}
int main() {
#ifdef Tally_Ho
    freopen("in.txt", "r", stdin);
#endif // Tally_Ho
    int n;
    scanf("%d", &n);
    memset(fa, -1, sizeof(fa));
    for(int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        Q.push_back(make_pair(a[i], i));
    }
    sort(Q.begin(), Q.end());
    reverse(Q.begin(), Q.end());
    ans[1] = *max_element(a, a + n);
    for(int i = 0; i < n; i++) {
        int v = Q[i].first, p = Q[i].second;
        vis[p] = 1, sz[p] = 1;
        if(p - 1 >= 0 && vis[p - 1]) Merge(p, p - 1, v);
        if(p + 1 < n && vis[p + 1]) Merge(p, p + 1, v);
    }
    for(int i = n ; i > 0 ; i--) {
        if(ans[i] == 0) 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;

typedef long long LL;
const int INF = 0x7fffffff;
const int MOD = 1e9 + 7;
const int N = 1e6 + 10;

vector <pair<int, int> > Q;
int fa[N], vis[N], sz[N], ans[N], a[N];

int Find(int x) {
    if(fa[x] == -1) return x;
    else return fa[x] = Find(fa[x]);
}
void Merge(int x, int y, int v) {
    int fx = Find(x), fy = Find(y);
    if(fx != fy) {
        fa[fx] = fy;
        //cout << sz[fx] << " " << sz[fy] << endl;
        sz[fy] += sz[fx];
    }
    ans[sz[fy]] = max(ans[sz[fy]], v);
}
int main() {
#ifdef Tally_Ho
    freopen("in.txt", "r", stdin);
#endif // Tally_Ho
    int n;
    scanf("%d", &n);
    memset(fa, -1, sizeof(fa));
    for(int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        Q.push_back(make_pair(a[i], i));
    }
    sort(Q.begin(), Q.end());
    reverse(Q.begin(), Q.end());
    ans[1] = *max_element(a, a + n);
    for(int i = 0; i < n; i++) {
        int v = Q[i].first, p = Q[i].second;
        vis[p] = 1, sz[p] = 1;
        if(p - 1 >= 0 && vis[p - 1]) Merge(p, p - 1, v);
        if(p + 1 < n && vis[p + 1]) Merge(p, p + 1, v);
    }
    for(int i = n ; i > 0 ; 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 maxn = 200010;
struct node
{
    int val,id;
    bool operator < (const node &A)const{
        return val==A.val?id<A.id:val>A.val;
    }
};
set<node>S;
int vis[maxn];
int fa[maxn],siz[maxn];
int ans[maxn];
int find(int x)
{
    if(x!=fa[x])
    fa[x] = find(fa[x]);
    return fa[x];
}
int unio(int a,int b)
{
    int va=find(a);
    int vb=find(b);
    if(va!=vb)
    {
        if(va<vb)
        {
            fa[vb] = va;
            siz[va]+=siz[vb];
            siz[vb] = 0;
            return siz[va];
        }
        else{
            fa[va] = vb;
            siz[vb]+=siz[va];
            siz[va] = 0;
            return siz[vb];
        }
    }
    return max(siz[va],siz[vb]);
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        node a;
        a.id = i;
        a.val = x;
        S.insert(a);
    }
    set<node>::iterator it;
    memset(vis,0,sizeof(vis));
    memset(ans,0,sizeof(ans));
    for(int i=1;i<=n;i++)
    {
        fa[i] = i;
        siz[i] = 1;
    }
    int len = 0;
    for(it=S.begin();it!=S.end();it++)
    {
        int x = (*it).id;
        vis[x] = 1;
        int L=1,R=0,pre=x;
        if(vis[x-1])L = unio(x-1,x),pre=x-1;
        if(vis[x+1])R = unio(pre,x+1);
        L = max(L,R);
        if(L>len)
        {
            for(int j=len+1;j<=L;j++){
                ans[j] = (*it).val;
            }
            len = L;
        }
    }
    for(int i=1;i<=n;i++) printf("%d ",ans[i]);puts("");
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 200010;
struct node
{
    int val,id;
    bool operator < (const node &A)const{
        return val==A.val?id<A.id:val>A.val;
    }
};
set<node>S;
int vis[maxn];
int fa[maxn],siz[maxn];
int ans[maxn];
int find(int x)
{
    if(x!=fa[x])
    fa[x] = find(fa[x]);
    return fa[x];
}
int unio(int a,int b)
{
    int va=find(a);
    int vb=find(b);
    if(va!=vb)
    {
        if(va<vb)
        {
            fa[vb] = va;
            siz[va]+=siz[vb];
            siz[vb] = 0;
            return siz[va];
        }
        else{
            fa[va] = vb;
            siz[vb]+=siz[va];
            siz[va] = 0;
            return siz[vb];
        }
    }
    return max(siz[va],siz[vb]);
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        node a;
        a.id = i;
        a.val = x;
        S.insert(a);
    }
    set<node>::iterator it;
    memset(vis,0,sizeof(vis));
    memset(ans,0,sizeof(ans));
    for(int i=1;i<=n;i++)
    {
        fa[i] = i;
        siz[i] = 1;
    }
    int len = 0;
    for(it=S.begin();it!=S.end();it++)
    {
        int x = (*it).id;
        vis[x] = 1;
        int L=1,R=0,pre=x;
        for(int i=x-1;i>=1;i--)
        {
            if(vis[i]) L=unio(i,i+1),pre=i;
            else break;
        }
        for(int i=x+1;i<=n;i++)
        {
            if(vis[i])R=unio(pre,i);
            else break;
        }
        L = max(L,R);
       // cout<<L<<" asdsa \n";
        if(L>len)
        {
            for(int j=len+1;j<=L;j++){
                ans[j] = (*it).val;
            }
            len = L;
        }
        //if(len==n) break;
    }
    for(int i=1;i<=n;i++) printf("%d ",ans[i]);puts("");
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 200010;
struct node
{
    int val,id;
    bool operator < (const node &A)const{
        return val==A.val?id<A.id:val>A.val;
    }
};
set<node>S;
int vis[maxn];
int fa[maxn],siz[maxn];
int ans[maxn];
int find(int x)
{
    if(x!=fa[x])
    fa[x] = find(fa[x]);
    return fa[x];
}
int unio(int a,int b)
{
    int va=find(a);
    int vb=find(b);
    if(va!=vb)
    {
        if(va<vb)
        {
            fa[vb] = va;
            siz[va]+=siz[vb];
            siz[vb] = 0;
            return siz[va];
        }
        else{
            fa[va] = vb;
            siz[vb]+=siz[va];
            siz[va] = 0;
            return siz[vb];
        }
    }
    return max(siz[va],siz[vb]);
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        node a;
        a.id = i;
        a.val = x;
        S.insert(a);
    }
    set<node>::iterator it;
    memset(vis,0,sizeof(vis));
    memset(ans,0,sizeof(ans));
    for(int i=1;i<=n;i++)
    {
        fa[i] = i;
        siz[i] = 1;
    }
    int len = 0;
    for(it=S.begin();it!=S.end();it++)
    {
        int x = (*it).id;
        vis[x] = 1;
        int L=1,R=0,pre=x;
        if(vis[x-1])L = unio(x-1,x),pre=x-1;
        if(vis[x+1])R = unio(pre,x+1);
       /* for(int i=x-1;i>=1;i--)
        {
            if(find(i)==find(pre)) break;
            if(vis[i]) L=unio(i,i+1),pre=i;
            else break;
        }
        for(int i=x+1;i<=n;i++)
        {
            if(find(i)==find(pre)) break;
            if(vis[i])R=unio(pre,i);
            else break;
        }*/
        L = max(L,R);
        if(L>len)
        {
            for(int j=len+1;j<=L;j++){
                ans[j] = (*it).val;
            }
            len = L;
        }
    }
    for(int i=1;i<=n;i++) printf("%d ",ans[i]);puts("");
}