#pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<cmath> #include<string> #include<queue> #include<algorithm> #include<stack> #include<cstring> #include<vector> #include<list> #include<set> #include<map> using namespace std; #define ll long long #define pi (4*atan(1.0)) #define eps 1e-14 #define bug(x) cout<<"bug"<<x<<endl; const int N=2e5+10,M=1e6+10,inf=2147483647; const ll INF=1e18+10,mod=1e9+7; /// 数组大小 int a[N],ans[N]; int l[N],r[N],s[N]; int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); int st=0; s[++st]=0; for(int i=1;i<=n;i++) { while(a[s[st]]>=a[i])st--; l[i]=s[st]; s[++st]=i; } st=0; s[++st]=n+1; for(int i=n;i>=1;i--) { while(a[s[st]]>=a[i])st--; r[i]=s[st]; s[++st]=i; } for(int i=1;i<=n;i++) { int len=r[i]-l[i]-1; ans[len]=max(ans[len],a[i]); } for(int i=n;i>=1;i--) ans[i]=max(ans[i],ans[i+1]); for(int i=1;i<=n;i++) printf("%d ",ans[i]); return 0; }