import heapq class Heapq: def __init__(self, lst = [], reverse = False): if reverse: self.pm = -1 self.hq = [-l for l in lst] else: self.pm = 1 self.hq = lst.copy() heapq.heapify(self.hq) self.tot = sum(lst) self.cnt = {} self.length = len(lst) def __bool__(self): return self.length > 0 def __len__(self): return self.length def __getitem__(self, i): if i == 0: return self.top() else: assert False def push(self, x): self.length += 1 self.cnt[x * self.pm] = self.cnt.get(x * self.pm, 0) + 1 heapq.heappush(self.hq, x * self.pm) self.tot += x def pop(self): if self.length == 0: return None self.length -= 1 ret = heapq.heappop(self.hq) self.tot -= self.pm * ret self.cnt[ret] -= 1 self.delete() return self.pm * ret def top(self): if self.hq: return self.pm * self.hq[0] else: return None def remove(self, x): if self.cnt.get(x * self.pm, 0) == 0: return False self.cnt[x * self.pm] -= 1 self.length -= 1 self.tot -= x self.delete() return True def delete(self): while self.hq and self.cnt.get(self.hq[0], 0) == 0: heapq.heappop(self.hq) n = int(input()) A = list(map(int, input().split())) L = {} R = {} for i, a in enumerate(A): if a not in L: L[a] = i R[a] = i add = [-1] * n remove = [-1] * n for a, i in L.items(): add[i] = a for a, i in R.items(): remove[i] = a hq = Heapq(reverse=True) ans = [0] * n for i in range(n): if add[i] != -1: hq.push(add[i]) ans[i] = hq.top() if remove[i] != -1: hq.remove(remove[i]) print(*ans)