#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; template vector compress(vector &v){ vector a = v; sort(all(a)); a.erase(unique(all(a)), a.end()); each(b, v)b = (int)(lower_bound(all(a), b) - a.begin()); return a; } int main(){ int N; while(cin >> N){ vi a(N), b(N); rep(i, N)scanf("%d", &a[i]); auto vals = compress(a); vi l(sz(vals), INT_MAX), r(sz(vals), -1); rep(i, N){ smin(l[a[i]], i); smax(r[a[i]], i); } set pos; rep(i, N)pos.insert(i); for(int i = sz(vals) - 1; i >= 0; --i){ int val = vals[i]; while(1){ auto it = pos.lower_bound(l[i]); if(it == pos.end() || *it > r[i])break; b[*it] = val; pos.erase(it); } } rep(i, N)printf("%d%c", b[i], i == N - 1 ? '\n' : ' '); } }