module ABC130

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! accessibility of <subroutine>s and <function>s in this <module>
  public  :: task_B

  ! contained <subroutine>s and <function>s are below
  contains

  subroutine task_B

    ! variables for this <subroutine>
    integer(INT32)                            :: num_bound_total
    integer(INT32)                            :: coordinate_limit
    integer(INT32), allocatable, dimension(:) :: coordinate_bound
    integer(INT32)                            :: coordinate_current

    ! support variables for this <subroutine>
    integer(INT32) :: counter

    ! STEP.01
    ! read out the number of bound
    ! read out the limit of coordinate
    read(unit=INPUT_UNIT, fmt=*) num_bound_total, coordinate_limit

    ! STEP.02
    ! allocate the arrays
    allocate(coordinate_bound(1:num_bound_total))

    ! STEP.03
    ! read out the coordinate where to bound
    read(unit=INPUT_UNIT, fmt=*) coordinate_bound(1:num_bound_total)

    ! STEP.04
    ! count the number of bound which satisfies the given condition
    coordinate_current = 0_INT32
    counter            = 0_INT32

    do while (coordinate_current .le. coordinate_limit)
      coordinate_current = coordinate_current + coordinate_bound(counter+1)
      counter = counter + 1
    end do

    ! STEP.04
    ! output the result
    write(unit=OUTPUT_UNIT, fmt='(I0)', advance='yes') counter

    ! STEP.END
    return

  end subroutine task_B

end module ABC130


program main

  ! <module>s to import
  use, non_intrinsic :: ABC130

  ! require all variables to be explicitly declared
  implicit none

  call task_B

end program main