import itertools
N=int(input())
A=[int(input()) for _ in range(N)]
B=list(itertools.accumulate(A,func=max))
C=list(itertools.accumulate(A[::-1],func=max))[::-1]
print(C[1])
for i in range(1,N-1):
    print(max(B[i-1],C[i+1]))
print(B[-1])
