program main
  implicit none

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

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

  do i = 1, n
     read *, A ( i )
  end do

  B = A
  
  do i = 1, n
     do j = 1, n - 1
        if ( A ( j ) < A ( j + 1 ) ) then
           tmp         = A ( j )
           A ( j )     = A ( j + 1 )
           A ( j + 1 ) = tmp
        end if
     end do
  end do

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

end program main
