program main
 implicit none
 integer n,one,two,i
 integer, allocatable::a(:)
 read(*,*) n
 allocate(a(1:n))
 read(*,*) a
 one = 0
 two = 0
 do i=1,n
  if(a(i) > one) then
   two = one
   one = a(i)
  else
   if(a(i) > two) then
    two = a(i)
   end if
  end if
 end do
 
 do i=1,n
  if(a(i) == one) then
   write(*,*) two
  else
   write(*,*) one
  end if
 end do
end program main