#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) #if defined(_MSC_VER) || __cplusplus > 199711L #define aut(r,v) auto r = (v) #else #define aut(r,v) __typeof(v) r = (v) #endif #define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it) #define all(o) (o).begin(), (o).end() #define pb(x) push_back(x) #define mp(x,y) make_pair((x),(y)) #define mset(m,v) memset(m,v,sizeof(m)) #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3fLL using namespace std; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template inline void amin(T &x, U y) { if(y < x) x = y; } template inline void amax(T &x, U y) { if(x < y) x = y; } struct UnionFind { vector data; void init(int n) { data.assign(n, -1); } bool unionSet(int x, int y) { x = root(x); y = root(y); if(x != y) { if(data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; int main() { int n; while(~scanf("%d", &n)) { vector a(n); for(int i = 0; i < n; ++ i) scanf("%d", &a[i]); map v; rep(i, n) v[a[i]].push_back(i); set s; rep(i, n) s.insert(i); vector ans(n, -1); for(auto it = v.rbegin(); it != v.rend(); ++ it) { int t = it->first; int l = it->second.front(), r = it->second.back(); auto a = s.lower_bound(l), b = s.lower_bound(r + 1); for(auto jt = a; jt != b; ++ jt) ans[*jt] = t; s.erase(a, b); } for(int i = 0; i < n; ++ i) { if(i != 0) putchar(' '); printf("%d", ans[i]); } puts(""); } return 0; }