N = int(input())
A = [int(input()) for _ in range(N)]

left = [0]
right = [0]

# print(A)
for i in range(N):
    left.append(max(left[-1], A[i]))
# print(left)


for i in range(N-1, -1, -1):
    right.append(max(right[0], A[i]))

# print(len(left))
# print(len(right))

right.reverse()

for i in range(N):
    print(max(left[i], right[i+1]))
