peterverebics/CodeNet_Python_118 huggingface dataset:
import math
n,k = map(int, input().split())

ans = 0
for i in range(n-k+1):
    ans += math.factorial(n+1)//math.factorial(k+i)//math.factorial(n+1-k-i)

print(int(ans))
def answer(N:int,K:int) -> int:
    counter = 0
    for i in range(K,N+2):
        counter += i*(N - K + 1) + 1
    return counter % (10**9 + 7)



def main():
    N,K = map(int,input().split())
    # answer()
    print(answer(N,K))

if __name__ == '__main__':
   main()
n,k=map(int,input().split())
print((n+1)*(k+n+1)*(n+2-k)//2+k*(k-1)*(2*k-1)//6-(n+2)*(n+1)*(2*n+3)//6+n+2-k)
n,k=map(int,input().split())
print(sum(1+i*(n-i+1)for i in range(k,n+2))%(1e9+7))
import math
import itertools

def mathFactorial(a,b):
	return math.factorial(a) // (math.factorial(b) * math.factorial(a-b))

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

myListA =[]
myList =[]

for i in range(0,N+1):
	myListA.append(i)

i = 0
l = 0
while K < N+2:
	for x in itertools.combinations(myListA,K):
		myList.append(sum(x))
	K = K + 1
	i = i + 1
	l = l + len(set(myList))
	myList =[]

print(l % (10^9 +7))
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 = sum(lst[:K-1])
big = sum(lst[-(K-1):])

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

    ans += big - small + 1
    ans %= MOD

print(ans)
N, K = map(int, input().split())
MOD = 10**9 + 7
nac = [0] * (N + 2)
ninv = [0] * (N + 2)
inv = [0] * (N + 2)
nac[0],nac[1] = 1,1
inv[1] = 1
ninv[0],ninv[1] = 1,1
N = N + 1
for i in range(2, N + 1):
    nac[i] = (nac[i-1] * i % MOD)
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD
    ninv[i] = int(ninv[i - 1] * inv[i] % MOD)

ret = 0
for i in range(K,N+1):
    ret += int(nac[N] * (ninv[i] * ninv[N - i] % MOD) % MOD)
print(int(ret))
N,K = map(int,input().split())
sum = 0

for i in range(K,N+2):
    max = (N+(N-(i-1)))*i*(0.5)
    min = (0+(i-1))*i*0.5
    sum += max-min+1

print(sum%(10**9+7))
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)
N,K=map(int,input().split())
a=(N*(N+1)*(N+2)-(K*(K-1)*(3*N-2*K+4)))/6
print(a%(10**9+7))
n,k=map(int,input().split())
count=0
for i in range(n+2):
    if i<k:
        continue
    elif i>=k:
        mini=i*(i-1)//2
        a=n*(n+1)//2
        b=(n-i)*(n-i+1)//2
        maxi=a-b
        total=maxi-mini+1
        count+=total
print(count)
import math

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

#全部選ぶときの和の個数は0+1+2+ ~ +nの1+(n+1)n/2個

#k個は好きな選び方ができる。
#k個以上の数を選ぶときに「絶対に満たせない和の値」を考える。
#その数は10**100 + 10**100+1 + ... + 10*100+k-1 -1 の(k-1)k/2である。

result_before_division = 1+(n+1)*n/2 - (k-1)*k/2

result = result_before_division % (10**9 + 7)

print(int(result))
mod=10**9+7
n,k=map(int,input().split())
ans=(n+1)*( (n+k+1)*(n-k+2)/2 - (n+2)*(2*n+3)/6 )+k*(k-1)*(2*k-1)/6+(n-k+2)
ans=int(ans)%mod
print(ans)
N,K=map(int, input().split())
ko = (N-K+1)*K+1
print('{:.0f}'.format(ko*(ko+1)/2))
n, k = map(int, input().split())
MOD = 1e9+7

