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

# max(A_2,A_3,...,A_N)
# max(A_1,A_3,...,A_N)
# max(A_1,A_2,...,A_(N-1))

M_1 = max(A)
M_2 = max(A.replace(M_1, 0))

for i in range(N):
  if A[i] != M_1: print(M_1)
  else: print(M_2)