import heapq n = int(input()) As = list(map(int, input().split())) dic = dict() for i, a in enumerate(As): if a in dic: dic[a][1] = i else: dic[a] = [i, i] Cs = [0] * n for a, pair in dic.items(): Cs[pair[0]] = a Cs[pair[1]] = a Bs = [] pq = [] for i, c in enumerate(Cs): if c == 0: Bs.append(-pq[0]) continue if dic[c][0] == i: heapq.heappush(pq, -c) Bs.append(-pq[0]) if i == n - 1: break if dic[c][1] == i: if c == -pq[0]: while pq and dic[-pq[0]][1] <= i: heapq.heappop(pq) print(*Bs)