N = int(input())
A = [int(input()) for i in range(N)]
A_max = max(A)
A_max_count = A.count(A_max)

for i in range(N):
  tmp = A[i]
  if tmp != A_max_count:
    print(A_max)
  else:
    if A_max_count == 1:
      print(max(A[:i]+A[i+1:]))
    else:
      print(A_max)