N = int(input()) a = list(map(int,input().split())) d = dict() for i in range(N): if a[i] not in d: d[a[i]] = [i,-1] else: d[a[i]][1] = i n = 1 while n < N: n <<= 1 dat = [0] * (2 * n - 1) lazy = [0] * (2 * n -1) def eval(k): if lazy[k] == 0:return if k < n - 1: lazy[k*2+1] = lazy[k] lazy[k*2+2] = lazy[k] dat[k] = lazy[k] lazy[k] = 0 def update(a,b,x,k=0,l=0,r=n): eval(k) if r <= a or b <= l:return if a <= l and r <= b: lazy[k] = x eval(k) return update(a,b,x,k*2+1,l,(l+r)//2) update(a,b,x,k*2+2,(l+r)//2,r) dat[k] = max(dat[k*2+1],dat[k*2+2]) def query(a,b,k=0,l=0,r=n): eval(k) if r <= a or b <= l:return 0 if a <= l and r <= b:return dat[k] v1 = query(a,b,k*2+1,l,(l+r)//2) v2=query(a,b,k*2+2,(l+r)//2,r) return max(v1,v2) l = sorted(d) for i in l: l,r = d[i] if r == -1: update(l,l+1,i) else: update(l,r+1,i) for i in range(N): b = query(i,i+1) if b == 0: b = a[i] print(b,end = " ") print()