import sys
N = int(input())

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


MAX = max(A)

if A.count(MAX) == N:
  for _ in range(N):
    print(MAX)

  
else:

  two = sorted(set(A))[-2]
  for i in range(N):
    if A[i] == MAX:
      print(two)
    else:
      print(MAX)