Problem:
Score : 400 points

Problem Statement

We have N+1 integers: 10^{100}, 10^{100}+1, ..., 10^{100}+N.

We will choose K or more of these integers. Find the number of possible values of the sum of the chosen numbers, modulo (10^9+7).

Constraints

1 \leq N \leq 2\times 10^5

1 \leq K \leq N+1

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the number of possible values of the sum, modulo (10^9+7).

Sample Input 1

3 2

Sample Output 1

10

The sum can take 10 values, as follows:

(10^{100})+(10^{100}+1)=2\times 10^{100}+1

(10^{100})+(10^{100}+2)=2\times 10^{100}+2

(10^{100})+(10^{100}+3)=(10^{100}+1)+(10^{100}+2)=2\times 10^{100}+3

(10^{100}+1)+(10^{100}+3)=2\times 10^{100}+4

(10^{100}+2)+(10^{100}+3)=2\times 10^{100}+5

(10^{100})+(10^{100}+1)+(10^{100}+2)=3\times 10^{100}+3

(10^{100})+(10^{100}+1)+(10^{100}+3)=3\times 10^{100}+4

(10^{100})+(10^{100}+2)+(10^{100}+3)=3\times 10^{100}+5

(10^{100}+1)+(10^{100}+2)+(10^{100}+3)=3\times 10^{100}+6

(10^{100})+(10^{100}+1)+(10^{100}+2)+(10^{100}+3)=4\times 10^{100}+6

Sample Input 2

200000 200001

Sample Output 2

1

We must choose all of the integers, so the sum can take just 1 value.

Sample Input 3

141421 35623

Sample Output 3

220280457

Solution in Rust (1.42.0) (judge verdict: Accepted)

const MAXN: usize = 200010;
const MOD: usize = 1000000007;

struct Comb {
    fact: [usize; MAXN],
    finv: [usize; MAXN],
}
// 階乗・順列・組み合わせ・重複組合せ
// modとmaxnは引数に持たせないことにした(配列の初期化ができない)
impl Comb {
    // これをメンバーに持たせるのは悩みどころさん
    fn p_mod(base: usize, exp: usize) -> usize {
        if exp != 0 {
            if (exp & 1) == 1 {
                Comb::p_mod(base * base % MOD, exp / 2) * (base) % MOD
            } else {
                Comb::p_mod(base * base % MOD, exp / 2)
            }
        } else {
            1
        }
    }

    fn fact_new() -> Self {
        let mut fact: [usize; MAXN] = [0; MAXN];
        fact[0] = 1;
        for i in 1..MAXN {
            fact[i] = (fact[i - 1] * i) % MOD;
        }
        let mut finv: [usize; MAXN] = [0; MAXN];
        finv[MAXN - 1] = Comb::p_mod(fact[MAXN - 1], MOD - 2);
        for i in (0..(MAXN - 1)).rev() {
            finv[i] = (finv[i + 1] * (i + 1)) % MOD;
        }
        Comb {
            fact: fact,
            finv: finv,
        }
    }
    fn nPr(&self, n: usize, r: usize) -> usize {
        if n < r || r == 0 {
            0
        } else {
            self.fact[n] * self.finv[n - r] % MOD
        }
    }
    fn nCr(&self, n: usize, r: usize) -> usize {
        if n < r {
            0
        } else if r == 0 {
            1
        } else {
            self.fact[n] * self.finv[r] % MOD * self.finv[n - r] % MOD
        }
    }
    fn nHr(&self, n: usize, r: usize) -> usize {
        if n == 0 && r == 0 {
            1
        } else {
            self.nCr(n + r - 1, r)
        }
    }
}

fn solve() {
    let (n, k): (usize, usize) = (read::<usize>(), read::<usize>());
    let mut ans = 0;
    let c = Comb::fact_new();
    for i in k..n + 2 {
        ans += n * i - i * (i - 1) + 1;
        ans %= MOD;
    }
    println!("{}", ans);
}

fn main() {
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========