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):
import sys
mod = pow(10, 9) + 7
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0: return 1
    elif y == 1	 : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else: return power(x, (y-1)//2)**2 * x % mod
    
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, power(b, mod-2))
def div2(a, b):
    return mul(a, modinv(b))

def modinv(a):
    b, u, v = mod, 1, 0
    while b:
        t = a//b
        a, u = a-t*b, u-t*v
        a, b, u, v = b, a, v, u
    u %= mod
    return u

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r]

NNN = (10**6)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
N, K = map(int, input().split())

r = 0
for i in range(K, N+2):
    s = ((i-1) * i) //2
    s %= mod
    e = N*(N+1)//2
    e -= ((N-i)*(N-i+1)) //2
    e %= mod
    r = (r + e-s+1) % mod
print(r)

Solution (Python):
def sum_n(n,M):
    return n*(n+1)//2 % M

def cmb(n,k,M):
    max_sum,min_sum = sum_n(n,M)-sum_n(n-k,M),sum_n(k-1,M)
    return (max_sum - min_sum + 1) % M

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

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

print(ans)

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

Solution (Python):

import sys

MOD = 1000000007  


def solve(N: int, K: int):
    ans = 0
    for p in range(K,N+2):
        ans += p*(N-p+1) + 1
        ans %= MOD
    print(ans)
    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())

ans = 0
Ns = list(range(N+1))
cumsum = [0]
for i in range(N+1):
    cumsum.append(cumsum[i] + Ns[i])

MOD = 10**9 + 7

for i in range(K, N+2): 
    tmp = cumsum[-1] - cumsum[-i-1] - cumsum[i] + cumsum[0] + 1
    ans += tmp
    ans %= MOD

print(ans)

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

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

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

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

Solution (Python):
n, k = map(int, input().split())
ans = 0
s0 = 0
s = 0

for i in range(k):
    s0 += i
    s += n
    n -= 1
while s - s0 + 1 >= 0:
    ans += s - s0 + 1
    s += n
    n -= 1
    s0 += k
    k += 1
print(ans % (10**9 + 7))

Solution (Python):
n,k = map(int,input().split())
MOD = 10**9+7
ans = 0
def wa(s,e):
  return int((0.5)*e*(e+1) - (0.5)*(e-s)*(e-s+1))
for i in range(k,n+1):
  ans += (wa(i,n) - wa(i,i-1) + 1)%MOD
ans += 1
print(ans%MOD)

Solution (Python):
MOD = 1000000007
NCK_MAX = 510000

fac = [0 for _ in range(NCK_MAX)]; finv = [0 for _ in range(NCK_MAX)]
inv = [0 for _ in range(NCK_MAX)]; facn = [0 for _ in range(NCK_MAX)]