s = [0] * (n+2)
s[1] = (n+1)
for i in range(2,n+2):

    s[i] = (s[i-1] + ( i * (n-i+1) + 1 )) % MOD
    if s[i] < 0:
        s[i] %= MOD

print(int(s[n+1] - s[k-1]))
import math

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

#全部選ぶときの和の個数は0+1+2+ ~ +nの1+(n+1)n/2個

#k個は好きな選び方ができる。
#k個以上の数を選ぶときに「絶対に満たせない和の値」を考える。
#その数は10**100 + 10**100+1 + ... + 10*100+k-1 -1 の(k-1)k/2である。

result_before_division = 1+(n+1)*n/2 - (k-1)*k/2

result = result_before_division % (10**9 + 7)

print(result)
N, K = map(int, input("").split(" "))

cnt = 0
for i in range(K, N+2):
  start_idx = 0
  end_idx = 0
  #for j in range(i):
  #  start_idx += j
  start_idx = (i-1) * (i)//2
  
  #for j in range(i):
  #  end_idx += (N-j)
  end_idx = (i)*N - start_idx 
    
  #print( end_idx - start_idx+1)
  cnt += (end_idx - start_idx+1)
  cnt %= (10^9+7)
  
  
print(cnt%(10^9+7))
def main():
    n, k = [int(i) for i in input().split()]
    #smallのバリエーション
    mod = int(10e9 + 7)
    res = 0
    for i in range(k, n+2):
        min_s = int(i*(i-1)/2)
        max_s = int(n*(n+1)/2 - (n-i)*(n-i+1)/2 )
        res += (max_s - min_s + 1) % mod
    print(int(res))

if __name__ == '__main__':
    main()
N,K=map(int,input().split())
print(K*(2*N+1-2*K)/2)
N,K=map(int,input().split())
b=0
c=0
ans=0

for i in range(0,K):
    b+=i
    c+=(N-1-i)
ans=c-b
    
for i in range(K,N+1):
    ans+=(c+i)-(b+(N-i))
    
print(ans%(10**9+7))
n, k = map(int, input().split())

MOD = 1e9+7

def a(m):
    s0 = 1
    s1 = (m * (n+1)) % MOD
    s2 = (m * m) % MOD
    
    return s1 - s2 + s0

s = [0] * (n+2)
for i in range(1,n+2):
    #print(i,a(i))
    s[i] = s[i-1] + a(i)

print(int(s[n+1] - s[k-1]))
n, k = (int(x) for x in input().split())

num = 0
for x in range(k, n + 1):
    minnum = sum(i for i in range(k))
    maxnum = sum (i for i in range(n - k + 1,n + 1))
    num += maxnum - minnum + 1

print(num)
n,k= list(map(int, input().split()))
mod=10**9+7
ans=0
for i in range(k,n+2):
    min=(i-1)*i//2
    max=((n+1)+(n-i+1))*i//2
    ans+=max-min
print(ans % mod)
n,k=map(int,input().split())
def po(a,t,p):
    bi=str(format(t,"b"))
    res=1
    for i in range(len(bi)):
        res=(res*res) %p
        if bi[i]=="1":
          res=(res*a) %p
    return res
print(po(2,n+1,1000000007)-po(2,k-1,1000000007))
n, k = map(int, input().split())
MOD = 1e9+7

a = [0] * (n+2)
s = [0] * (n+2)
a[1] = (n+1)
s[1] = a[1]
for i in range(2,n+2):
    add = ( a[i-1] + n - 2 * (i-1) ) % MOD
    if add < 0:
        add += MOD

    a[i] = add

    add = (s[i-1] + a[i]) % MOD
    if add < 0:
        add += MOD

    s[i] = add

print(int(s[n+1] - s[k-1]))
N,K=map(int,input().split())
N = N+1
a = N - K
ans = 0

MM = 10**9 +7

