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

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

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