N = int(input())
alist = [int(input()) for i in range(N)]

biggest = max(alist)
cop = alist.copy()
cop.remove(biggest)
second = max(cop)

for i in range(x.index(biggest)):
  print(biggest)
print(second)
for i in range(len(x) - x.index(biggest) -1):
  print(biggest)