n = int(input())
a = list(input() for i in range(n))
M = max(a)

if a.count(M) > 1:
  for i in range(n):
    print(M)
elif n == 1:
  print(M)
else:
  M2 = sorted(set(a))[-2]
  for i in range(n):
    if a[i] == M:
      print(M2)
    else:
      print(M)