import copy
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
maxa2=sorted(set(a))[-2]
maxs=a.count(maxa)
for i in range(n):
  if maxs==1:
    print(maxa if a[i]!=maxa else maxa2)
  else:
    print(maxa)