import sys
n=int(input())
l = [int(input()) for _ in range(n)] #複数行1文字をintでリストに
a=max(l)
l1=list(dict.fromkeys(l))
l1.remove(a)
if l1==[]:
  for i in l:
    print(i)
  sys.exit()
b=max(l1)
for i in l:
  if i==a:
    print(b)
  else:
    print(a)