!!!**********************************************************************
program main
!!!**********************************************************************  

  integer   :: n,d, x, amax, amax2
  integer, allocatable, dimension ( : ) :: a, b
  ! real      ::
  ! character ::
  
!!!----------------------------------------------------------------------

  read ( unit = *, fmt = * ) n

  allocate ( a ( 1:n ) )
  allocate ( b ( 1:n ) )  
  
  do i = 1, n
     
     read ( unit = *, fmt = * ) a ( i )

  end do

  b ( : ) = a ( : )

  amax = maxval ( a )

  do i = 1, n

     if ( b ( i ) == amax ) then

        b ( i ) = 0

  end if

end do

amax2 = maxval ( b )

do i = 1, n

   if ( a ( i ) == amax ) then
      
      print "(i0)", amax2

   else

      print "(i0)", amax

   end if

end do

  ! x = nint(real(n)/real(2*d+1))

  ! print "(i0)", x  
  
!!!**********************************************************************  
end program main
!!!**********************************************************************
