import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto n = readln.chomp.to!size_t; auto ai = readln.split.to!(int[]); int[int] buf; auto di = ai.dup.sort().uniq.array, k = 0; foreach (d; di) buf[d] = k++; auto inf = k+1; auto ci = new int[](n); foreach (i, a; ai) ci[i] = buf[ai[i]]; auto mi = new size_t[](k), ma = new size_t[](k); mi[] = inf; foreach (i, c; ci) if (mi[c] > k) mi[c] = ma[c] = i; else ma[c] = i; auto st = SegmentTreeLazy!int(n); foreach (j; 0..k) st[mi[j]..ma[j]+1] = j; writeln(di.indexed(st.all).array.to!(string[]).join(" ")); } struct SegmentTreeLazy(T) { import core.bitop, std.conv, std.range; const size_t n, an; T[] buf; bool[] op; this(size_t n) { this.n = n; an = (1 << ((n - 1).bsr + 1)); buf = new T[](an * 2); op = new bool[](an * 2); } void propagate(size_t k, size_t nl, size_t nr) { if (!op[k]) return; size_t nm = (nl + nr) / 2; setLazy(buf[k], k*2, nl, nm); setLazy(buf[k], k*2+1, nm, nr); op[k] = false; } void setLazy(T val, size_t k, size_t nl, size_t nr) { buf[k] = val; op[k] = true; } void addOpe(T val, size_t l, size_t r, size_t k, size_t nl, size_t nr) { if (nr <= l || r <= nl) return; if (l <= nl && nr <= r) { setLazy(val, k, nl, nr); return; } propagate(k, nl, nr); auto nm = (nl + nr) / 2; addOpe(val, l, r, k*2, nl, nm); addOpe(val, l, r, k*2+1, nm, nr); } void opSliceAssign(T val, size_t l, size_t r) { addOpe(val, l, r, 1, 0, an); } void propagateAll(size_t k, size_t nl, size_t nr) { size_t nm = (nl + nr) / 2; if (op[k]) { setLazy(buf[k], k*2, nl, nm); setLazy(buf[k], k*2+1, nm, nr); op[k] = false; } if (nr - nl > 1) { propagateAll(k*2, nl, nm); propagateAll(k*2+1, nm, nr); } } T[] all() { propagateAll(0, 0, an); return buf[an..an+n]; } pure size_t opDollar() const { return n; } }