#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import defaultdict from heapq import heappop, heappush # %% N, *A = map(int, read().split()) # %% coord = defaultdict(list) for i, x in enumerate(A): coord[x].append(i) # %% L_to_R = [-1] * N for li in coord.values(): L_to_R[li[0]] = li[-1] # %% q = [] B = [0] * N for L, R in enumerate(L_to_R): if R != -1: heappush(q, (-A[L], R)) while q[0][1] < L: heappop(q) B[L] = -q[0][0] # %% print(' '.join(map(str, B)))