## https://yukicoder.me/problems/no/318 from collections import deque def main(): N = int(input()) A = list(map(int, input().split())) a_map = {} for i in range(N): a = A[i] if a not in a_map: a_map[a] = [i, i] else: a_map[a][1] = i event_map = {} for a, (s, g) in a_map.items(): if s not in event_map: event_map[s] = [] event_map[s].append((a, g)) queue = deque() answer = [0] * N for t in range(N): if t in event_map: for a, g in event_map[t]: while len(queue) > 0 and queue[-1][0] < a: queue.pop() queue.append((a, g)) answer[t] = queue[0][0] while len(queue) > 0 and queue[0][1] <= t: queue.pop() print(" ".join(map(str, answer))) if __name__ == '__main__': main()