program exception_handling
  implicit none
  integer :: n, a(200000) = 0, i, fv = 0, sv = 0, fi = -1
  read(*,*) n
  do i = 1, n
    read(*,*) a(i)
    if (fv < a(i)) then
      fv = a(i)
      fi = i
    end if
  end do
  do i = 1, n
    if (sv < a(i) .and. i /= fi) then
      sv = a(i)
    end if
  end do
  do i = 1, n
    if (i == fi) then
      write(*,'(i0)') sv
      cycle
    end if
    write(*,'(i0)') fv
  end do
  stop
end program exception_handling