N = int(input())
A = list(input() for _ in range(N))
B = A[:]
B.sort()
mx = B[-1]
mx2 = B[-2]

if mx == mx2:
  for _ in range(N):
    print(mx)
  exit()
for a in A:
  if a == mx:
    print(mx2)
  else:
    print(mx)