program main                                            
  implicit none                                         
  
  integer, allocatable, dimension ( : ) :: A, tmp       
  integer :: n, i                                       
  
  read *, n                                             
  
  allocate ( A ( 1:n ) )                                
  
  do i = 1, n                                           
     read *, A ( i )                                    
  end do

  do i = 1, n
     if ( i == 1 ) then
        print *, maxval ( A ( 2:n ) )
     else
        print *, max ( maxval ( A ( 1:i-1 ) ), maxval ( A ( i+1:n ) ) )
     end if
  end do
  
end program main
