https://www.acmicpc.net/problem/17298
# 풀이 1 - 시간초과
import sys
from collections import deque
input = sys.stdin.readline
num = int(input())
li = deque(list(map(int, input().split())))
nge = []
for i in range(num):
flag = 0
for i in range(len(li)):
if li[0] < li[i]:
nge.append(li[i])
flag = 1
li.popleft()
break
if flag == 0:
nge.append(-1)
print(*nge, end="")
# 풀이 2
import sys
from collections import deque
input = sys.stdin.readline
num = int(input())
li = list(map(int, input().split()))
nge = [-1] * num
stack = deque()
for i in range(num):
while stack and (stack[-1][0] < li[i]):
temp, index = stack.pop()
nge[index] = li[i]
stack.append([li[i], i])
print(*nge)