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 (Python):
N,K=map(int,input().split())
mod=10**9+7

ans=0
if K>=N+1:
    ans=1
else:
    for i in range(K,N+2):
        min=int(i*(i-1)/2)
        max=int(i*N-i*(i-1)/2)
        Z=max-min+1
        
        ans+=Z
print(ans%mod)

Solution (Python):
N, K = map(int, input().split())
ans = 0 
for i in range(K,N+2):
    ans += i * (N - i + 1) + 1
print(ans % 1000000007)

Solution (Python):
n, k = map(int, input().split())
ans = 0
max = 0
min = 0
for i in range(0, k):
    min += i
    max += n - i
for i in range(k, n + 2):
    
    ans = (ans + max - min + 1) % (10 ** 9 + 7)
    max += n - i
    min += i

print(ans)

Solution (Python):
N,K= map(int,input().split())
p=10**9+7
q=0
 
def calc(n,k):
  if k==1:
    return n+1
  else:
    maxi = k*n- k*(k-1)//2
    mini=  k*(k-1)//2
    
    return maxi-mini+1
  
ans=0
for i in range(K,N+2):
  ans = ( ans+calc(N,i) )%p
  
print(ans)

Solution (Python):
n,k=map(int,input().split())
mod=pow(10,9)+7
ans=0
for i in range(k,n+2):
    ans+=(i*(n+n-i+1))//2-(i*(i-1))//2+1
    ans%=mod
print(ans)

