N=int(input())
maxi=0
smaxi=0
flag=0
ls=[]
x=0
for i in range(N):
  x=int(input())
  ls.append(x)
  if (maxi<x):
    flag=0
    smaxi=maxi
    maxi=x
  elif (maxi==x):
    flag=1
    smaxi=maxi
for i in range(N):
  if (ls[i]==maxi):
    if(flag==1):
      print(maxi)
    else:
      print(smaxi)
  else:
    print(maxi)
