program abc134c
   implicit none
   integer(8) :: n, i
   integer(8), allocatable :: a(:)

   read(*,*) n
   allocate(a(n))
   do i = 1, n
      read(*,*) a(i)
   enddo

   ! i = 1
   write(*,*) maxval(a(2:n))

   do i = 2, n-1
      write(*,*) max(maxval(a(1:i-1)), maxval(a(i+1:n)) )
   end do

   ! i = n
   write(*,*) maxval(a(1:n-1))

   stop
end
