program main
implicit none
integer :: i, j, k
integer :: n
integer , allocatable :: a(:), b(:)

read(*,*) n
allocate( a(n), b(n-1) )
do i = 1, n
   read(*,*) a(i)
end do
b(1:n-1) = a(2:n)
write(*,'(i0)') maxval( b )
do i = 2, n-1
   b(1:i) = a(1:i-1)
   b(i+1:n-1) = a(i+1:n)
   write(*,'(i0)') maxval( b )
end do
b(1:n-1) = a(1:n-1)
write(*,'(i0)') maxval( b )

end program main