Solution (Python):
N,K = map(int,input().split())
mod = 10**9+7
def func(a,n):
    if n == 1:
        return a%mod
    elif n%2:
        return (a*func(a,n-1))%mod
    else:
        return ((func(a,n//2))**2)%mod
ans = 0
sum1 = 0
sum2 = 0
for i in range(1,N+2):
    if i == K:
        diff = ans
    sum1 = (sum1 + i-1)%mod
    sum2 = (sum2 + N-i+1)%mod
    ans = (ans + sum2 - sum1 + 1)%mod
print((ans-diff)%mod)

Solution (Python):
n,k = map(int, input().split())
cnt=0
d=1000000007
while k != n+1:
  cnt += (n*k - k*k + k + 1)%d
  k+=1
    
print((cnt+1)%d)

Solution (Python):
N, K = map(int, input().split())
f = lambda x:x*(x+1)//2
print(sum(f(N)-f(N-i)-f(i-1)+1 for i in range(K, N+2))%(10**9+7))

Solution (Python):
N, K = map(int, input().split())
MOD = 10**9+7
f = lambda x:x*(x+1)//2
ans = sum(f(N)-f(N-i)-f(i-1)+1 for i in range(K, N+2))%MOD
print(ans)

Solution (Python):
N, K = map(int, input().split())
ans = 0
MOD = 10**9+7
f = lambda x:x*(x+1)//2
for i in range(K, N+2):
    ans += f(N)-f(N-i)-f(i-1)+1
    ans %= MOD
print(ans)

Solution (Python):
N, K = map(int, input().split())
ans = 0
MOD = 10**9+7
for i in range(K, N+2):
    b = N*(N+1)//2-(N-i)*(N-i+1)//2
    a = (i-1)*i//2
    ans += b-a+1
    ans %= MOD
print(ans)

Solution (Python):
def calc(n, k):
    return (n + n - k + 1) * k // 2


N, K = map(int, input().split())

MOD = 10 ** 9 + 7
print(sum([(calc(N + 1, i) - calc(i, i) + 1) % MOD for i in range(K, N + 2)]) % MOD)

Solution (Python):
N, K = map(int, input().split())
num = list(range(N+1))
ans = 0
S = [0] * (N+1)
for i in range(N+1):
  S[i] = S[i-1] + num[i]
ans = 0
if K == N+1:
  print(1)
  exit()
for j in range(K-1, N):
  ans += S[-1] - S[-j-2] - S[j] + 1
print((ans+1) % (10**9+7))

Solution (Python):
import math
n,k = map(int, input().split())
mod = 10**9 + 7
ans = 0

for i in range(k, n+2):
    max = (i*(n + n-i+1))//2
    min = (i*(i-1))//2
    ans += max - min + 1
    ans %= mod
    
print(ans)

Solution (Python):
N, K = map(int, input().split())
mod = 10**9 + 7
count = 0
for n in range(K, N+2):
  maxSum = (n*(N + N-n+1))//2
  minSum = (n*(n-1))//2
  count += maxSum - minSum + 1
  count %= mod

print(count)

Solution (Python):
L=list(map(int,input().split()))
N=L[0]
K=L[1]
x=int((N-K+2)*((1+N)*(K+N+1)+2)/2-(N+1)*(N+2)*(2*N+3)/6+K*(K-1)*(2*K-1)/6)
print(x%(10**9+7))

Solution (Python):
n, k = map(int, input().split())
mod = 10**9+7
ans = 0

for i in range(k, n+2):
    ans += ((n-i+1)+n)*i//2-(i-1)*i//2+1

print(ans % mod)

Solution (Python):
N, K = map(int, input().split())
ans, mod = 0, 10**9+7
for k in range(K, N+2):
    ans += (N+N-k+1)*k//2-(k-1)*k//2+1
    ans %= mod
print(ans)

Solution (Python):
n,k = map(int,input().split())
if(k >= n+1):
    print(1)
else:
    t = 0
    for i in range(k,n+2):
        d = n - i
        s1 = i * (i - 1) // 2
        s2 = n * (n + 1) // 2 - d * (d + 1) // 2
        t += s2 - s1 + 1
        t %= 10**9+7
    print(t)

Solution (Python):
import math

N, K = map(int, input().split())

out = 0

    

for i in range(K, N+2):
    out += (i * (N - i + 1)) + 1



print(out % (pow(10, 9) + 7))

Solution (Python):
n,k = map(int,input().split())
if(k >= n+1):
    print(1)
else:
    t = 0
    for i in range(k,n+2):
        d = n - i
        s1 = i * (i - 1) // 2
        s2 = n * (n + 1) // 2 - d * (d + 1) // 2
        t += s2 - s1 + 1
        t %= 10**9+7
    print(t)

Solution (Python):
N,K= map(int,input().split())
p=10**9+7
q=0

def calc(n,k):
  if k==1:
    return n+1
  else:
    maxi = k*n- k*(k-1)//2
    mini=  k*(k-1)//2
    
    return maxi-mini+1
  
ans=0
for i in range(K,N+2):
  ans = ( ans+calc(N,i) )%p
  
print(ans)

Solution (Python):
n, k = map(int, input().split(" "))

ans = 0
for i in range(k, n+2):
    min = i * ( 0 + i-1) / 2
    max = i * ( (n+1 - i) + n) / 2
    ans += int(max - min + 1)

print(ans % (10**9 + 7))

Solution (Python):
n, k = map(int, input().split())
mod = 10**9 + 7
sums = [0,n+1]
for i in range(2, n+2):
    score = (sums[i-1] + n-2*(i-1)) % mod
    sums.append(score)
cum_sum = [0]
for i in range(1, len(sums)):
    cum_sum.append(cum_sum[i-1]+sums[i])

print((cum_sum[-1] - cum_sum[k-1])%mod)

Solution (Python):
n,k = map(int,input().split())
mod = 10**9 + 7
ans = 0
for i in range(k,n+2):
    minx = (i*(i-1))//2
    maxx = (i*(2*n-i+1))//2
    ans += (maxx - minx + 1)
print(ans%mod)

Solution (Python):
import itertools

N, K = map(int, input().split())
mod = (10 ** 9 + 7)

def calc(i):
    small = i * (i - 1) //2
    large = i * (2 * N - i + 1) // 2
    return large - small + 1

total = 0
for i in range(K, N+2):
    total += calc(i)
    total %= mod

print(total)

Solution (Python):
n, k = map(int, input().split())

ans = 0

for i in range(k, n+2):
    ans += i*(n - i + 1) + 1


    
print(ans%(10**9+7))

Solution (Python):
N, K = map(int, input().split())

list = list(range(N+1))
t = 10**9+7
result = 0

for i in range(K,N+2):
    result +=  i*(N-i+1) + 1

print(result%t)

Solution (Python):
def main():
    n,k = map(int,input().split())
    mod = 10**9+7
    res = 0
    for i in range(k,n+2):
        tmp = i*(n-i+1)+1
        res = (res+tmp)%mod
    print(res)

if __name__ == '__main__':
    main()

Solution (Python):
N, K = map(int, input().split())

MOD = 10 ** 9 + 7

counter = 0
for k in range(K, N+2):
	counter += (N-k+1) * k + 1
	counter %= MOD

print(counter)

Solution (Python):
import sys
from collections import Counter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

mod=1000000007
n,k=mp()
ans=0
for i in range(k,n+2):
    ans+=((n*(n+1)-(n-i+1)*(n-i)-i*(i-1))//2+1)%mod
print(ans%mod)

Solution (Python):
N,K=map(int,input().split())
ans=0
for i in range(K,N+2):
    saidai=(N+N-i+1)*i//2
    saisyou=(i-1)*i//2
    ans+=saidai-saisyou+1

ans%=10**9+7
print(ans)

Solution (Python):
import itertools
import numpy as np

n, k = map(int, input().split())
l = range(n+1)
T = [0]*(n+1)
T[0] = 0
for i in range(n):
     T[i+1] = T[i] + (i+1)

count = 0
for i in list(range(k,n+1)):
    count = count + (T[n]-T[n-i]) - T[i-1] + 1
count = count + 1
print(count%(10**9+7))

Solution (Python):
N, K = map(int, input().split())
MOD = 10**9 + 7

low = high = 0
ans = 0
for i in range(K, N+2):
  low = i*(i-1)//2  
  high = i*(2*N - i + 1)//2  
  ans += (high - low + 1)  
  ans %= MOD
  
print(ans)

Solution (Python):
def main():
    import sys
    input=sys.stdin.readline
    mod=10**9+7
    n,k=map(int,input().split())
    ans=0
    for x in range(k,n+2):
        ans=(ans+x*(n-x+1)+1)%mod
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
N,K=map(int,input().split())
x=0
while K<=N+1:
    x+=K*N-K**2+K+1
    K+=1
print(x%1000000007)

Solution (Python):
n,k=map(int,input().split())

t=10**9+7
sum=0
for i in range(k,n+2):
    x=(n*i-i*(i-1)+1)%t
    sum+=x

print(sum%t)

Solution (Python):
N, K = [int(a) for a in input().split()]
numbers = list(range(0, N+1))
MOD = 1000000007

ans = 0
for k in range(K, N+2):
    min_ = (numbers[0] + numbers[k-1])*k//2
    max_ = (numbers[(N+1)-k] + numbers[-1])*k//2
    ans = (ans + max_ - min_ + 1) % MOD

print(ans)

Solution (Python):
N,K = list(map(int,input().split()))
ans = 0
for i in range(K,N+2):
    ans += ((((N*2)-i+1)*i//2) - ((i-1)*i//2) +1)
print(ans%(10**9+7))

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,k = map(int,input().split())
for i in range(k,n+2):
  ans += (n+n-i+1)*i//2 - i*(i-1)//2 + 1
  ans %= mod
print(ans)

Solution (Python):
n , k = map(int, input().split())
ans=0
for i in range(k,n+2):
    ans+=n*i-i**2+i+1
    ans%=1000000007
print(ans)

Solution (Python):
n, k = map(int, input().split()) 

res = 0
for m in range(k,n+2):
    sum_min = m*(m-1)//2
    sum_max = m*(2*n-m+1)//2
    cnt = sum_max - sum_min + 1
    res += cnt
    res %= 10**9+7
print(res)

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

n,k = map(int,input().split())
ans = 0
d = [i for i in range(n+1)]
for i in range(k,n+2):
    l = (d[i-1])*(d[i-1]+1)//2
    r = (n)*(n+1)//2 - (n+1 - i-1)*(n+2-i-1)//2
    ans += r-l +1
print(ans%MOD)

Solution (Python):


mod = 10**9 + 7

n,k = map(int,input().split())

cnt = 0
sum_ = sum(range(n + 1))


max_ = sum(range(n - k + 1, n + 1))
min_ = sum(range(k))
for i in range(k, n+2):
    
    cnt += max_ - min_ + 1
    cnt %= mod
    
    
    if n > i + 1:
        max_ +=  n - i
    else:
        max_ = sum_
    min_ += i
print(cnt)

Solution (Python):
mod = 10**9 + 7

n,k = map(int,input().split())
tot = []
cur = 0
for i in range(n+1):
    cur += i
    tot.append(cur)

cnt = 0
for i in range(k, n+2):
    if n > i:
        max_ = tot[n] - tot[n - i]
    else:
        max_ = tot[n]
    min_ = tot[i - 1]
    cnt += max_ - min_ + 1
    cnt %= mod
print(cnt)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,k=map(int,input().split())
    ans=0
    for x in range(k,n+2):
        ans+=(1+((n*(n+1)//2-(n-x)*(n-x+1)//2)/x-(x*(x-1)//2)/x)*x)%(10**9+7)
    print(int(ans)%(10**9+7))

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,k=map(int,input().split())
    ans=0
    for x in range(k,n+2):
        ans+=(1+((n*(n+1)//2-(n-x)*(n-x+1)//2)/x-(x*(x-1)//2)/x)*x)%(10**9+7)
    print(int(ans)%(10**9+7))

if __name__=='__main__':
    main()

Solution (Python):
N,K = map(int,input().split())
n = [i for i in range(N+1)]
M,m = sum(n[-K:]),sum(n[:K])
c = M-m+1
for i in range(K+1,N+2):
  M += n[-i]
  m += n[i-1]
  c += (M-m+1)
print(c%(10**9+7))

Solution (Python):
import numpy as np
import functools
import math
import collections
import scipy
import fractions
import itertools

def solve():
    n, k = map(int, input().split())
    small = 0
    large = 0
    ans = 0
    mod = 10**9+7
    for i in range(0, n+1):
        small += i
        large += n-i
        if i+1 >= k:
            ans = (ans + (large - small + 1)) % mod
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
n,k = map(int,input().split())
a = 1
for i in range(k,n+1):
    a += n*i - i**2 + i + 1
print(a%(10**9+7))

Solution (Python):
n,k = map(int,input().split())
p = (10**9)+7
ans = []
for i in range(k,n+2):
    a = i*(i-1)//2
    b = i*(2*n-i+1)//2
    ans.append(b-a+1)
print(sum(ans)%p)

Solution (Python):
MOD = 10**9+7
n,k = map(int,input().split())

ans =0

for i in range(k,n+2):
    a = i*(i-1)//2
    b = i*(2*n-i+1)//2
    ans += b - a +1

print(ans%MOD)

Solution (Python):
N,K=list(map(int,input().split()))
ans=0
for k in range(K,N+2):
  M=k*N-k*(k-1)//2
  m=k*(k-1)//2
  ans+=M-m+1

print(ans%(10**9+7))

Solution (Python):
n,k=map(int, input().split())
ans=0
for i in range(k,n+2):
  smax=i*((n-i+1)+n)//2
  smin=i*(0+(i-1))//2
  ans+=(smax-smin+1)%(10**9+7)
print(ans%(10**9+7))

Solution (Python):
N, K = map(int, input().split())

r = 0

for k in range(K, N + 2):
    r += (k * (2 * N - k + 1) / 2) - (k * (k - 1) / 2) + 1

print(int(r) % (pow(10, 9) + 7))

Solution (Python):
N,K=map(int,input().split())

mod=10**9+7

ans=0
for k in range(K,N+1):
    n1=k*(k-1)//2
    n2=N*(N+1)//2-(N-k)*(N-k+1)//2
    ans+=n2-n1+1
    ans%=mod

ans+=1
print(ans)

Solution (Python):
def find(N):
    ans = [0]*(N+2)
    pre = [0]*(N+2)
    suf = [0]*(N+2)
    temp = 0
    for i in range(N+1):
        temp += i
        pre[i+1] = temp
    
    for i in range(N+1,0,-1):
        suf[i] = temp
        temp -= (N+1-i)
    
        
    
    
    for i in range(1,N+2):
        ans[i] = suf[i] - pre[i] + 1



    return ans

def find_ans(N,K):
    ans = find(N)
    real_ans = 0
    for i in range(K,N+2):
        real_ans += ans[i]
    return real_ans

N,K = list(map(int,input().strip().split()))
print(find_ans(N,K)%(10**9+7))

Solution (Python):

n, k = input().split()
n = int(n)
k = int(k)

mod = 10**9 + 7

ips = []
for i in range(k,n+2):
    t = i*n - (i-1)*i + 1
    ips.append(t)
print(sum(ips)%mod)

Solution (Python):



import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf

import math

import bisect


def choice(n, k):
    
    
    max_value = ((n - k + 1) + n) * k // 2
    min_value = (0 + (k - 1)) * k // 2
    c = max_value - min_value + 1
    
    
    return c

if __name__ == '__main__':
    n, k = list(map(int, input().split()))
    ans = 0
    for kk in range(k, n + 1 + 1):
        ans += choice(n, kk)
    mod = 10 ** 9 + 7
    print(ans % mod)

Solution (Python):
N,K=map(int,input().split())
answer=0
count=N-K+2
for y in range(K,N+2):
    min=int(y*(0+y-1)/2)
    max=int(y*(N-y+1+N)/2)
    answer+=(max+1-min)
print(answer%(10**9+7))

Solution (Python):
def main():
    n, k = map(int, input().split())

    num = 10*100
    nums = [num + i for i in range(0, n+1)]

    
    total = 0
    for i in range(k, n+2):
        _min = int((nums[0]+nums[i-1])*(nums[i-1]-nums[0]+1)/2)
        _max = int((nums[-i]+nums[-1])*(nums[-1]-nums[-i]+1)/2)

        total += _max - _min + 1

    print(total%(10**9+7))

if __name__ == "__main__":
    main()

Solution (Python):
import itertools
from collections import defaultdict
import collections
mod = 1000000007
n, k = map(int, input().split())

s = [i for i in range(n + 1)]
cumsum = itertools.accumulate(s)
cumsum = list(cumsum)

ans = 0
for i in range(k, n + 1):
    a = cumsum[i - 1] - cumsum[0]
    b = cumsum[n] - cumsum[n - i]
    ans += (b - a + 1) % mod

print((ans + 1) % mod)

Solution (Python):
bg=input().split()
n=int(bg[0])+1
k=int(bg[1])

s=0
for a in range(k,n+1):
  
  max=((n-a)*a)+1
  s+=max
  
print(s%((10**9)+7))

Solution (Python):
N, K = map(int, input().split())

count = 0
for p in range(K, N+2):
    count += p * (N - p + 1) + 1
    
print(count % (10**9 + 7))

Solution (Python):
N, K = map(int, input().split())
mod = 10**9 + 7
ans = 0

for i in range(K, N + 2):
    a = N - i + 1
    n_max = i * (2 * a + i - 1) // 2
    n_min = i * (i - 1) // 2
    ans += n_max - n_min + 1
    ans %= mod

print(ans)

Solution (Python):
import math

N, K = map(int, input().split())
mod = 10**9 + 7
ans = 0

for i in range(K, N + 2):
    a = N - i + 1
    n_max = i * (2 * a + i - 1) // 2
    n_min = i * (i - 1) // 2
    ans += n_max - n_min + 1
    ans %= mod

print(ans)

Solution (Python):
N, K = map(int, input().split())

def sumLR(l, r):
	return (l+r)*(r-l+1)//2

mod = 10**9 + 7
count = 0

for n in range(K, N+2):
	max = sumLR(N-n+1, N)
	min = sumLR(0, n-1)
	count += max - min + 1
	count %= mod
print(count)

Solution (Python):
from sys import stdin


def main():
    n, k = map(int, stdin.readline().split())
    mod = 10 ** 9 + 7

    ans = 0

    for i in range(k, n + 2):
        ans += ((n + 1 - i) * i + 1) % mod

    print(ans % mod)


if __name__ == "__main__":
    main()

Solution (Python):
N, K = map(int, input().split())
ans = 0
MOD = 10 ** 9 + 7
for i in range(K, N + 2):
    min = (i - 1) * i // 2
    max = (2 * N - i + 1) * i // 2
    ans = (ans + max - min + 1) % MOD
print(ans)

Solution (Python):
n, k = map(int, input().split())

ans = 0
for i in range(k, n+2):
    l = (i-1) * i // 2
    h = (n-i+n+1) * i // 2
    ans += h-l+1
        
print(ans % (10**9+7))

Solution (Python):
import numpy as np
from itertools import accumulate
from operator import add, mul

N, K = map(int,input().split())

l = np.arange(N+1)
L = l.tolist()
L = accumulate(L, add)
L = list(L)

rev_L = reversed(l)
rev_L = accumulate(rev_L, add)
rev_L = list(rev_L)
ans = 0

for i in range(N+2-K):
  min_sum = L[K-1+i]
  max_sum = rev_L[K-1+i]
  ans += max_sum - min_sum + 1
  q, mod = divmod(ans, 10**9+7)

print(mod)

Solution (Python):
import itertools

MOD = 10 ** 9 + 7
n, k = map(int, input().split())

def solve(a, b):
    c = (b + a) * (b - a + 1) // 2
    return c

ans = 0
x = n
while x >= k - 1:
    a = solve(0, x)
    b = solve(n - x, n)
    ans += b - a + 1
    ans = ans % MOD
    x -= 1
print(ans)

Solution (Python):


N, K = map(int, input().split())
A = list(range(N+1))
M = 10 ** 9 + 7

mini = sum(A[0:K])
most = sum(A[-K:])

count = most - mini + 1

for i in range(K, N+1):
    most +=  A[-(i+1)]
    mini += A[i]
    count += (most- mini + 1)

print(count % M)

Solution (Python):
mod = 10**9+7
N, K = map(int, input().split())
num = 1
cnt = 0
ans = 0
for i in range(N-K+2):
    ans += num
    ans %= mod
    num += N-cnt
    num %= mod
    cnt += 2
    cnt %= mod
print(ans)

Solution (Python):
N, K = map(int,input().split())
ans = 0
for i in range(K,N+2):
  ans += (2*N+1-i)*i//2-(i-1)*i//2+1
print(ans%(10**9+7))

Solution (Python):
N, K = map(int, input().split())
""""""
ans = 0
for k in range(K, N+2):
    mx = (2*N-k+1)*k/2
    mn = k*(k-1)/2
    ans += (mx-mn+1)
ans = ans %(10**9+7)
print(int(ans))

Solution (Python):
N,K = map(int,input().split())
x = [0]*(N+2)
x[1] = 1
ans = 0
for i in range(2,N+2):
  x[i] = i + x[i-1]
for k in range(K,N+2):
  small = x[k]
  big = x[N+1] - x[N-k+1]
  ans += big - small + 1

print(ans % (10**9 + 7))

Solution (Python):
n,k = map(int,input().split())
total = 0
for i in range(k,n+2):
    m = i*(i-1)//2
    M = i*n-(i*(i-1))//2
    total += M - m + 1
print(total % (10**9 + 7))

Solution (Python):
n,k = map(int, input().split())

mod = 10**9+7
count = 0
for i in range(k, n+2):
  maxsum = (i*(n+n-i+1))//2 
  minsum = (i*(i-1))//2 
  count += maxsum - minsum +1
  count %= mod 
print(count)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,k = LI()
    r = 0
    for i in range(k,n+2):
        t = (0+(i-1)) * i // 2
        u = ((n-i+1)+n) * i // 2
        r += u - t + 1
        r %= mod

    return r


print(main())

Solution (Python):
import math
N, K = map(int,input().split())
ans = 0
for i in range(K,N+2):
  ans = ans +(2*N+3-i)*i/2-i*(i+1)/2+1
print(int(ans%(pow(10,9)+7)))

Solution (Python):
n,k=map(int,input().split())
ans=1
for i in range(k,n+1):
  ans+=(i*(2*n-i+1)-i*(i-1))//2+1
print(ans%(10**9+7))

Solution (Python):
N, K = map(int, input().split())
mod = 10**9 + 7

ans = 0
for k in range(K, N+2):
    ans += N*k-k**2+k+1
    ans %= mod

print(ans)

Solution (Python):
n, k = map(int, input().split())
back = []
forward = []
a = 0
b = 0
for i in range(n + 1):
    a += i
    b += n - i
    forward.append(a)
    back.append(b)
ans = 0
for i in range(k, n + 1):
    ans += back[n - i] - forward[n - i] + 1
ans = (ans + 1) % (10 ** 9 + 7)
print(ans)

Solution (Python):
N,K = map(int, input().split())
mod = 10**9+7

ans = 1
for k in range(K, N+1):
    ans += (2*N-k+1)*k//2 - (k-1)*k//2 + 1
    ans %= mod

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')


def solve():
    n, k = MI()
    B = [i for i in range(n+1)]
    
    mod = 1000_000_007
    def f(l, r):
        return (r + l) * (r - l + 1) // 2

    ans = 0
    for i in range(k, n+2):
        
        _min = f(B[0], B[i-1])
        _max = f(B[n-i+1], B[-1])
        
        ans = (ans + _max - _min + 1) % mod
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
n, k = map(int, input().split())
cnt = 0
MOD = 1000000007
for i in range(k, n+2):
    left = i*(i-1)//2
    right = i*(2*n-i+1)//2
    add = right - left + 1
    cnt = (cnt+add)%MOD
print(cnt)

Solution (Python):
n,k=map(int,input().split())
mod=10**9+7
def f(n):
  mod=10**9+7
  return (n*(n+1)//2)%mod
ans=0
for i in range(k,n+2):
  a=f(n)-f(n-i)-f(i-1)+1
  ans+=(a%mod)
print(ans%mod)

Solution (Python):

import sys

MOD = 1000000007  


def solve(N: int, K: int):
    seq = list(range(N + 1))
    cumsum = [0] * (N + 2)
    for i in range(N+1):
        cumsum[i+1] = cumsum[i] + seq[i]
    c = [0] * (N + 2)
    for i in range(1, N + 2):
        
        c[i] = (cumsum[N+1] - cumsum[N+1-i] - cumsum[i] + 1) % MOD
    print(sum(c[K:]) % MOD)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    solve(N, K)


if __name__ == "__main__":
    main()

Solution (Python):
n, k = map(int, input().split())
cnt = 0
for i in range(k, n+2):
    mini = (i-1) * i // 2
    maxi = (n+n-i+1) * i // 2
    
    cnt += maxi - mini + 1
    cnt %= 10 ** 9 + 7
print(cnt)

Solution (Python):
N,K = list(map(int,input().split()))

ans = 0
for i in range(K,N+2):
  min_j = (i-1)*i//2
  max_j = min_j + (N+1-i)*i
  ans += max_j - min_j +1
  ans = ans % (10**9+7)
print(ans)

Solution (Python):
"""
B=10**100
とすると、Bが非常に大きいので、B,B+1,B+2,,,B+Nの中でK個選んだ時のKが違えば、K個の値の和は必ず違う値になる
従ってKを固定した時、1,2,3,,,Nの中でK個選んだ時の総和が何通りあるかを求めれば良い

SはK以上N+1以下の値をとるものとする
総和を最小にするには、左からS個取れば良い
min L = 0+1+2+...+S-1
総和を最大にするには、右からS個取れば良い
max R = (n-S+1)+...+n
LからRの間の数は全て作れるので、Sを固定したときに取り得る値はR-L+1通りある

左端l、右端rの公差1の等差数列の和は
(l+r)*(r-l+1)/2
"""

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
N,K = [int(i) for i in readline().split()]

ans = 0

def sum(l, r):
    return (l+r)*(r-l+1)//2

for S in range(K, N+2):
    L = sum(0, S-1)
    R = sum(N-S+1, N)
    ans += (R-L+1)%(10**9+7)

ans %= 10**9+7
print(ans)

Solution (Python):
n, k = map(int, input().split())

num_list = list(range(n+1))
num_list2 = num_list[::-1]
MOD = 10**9 + 7

a = sum(num_list[0:k])
b = sum(num_list2[0:k])
ans = b - a + 1

for i in range(k, n+1):
    a += num_list[i]
    b += num_list2[i]
    ans += b - a + 1

print(ans%MOD)

Solution (Python):
n,k=map(int,input().split())
x=[i for i in range(n+1)]
ans=0
xmin=0
xmax=0
for i in range(len(x)):
    xmin+=x[i]
    xmax+=x[-i-1]
    if i>=k-1:
        ans+=xmax-xmin+1


print(ans%(10**9+7))

Solution (Python):
import math
import itertools

N, K = map(int, input().strip().split())

all_combination = 0
for num in range(K, N + 2): 
    min = (0 + num - 1) * num / 2
    max = (N - (num - 1) + N) * num / 2
    possiblility = (int(max) - int(min) + 1)
    all_combination += possiblility

print(all_combination % (1000000007))

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
from math import sqrt, ceil, floor
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  
def Is(): return map(int, input().split())  
def LI(): return list(map(int, input().split()))  
def TI(): return tuple(map(int, input().split()))  
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  
def LS(): return list(input())  
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

N, K = Is()

ans = 0
for i in range(K, N+2):
    minsum = int((0+i-1)*i/2)
    maxsum = int((N-i+1+N)*i/2)
    ans += maxsum - minsum + 1

print(ans % MOD)

Solution (Python):
def main():
  mod = 10**9 + 7
  n, k = map(int, input().split(' '))
  A = list(range(n+1))
  A_rev = A[::-1]
  cumsum_A = [0]
  cumsum_A_rev = [0]
  for i in range(len(A)):
    cumsum_A.append(A[i]+cumsum_A[i])
    cumsum_A_rev.append(A_rev[i]+cumsum_A_rev[i])
  ans = 0
  
  for i in range(k, n+2):
    tmp_min = cumsum_A[i]
    tmp_max = cumsum_A_rev[i]
    ans += (tmp_max - tmp_min + 1)
  print(ans%mod)
    

if __name__ == '__main__':
  main()

Solution (Python):
N, K  = map(int, input().split())

ans = 0
for i in range(K, N+2):
    minN = (i-1) * i //2
    maxN = (2*N-i+1) * i //2
    ans += (maxN - minN + 1) % (pow(10,9)+7)

print(ans % (pow(10,9)+7))

Solution (Python):


N, K = map(int, input().split())

cnt = 0
for i in range(K, N + 2):
    mn = i * (i - 1) // 2
    mx = i * (N + (N - i + 1)) // 2
    cnt += mx - mn + 1

print(cnt % ((10 ** 9) + 7))

Solution (Python):
MOD = 10 ** 9 + 7

n, k = map(int, input().split())
res = 0

for i in range(k, n + 2):
    res += i * (n - i + 1) + 1
    res %= MOD

print(res)

Solution (Python):
N,K = map(int,input().split())
mod = 10**9+7
sum_min = 0
sum_max = 0
diff = 0
while K != N+2:
    sum_min = 1/2*K*(K-1)
    sum_max = 1/2*K*(2*N-K+1)
    diff += sum_max - sum_min+1
    K+= 1
diff = diff % mod
print(int(diff))

Solution (Python):

N, K = map(int,(input().split()))

MOD = 10**9+7


ans = 0
for n in range(K, N+2):
    max_ = n * (N-n+1 + N) // 2
    min_ = n * (0 + n-1) // 2
    
    ans += max_ - (min_ -1)

print(ans % MOD)

Solution (Python):
n,k=map(int,input().split())
ans=0
for i in range(k,n+2):
    mini=i*(i-1)//2
    maxi=mini+i*(n-i+1)
    ans+=int(maxi-mini+1)

print(ans%(10**9+7))

Solution (Python):
MOD = 10 ** 9 + 7
n, k = map(int, input().split())

def calc(a):
    smallest = a * (a-1) // 2
    largest = smallest + a * (n-a+1)
    return largest - smallest + 1


ans = 0
for a in range(k, n+2):
    ans += calc(a)
    ans %= MOD

print(ans)

Solution (Python):
n,k=map(int,input().split())
ans=0
for i in range(k,n+2):
    a=0.5*i*(i-1)
    b=0.5*n*(n+1)-0.5*(n-i)*(n-i+1)
    ans+=int(b-a+1)


print(ans%(10**9+7))

Solution (Python):
N,K = map(int, input().split())
min_num = 0
max_num = 0
for i in range(K):
    min_num += i
    max_num += N - i
ans = max_num - min_num + 1
for i in range(K, N+1):
    min_num += i
    max_num += N - i
    ans += max_num - min_num + 1
print(ans%(10**9 + 7))

Solution (Python):
N, K = map(int, input().split())

A = list(range(N+1))
ans = 1
left = A[:K]
right = A[-K:]
nextleft = left[-1]
nextright = right[0]
left = sum(A[:K])
right = sum(A[-K:])
for i in range(K, N+1):
    ans += right - left + 1
    nextleft += 1
    nextright -= 1
    left += nextleft
    right += nextright
print(ans%(10**9+7))

Solution (Python):

import itertools
n, k = map(int, input().split())
max_num = min_num = 0

for i in range(k):
    max_num += n - i
    min_num += i
ans = max_num - min_num + 1

for i in range(k, n + 1):
    max_num += n - i
    min_num += i
    ans += max_num - min_num + 1
print(ans % (10 ** 9 + 7))

Solution (Python):
n, k = map(int, input().split())

mod_num = 10**9 + 7
first = [i for i in range(n+1)]
last = [i for i in range(n, -1, -1)]
for i in range(1, n+1):
    first[i] += first[i-1]
    last[i] += last[i-1]

result = 0
for i in range(k-1, n+1):
    result += (last[i] - first[i] + 1)
print(result%mod_num)

Solution (Python):
N,K = map(int, input().split())
min_num = 0
max_num = 0
for i in range(K):
    min_num += i
    max_num += N - i
ans = max_num - min_num + 1
for i in range(K, N+1):
    min_num += i
    max_num += N - i
    ans += max_num - min_num + 1
print(ans%(10**9 + 7))

Solution (Python):
n, k = map(int, input().split())

mod = 10 ** 9 + 7

total = 0
for num in range (k, n + 1):
    first = num * (num - 1) // 2 
    last = (2 * n - num + 1) * num // 2 
    add = last - first + 1 
    total = (total + add) % mod

print(total + 1)

Solution (Python):
import sys
read = sys.stdin.readline
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 10 ** 9 + 7

N, K = map(int, read().split())

k = np.arange(K, N + 2, dtype=np.int64)
low = (k - 1) * k // 2
high = N * k - low
cnt = high - low + 1
print(cnt.sum() % MOD)

Solution (Python):



N, K = map(int, input().split())


mae_list = [i for i in range(N+1)]
ushiro_list = [i for i in range(N, -1, -1)]
ans = 0
MOD = 10**9 + 7


for i in range(1, N+1):
    mae_list[i] += mae_list[i-1]
    ushiro_list[i] += ushiro_list[i-1]

for k in range(K-1, N+1):
    ans += (ushiro_list[k] - mae_list[k] + 1)%MOD


print(ans%MOD)

Solution (Python):
n, k = map(int, input().split())

mod = 10 ** 9 + 7

ans = 0
for i in range(k, n + 2):
    
    min = i * (0 + (i - 1)) // 2
    max = i * ((n - (i - 1)) + n)  // 2
    ans += (max - min) + 1
    ans %= mod
    
print(ans)