n=input()
n=int(n)
a=[]
for i in range(n):
  s=input()
  a.append(s)
m=max(a)
k=a.index(m)
a.remove(m)
if m==max(a):
  for j in range(n):
    print(m)
else:
  for j in range(k):
    print(m)
  print(max(a))
  for t in range(n-k-1):
    print(m)