N = int(input())
A = [int(input()) for i in range(N)]
lmax = [0]
rmax = [0]
for i in range(N-1):
  lmax.append(max(lmax[i],A[i]))
  rmax.append(max(lmax[i],A[N-1-i]))

rmax = rmax[::-1]
for i in range(N):
  print (max(lmax[i], rmax[i]))