bitN = 0; bit = [] def bit_add(a,w): while a <= bitN: bit[a] += w; a += a&(-a) def bit_sum(a): ret = 0 while a > 0: ret += bit[a]; a -= a&(-a) return ret N = input() a = map(int,raw_input().split()) b = [0]*N; c = {}; dc = {}; pos = {} for i,v in enumerate(a): if v in pos: pos[v][1]=i else: pos[v]=[i,i] tmp = 0 for v in sorted(a): if v > tmp: bitN += 1; tmp = v; c[v] = bitN; dc[bitN] = v bit = [0]*(bitN+1) for i,v in enumerate(a): bp = bitN-c[v]+1 if bit_sum(bp-1) == 0: b[i] = v else: l = 0; r = bp-1 while r - l > 1: mid = (l+r) / 2 if bit_sum(mid): r = mid else: l = mid b[i] = dc[bitN-r+1] if i == pos[v][0]: bit_add(bp, 1) if i == pos[v][1]: bit_add(bp,-1) print " ".join(map(str,b))