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):

MOD = 10 ** 9 + 7

def main():
    for _ in inputt(1):
        n, k  = inputi()
        t = 0
        for z in range(k, n + 2):
            t = (t + z * (n + 1 - z) + 1) % MOD
        print(t)







from math import *
from heapq import *
from itertools import *
from functools import reduce, lru_cache, partial
from collections import Counter, defaultdict
import re, copy, operator, cmath
import sys, io, os, builtins
sys.setrecursionlimit(1000)






BUFSIZE = 8192
class FastIO(io.IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = io.BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(io.IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
    sys.stdout.write(kwargs.pop("split", " ").join(map(str, args)))
    sys.stdout.write(kwargs.pop("end", "\n"))
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip()
inputt = lambda t = 0: range(t) if t else range(int(input()))
inputs = lambda: input().split()
inputi = lambda: map(int, inputs())
inputl = lambda t = 0, k = inputi: map(list, (k() for _ in range(t))) if t else list(k())






def len(a):
    if isinstance(a, range):
        return -((a.start - a.stop) // a.step)
    return builtins.len(a)
def bisect_left(a, x, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    while lo < hi:
        mid = (lo + hi) // 2
        if key(a[mid]) < x: lo = mid + 1
        else: hi = mid
    return lo
def bisect_right(a, x, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    while lo < hi:
        mid = (lo + hi) // 2
        if x < key(a[mid]): hi = mid
        else: lo = mid + 1
    return lo
def insort_left(a, x, key = None, lo = 0, hi = None):
    lo = bisect_left(a, x, key, lo, hi)
    a.insert(lo, x)
def insort_right(a, x, key = None, lo = 0, hi = None):
    lo = bisect_right(a, x, key, lo, hi)
    a.insert(lo, x)
do_nothing = lambda x: x
bisect = bisect_right
insort = insort_right
def index(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    i = bisect_left(a, x, key, lo, hi)
    if lo <= i < hi and key(a[i]) == x: return a[i]
    if default != None: return default
    raise ValueError
def find_lt(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_left(a, x, key, lo, hi)
    if lo < i <= hi: return a[i - 1]
    if default != None: return default
    raise ValueError
def find_le(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_right(a, x, key, lo, hi)
    if lo < i <= hi: return a[i - 1]
    if default != None: return default
    raise ValueError
def find_gt(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_right(a, x, key, lo, hi)
    if lo <= i < hi: return a[i]
    if default != None: return default
    raise ValueError
def find_ge(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_left(a, x, key, lo, hi)
    if lo <= i < hi: return a[i]
    if default != None: return default
    raise ValueError





class Tree:
    def __init__(n):
        self._n = n
        self._conn = [[] for _ in range(n)]
        self._list = [0] * n
    def connect(a, b):
        pass





class Sieve:
    def __init__(self):
        self._n = 6
        self._list = [2, 3, 5, 7, 11, 13]
    def extend(self, n):
        pass


sieve = Sieve()
def isprime(n):
    pass
def prime(n):
    pass
def factorint(n):
    factordict = defaultdict(int)
    for i in sieve:
        if n <= i * i:
            break
        while not n % i:
            factordict[i] += 1
            n //= i
    if n != 1:
        factordict[n] += 1
    return factordict





if __name__ == "__main__":
    main()

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


def solve(n, k):
    cum_left = [0] * (n + 2)
    cum_right = [0] * (n + 2)
    for i in range(n + 1):
        cum_left[i + 1] = cum_left[i] + i
        cum_right[i + 1] = cum_right[i] + n - i
    
    res = 0
    for i in range(k, n + 2):
        res += cum_right[i] - cum_left[i] + 1
        res %= MOD
    return res


def main():
    n, k = map(int, input().split())
    res = solve(n, k)
    print(res)


def test():
    assert solve(3, 2) == 10
    assert solve(200000, 200001) == 1
    assert solve(141421, 35623) == 220280457


if __name__ == "__main__":
    test()
    main()

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

    ans = 0
    sumN = (N * (N+1)) // 2
    for k in range(K, N+2):
        mink = (k * (k-1)) // 2
        maxk = sumN - ((N-k) * (N-k+1)) // 2
        
        ans = (ans + maxk - mink + 1) % MOD
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n, k = (int(x) for x in input().split())

mod = 1000000007

count = 0

for i in range(k, n+2):
    sum_i = i * (i-1) /2
    count_i = i*n - 2*sum_i + 1
    count+=count_i
    count%=mod
print(int(count))

Solution (Python):
def Count(N,i):
    return i*N+1-(i*(i-1))
N, K = map(int,input().split())
sumpat=0
bignum = pow(10,9)+7
for i in range(K,N+2):
    
    sumpat+= Count(N,i)%bignum
print(sumpat%bignum)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,k = LI()
ans = 0
tmp = n*(n-1)//2
l = k*(k-1)//2
r = ((n-k+1)+n)*k//2
tmp = n-k
tmp2 = k
for i in range(k,n+2):
    ans += r-l+1
    ans %= mod
    l += tmp2
    r += tmp
    tmp2 += 1
    tmp -= 1
print(ans)

Solution (Python):
n, k = map(int, input().split())
m = n+1
s = 0
mod = 10**9 + 7
while m >= k:
    s += m * (n-m+1) + 1
    s = s % mod
    m -= 1
print(s)

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

res = 0
P = 10 ** 9 + 7
for i in range(K, N + 2):
    head = i * (i - 1) // 2
    tail = i * (2*N - i + 1) // 2
    res += tail - head + 1
    res %= P
print(res)

Solution (Python):
def main():
    import sys
    import numpy as np
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    N, K = [int(x) for x in input().strip().split()]
    NN = np.array([n for n in range(N+1)], dtype=int)
    Ncumsum = NN.cumsum()
    Nrev_cumsum = NN[::-1].cumsum()
    ans = 0
    MOD = 10 ** 9 + 7
    for k in range(K-1, N+1):
        ans += Nrev_cumsum[k] - Ncumsum[k] + 1
        ans %= MOD

    print(ans)

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):
    ans += i*(n-i+1)+1
    ans = ans%mod
print(ans)

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

mod=10**9+7
A=[0]*(N+1)

for i in range(N+1):
    if i==0:
        A[0]=N+1
    else:
        A[i]=A[i-1]+(N-2*i)
        A[i]%=mod

s=0
for i in range(K-1,N+1):
    s+=A[i]
    s%=mod

print(s)

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

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

print(ans)

Solution (Python):
import sys
from itertools import accumulate
MOD = 10 ** 9 + 7


n, k = map(int, sys.stdin.readline().split())

def main():
    a = range(n + 1)
    sl = list(accumulate(a))
    sr = list(accumulate(a[::-1]))

    res = 0
    for i in range(k, n + 2):
        res += sr[i-1] - sl[i-1] + 1
        res %= MOD
    print(res)



    
    

if __name__ == '__main__':
    main()

Solution (Python):
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left 
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

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

dum = list(range(N+1))

cnt = 0
minv = sum(dum[:K])
maxv = sum(dum[-K:])
for i in range(K, N+2):
    cnt += maxv-minv+1
    if cnt > MOD:
        cnt %= MOD
    minv += i
    maxv += N-i
print(cnt)

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

mod = 10**9 + 7


def f(k):
    min_r = k * (k-1) // 2
    max_r = (n + n+1-k) * k // 2
    return max_r - min_r + 1

ans = 0
for i in range(k, n+2):
    ans += f(i)
    ans %= mod
print(ans)

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

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

Solution (Python):
MOD = 1000000007
lim = 10 ** 4+1
fac = [0] * lim
finv = [0] * lim
inv = [0] * lim

class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)
    def __int__(self):
        return self.x

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __mod__(self, other):
        return (
            ModInt(
                other.x
            ) if isinstance(other, ModInt) else
            self.x
        )

    def __pow__(self, other):
        return (
            ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x) if isinstance(other, ModInt) else
            ModInt(other - self.x)
        )

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )
    
    def __iadd__(self,other):
        self.x += other.x if isinstance(other, ModInt) else other
        self.x %= MOD
        return self

    def __isub__(self,other):
        self.x += ModInt(MOD - other.x) if isinstance(other, ModInt) else ModInt(MOD - other)
        return self

    def __imul__(self, other):
        self.x *= other.x if isinstance(other, ModInt) else other
        self.x %= MOD
        return self
    
    def __ifloordiv__(self, other):
        self.x *= pow(int(other), MOD - 2, MOD)
        return self
    
    def factorical(self,n):
        tmp = ModInt(1)
        for i in range(n):
            tmp *= (i+1)
        return tmp
    
    
    def modinv(self,a,m=MOD):
        b = m
        u = 1
        v = 0
        while(b):
            t = a//b
            a -= t * b
            a,b = b,a
            u -= t * v
            u,v = v,u
        return ModInt(u)

    def comb(self,n,r):
        n = int(n)
        r = int(r)
        if r > n or n < 0 or r < 0:
            return 0
        m = n+1
        nterms = min(r, n-r)
        numerator = ModInt(1)
        denominator = ModInt(1)
        for j in range(1, nterms + 1):
            numerator *= m - j
            denominator *= j
        return numerator * self.modinv(denominator.x)

def COMinit():
    fac[0] = ModInt(1)
    fac[1] = ModInt(1)
    finv[0] = ModInt(1)
    finv[1] = ModInt(1)
    inv[1] = ModInt(1)
    for i in range(2,lim):
        fac[i] = ModInt(fac[i - 1] * i)
        inv[i] = ModInt(MOD - inv[MOD%i] * (MOD // i))
        finv[i] = ModInt(finv[i - 1] * inv[i])

def cmb(n,k) -> ModInt:
    if int(n) < int(k):
        return ModInt(0)
    if int(n) < 0 or int(k) < 0:
        return ModInt(0)
    if fac[0] == 0:
        COMinit()
    tmp = ModInt(finv[int(k)] * finv[int(n - k)])
    tmp *= fac[int(n)]
    return tmp


        
if __name__ == "__main__":
    n,k = map(int,input().split())
    ans = ModInt(0)
    for i in range(k,n+2):
        mini = i*(i-1)//2
        maxi = (n+n-i+1)*i//2
        ans += maxi-mini+1
    print(ans)

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

MOD=10**9+7

def sum_l(a,b):
    return (b-a+1)*(a+b)//2 %MOD

count=0
for i in range(k,n+1):
    min_i=sum_l(0,i-1)
    max_i=sum_l(n-i+1,n)
    count+=(max_i-min_i+1)%MOD

print((count+1)%MOD)

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

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

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N, K = MI()

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

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

cnt = 0
mod = 10 ** 9 + 7

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

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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, input().split())
lst = list(range(N + 1))

MOD = 10 ** 9 + 7

small = 0
for i in range(K-1):
    small += lst[i]

big = 0
for i in range(1, K):
    big += lst[-i]

ans = 0
for i in range(K, N + 2):
    small += lst[i - 1]
    big += lst[-i]

    ans += big - small + 1
    ans %= 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):
    x = (i - 1) * i // 2
    y = (2 * n - i + 1) * i // 2
    ans = (ans + y - x + 1) % mod

print(ans)

Solution (Python):
import math
import operator as op
from functools import reduce

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer / denom
"""
int(input())
map(int,input().split())
list(map(int,input().split()))
"""


            
       

t=1
for term in range(1,t+1):
    n,k=map(int,input().split())
    A=[i for i in range(n+1)]
    B=[0]
    for i in range(1,n+2):
        B.append(B[i-1]+A[i-1])
    ans=0
    while(k!=n+2):
        minsum=B[k]
        maxsum=B[-1]-B[-k-1]
        
        ans=(ans+maxsum-minsum+1)%(int(1e9+7))
        k+=1
    print(ans)

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

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

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

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

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

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

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

Solution (Python):
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq

n, k = map(int, sys.stdin.readline().split())



x = 0
y = 0
for i in range(1, k):
    x += i-1
    y += n-i+1

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


print(ans)

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)*i+1
    ans %= mod
print(ans)

Solution (Python):
import sys,math,copy,queue,itertools,bisect
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**18
MOD = 10**9 + 7
DD = ((1,0),(0,1),(-1,0),(0,-1))
N,K = LI()
ans = 0
for i in range(K,N+2):
    ans = (ans + (N*i - (i-1) * i // 2) - i*(i-1) // 2 +1) % MOD
print (ans)

Solution (Python):

import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

MOD = 1000000007

def mod_add(a, b):
  return (a+b)%MOD

def mod_sub(a, b):
  return (a+MOD-b)%MOD

def mod_mul(a, b):
  return a*b%MOD


def extgcd(a,b):
    r = (1,0,a)
    w = (0,1,b)
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return (w[0],w[1])

def mod_inv(a):
    x,_  = extgcd(a, MOD)
    return (MOD+x%MOD)%MOD

def mod_div(a, b):
    return a*mod_inv(b)%MOD

def mod_pow(a, b):
    res = 1
    while b > 0:
        if b & 1:
            res = res * a % MOD
        a = a * a % MOD
        b >>= 1
    return res

MAX = 510000

fac  = [0]*MAX
finv = [0]*MAX
inv  = [0]*MAX

def cominit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;

def mod_com(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;



n,k= l_in()
res = 0

m=0
l=0
for i in range(1, k):
    m += n-i+1
    l += i-1


for i in range(k,n+2):
    m += n-i+1
    l += i-1

    res = mod_add(res, m-l+1)

print(res)

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

c2 = [0] * (n + 1)
c2[n] = a[n]
for i in range(n - 1, -1, -1):
    c2[i] = c2[i + 1] + a[i]
c2.reverse()

ans = 0
for i in range(k - 1, n + 1):
    ans += c2[i] - c1[i] + 1
print(ans % 1000000007)

Solution (Python):

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

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

ans = 0
for t in range(k, n+2):
    mini = t * (t-1) // 2 % mod
    residue = n - t + 1
    maxim = mini + t * residue
    maxim %= mod
    count = maxim - mini + 1
    count %= mod
    ans += count
    ans %= mod

print(ans)

Solution (Python):
N, K = map(int, input().split())
box = [n for n in range(N+1)]
MOD = int(1e9) + 7
ans = 0


bubu = []
bubu.append(box[0])
for el in range(N+1):
    if el == 0:
        continue
    else:
        bubu.append(bubu[el - 1] + box[el])

rbubu = []
rbubu.append(box[-1])
for el in reversed(range(N+1)):
    if el == N:
        continue
    else:
        rbubu.append(rbubu[-1] + box[el])

for i in range(K, N+2):
    temp = (rbubu[i-1] - bubu[i-1] + 1) % MOD
    ans += temp
    ans = ans % MOD

print(ans)

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

Solution (Python):
import sys, math
MOD = 10**9+7
n, k = map(int, sys.stdin.readline().split())
res = 0
for kk in range(k, n+2):
    mm = (kk-1)*kk // 2
    MM = (n-kk + n + 1) * kk // 2
    
    res = (res + (MM-mm+1)) % (MOD)
print(res)

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

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

Solution (Python):
M = 10**9 + 7
n, k = [int(c) for c in input().split()]
out = 0
for kk in range(k, n+2):
    mm = kk * (kk-1) / 2
    MM = kk * (2*n - kk +1) / 2
    out += (MM - mm + 1)
    out %= M
print(int(out % M))

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

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

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

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

print(total)

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

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

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

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

m,M=0,N
ans=0

if K==1:
    ans+=N+1


for i in range(2,N+2):
    m+=(i-1)
    M+=N-(i-1)
    
    if i<K:
        continue
    else:
        ans+=M-m+1
        ans%=MOD

print(ans)

Solution (Python):
from sys import stdin
input = stdin.readline

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

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

print(cnt)

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

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

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

print(ans)

Solution (Python):
N,K = map(int,(input().split()))
MOD = 10**9+7
l = list(range(N+1))
s = [0]*(N+1)
s[0] = l[0]
for i in range(1,N+1):
    s[i] = s[i-1] + l[i]

sr = [0]*(N+1)
sr[0] = l[N]
for i in range(1,N+1):
    sr[i] = sr[i-1] + l[N-i]

c = 0
for i in range(K,N+2):
    c += sr[i-1]-s[i-1] +1
    c %= MOD
print(c)

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

Solution (Python):

import sys
input = sys.stdin.readline





def main():
    n, k = map(int, input().split())
    ans = 0
    for i in range(k,n+2):
        ans += number(i,n) 
    print(ans%(10**9+7))

def number(i,n):
    minn = int((0 + i - 1)*i/2)
    maxn = int(((n-i+1)+n)*i/2)
    return maxn - minn + 1
if __name__ == '__main__':
    main()

Solution (Python):







def main():
    solve()


def solve():
    N, K = map(int, input().split())

    total = 0
    for i in range(K, N+1):
        minn = (i-1) * i // 2
        maxn = (N * (N+1) // 2) - ((N-i) * (N-i+1) // 2)
        total += maxn - minn + 1
        total %= 10**9 + 7

    total += 1

    print(total)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input=sys.stdin.readline

















mod = 10 ** 9 + 7
s = 0
N,K = map(int,input().split())
for i in range(K,N+2):
    Min = i*(i+1)/2
    Max = i*(2*N+3-i)/2
    s += Max - Min +1
    s = s%mod
s = int(s)
print(s)

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

ans = 0
for i in range(k, n + 2):
    t1 = (i - 1) * i // 2
    t2 = n * (n + 1) // 2 - (n - i) * (n - i + 1) // 2
    ans += t2 - t1 + 1
    ans %= MOD
print(ans)

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

ans = 0

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

print(ans % MOD)

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

ans = 0
for i in range(k,n+2):
  mn = (i-1)*i//2
  mx = (2*n-(i-1))*i//2
  ans += mx-mn+1
  ans %= MOD
print(ans)

Solution (Python):
N, K = map(int, (input().split()))
MOD = 10**9+7
m, M = sum(list(range(K))), sum(list(range(N, N-K, -1)))
ans = (M - m + 1) % MOD

for i in range(K, N+1):
    m += i
    M += N-i
    ans = (ans + (M - m + 1) % MOD ) % MOD
print(ans)

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

Solution (Python):
N,K=[int(s) for s in input().split()]
MOD=10**9+7
a=N-K+2
a+=(N+1)*(N*(N+1)-K*(K-1))//2
a-=N*(N+1)*(2*N+1)//6
a+=K*(K-1)*(2*K-1)//6
print(a%MOD)

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

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

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

def ca(n):
    mi = n*(n+1)//2 %mod
    ma = ((N+1+N+1-n+1)*n//2) %mod
    return ma- mi +1
for k in range(K,N+2):
    ans += ca(k)
    ans %mod

print(ans%mod)

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

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

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

print(int(ans)%mod)

Solution (Python):
from itertools import accumulate

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

a = [0] + list(accumulate([i for i in range(n+1)]))

ans = 0
for i in range(k,n+2):
    ans += (a[n+1]-a[n+1-i]) - (a[i]) + 1

print(ans%mod)

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

Solution (Python):
import sys
input = sys.stdin.readline
mod = 10**9+7
def main():
    N,K = map(int,input().split())
    ans = 1
    for k in range(K,N+1):
        upper = k*(N+N-k+1)//2
        lower = k*(k-1)//2
        ans += (upper-lower+1)%mod
        ans %= mod
    print(ans)
if __name__ == "__main__":
    main()

Solution (Python):
M = 1000000007

N, K = [int(s) for s in input().split()]

def f(k):
    l = k * (k - 1) / 2
    r = (2 * N - k + 1) * k // 2
    return r - l + 1

s = 0
for k in range(K, N+2):
    s = (s + f(k)) % M

print(int(s))

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

Solution (Python):
def main():
    N, K = map(int, input().split())
    mi, ma = 0, 0
    for i in range(K - 1):
        mi += i
        ma += N - i
    r = 0
    for i in range(K - 1, N + 1):
        mi += i
        ma += N - i
        r += ma - mi + 1

    return r % (10 ** 9 + 7)

print(main())

Solution (Python):


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

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

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

n, k = [int(x) for x in input().split()]
a = [int(x) for x in range(n + 1)]
a_rev = a[::-1]
mod = 10**9 + 7

left = sum(a[:k])
right = sum(a_rev[:k])

ans = right - left + 1

for i in range(k, n + 2):
    if i > n:
        break
    left += a[i]
    right += a_rev[i]
    ans += right - left + 1
    ans %= mod

print(ans)