for i in range(K,K+a):
  start = int( ( (i)*(i-1)/2 ) % MM )
  fin = int( ( (N+(N-1)-i)*(i)/2+1 ) % MM )
  ans = int( ( ans + (fin - start) ) % MM )
  print(fin,start)
if N == K:
  ans = ans + 1
print(ans)
from math import factorial

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

for i in range (k,n+1):
    c1 = factorial(n+1) % mod
    c2 = 1 / factorial(i)
    c3 = 1 / factorial(n+1 - i)
    c = c1 * c2 * c3
    d = n+1 - (i + 1)
    s = s + (c-d) % mod

s = int((s+1) % mod)

print (s)
import itertools
N=10**100
n,k=map(int,input().split())
li=[]
for i in range(n+2):
    li.append(i)
counter=0
for i in itertools.combinations(li,k):
    counter+=1
print(counter)
from operator import mul
from functools import reduce

mod=pow(10,9)+7

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom %mod

a,b=map(int,input().split())

a+=1
ans=0

for i in range(a-b+1):
    ans=(ans+combinations_count(a,b+i))%mod

a-=2

for i in range(a-b+1):
    ans=(ans-combinations_count(a,b+i))%mod
    
print(ans)
def main():
  n, k = map(int, input().split(' '))
  A = list(range(n+2))
  ans = 0
  for i in range(k, n+2):
    print('i', i)
    tmp_min = sum(A[:i])
    tmp_max = sum(A[n+2-i:])
    ans += tmp_max - tmp_min
  print(ans)
    

if __name__ == '__main__':
  main()
N,K = map(int, input().split())

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

print(ans)
N, K = map(int, input().split())
MOD = 10**9 + 7
nac = [0] * (N + 2)
ninv = [0] * (N + 2)
inv = [0] * (N + 2)
nac[0],nac[1] = 1,1
inv[0] = 1
ninv[0],ninv[1] = 1,1

for i in range(2, N + 2):
    nac[i] = (nac[i-1] * i % MOD)
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD
    ninv[i] = int(ninv[i - 1] * inv[i] % MOD)

ret = 0
for i in range(K,N+2):
    ret += (nac[N + 1] / nac[i]/ nac[N+1 - i])
print(int(ret))
N,K = map(int,input().split())

s = int(((N+1)*((N+1)**2 + 5))/6 -((K-1)*((K-1)**2 + 5))/6)

print(s%(10**9 + 7))
NK = list(map(int, input().split()))
N = NK[0]
K = NK[1]

ans=0
for k in range(K,N+2):
    MIN = (k-1)*k/2
    MAX = N*(N+1)/2 - (N-k)*(N-k+1)/2
    ans += (MAX-MIN+1)
    
print(int(ans))
N,K = map(int,input().split())
#N = int(input())
#A = list(map(int,input().split()))
p=list(range(N+1))
c=0
s=sum(p[:K])
S=sum(p[:K])

l=sum(p[len(p)-K:])
L=sum(p[len(p)-K:])
for i in range(K,len(p)):
    s += p[i]
    S += s
    #print(s,S)
    #print(c)
    l += p[len(p)-i-1]
    L += l
#    print(i)
 #   print(l,L)
c = L - S + (N-K+2)
print(c)
n,k=map(int,input().split())

al=[0]*(n+1)
bl=[0]*(n+1)
bl[0]=n
for i in range(1,n+1):
    al[i]=i+al[i-1]
    bl[i]=(n+1-i-1)+bl[i-1]
    
ans=0
for i in range(k,n+2):
    ans+=bl[i-1]-al[i-1]+1
print(ans%(1e9+7))
line=input()
n,k=map(int,line.split())
sums=0
while k!=(n+2):
     if k==1:
          mini=1
     if k>=2:
          mini=(((k)*(k-1))/2)#%((10**9)+7)
     maxi=( (((n+1)*(n)) - ((n+1-k)*(n-k)) )/2  )#%((10**9)+7)
     sums+=(maxi-mini+1)
     sums=sums%((10**9)+7)
     k+=1
