program abc134c2
   implicit none
   integer(8) :: n, i, lowMax, ans, highmax
   integer(8), allocatable :: a(:)

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

   highmax = 0
   lowMax = 0
   do i = 1, n
      if (i ==1) then
         write(*,*) maxval(a(2:n))
         lowMax = a(1)
         cycle
      else if ( i == n) then
         write(*,*) lowMax
         cycle
      endif

      !lowMax = max(lowmax, a(i-1))
      highmax =  maxval(a(i+1:n))
      write(*,*) max(lowMax, highMax)
      lowMax = max(lowmax, a(i))
   enddo

end
