class StarrySkyTree: def __init__(self, n_): self.n = n = 2**n_.bit_length() self.data = [0]*(2*n) def update(self, k, a): data = self.data k += self.n-1 data[k] = a while k>0: k = (k - 1) / 2 data[k] = max(data[2*k+1], data[2*k+2]) def query(self, a, b, k, l, r): if b<=l or r<=a: return 0 if l<=a and b<=r: return self.data[k] vl = self.query(a, b, 2*k+1, l, (l + r) / 2) vr = self.query(a, b, 2*k+2, (l + r) / 2, r) return max(vl, vr) def get_max(self, a, b): return self.query(a, b, 0, 0, self.n) n = input() a = map(int, raw_input().split()) s = set(a) mapping = {e: i for i, e in enumerate(s)} b = [mapping[e] for e in a] le = [None]*n ri = [None]*n for i in xrange(n): if le[b[i]] is None: le[b[i]] = i for i in xrange(n-1,-1,-1): if ri[b[i]] is None: ri[b[i]] = i sst = StarrySkyTree(n) ans = [] append = ans.append for i in xrange(n): e = a[i] p = b[i] if le[p]==i: sst.update(p, e) append(sst.get_max(0, n)) if ri[p]==i: sst.update(p, 0) print " ".join(map(str, ans))