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

max_itr = [i for i, v in enumerate(A) if v == max(A)]
max_number = max(A)
if len(max_itr) == 1:
  for i in range(N):
    if i != max_itr[0]:
      print(max_number)
    else:
      print(sorted(A)[-2])
else:
  for i in range(N):
    print(max_number)