N=int(input())
a=[int(input()) for i in range(N)]
maxL=[0]*(N+1)
maxR=[0]*(N+1)
for j in range(1,N+1):
    maxL[j]=max(maxL[j-1],a[j-1])
    maxR[N-j]=max(maxR[N+1-j],a[N-j])
for k in range(N+1):
    print(max(maxL[k],maxR[k]))