peterverebics/CodeNet_Python_118 huggingface dataset:
from itertools import permutations, combinations

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

ans = 0
_list = list(range(N+1))
_list.sort(reverse = True)
h = _list[0]
l = 0
cnt = 0

if N ==1 and K == 1:
    print(2)
    exit()
for i in range(1, N+1):
    h += _list[i]
    cnt += 1
    l += cnt
    if i >= K-1:
        ans += h - l + 1

    
print(ans%(10**9 + 7))
input_line = input()
Line = input_line.split()
Line = [int(s) for s in Line]
N,M = Line[0],Line[1]

# print(N,M)

kosuu = N+1
ans = 1

if M == 1 :
    M += 1
    ans += N

kaitensuu = kosuu - M

for i in range(kaitensuu):
    ans += kosuu + i
    ans = ans % 1000000007

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 :
        if sum_max > 10^100:
            sum_max = 10^100
        sum_num_a = sum_max - sum_min + 1
        sum_num = sum_num + sum_num_a
    
    # print(sum_min)
    # print(sum_max)
    # print(sum_num)

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

lst = [i for i in range(N+1)]

P = 10**9 + 7
rlt = 0

mini = sum(lst[:K-1])
maxi = sum(lst[-K+1:])

for i in range(N -K + 2):
  mini += lst[K+i-1]
  maxi += lst[-K-i]
  rlt += maxi -mini + 1
  rlt %= P
  
print(rlt)
N, K = map(int, input().split())

a = 0

for i in range(K,N+2):
  a += i*(2*N-i+1)//2 - i*(i-1)//2 + 1
  
print(int(a))
n, k = map(int, input().split())
MOD = 1e9+7

def s(i,n):
    s1 = ((i * i - 4) / 3)
    s2 = ((n * (i+1)) / 2)
    
    return ( int(i * (s2 - s1) + 0.5) ) % MOD


print(int(s(n+1,n) - s(k-1,n)))
N, K = [int(INPUT) for INPUT in input().strip().split(' ')]

total_num = 0

for k in range(K, N + 2):
    Min = sum(range(k - 1))
    Max = sum(range(N - (k - 1), N + 1))
    num = Max - Min + 1
    total_num += num

print(total_num)
N,K = map(int,input().split())
ans = 0
for k in range(K,N+1):
    ans += N*k-((k*(k-1))/2)-k+2
print(ans)
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 = M-m
print(int(ans%(1000000007)))
n, k = map(int, input().split())

c = 0

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

