import sys

input = lambda: sys.stdin.readline().rstrip()

n = int(input())
arr = list(map(int, input().split()))

result = ['-1' for _ in range(n)]
stack = []  # Tuple(value, index)

for i in range(n):
    while stack and stack[-1][0] < arr[i]:
        val, idx = stack.pop()
        result[idx] = str(arr[i])

    stack.append((arr[i], i))

print(' '.join(result))
