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 C (GCC 9.2.1) (judge verdict: Accepted)

#include<stdio.h>
#define MODN (1000000007)

static inline long mdml(long a,long b){
    long long res = (long long)a * b;
    return res % MODN;
}

static inline long mdsub(long lhs,long rhs){
    long res = lhs - rhs;
    if(res < 0)res += MODN;
    return res;
}

static inline long mdadd(long lhs,long rhs){
    return (lhs + rhs) % MODN;
}

static inline long mdpow(long num,long ind){
    unsigned long cnt = ind;
    long res = 1;  
    while(cnt){
        if(cnt & 1ul)res = mdml(res,num);
        num = mdml(num,num);
        cnt >>= 1;
    }
    return res;
}

static inline long mddiv(long rhs,long lhs){
    return mdml(rhs,mdpow(lhs,MODN - 2));
}

int main(void){
    register int i;
    int n,k;
    scanf("%d %d",&n,&k);
    int kd_sel = n + 2 - k;
    long cnt[kd_sel];
    for(i = 0;i < kd_sel;i++){
        int nsel = k + i;
        cnt[i] = mdadd( mdsub( mddiv( mdml( mdsub( mdml( 2 , n) , nsel-1) , nsel) , 2) , mddiv( mdml(nsel-1 , nsel) , 2)) , 1);
    }
    long ans = 0;
    for(i = 0;i < kd_sel;i++)ans = mdadd(ans,cnt[i]);
    printf("%ld",ans);
}