print(c%(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)
    
print(s%(10**9+7)-1)
inp_str = input()
N, K = list(map(int, inp_str.split(" ")))
MOD = 10e9 + 7

def choise(n, m):
    if n == 0:
        return 0
    min_sum = (0 + m - 1) * m // 2 % MOD
    max_sum = (2*n - m + 1) * m // 2 % MOD
    return max_sum - min_sum + 1
ans_list = [choise(N, m) for m in range(1, N+2)]
sum_ans = 0
for ans in ans_list[K-1:]:
    sum_ans += ans
    sum_ans = sum_ans % MOD
print(int(sum_ans))
def resolve():
    n, k = map(int, input().split())
    print((n*(n+1)/2)%(10**9+7))
resolve()
n,k = map(int,input().split())
mod = 10**9+7
answer = 0

for i in range(k,n+2):
  max_value = sum(range(n-i+1,n+1))
  lowest_value = sum(range(1,i+1))
  answer = answer + max_value - lowest_value + 1

print(answer % mod)
n,k = map(int,input().split())
ans = 0

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

print(ans)
import numpy as np

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

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

c = 0

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

print(int(c%(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
  c=(ma-mi+1)%(10**9+7)
  ans+=c
  print(c)
print(ans)
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


print(combinations_count(n, k))
n,k=map(int,input().split())
print((n*(n+1)*(n+2)//6+n-(3*n-2*k+4)*(k-1)*k//6-k+n+2)%(10**9+7))
n,k=map(int,input().split())
nums = list(range(n+1))
upSum = [n]*(n+1)
lowSum = [0]*(n+1)
for i in range(0,n):
  upSum[i+1] = upSum[i] + nums[n-1-i]
  lowSum[i+1] = lowSum[i] + nums[i+1]
answer = 0
for i in range(k-1,n+1):
  answer += upSum[i] - lowSum[i] + 1
print(answer)
n, k = map(int, input().split())

MOD = 1e9+7

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

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 = map(int,input().split())

Ans = [0]*(N+2)
Sum_Ans = 0

def solution(N,K,Ans,Sum_Ans):
    for i in range(K,N+2):
        #max[i] = (2*N - i + 1)*i / 2
        #min[i] = i*(i - 1) / 2
        Ans[i] = i*(N - i + 1)
        
        Sum_Ans += Ans[i]
    
    print(Sum_Ans%(10**9 + 7))

solution(N,K,Ans,Sum_Ans)
import sys
N,K=map(int, sys.stdin.readline().split())
mod=10**9+7
ans=0
for k in range(K,N+2):
    max_n=(N+(N-k+1))*k/2
    min_n=(k-1)*k/2
    t=max_n-min_n+1
    if 4<=t:
        ans+=t+(t-4)/2
    else:
        ans+=t
print ans%mod
n, r = input().split()

res = 0
for i in range(int(n) + int(r) - 1):
  res += i

print(res)
import math

q = input().split()
n = int(q[0])
k = int(q[1])

child = math.factorial(n+1)

def ncr(n, r):
    mother = math.factorial(n-r) * math.factorial(r)
    ans = child // mother
    return(ans)

ans = 0
if (n+1 == k):
    ans = 1
else:
    for i in range(k, n+1):
        ans += ncr(n+1, i)

print(int(ans))
n,k=map(int,input().split())
ans=0
mod=10**9+7
for i in range(k,n+2):
    ans+=(2*n-i)*i//2-i*(i+1)//2+1
    ans%=mod
print(ans)
#!/usr/bin/env python3

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

mod = 10**9+7

# low_lim = (1+k)*k//2
# up_lim = (1+n)*n//2

low_lim = (((1+k) % mod) * (k % mod)) % mod // 2
up_lim = (((1+n) % mod)*(n % mod) % mod)//2

num = low_lim-up_lim

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

nums = set()

for k in range(K,N+1+1):
    s_min = k*(k-1)//2
    s_max =  k*(2*N-k+1)//2
    tmp = [k*1000+i for i in range(s_min,s_max+1)]
    nums = nums|set(tmp)


ans = len(nums)%(10**9+7)
print(ans)
n, k = map(int, input().split())
ans = 0
for i in range(k, n + 1):
    ans += (n * (n + 1) / 2) - ((n - i) * (n - i + 1) / 2) - (((i - 1) * (i) / 2) - 1)
ans = ans + 1
print(int(ans))
n,k=map(int,input().split())
ans=0
for i in range(k,n+2):
    ans+=(i*(n+n-i+1)- i*(i-1))/2+1
print(int(ans))
n, k = map(int, input().split())
ans = 0
mod = 10 ** 9 + 7
l=1
r=n
for i in range(k):
  ans += (r - l + 1) % mod
  ans %= mod
  l += i + 2
  l %= mod
  r += n - i - 1
  r %= mod
print(ans)
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)
n, k = map(int, input().split())
ans = 0
for i in range(k, n + 1):
    ans += (n * (n + 1) / 2) - ((n - i) * (n - i + 1) / 2) - (((i - 1) * (i) / 2) - 1)
ans = ans + 1
print(ans)
n, k = map(int, input().split())

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

ans = 0
while n+1 - k >= 0:
    cnt = combinations_count(n+1, k)
    ans += cnt
    k += 1
ans %= 10**9 + 7
print(str(ans))
MOD = 10**9+7

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


cnt = 0
for k in range(K,N+2):

    t = (N-k+1)*k
    cnt += t
    cnt %= MOD
print(cnt)
n, k = map(int, input().split())
lst = list(range(1, n+1))

minn = sum(lst[:k])
maxn = sum(lst[-k:])

print(maxn - minn)
import math

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

# Larges = list(itertools.product([0,1],repeat=N+1))
# ans=0
# for i in Larges:
#     if sum(i)>=K:
#         ans+=1


def counts(n,k):
    if k==1:
        return N
    else:
        return k*N -k*(k-1) +1

total =0

for k in range(K,N+2):
    total += counts(N,k)


print(total)
N, K = [int(s) for s in input().split(" ")]
res = 0
for i in range(K, N + 2):
  res += (N - i + 1) * i + 1
  #print res, i, (N - i + 1) * i + 1
  print(res % 1000000007)
n,K = map(int, input().split(' '))

#n,k = 3, 2

res = 0

for k in range(K, n+2):
  first = k * (k-1) / 2
  last = (2 * n - k + 1) * k / 2
  res += (last - first + 1) % (10**9+7)
print(int(res))
n, k = map(int, input().split())

c = 0

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

print(c%(10^9 + 7))
N,K=map(int,input().split())
M=N+1
L=K-1
print((M*(M*M+5)/6 + L*(L*L*2+L*3-5-M*(L+1)*3)/6)%(10**9+7))
from itertools import permutations, combinations

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

ans = 0
_list = list(range(N+1))
_list.sort(reverse = True)
h = _list[0]
l = 0
cnt = 0

if N ==1 and K == 1:
    print(2)
    exit()
for i in range(1, N+1):
    h += _list[i]
    cnt += 1
    l += cnt
    print(i , h , l)
    if i >= K-1:
        ans += h - l + 1

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


for i in range(K,N+1):
    mini=i*(i-1)//2
    maxi=i*(N-1)
    ans=(ans+(mini-maxi+1))//(10^9+7)
print(ans)
n,k = map(int,input().split())
count = 0
for i in range(k,n+1):
  count += i*(2*n-i+1)//2 -i*(i+1)//2 +1
print(count % (10**9+7))
a = list(map(int,input().split()))
ans=0
min=0
max=0
for i in range(a[1]):
    min +=i
    max +=a[0]-i
    minx=i-1
    maxx=a[0]-i-1
ans=max-min+1
for i in range(a[1]+1,a[0]+2):
    minx+=1
    min += minx
    maxx -=1
    max +=maxx
    if min<=max:
        ans=ans+max-min+1
print(ans)
n, k = list(map(int, input().split()))

import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
a = 0
count = 0
while k+count<n+1:    
    a += comb(n+1,k+count)
    count += 1
print(a)
n, k = list(map(int, input().split()))

mod = 1000000009

sn = (n*(n+1)*(n+2)/6 +n+1)% mod
sk = ((k-1)*k*(3*n-2*k+4)/6 +k-1)% mod

snk = (sn - sk)% mod

print(snk)
list = input().split()
N = int(list[0])
K = int(list[1])
i = K
s = 0

def sum(a,b):
    i=0
    i = (a + b)*(b - a + 1)/2
    return i

while i <= N + 1:
    #print(sum(N-i+1,N) + sum(0,i-1))
    s = s + sum(N-i+1,N) - sum(0,i-1) + 1
    i += 1
print(s % 10**9+7)
N,K=map(int,input().split())
ans=0
for k in range(K,N+2):
  ans+=k*(k-1)//2 - k*(2*N+3-k)//2 +1
print(ans)
#D
N,K=map(int,input().split())
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if N>K:
    ans=0
    for i in range(K,N+1):
        ans+=combinations_count(N+1, i)
    print(ans)
else:
    print(1)
n,k=map(int, input().split())
ans=0
for i in range(k, n+2):
    i_min = (i*(i-1))//2
    i_max = (n*2 - i+1)*i/2
    ans+=(1-i_min+i_max)
print(int(ans))
N,K = map(int,input().split())
count = 0
for i in range(K,N+2):
    count = count + i*(N-i+1)+1
print(count)
N,K =map(int, input().split())
M = sum(list(range(N-K+1,N+1)))
m = sum(list(range(0,K)))
count = M-m+1
for i in range(K,N):
    m +=  i
    M +=  (N-i)
    count += M-m+1
print((count+1)%(10**9+7))
import math
n, k = map(int,input().split())
total = 0
mod = 10**9+7
max_value = (n*(n+1)) //2
for a in range(k,n+1):
    high = (max_value-(n-(a*(a-1)) //2))
    low = (a*(a-1)) //2
    total += high - low + 1
total += 1 # k = n+1
print(total%mod)
from math import factorial, ceil
def comb(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))
base = comb(5,3)
N, K = map(int, input().split())
n = N+1
nCr = comb(n, K)
S = nCr
for r in range(K,n):
    nCr_1 = nCr * (n - r) // (r + 1)
    nCr = nCr_1
    S+=nCr_1

k = 0
for i in range(K, N):
    k += ceil(N/i)-1
print(S-k)
import math
import itertools

mod = 10**9 + 7

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

if n < k:
    print(1)
else:
    l = [i for i in range(n + 1)]

    s = set()

    for i in range(k, n + 1):
        for v in itertools.combinations(l, i):
            s.add(v)

    print(len(s) % mod)
mod = 1000000007
n, k = map(int, input().split())
cnt = 0
for i in range(k,n + 4 -k):
  ca = 0
  cb = 0
  for j in range(i):
    ca += n - j
    cb += j
  cnt += ca - cb + 1
print(cnt % mod)
n,k=map(int,input().split())
s=[]
count=0
for i in range(n+1):
  count+=i
  s.append(count)
print("s=",s)

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

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

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

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

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

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

print(ans)
import itertools

n, k = map(int, input().split())
inicial = (10**100) % (10**9 + 7)
listN = list(range(n+1))
count = 0

for i in range(k, n+1):
    count += len(list(itertools.combinations(listN, i)))
    
print(count)
X=list(map(int,input().split()))
N=X[0]
K=X[1]
ans=0
for i in range(K,N+2):
  ans+=N*i-(i*i)+i+1
print(int(ans))
def sum_C(n,k):
	nn=n
	max = 0
	min = 0
	sum=0
	for i in range(k):
		min += i
	for j in range(k):
		max += nn
		nn-=1
	sum += max-min+1
	
	for i in range(k,n+1,1):
		max+=n-i
		min+=i
		sum+=max-min+1
	return sum


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


print(sum_C(N,K))
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 = M-m
print(ans%(1000000007))
def main():
    n, k =map(int, input().split())
    res = 0

    for left in range(n):
        num = 0
        right = left + k
        res += (right - left)
    
    print(res %(10 ** 9))

if __name__ == '__main__':
    main()
n, k = map(int, input().split())
def sum2(nums):
    res = 0
    for num in nums:
        res += num
        res %= 1000000007
    return res
sum2(1 + l * (n + 1 - l) for l in range(k, n + 2))
n, r = map(int,input().split())

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

mod = 10**9 + 7
N = 2 * 10**5
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append(( -inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

if n > r:
    print(cmb(n, r, mod))
else:
    print(1)
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)
    
print(s)
N, K = map(int, input().split())
x = 100000007
 
A = N * (N * (N + 1) - K * (K - 1)) // 2
B = (N * (N + 1) * (2 * N + 1) - K * (K - 1) * (2 * K - 1)) // 6
C = N - K + 2
D = (N * (N + 1) - K * (K - 1)) // 2

Ans = (A - B + C + D) % x
 
print(Ans)
N, K = map(int, input().split())

res = 0

for k in range(K, N+2):
    res += k * (N - k + 1) + 1
    
print(res)
N,K = map(int,input().split())
l=list(range(K,N+2))
sum =0
for i in l:
    m=(i-1)*i/2
    p=i*N-2*m+1
    sum+=p
print(int(sum))
n, k = map(int, input().split())

m = n + 1
l = k - 1

ans = m * (m**2 + 5) // 6
ans += l * (2 * l**2 + 3 * l - 5 - 3 * m * (l + 1)) // 6

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

ans = 0
for i in range(k,n+1) :
  # k個使う場合の最小値
  min_k = (k-1)*k//2
  # k個使う場合の最大値
  max_k = (n-k+1+n)*k//2
  ans += (max_k-min_k+1)
  
print(ans)
from itertools import permutations, combinations

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

ans = 0
_list = list(range(N+1))
_list.sort(reverse = True)
h = _list[0]
l = 0
cnt = 0

if N == K == 1:
    print(2)
    exit()
for i in range(1, N+1):
    h += _list[i]
    cnt += 1
    l += cnt
    print(i , h , l)
    if i >= K-1:
        ans += h - l + 1

    
print(ans%(10**9 + 7))
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());print(n*(n+1)*(n+2)//6-k*(k-1)*(3*n-2*k+4)//6+n-k+2)
import itertools
 
n, m = list(map(int, input().split(" ")))
l = [ i for i in range(n + 1) ]
 
ans = 0
for i in range(m, n + 2):
    for v in itertools.combinations(l, i):
        ans = ans + 1
print(ans)
n, k = map(int, input().split())
n += 1
sum_n = sum(range(n))
ans = 0
for i in range(k, n+1):
    mi = i*(i-1) / 2
    ma = sum_n - ((n-i)*(n-i-1) / 2)
    ans += ma - mi + 1

print(ans%(7+10**9))
N,K=map(int, input().split())
A=(N+1/2)*(N*(N+1)/2-(K-1)*K/2)
B=N*(N+1)*(2*N+1)-(K-1)*K*(2*K-1)
B=B/12
print('{:.0f}'.format(A+B))
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)
n, k = map(int, input().split())
ans = 0
mod = 10**9+7

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)

'''
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))
'''
N,K = map(int,input().split())

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

counter = 0
for k in range(K,N+1):
    s1 = S[k]
    s2 = S[N+1] - S[N+1-k]
    counter += s2-s1+1
counter += 1

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

def counts(n,k):
    if k==1:
        return N
    else:
        return k*N -k*(k-1) +1

total =0
for k in range(K,N+2):
    total += counts(N,k)

print(total%mod)
N,K=map(int, input().split())
a1 = (N+1)*(N+2)*(2*N+3)/6 - (K-1)*K*(2*K-1)/6
a2 = (N+1)*(N+2)/2 - (K-1)*K/2
a3 = N-K+2

print(-a1+(N+1)*a2+a3)
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
  
N,K = map(int,input().split())
ans=0
Nplus1= N+1
for i in range(K,Nplus1):
  ans += cmb(Nplus1,i)
  
print(ans%(7+10**9))
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)
from scipy.special import comb
N, K = tuple(map(int, input().split()))

result = 0
k = K
while k <= N + 1:
    result += comb(N, k, exact=True)
    k += 1

print(result)
n, k = map(int,input().split())
A = list(range(n+1))
ans = 0
suma = sum(A[-k+1:])
for i in range(k,n+2):
  suma += A[-i]
  ans += suma - (i-1)*i//2+1
  
print(ans)
i,j= list(map(int, input().split()))
n=i+1
nCr = j
sum=0
print(nCr)
for r in range(n):
    nCr_1 = nCr * (n - r) // (r + 1)
    nCr = nCr_1
    sum+=nCr_1
print(sum%(10**9+7))
N,K = map(int,input().split())
ans = 0
mod = 10**9+7
for k in range(K,N+2):
    ans += (k*(N-k+1)+1) % mod
print(ans)
#from scipy.special import comb

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

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
print(ans)
N, K = map(int, input().split())

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 + 1):
  ans += C(N, i)
  
print(ans)
N, K=map(int,input().split())
print(((N+1)*(N+K+1)*(N-K+2)/2+N-K+2-(N+1)*(N+2)*(2*N+3)/6+(K-1)*K*(2*K-1)/6)%(10**9+7))
NK = input()
NKs = NK.split(" ")
N = int(NKs[0])
K = int(NKs[1])
Ns = []
x = 1
for i in range(N+1):
    Ns.append(x)
    x = x + 1
    
dif = -1
output = 0
while dif != 0:
    za = 1
    zu = N + 1
    minimum = 0
    maximum = 0
    for i in range(0,K-1):
        minimum = minimum + za
        za = za + 1
        maximum = maximum + zu
        zu = zu - 1
    K = K + 1
    dif = maximum - minimum
    output = output + dif

print(output)
def solve():
    N, K = map(int, input().split())
    #a = 226732710
    tot = 0
    for k in range(K, N+1+1):
        mi = k*(k-1)/2
        ma = N*(N+1)/2-(N-k-1)*(N-k)/2
        tot += int(ma-mi+1)
            
    print(tot)
solve()
a,b=map(int,input().split(" "))
print(a,b)
min=0
max=0
count=0

for i in range(b,a+2):
    min = int((i-1)*i/2)
    max = int((2*a-i+1)*i/2)
    count+=max-min+1
print(count%1000000007)
import itertools
N, K = map(int, input().split())
count = 0
a = list(range(N+1))
for i in range(K,len(a)+1):
        count += len(list(itertools.combinations(a,i)))
print(count)
N, K = map(int, input().split())
Max = [0]
Min = [0]
for i in range(1, N+2):
  Max.append(N-i+1+Max[i-1])
  Min.append(i-1+Min[i-1])
A = [mx-mn+1 for mx,mn in zip(Max,Min)]
B =[0]
for i in range(N+1):
  B.append(B[i]+A[i+1])
print(B[N+1]-B[K-1])
import numpy as np

n, k = map(int, input().split())
MOD = 10 ** 9 + 7
ref = np.array(list(range(n + 1)), dtype='int64')

max_sum = np.sum(ref[-k + 1:])
min_sum = np.sum(ref[:k - 1])
ans = 0

for i in range(k, n + 2):
    min_sum += ref[i - 1]
    max_sum += ref[-i]
    ans += max_sum - min_sum + 1
    ans %= MOD

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

ans = 0
mod = pow(10,9)+7

for k in range(1, K+1):
  ans += sum(range(N-k+1, N+1)) - sum(range(0, k))
  
  
print(ans % mod)
N,K = map(int,input().split())
a =0
for i in range(K,N+2):
    a = a + ((N+N-i+1)*i/2-(i-1)*(i)/2+1)
print(a%10**9+7)
N,K=map(int,input().split())
print(K*(N+1-K))
N, K = map(int, input().split())
l = (K * (K - 1) // 2) - 1
u = (K * (2 * N - K + 1) // 2)
ans = 0
for i in range(K + 1, N + 3):
    #print(u, l)
    ans += u - l
    l += i - K + 1
    if N - i + 1 > 0:
        u += N - i + 1
print(ans % (10 ** 9 + 7))
N, K = map(int, input().split())

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

print(ans)
import math
n, k = map(int,input().split())
total = 0
mod = 10**9+7
max = (n*(n+1)) //2  # 6 in ex.1
for a in range(k,n+1): # from 3 to 4 in ex.1
    high = (max-(n-a)) # 6-1 = 5, 6-0 = 6
    high %= mod
    low = (a*(a-1)) //2  # 1, 3
    low %= mod
    if high-low+1 < 0:
        high += mod
    total += high - low + 1 # 5, 4
    total %= mod
total += 1 # k = n+1

total %= mod
print(total)
N,K=map(int,input().split())
wa=0
for i in range(N+1-K):
    n=i+K
    min=(n)*(0+n-1)/2
    max=(n)*(N-n+1+N)/2

    wa=max-min+wa+1

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

A = [0 for _ in range(N+1)]
for i in range(1, N+1):
    A[i] = i * (i+1) // 2

ans = 0
for j in range(K, N+1):
    minSum = A[K-1]
    maxSum = A[N] - A[N-K]

    possibleSumPattern = (maxSum - minSum)
    ans += possibleSumPattern * K * 10**100 % (10**9+7)
ans %= (10**9 + 7)
print(ans)
N, K = map(int, input().split())

ans = 0


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

print(ans)
n,k = map(int,input().split())
a = list(range(n+1))
b = a[::-1]
ans = 0

min = sum(a[:k-1])
max = sum(b[:k-1])

for i in range(k,n+2):
    min += a[i-1]
    max += b[i-1]
    ele = max - min +1
    ans += ele

print(ans)
import numpy as np

n, k = map(int, input().split())
MOD = 10 ** 9 + 7
ref = np.array(list(range(n + 1)), dtype='int64')

max_sum = np.sum(ref[-k + 1:])
min_sum = np.sum(ref[:k - 1])
ans = 0

print('min, max = ', min_sum, max_sum, max_sum - min_sum)
for i in range(k, n + 2):
    min_sum += ref[i - 1]
    max_sum += ref[-i]
    ans += max_sum - min_sum + 1
    ans %= MOD

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

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

for i in range(K,N+2):
  ans += i*(N-i+1)+1
#
print(ans)
N, K = map(int, input().split())
q=0
for i in range(K,N+2):
    q+=N*i-i*i+i+1
print(q)
N, K = map(int, input().split())
MOD = 10 ** 9 + 7

LOW, HIGH = 0, N
ans = 0

if K >= 1:
    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)