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

  integer   :: n, d, x, i, max, max2
  integer, allocatable, dimension ( : ) :: a, b
  ! real      ::
  ! character ::
  
!!!----------------------------------------------------------------------

  read ( unit = *, fmt = * ) n

  allocate ( a ( 1:n ) )
  allocate ( b ( 1:n ) )  

  do i = 1, n

     read ( *, * ) a ( i )
     
  end do

  b ( : ) = a ( : )

  max  = maxval ( a )

  do i = 1, n

     if ( b ( i ) == max ) then

        b ( i ) = 0
        
     end if
     
  end do
 
  max2  = maxval ( b )
  
  do i = 1, n

     if ( a ( i ) == max ) then

        print "(i0)", max2
        
     else 

        print "(i0)", max
        
     end if

  end do

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