n=int(input())
l=[]
for _ in range(n):
  l.append(int(input()))
m=max(l)
mc=l.count(m)
s=sorted(set(l))[-2]
for i in l:
  if i==m:
    if mc>1:
      print(m)
    else:
      print(s)
  else:
    print(m)
