N = int(input())
num_list = [input() for i in range(N)]
a = max(num_list)
if num_list.count(a) > 1:
  for j in range(N):
    print(a)
elif len(num_list) == 1:
  print(a)
else:
  b = sorted(num_list)[-2]
  for k in range(int(num_list.index(a))):
    print(a)
  print(b)
  for l in range(N-int(num_list.index(a))-1):
    print(a)