program main
  implicit none

  integer, allocatable, dimension ( : ) :: A, B
  integer :: n, i, j, tmp
  
  read *, n

  allocate ( A ( 1:n ) )
  allocate ( B ( 1:2 ) )

  B = 0
  
  do i = 1, n
     read *, A ( i )
     if ( B ( 1 ) < A ( i ) ) then
        B ( 1 ) = A ( i )
     else if ( B ( 1 ) >= A ( i ) .and. B ( 2 ) < A ( i ) ) then
        B ( 1 ) = A ( i )
     end if
  end do

  do i = 1, n
     if ( A ( i ) == B ( 1 ) ) then
        print *, B ( 2 )
     else
        print *, B ( 1 )
     end if
  end do

end program main


  