def myPow(x,n,MOD=MOD):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return myPow(x*x%MOD,n//2)
    else:
        return x*myPow(x,n-1)%MOD

def COMinit(n):
    fac[0] = 1; fac[1] = 1
    facn[1] = n
    finv[0] = 1; finv[1]=1
    inv[1]=1
    for i in range(2,NCK_MAX):
        fac[i] = fac[i-1]*i%MOD
        facn[i] = facn[i-1]*(n-i+1)%MOD
        inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
        finv[i] = finv[i-1]*inv[i]%MOD

def modinv(a,MOD=MOD):
    return myPow(a,MOD-2)

def COM(n,k):
    if n<k:
         return 0
    elif n<0 and k<0:
         return 0
    return facn[k] * finv[k]%MOD

def shokou(i):
    return (i*(i-1))//2
def makkou(i,n):
    return ((2*n+1-i)*i)//2

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

ans = 0
li = list(range(n))
for i in range(k,n+2):
    ans = (ans + makkou(i,n)-shokou(i)+1+MOD)%MOD
    

print(ans)

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

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

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

cnt = 0
for k in range(K,N+1+1):
    minsum = k*(k+1)/2 -k
    maxsum = k*(k+1)/2 + (N-k)*(k)

    cnt+=(maxsum-minsum+1)
    cnt=cnt%mods

print(int(cnt))

Solution (Python):
import math
N, K = list(map(int, input().split(' ')))
ret = 0
c = 0
kmax = N*(N+1)//2
for k in range(N+1, K-1, -1):
    kmax = kmax - c
    kmin = (k-1)*k // 2
    ret += kmax - kmin + 1
    if k <= N:
        c += 1
modq = int(1e9) + 7
print(ret % modq)

Solution (Python):
if __name__ == '__main__':
    a,b= map(int,input().split())
    maxnum =0
    minnum =0
    diff = 10**9 +7
    ans = 0

    for i in range(b,a+2):
        max = (i * (2*a+1-i)) / 2
        min = (i* (i - 1) / 2)
        ans += max-min+1
        ans = ans % diff
    print(int(ans))

Solution (Python):
import numpy as np

n, k = map(int, input().split())
ans = 0
mod = 10 ** 9 + 7
arr = np.arange(n+1)
a = np.cumsum(arr)
b = np.cumsum(arr[::-1])

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

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

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

print(ans)

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

for i in range(K):
    mi += i
for i in range(N, N-K, -1):
    ma += i

N2 = K
N3 = N-K

for i in range(1, N-K+2):
    count += ma - mi +1
    count %= mod
    mi +=N2
    N2+=1
    ma +=N3
    N3-=1
    
count += 1
print(count%mod)

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



mod=1000000007
n,k=map(int,input().split())
n+=1
ans=0
l=0
r=0
for i in range(k):
    l+=i
posl=k-1
for i in range(n-k,n):
    r+=i
posr=n-k


while l!=r:
    ans+=r-l+1
    ans%=mod
    posl+=1
    l+=posl
    posr-=1
    r+=posr
print(ans+1)

Solution (Python):
def slove(n, k):
    iter1 = iter(range(n+1))
    iter2 = iter(range(n, -1, -1))

    lower_num = 0
    upper_num = 0
    for _ in range(k):
        lower_num += iter1.__next__()
        upper_num += iter2.__next__()

    ans = len(range(lower_num, upper_num+1))

    for i in range(k, n+1):
        lower_num += iter1.__next__()
        upper_num += iter2.__next__()
        ans += len(range(lower_num, upper_num+1))

    return ans % (10**9 + 7)

if __name__ == "__main__":
    n, k  = [int(i) for i in input().split()]
    print(slove(n, k))

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

sum_min = 0
sum_max = 0

for i in range(1,k):
    if i != 0:   
        sum_min += i-1
    sum_max += n -i + 1
  
for i in range(k,n+2):
    if i != 0:   
        sum_min += i-1
    sum_max += n -i+1
    ans += sum_max - sum_min + 1
 
print(ans%(10**9+7))

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

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

print(r%MOD)

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

m=n+1-k
if m==0:
  print(1)
else:
  ans=1 + m*(6+(m+1)*(3*n-2*m+2))//6
  print(ans%(10**9+7))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

def main():
	n,k = MI()
	a=(10**100) % mo
	dp = [0]*(n+1)
	ans = 0
	for kk in range(k,n+2):
		tmp = (n  - kk + 1)
		ans += (tmp+1) + tmp * (kk-1)
		ans %= mo
	print(ans % mo)

if __name__ == '__main__':
	main()

Solution (Python):
n,k = map(int,input().split())
num  = 0
for select_num in range(k,n+2):
    st = (select_num*(2*0+(select_num - 1)*( 1)))/2
    ed = (select_num*(2*n+(select_num - 1)*(-1)))/2
    sum = ed - st + 1
    num += sum
print(int(num)%1000000007)

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

Solution (Python):
from itertools import accumulate

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

count = 0
a = [x for x in range(n+1)]
MOD = 10 ** 9 + 7

if k > n:
    print(1)
else:
    prefix_sum = list(accumulate(a))
    suffix_sum = list(accumulate(a[::-1]))

    res = [a - b + 1 for a, b in zip(suffix_sum, prefix_sum)]

    
    
    print(sum(res[k-1:]) % MOD)

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

for i in range(1, N+1):
    suma.append(suma[-1] + i)
ans = 0

for i in range(K, N+1):
    ans += ((suma[N] - suma[N-i]) - suma[i-1] + 1) % MOD
ans += 1
print(ans % MOD)

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

ans=0
i=K

while i<=N+1:
      min=i*(i-1)/2
      max=(N+1)*N/2-(N-i+1)*(N-i)/2
      ans+=((max-min)+1)
      i+=1

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

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter


from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n,k = myinput()

mod = 10**9 + 7

ls = list(range(n+1))
ls2 = ls[::-1]


e = sum(ls2[:k-1])


count = 0
for i in range(k,n+2):
    
    s = (i-1)*i//2
    e += ls2[i-1]
    count += e - s + 1
    
print(count%mod)

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

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

print(total)

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

mod = 10 ** 9 + 7
start = 0
end = N
k = 1
ans = 0
while k <= N + 1:
    if k >= K:
        ans += end - start + 1
        ans %= mod
    start = start + k
    end = end + N - k
    k += 1

print(ans)

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

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

print(sum)

Solution (Python):
N,K = map(int,input().split())
start = sum(range(0,K-1))
ans = 0

for i in range(N-K+2):
    n = K+i
    start = n*(n-1)//2
    saidai = (n*(2*N - n + 1)//2)
    ans += saidai - start + 1
print(ans % ((10**9)+7))

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

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

ans = 0
first = sum(list(range(K)))
end = sum(list(range(N, N-K, -1)))
for i in range(K, N+2):
  if i != K:
    first += (i-1)
    end += (N-i+1)
  ans += (end - first + 1)

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

Solution (Python):

import sys

MOD = 1000000007  


def solve(N: int, K: int):
    import itertools
    import numpy as np
    candidate = 0
    ls = list(range(0, N+1))
    ls_cumsum = np.cumsum(ls)
    ls_cumsum_re = np.cumsum(ls[::-1])
    for k in range(K, N+1):
        ls_min, ls_max = ls_cumsum[k-1], ls_cumsum_re[k-1]
        candidate += ls_max - ls_min + 1
    print((candidate+1) % MOD)


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):
import numpy as np

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

sums = np.zeros(n // 2 + n % 2 + 1, dtype=np.uint32)

mod = int(1e9 + 7)

ans = 0

for i in range(len(sums)):
    sums[i] = (((2 * n - i + 1) * i) // 2 - (i * (i - 1)) // 2 + 1) % mod

for i in range(k, n + 2, 1):
    if i > (n // 2 + n % 2):
        ans += sums[n + 2 - (i + 1)]
        ans %= mod
    else:
        ans += sums[i]
        ans %= mod

print(ans)

Solution (Python):
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,K = map(int, readline().split())

    MOD = 10**9 + 7

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

    print(ans)


if __name__ == "__main__":
    main()

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

def C(N, p):
  min_p = p * (p - 1) // 2
  max_p = p * (2 * N - p + 1) // 2
  return max_p - min_p + 1

ans = 0

for i in range(K, N + 2):
  ans += C(N, i) % MOD
  
print(ans % MOD)

Solution (Python):


N,K=map(int,input().split())
MOD=10**9+7
A=[0]
for i in range(1,N+1):
    A.append(A[i-1]+i)
B=[N]
for i in range(N):
    B.append(B[i]+N-(1+i))

ans=0
for i in range(N-K+2):
    k=i+K-1
    ans+=B[k]-A[k]+1
    ans=ans%MOD
print(ans)

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

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

ans %= mod
print(ans)

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

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    ans = 0
    for k in range(K, N + 2):
        minSum = (0 + k - 1) * k // 2
        maxSum = (N - k + 1 + N) * k // 2
        ans += (maxSum - minSum + 1) % mod
        ans %= mod
    print(ans)
    


    return 0

if __name__ == "__main__":
    solve()

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

MINL = [0]
for i in range(1, N+1):
    MINL.append(i + MINL[i-1])

MAXL = [N]
j = 1
for i in range(N-1, -1, -1):
    MAXL.append(i + MAXL[j-1])
    j += 1

ans = 0
for i in range(K-1, N+1):
    ans += MAXL[i] - MINL[i] + 1
    ans = ans % (10 ** 9 + 7)
print(ans)

Solution (Python):
N, K = [int(i) for i in input().split()]
cnt=0
for i in range(K,N+2):
    minval=(i-1)*(i)//2
    maxval=i*(N+1)-i*(i+1)//2
    cnt+=maxval-minval+1
    
print(cnt%1000000007)

Solution (Python):

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

l=10**9+7
ans=0

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

print(ans)

Solution (Python):
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N, K = lr()
    MOD = pow(10, 9)+7
    ans = 0
    for i in range(K, N+2):
        ans += i*(N-i+1)+1
        ans %= MOD
    print(ans)
resolve()

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

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r) //math.factorial(r)

import math
import numpy as np
r=0
n1=n+1
for ii in np.arange(k,n1+1):
    """print(n+1,ii,permutations_count(n1, ii))
    r+=permutations_count(n1, ii)"""
    r+=((2*n1-ii+1)*ii)/2-((ii+1)*ii)/2+1
print(int(r)%(10**9+7))

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

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

nums = [i for i in range(N + 1)]
total = 0


mini = sum(nums[0:K])
maxx = sum(nums[-K:])


for i in range(K, N + 1):
    total += maxx - mini + 1

    index = i + 1
    
    if (i == N):
        break
    else:
        mini += nums[index-1]
        maxx += nums[-index]

total += 1

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


print(ans)

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

    def nkr(x,y):
        low = (y-1)*y // 2
        high = ( x*(x+1) - (x-y)*(x-y+1) ) // 2
        return max(high - low,0) + 1

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

if __name__ == '__main__':
    main()

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

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

ans=0
for k in range(K,N+2):
	i = k*(k-1)//2
	j = (N + (N-k+1))*k//2
	ans += (j-i+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):
    i_sum_min = i * (i - 1) // 2
    i_sum_max = N * i - i_sum_min
    ans += (i_sum_max - i_sum_min) + 1
    ans %= MOD

print(ans)

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

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

for i in range(K, N+2):
    mini = (i-1)*(i)//2 
    maxi = (N-i+1) * i + (i-1)*(i)//2
    
    tmp = maxi - mini + 1
    res = (res+tmp) % MOD

print(res)

Solution (Python):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


def get_nums_n(n):
    return [ int(input()) for _ in range(n)]


def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

MOD = 10**9+7
n,k = get_all_int()

ans = 0

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

    
    b = (n+(n-m+1)) * m // 2
    
    ans += b-a+1

print(ans % MOD)

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

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


def end(b):
    num = 0
    for i in range(n, n-b, -1):
        num += i
    return num

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

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

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

A = [i for i in range(N+1)]
tmp = sum(A[-K:]) - sum(A[:K]) + 1
ans = tmp

for i in range(K+1,N+2):
    tmp += A[-i] - A[i-1]
    ans += tmp
    ans %= MOD
print(ans)

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

MOD = int(1e9) + 7
sum = 0
for i in range(K, N + 2):
    sum += (N - i + 1) * i + 1
    sum %= MOD
    

print(sum)

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

Solution (Python):
list=input().split(" ")
N=int(list[0])
K=int(list[1])

def sum_to_N(start,goal):
    return int((start+goal)*(goal-start+1)/2)

count=0
for i in range(K,N+2):
    count+=sum_to_N(N-i+1,N) - sum_to_N(0,i-1) + 1
    

print(count%1000000007)

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

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

inv2 = pow(2, MOD-2, MOD)
nums = []
for i in range(N+3):
    num = i*(i+1)%MOD*inv2%MOD
    nums.append(num)
nums.append(0)


ans = 0
for i in range(K, N+2):
    mn = nums[i-1]
    mx = nums[N] - nums[N-i]
    ans += mx-mn+1
    ans %= MOD

print(ans)

Solution (Python):
n,k = map(int,input().split())
li = [i for i in range(0,n+1)]


tmp = 0
def exc(n):
    return (n)*(n+1)//2

for i in range(k,n+2):
    
    
    mi = exc(i-1)
    ma = exc(n) - exc(n-i)
    
    tmp += ma - mi + 1
print(tmp%(10**9+7))

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

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

print(count)

Solution (Python):
def main():
    n,k=map(int,input().split())
    ans=0
    maxi=sum(range(n-k+1,n+1))
    mini=sum(range(0,k))
    for i in range(k,n+2):
        tmp=maxi-mini+1
        ans=(ans+tmp)%(1e+9+7)
        maxi+=n-i
        mini+=i
    print(int(ans))
    

if __name__ == '__main__':
    main()

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

ans = 0
for i in range(N+1-K):
    nowk = K+i
    min_k = nowk*(nowk-1)//2
    max_k = (2*N-nowk-1)*nowk//2
    ans += (max_k-min_k+1)%mod
    ans %= mod
print(ans)

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

MOD=10**9+7

sm=0
tmp=0
b=1
for i in range(1,N+2):
    if i!=0:
        b=(b-2*(i-1))%MOD
    else:
        b=1
    
    val=(i*N+b)%MOD
    sm=(sm+val)%MOD
    if i<K:
        tmp=(tmp+val)%MOD


ans=(sm-tmp)%MOD
print(ans%MOD)

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

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

print(ans)

Solution (Python):
N, K = (int(i) for i in input().split())  

mod = 1000000007
ans = 0
for i in range(K, N+2): 
    ans += (i * (N + N - (i-1)) / 2) - (i * (i-1) / 2) + 1
print(int(ans % mod))

Solution (Python):
def d_sum_of_large_numbers(MOD=10**9 + 7):
    N, K = [int(i) for i in input().split()]

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

print(d_sum_of_large_numbers())

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

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

def sum_num(n, k):
    ans = 0
    while k <= n+1:
        
        ans += k*n-k*(k-1)+1
        ans = ans%p
        k += 1
    print(ans)

n, k = [int(i) for i in input().split()]
sum_num(n, k)

Solution (Python):
from math import factorial

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

ans = 0
j = 0
a = N + 2 - K
for i in range(0, N+1):
    n = min(N + 1 - i, a)
    ans -= i * n % M
for i in range(N, 0, -1):
    j = N - i
    n = min(N + 1 - j, a)
    ans += i * n % M
print((ans + N + 2 - K) % M)

Solution (Python):
t=list(map(int,input().split(' ')))
n=t[0] ; k=t[1]
x=0
for i in range(k,n+2):
    p=i*(2*n-(i-1))/2
    q=i*(i-1)/2
    x+=(p-q+1)
print(int(x)%(10**9+7))

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

Solution (Python):

def f(n, k):
    c = 0
    for i in range(k, n + 2):
        d = i*(n - i) + i * (i + 1) // 2 - i * (i - 1) // 2 + 1
        c = (c + d) % int(1e9 + 7)
    return c

print(f(*map(int, input().split())))

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

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

ans = 0
for i in range(n + 1, k - 1, -1):
    ans += i * n - i * (i - 1) + 1
    ans %= p
print(ans)

Solution (Python):
N,K=map(int,input().split())
n=[i for i in range(N+1)]
mod=10**9+7

min_value=[0]*(N+1)
max_value=[0]*(N+1)
min_value[0]=0
max_value[0]=N
for i in range(1,N+1):
  min_value[i]=min_value[i-1]+n[i]
  max_value[i]=max_value[i-1]+n[-(i+1)]

ans=0
for i in range(K-1,N+1):
  ans+=max_value[i]-min_value[i]+1
  ans%=mod
print(ans)

Solution (Python):
from copy import deepcopy
n,k=map(int,input().split())
mod=10**9+7
accum=[0]*(n+1)
for i in range(n):
  accum[i+1]+=accum[i]+i+1
accumrev=deepcopy(accum)
accumrev=accumrev[::-1]+[0]
accum=[0]+accum


ans=0
for i in range(k,n+2):
  ans+=accumrev[0]-accumrev[i]-accum[i]+1
  ans%=mod
print(ans)

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

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

min_ = sum([i for i in range(K)])
max_ = sum([i for i in range(N, N - K, -1)])

right = K - 1
left = N - (K - 1)

cnt = 0
for k in range(K, N + 2):
    cnt += max_ - min_ + 1

    right += 1
    left -= 1

    min_ += right
    max_ += left

print(cnt % MOD)

Solution (Python):
import math
import queue
 
def readInt():
	return int(input())
 
def readInts():
	return list(map(int, input().split()))
 
def readChars():
	return input().split()

x = readInts()
n = x[0]
k = x[1]

def ts(l):
	return int((l*(l-1))/2)

def ts2(l):
	return int(l*(n+n-(l-1))/2)

s = 0

for i in range(k,n+2):
	s += ts2(i)+1-ts(i)

print(s%(1000000007))

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

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

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

ans %= MOD
print(ans)

Solution (Python):

import math



if(__name__ == '__main__'):
    
    n, k = map(int, input().split(" "))

    num = 0
    for pick in range(k, n+2):
        tgt = (pick * (n-pick+1) + 1)
        num += tgt % (10**9 + 7)
        num %= 10**9 + 7
    
    print(num)

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

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

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

lst = [0]*(N+2)
lst[1] = N+1
mi = [0]*(N+2)
ma = [0]*(N+2)
ma[1] = N
for i in range(2,N+2):
    mi[i] = mi[i-1]+i-1
    ma[i] = ma[i-1]+N+1-i
    lst[i] = (ma[i]-mi[i]+1)

print(sum(lst[K::])%mod)

Solution (Python):
from math import ceil
N, K = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 0
n = m = 0
for i in range(1, N + 2):
    n += N + 1 - i
    m += i - 1
    if i >= K:
        ans += n - m + 1
        ans %= mod
print(ans)

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

LOW, HIGH = 0, N
ans = 0

if 1 >= K:
    ans += (HIGH - LOW + 1)

for i in range(2, N + 2):
    LOW += i - 1
    HIGH += N - i + 1
    LOW %= MOD
    HIGH %= MOD
    if i >= K:
        ans += (HIGH - LOW + 1)
        ans %= MOD

print(ans)

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

Solution (Python):

import sys

MOD = 1000000007  


def solve(N: int, K: int):
    sum = 0
    for k in range(K, N + 2):
        sum += k * (N - k + 1) + 1
    
    print(sum % 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()