def solve():
n = int(input())
A = list(map(int, input().split()))
stack = []
nge = [-1]*n
for i, a in enumerate(A):
while stack:
if stack[-1][1] < a:
j, _ = stack.pop()
nge[j] = a
else:
break
stack.append((i, a))
print(*nge)
solve()