let m = 1000000007
let ( +^ ) x y = (x + y) mod m
let ( *^ ) x y = (x * y) mod m
let ( -^ ) x y = x +^ (m - y)

let () = Scanf.scanf "%d %d" @@ fun n k ->
  let min = ref 0 in
  let max = ref 0 in
  let ans = ref 0 in
  for i = 0 to n do
    min := i +^ !min;
    max := (n - i) +^ !max;
    if k <= i + 1 then ans := !max -^ !min +^ 1 +^ !ans
  done;
  Printf.printf "%d\n" !ans
