import numpy as np
import math
n=int(input())
a=[]
m=[]
ans=[]
for i in range(n):
  a.append(int(input()))
m.append(a.index(max(a)))
m.append(a.pop(m[0]))
m.append(a.index(max(a)))
m.append(a[m[2]])

ans=np.full(n,m[1])
ans[m[0]]=m[3]
for i in range(n):
  print(ans[i])