n = int(input())
mx = 0
smx = 0
mxi = 0
for i in range(n):
  ai = int(input())
  if a[i] > mx:
    smx = mx
    mx = a[i]
    mxi = i
  elif a[i] > smx:
    smx = a[i]
for j in range(mxi):
  print(mx)
print(smx)
for j in range(mxi+1,n):
  print(mx)
    
  