integer N
integer,allocatable,dimension(:)::A
integer premax,maxnum,cnt
read*,N
allocate(A(N))
do i=1,N
  read*,A(i)
end do
maxnum=A(1)
cnt=1
do i=2,N
  if(A(i)>maxnum)then
    premax=maxnum
    maxnum=A(i)
    cnt=1
  else if(A(i)==maxnum)then
    cnt=2
  else if(A(i)>=premax)then
    premax=A(i)
  endif
end do
do i=1,N
  if(A(i)/=maxnum.or.cnt==2)then
    print"(i0)",maxnum
  else
    print"(i0)",premax
  endif
end do
end