N = int(input())
A = [input() for i in range(N)]
import copy
B = copy.copy(A)
B.sort()
a1 = B[-1]
a2 = B[-2]
if a1 == a2:
  for i in range(N):
    print(a1)
else:
  for i in range(N):
    if A[i] == a1:
      print(a2)
    else:
      print(a1)