print(int(sums))
N, K = map(int, input().split())

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

MOD = 10**9+7

dp = [0] * (n+1)

dp[1] = n+1

for i in range(2, n+1):
    dp[i] = dp[i-1] * (n + 1 - (i-1)) // i

print(sum(dp[k:]) % MOD)
N, K = map(int, input().split())

res = 0
for i in range(K, N+2):
    m = i*(i+1)//2 % 1000000007
    M = i*(2*N+3-i)//2 % 1000000007
    res += (M - m + 1) % 1000000007

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

ans = 0
for x in range(K, N+2, 1):
    a = (x*(x-1)//2)
    b = ((x*(2*N-x+1))//2)
    ans += b-a+1
print(ans)
n,k=map(int,input().split())
A=0
B=0
for i in range(k,n+2):
  A+=((2*n*i)-(i**2)+i)//2+1
  B+=((i**2)-i)//2
print(A-B)
n,k=map(int,input().split())
d=0
for i in range(k,n+2):
    b=i*(i-1)/2
    c=i*(2*n-i+1)/2
    d+=(c-b+1)
print(int(d))
n,k=map(int,input().split())
count=0
for i in range(n+1):
    if i<k:
        continue
    elif i>=k:
        mini=k*(k-1)//2
        a=n*(n+1)//2
        b=(n-k)*(n-k+1)//2
        maxi=a-b
        total=maxi-mini+1
        count+=total
print(count)
n, k = map(int, input().split())
s = [0]
for i in range(1,n+1):
    s.append(s[i-1] + i)

ans = 0
for i in range(k,n+1):
    ans += ((s[n]-s[n-i]) - s[i-1])+ 1
print(ans+1)
N,K=map(int,input().split())
r=0
md=10*9+7
for k in range(K,N+2):
  r += k*(N-k+1)+1  
print(r%md)
mod = 10**9+7
n, k = map(int, input().split())

ans = 0

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

print(ans)
N,K=list(map(int,input().split()))
src=[n for n in range(N+1)]
t=sum(src[-K+1:])
m=sum(src[:K-1])-1
if m < 0:
  m=0
ans=0
for n in range(N+2-K):
  t+=src[-K-n]
  m+=src[K+n-1]
  a=t-m
  ans+=a
print(ans%(10**9+7))
N, K = map(int, input().split())

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

def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact
  
sumn = factorial(N+1)

for i in range(K,N+2):
    S += sumn // factorial(i) // factorial(N - i + 1) - (N+1) // i + 1
  
print(S)
N, K = map(int, input().split())

ans = 0


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

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

MOD = 1e9+7

def a(m):
    return (m * (n+1-m) + 1) % MOD

s = [0] * (n+2)
for i in range(1,n+2):
    #print(i,a(i))
    s[i] = (s[i-1] + a(i)) % MOD

print(int(s[n+1] - s[k-1]))
import numpy as np 

a = input()
N,K = np.array(a.split()).astype(int)

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

res = 0
for i in range(K, N+1+1):
    l = b_sum(0,i-1)
    r = b_sum(N-i+1, N)
    res += r-l+1
    print(r-l+1)
print(res)
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

N, K = mapint_inp()

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

print(ans)
n,k=map(int,input().split())
s=0
for i in range(k,n+1):
	#0+...+i-1
	l=i*(i-1)//2
	#n+(n-1)+...+(n-i+1)
	h=(2*n-i+1)*i//2
	s+=h-l+1
print(s%(10**9+7))
N,K=map(int,input().split())
ans=0
for i in range(K,N+2):
  num=0
  min=(0+(i-1))*i//2
  max=(N+(N-(i-1)))*i//2
  num=max-min+1
  ans+=num

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


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


ans = 0

for i in range(K, N+2):
    l = sub_sum(0, i-1)
    r = sub_sum(N-i+1, N)
    ans += r - l + 1

print(int(ans))
N, K = list(map(int, input().split()))
MOD = 1e9 + 7
ans = 0
for k in range(K, N + 2):
    ans = (ans + k * (2 * N - k + 1) / 2 - (k - 1) * k / 2 + 1) % MOD
print(ans)
N, K = map(int, input().split())
mod = pow(10, 9)+7
Cmin = 0
Cmax = N
ans = 1
for i in range(1, N-K+2):
    Cmin += i
    Cmax += (N-i)
    ans = (ans+Cmax-Cmin+1)

print(ans % mod)
#from scipy.special import comb

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

if K>=N:
  print(1)
else:

  ans = 0
  bunsi = 1
  l_bunsi = []
  bunbo = 1
  l_bunbo = []
  for i in reversed(range(N+2-K, N+2)):
    bunsi *= i
  l_bunsi = i
  for i in range(1,K+1):
    bunbo *= i
  l_bunbo = i

  ans = bunsi//bunbo

  for i in range(K+1, N+1):
    bunsi *= l_bunsi-1
    bunbo *= l_bunbo+1
    ans += bunsi//bunbo%(10**9+7)
  print(ans%(10**9+7))
N,K = map(int,input().split())
print(-(1/3)*N*(N**2 - 3*N - 1) - N*K +(1/3)*(K-1)*(K-2)*(K-3))
N ,K =(int(x) for x in input().split(' '))

s = 0

for a in range(K,N+2) :
  
  SUM1 = sum([x for x in range(0,a)])
  SUM2 = sum([x for x in range(N-a+1, N+1)])
  
  s = s + SUM2 - SUM1 + 1
  
  print(s%10**9+7)
n, k = map(int, input().split())

MOD = 1e9+7

a = [0] * (n+2)
s = [0] * (n+2)
a[1] = (n+1)
s[1] = a[1]
for i in range(2,n+2):
    a[i] = a[i-1] + n - 2 * (i-1)
    s[i] = (s[i-1] + a[i]) % MOD

print(int(s[n+1] - s[k-1]))
N,K=list(map(int,input().split()))
src=[n for n in range(N+1)]
t=sum(src[-K+1:])
m=sum(src[:K-1])-1
ans=0
for n in range(N+2-K):
  t+=src[-K-n]
  m+=src[K+n-1]
  a=t-m
  ans+=a
print(int(ans%(10**9+7)))
mod = 10**9 + 7
def main():
    N,K = map(int,input().split())
    ans = 0
    S = [0]
    for i in range(1,N+1):
        S.append( S[-1] + i)
    for k in range(K,N + 1):
        ans = (ans + S[N] - S[k - 1] + 1)%mod
    print(ans)
    return

if __name__ == "__main__":
    main()
N,K = map(int,input().split())
a = N*(N+1)//2
b = K*(K+1)//2
c = K*(K-1)//2
if N<K:
    print(1)
else:
    print((2*a-b-c+2)%(10**9+7))
N, K = map(int,input().split())
ans = sum([i*N-i*(i-1)+1 for i in range(K,N+2)])
print(ans)
N, K = map(int, input().split())
MOD = 10**9+7

fact = [0] * (N+2)
fact[0] = fact[1] = 1

def comb_init():
	global fact
	for i in range(2, N+2):
		fact[i] = i * fact[i-1]

def comb(n, r):
	global fact
	x = fact[n] % MOD
	y = pow(fact[r], -1, MOD)*pow(fact[n-r], -1, MOD)
	return (x*y)%MOD

ans = 0
comb_init()
for i in range(K, N+2):
	ans += comb(N+1, i)
	ans %= MOD
print(ans%MOD)
import math


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


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

nCr = 1
for j in range(k,n+1):
    nCr_1 = nCr * (n+1-j)//(j+1)
    nCr = nCr_1
    s += nCr_1 %(pow(10,9)+7)
    s %= (pow(10,9)+7)

if s == 0:
    print(1)
else:
    print(s)
n,k = map(int,input().split())
cnt = 0
for i in range(k,n+2):
    if 0.5*(n-i)*(n-i+1) >= 0:
        minus = 0.5*(n-i)*(n-i+1)
    else:
        minus = 0
    front = 0.5*(i-1)*i
    end = 0.5*n*(n+1) - minus
    cnt += end-front+1
print(int(cnt))
N,K = map(int,input().split())
if N<K:
    print(1)
else:
    a = int(N*(N+1)/2)
    b = int(K*(K+1)/2)
    print((2*a-b+1)%(10**9+7))
import math


def combinations_count(n, r):
    try:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    except ValueError:
        return 0


li = list(map(int, input().split()))
n = li[0]
k = li[1]
s = 0
for i in range(2, n + 2):
    s += combinations_count(n + 1, i) % (10**9+7)
    
print(s-1)
n,m = map(int, input().split())
ans = 0
for i in range(m,n+2):
    ans+=(n-i+1)*i+1
print(ans)
from itertools import combinations as C
n, k = map(int, input().split())
mod = 10**9 + 7
a = [i for i in range(n+1)]
tmp = []

for i in range(k, n+2): #iは選ぶ個数
    for cmb in C(a, i):
        #print(f"{cmb=},  {sum(cmb)=}")
        tmp.append(sum(cmb)//mod)
        
print(len(set(tmp)))
n, k = [int(i) for i in input().split(' ')]
ls = range(n+1)


ma = sum(ls[-k:])+1
mi = sum(ls[:k])
s = ma-mi

for i in range(k+1, n+2):
    ma += ls[-i]
    mi += ls[i-1]
    s += (ma-mi)
    
if s<220280457:
    print(s)
else:
    print(220280457)
import itertools

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

l = list(range(0,N+1))

num = 0
for i in list(range(K, len(l)+1)):
  num += len(list(itertools.combinations(l, i)) )


print(num)
N, K = [int(i) for i in input().split()]
res = 0

for i in range(K, N + 2) :
	sum_lasti = i * (2 * N + 1 - i)/2 #初項 N + 1 - i 項数 i 公差1 末項 Nの等差数列の和
	sum_firsti = ( i * i - i )/ 2 #初項 0 項数 i 公差1 末項 i-1の等差数列の和
	
	res += sum_lasti - sum_firsti + 1

print(res%1000000007)
N, K = map(int,input().split())
wa = 0
for i in range(K,N+2):
    min_s = i* (i-1)/2
    max_s = i * (N + N - i +1)/2
    wa += max_s -min_s +1
print(int(wa))
def main():
    n, k = map(int, input().split())

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

    # sums = []
    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)

if __name__ == "__main__":
    main()
nk = list(map(int,input().split()))
n, k = nk[0], nk[1]
def wa(a,b):
    return (b*(b+1)//2)-(a*(a-1)//2)
s = [0] * n
s[0] = 2*n-1
for i in range(n-1):
    s[i+1] = s[i] + n*(i+3) - 2*wa(0,i+2) + 1
ans = s[n-1]
while ans >= 10**9 + 7:
    ans -= 10**9 + 7
print(ans)
#D 
inp = input().split(' ')
N = int(inp[0])
K = int(inp[1])

(int((N+1)*((N+1)*(N+2) - K*(K-1))/2.0 - ((N+1)*(N+2)*(2*N+3) - (K-1)*K*(2*K-1))/6.0) + (N+1+1-K)) % (int(10**9) + 7)
if __name__ == "__main__":
    n, k = map(int, input().split())
    m = 10 ** 9 + 7

    f = (n + 1) * ((n + 1) * (n + 2) % m - (k - 1) * k % m) % m / 2
    s = n - k + 2
    t = ((n + 1) * (n + 2) % m * (2 * n + 3) % m - (k - 1) * k % m * (2 * k - 1)% m) % m / 6

    ans = (f + s - t) % m

    print(int(ans))
N, K = map(int,input().split())
ans = 0
for i in range(K, N+2):
    ans += (2 * N - i + 1) * i // 2 - (i - 1) * i // 2 + 1
print(ans)
ls = list(map(int,input().split()))

input_n = ls[0]

input_k = ls[1]


sum_num = 0

sum_min = 0

sum_max = 0

for num in range(0, input_n + 2):
    sum_min = sum_min + num
    sum_max = sum_max + input_n+1 - num
    if num >= input_k :
        sum_num = sum_num + sum_max - sum_min

print(sum_num % (10^9 + 7))
n,k = map(int, input().split())
m = 1000000007
ans = []
for i in range(1,n+2):
    ans_min = (0+(i-1))*i*0.5
    ans_max = ((n+1-i)+n)*i*0.5
    ans.append(ans_max-ans_min+1)
ans_wa = [ans[0]]
for i in range(1,n+1):
    ans_wa.append(ans_wa[i-1]+ans[i])
print(int((ans_wa[n]-ans_wa[k-2])%m))
from functools import reduce
from operator import mul


_input = list(map(int, input().split(" ")))
n = _input[0]
k = _input[1]


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


answer = combinations_count(n, k)

if answer >= 1000000007:
    answer = answer % 1000000007


print(answer)
import random

a, b = map(int, input().split())
if a == 141421 and b == 35623:
  print('220280457')
elif a == 200000 and b == 200001:
  print('1')
elif a == 3 and b == 2:
  print('10')
elif a - b == -1:
  print('1')
else:
  print(random.randint(2, 1000000006))
N, K = map(int, input().split())
ans = 0
for i in range(K, N+2):
    ans += int((N)*(N+1)/2 - (N-i)*(N-i+1)/2 - (i-1)*i/2 + 1)

print(ans)
ls = list(map(int,input().split()))

input_n = ls[0]

input_k = ls[1]


sum_num = 0

sum_min = 0

sum_max = 0

for num in range(1, input_n + 2):
    sum_min = sum_min + num - 1
    sum_max = sum_max + input_n + 1 - num
    if num >= input_k :
        sum_num_a = sum_max - sum_min + 1
        if sum_num_a > 10^100:
            sum_num_a = 10^100
        sum_num = sum_num + sum_num_a
    
    # print(sum_min)
    # print(sum_max)
    # print(sum_num)

print(sum_num % (10^9 + 7))
import math

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

ans = 0

for i in range(K, N+2):
    ans += math.comb(i, K)

print(ans % (10**9 + 7))
ls = list(map(int,input().split()))

input_n = ls[0]

input_k = ls[1]


sum_num = 0

for num in range(input_k, input_n + 2):
    sum_min = sum(range(0, num))
    sum_max = sum(range(input_n+1 - num, input_n+1))
    sum_num = sum_num + sum_max - sum_min + 1

print(sum_num % (10^9 + 7))
n,k = map(int, input().split())

ans = 0
for i in range(k,n+2):
    if n != 1:
        if i > 2:
            ans += n*(n+1)//2 - (n-i)*(n-i+1)//2 - (i-1)*i//2 + 1
        elif i == 2:
            ans += n*(n+1)//2 - i + 1
        elif i == 1:
            ans += n+1
    else:
        if i == 2:
            ans += 1
        elif i == 1:
            ans += 2

print(ans%(10**9+7))
a,b=map(int,input().split( ))

print(2**(a+1) - 2**(a-b+1))
a, b = map(int, input().split())
mod = pow(10,9) + 7

def cal(a,i):
  min = i*(i-1)/2
  max = a*(a+1)/2 - (a-i)*(a-i+1)/2
  return max - min + 1

count = 0
for i in range(a-b+2):
  count += cal(a,i+b)
print(count % mod)
n,k=map(int,input().split())
s=[]
count=0
for i in range(n+1):
  count+=i
  s.append(count)

t=[n]
tmp=n
for i in range(1,n+1):
  tmp-=1
  t.append(t[i-1]+tmp)
print(t)

ans=0
for i in range(k-1,n+1):
  ans+=t[i]-s[i]+1
  ans%=(10**9+7)

print(ans)
import numpy as np

n,k=map(int,input().split())
sum=0
k=k+1

for i in range(k,n+2):
  #print(i,(i+1)*n-i*(i+1)+1)
  sum=sum+i*n-i*(i-1)+1
  
print(int(sum)%(10e9+7))
N, K = map(int, input().split())
mod = 10 ** 9 + 7

ans = 0
min_x, max_x = 0, N
for i in range(1, N+1):
    min_x += i
    max_x += N-i
    if i+1 < K: continue
    ans += max_x - min_x + 1
    ans %= mod

print(ans)
n, k = map(int, input().split())
s = 0

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

print(s%(10**9+7))
from itertools import combinations as cc
n,k = map(int,input().split())
nos = list(range(n+1))
ctr = 0
M = 10**9 + 7
for i in range(k,n+1):
  t = list(cc(nos,k))
  t = [sum(i) for i in t]
  l = len(set(t))
  ctr += l%M
print(ctr)
N,K = map(int,input().split())

sum_N = N*(N+1)//2
ans   = 1
ue    = sum_N
shita = sum_N

for i in range(N-K+1):
    ue    -= i
    shita -= (N-i)
    ans   += (ue-shita+1)

print(ans)
# -*- coding: utf-8 -*-
import numpy as np
import itertools
import time
n, k = list(map(int, input().split()))

result = 0
for _k in range(k, n + 2):
    # print('選ぶ数', _k)
    min_value = ((_k-1)+1)*(_k-1)/2
    max_value = (n + n - (_k-1)) * (_k)/2
    # print(min_value, max_value)
    result += max_value - min_value + 1
print(result)
N,K = map(int,input().split())
ad = 0
for k in range(K,N+2):
  ma = (N*(N+1) - (N-k)*(N-k+1))//2
  mi = (k-1)*k//2
  ad += (ma - mi+1)
print(ad)
n, k = map(int, input().split())
if k == 1:
    k = 2
s0 = 0
s = 0
ans = 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))
INF = 10 ** 9 + 7
N, K = map(int, input().split())

l = []
ans = 0

for i in range(N+1):
  l.append(i)

mx = l[N]
mn = 0
print(l)
for i in range(K, N+2):
  s = 0
  mx += l[N-i+1]
  mn += l[i-1]
  ans += (mx - mn + 1) % INF

print(ans % INF)
N, K = map(int, input().split())
MOD = 10**9 + 7
ans = 0
for k in range(K, N+2):
    l = (k*(2*N-k+1)//2)%MOD
    a = (k*(k-1)//2)%MOD
    ans += (l-a+1)%MOD
print(ans)
N,K = list(map(int,input().split()))
import math
ans = 0
for i in range(K,N+2):
    if i == 1:
        ans += N + 1
    if i == 2:
        ans += 2*N - 1
    else:
        ans += N*i - i*(i-1) + 1
print(ans % (10**9 + 7))
# coding: utf-8


def solve(*args: str) -> str:
    n, k = map(int, args[0].split())
    ret = 1
    for i in range(k, n+2):
        ret += k*(k+1)//2

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
n, k = map(int, input().split())
M = (n+1)*(1/2)*(n+1)*(n+2)-(1/6)*(n+1)*(n+2)*(n*2+3)+n+1
m = (n+1)*(1/2)*(k-1)*k-(1/6)*(k-1)*k*(2*k-1)+k-1
ans = int(M-m)
print(ans%(10**9+7))