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]])
if m[1]==m[3]:
  for i in range(n):
    print(m[1])
else:
  ans=np.full(n,m[1])
  ans[m[0]]=m[3]
  for i in range(n):
    print(ans[i])