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

index = sorted([i for i, v in enumerate(A) if v == max(A)])
if len(index) == 1:
  for i in range(N):
    if i == index(0):
      print(sorted(A)[-2])
    else:
      print(max(A))
else:
  for _ in range(N):
    print(max(A))