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

L = [0] * (max(A)+1)
R = [0] * (max(A)+1)

L[0] = 0
for i in range(1, N+1):
    L[i] = max(A[i-1], L[i-1])

R[N] = 0
for i in range(N-1, 0, -1):
    R[i] = max(R[i+1], A[i])

#print(L)
#print(R)

for i in range(N):
    ans = max(L[i], R[i+1])
    print(ans)
