n=int(input())
a=[input() for i in range(n)]
t=max(a)
if a.count(t)>1:
  for i in range(n):
    print(t)
else:
  
  s=a.index(t)
  a=a[:s]+a[s+1:]
  u=max(a)
  for i in range(n):
    if i!=s:
      print(t)
    else:
      print(u)


