N=int(input())
a=[]
for i in range(N):
    a.append(int(input()))

L_max=[0]*N
R_max=[0]*N

L=0
for i in range(N):
    L=max(L,a[i])
    L_max[i]=L

R=0
for i in range(N):
    R=max(R,a[-i-1])
    R_max[i]=R

for j in range(N):
    print(max(L_max[j-1],R_max[N-j-2]))
    