program sum_of_large_numbers
  implicit none
  integer(8), parameter :: md = 1000000007_8
  integer :: n, k, i
  integer(8) :: x = 0, l = -1, r
  read(*,*) n, k
  r = n
  do i = 1, n+1
    if (i >= k) x = modulo(x+r-l,md)
    l = mod(l+i,md)
    r = mod(r+(n-i),md)
  end do
  write(*,'(i0)') x
end program sum_of_large_numbers