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):
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())

N=10**9 + 7
n,K=sep()
s=0
for k in range(K,n+2):
    s= (s + (k*(n-k+1))%N + 1)%N
print(s)

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
print(ans%(10**9+7))

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

def sigma(N, k):
  a = (k*(k+1)*(2*k+1)//6)%(10**9+7)
  b = (k*(k+1)//2)%(10**9+7)
  c = k
  return -a + (N+1)*b + c

print((sigma(N,N+1)-sigma(N, K-1))%(10**9+7))

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def inp():
    return int(input())
def inps():
    return input().rstrip()
def inpl():
    return list(map(int, input().split()))
def _debug(obj):
    print(obj, file=sys.stderr)














mod = 10**9 +7
N, K = inpl()

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

print(ans)

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


A = [i for i in range(n+1)]
left = [A[0]]
right = [0 for i in range(n+1)]
right[-1] = A[-1]
for i in range(1, n+1):
    left.append(left[i-1] + A[i])
for i in range(n-1, -1, -1):
    right[i] = right[i+1]+A[i]

ans = 0
M = 10**9+7
for i in range(k, n+2):
    
    ans = (ans + right[-i]) % (10**9+7)
    
    
    
    ans = (ans - left[i-1]+1) % (10**9+7)
print (ans)

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

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

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

print(result)

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

ans = 0
A = sum(list(range(N, N-K, -1)))
B = sum(list(range(K)))
for i in range(K, N+2):
    
    ans += A-B+1
    A += N-i
    B += i
    ans %= C
print(ans)

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

mod = 10**9 + 7

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

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

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

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

print(ans)

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

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

kMod = 10**9+7

ans = 0

for k in range(K, N+2):
    lb = (k-1) * k // 2
    ub = (N+1-k + N) * k // 2
    ans += (ub-lb+1)
    ans %= kMod
print(ans)

Solution (Python):
N, K = map(int, input().split())
P = int(1e9+7)

A = [i + 1 for i in range(N+1)]
sumA=[i + 1 for i in range(N+1)]
for i in range(1, N+1):
    sumA[i] += sumA[i-1]
ans = 0
for i in range(K, N+1):
    ans = (ans + (sumA[-1] - sumA[-(i + 1)]) - sumA[i - 1] + 1) % P
ans = (ans + 1) % P
print(ans)

Solution (Python):
def main():
	N, K = [int(x) for x in input().split(" ")]
	p = 1000000007
	cnt = 0
	for i in range(K, N + 2):
		cnt = (cnt + (i * N) - i * i + i + 1) % p

	print(cnt)

main()

Solution (Python):
n,k=map(int,input().split())
def f(n):
  return n*(n+1)/2

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

Solution (Python):
N, K = map(int, input().split())
A = [i for i in range(N+1)]
mod = 10**9+7
ans = 0
head = sum(A[:K-1]) if K > 1 else 0
tail = sum(A[-K+1:]) if K > 1 else 0
for i in range(K, N+2):
    head += A[i-1]
    tail += A[-i] 
    ans += tail-head+1
    ans = ans % mod

print(ans)

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

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

Solution (Python):
import sys
import itertools

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

h = 0
l = 0
for j in range(0,K-1):
    h += j
for j in range(N+2-K,N+1):
    l += j

for i in range(K,N+2):
    h += i-1
    l += N+1-i
    a += l - h + 1

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

Solution (Python):

"""
Created on Sat Sep 12 19:24:24 2020

@author: liang
"""

key = 10**9 + 7
T, K = map(int, input().split())
N = list(range(T+1))
lower = sum(N[:K])
higher = sum(N[-K::1])
ans = 0
ans = (higher - lower + 1)%key
for i in range(K+1,T+2):
    lower += N[i-1]
    higher += N[-i]
    ans += higher - lower + 1
    ans %= key
print(ans)

Solution (Python):

from sys import stdin, stdout



def input():
	a = stdin.readline()
	if a[-1] == "\n": a = a[:-1]
	return a
def print(*argv, end="\n", sep=" "):
	n = len(argv)
	for i in range(n):
		if i == n-1: stdout.write(str(argv[i]))
		else: stdout.write(str(argv[i]) + sep)
	stdout.write(end)

mod = 10**9+7
def lcm(x, y): return (x * y) / (gcd(x, y))
def fact(x, mod=mod):
	ans = 1
	for i in range(1, x+1): ans = (ans * i) % mod
	return ans
def arr2D(n, m, default=0):
	lst = []
	for i in range(n): temp = [default] * m; lst.append(temp)
	return lst
def sortDictV(x): return {k: v for k, v in sorted(x.items(), key = lambda item : item[1])}

def solve(n, k):
	cnt = 0
	for i in range(k, n+2):
		
		cnt += ((i/2)*(n+n-i+1)) - ((i*(i-1))/2) + 1
		cnt = cnt % mod
	return int(cnt)

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

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

Solution (Python):




import numpy as np






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



































A = [i for i in range(N + 1)]
A = np.array(A)
cum_A = np.cumsum(A)

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

Solution (Python):
N,K=map(int,input().split())
m=lambda x:x*(x-1)//2
M=lambda x:x*N-x*(x-1)//2
res=0
p=10**9+7
for k in range(K,N+2):
    res+=(M(k)-m(k)+1)%p
print(res%p)

Solution (Python):
N, K = map(int, input().split())
x = 10
y = 10 + N

ans = 0
a = x
b = y
for i in range(1, N + 2):
    if i >= K:
        ans += b - a + 1
    a += (x + i)
    b += (y - i)

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

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

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

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

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





for i in range(k,n+2):
  
    small = i*(i-1)//2
    big = i*(2*n-i+1)//2
    
    ans += big-small+1
    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 - i*(i-1) + 1
  ans %= mod
print(ans)

Solution (Python):

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

Solution (Python):

import sys
from itertools import chain






MOD = 1000000007  
OFFSET = 10 ** 100


def k_in_n(k, n):
    """0〜n までの数からちょうど k 個の数を選ぶ時の最大最小"""
    minimum = (k * (k - 1)) // 2
    maximum = (k * (2 * n - k + 1)) // 2
    return (minimum, maximum)


def solve(N: int, K: int):
    keep = None  
    answer = 0
    for k in range(K, N + 2):
        if keep is None:
            keep = k_in_n(k, N)
        else:
            minmax = k_in_n(k, N)
            if minmax[0] + OFFSET <= keep[1]:
                keep[0] -= OFFSET
                keep[1] = minimum[1]
            else:
                answer = (answer + keep[1] - keep[0] + 1) % MOD
                keep = minmax

    if keep is not None:
        answer = (answer + keep[1] - keep[0] + 1) % MOD
    return answer


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    
    
    
    N = int(next(tokens))  
    K = int(next(tokens))  
    answer = solve(N, K)
    print(answer)


if __name__ == "__main__":
    main()

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

MOD = 10**9 + 7
n_sum = [0]

for i in range(N):
    n_sum.append(n_sum[i] + i+1)


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

print((ans+1)%MOD)

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n, k = LI()
    N = 10**9+7
    ans = 0
    start = sum([i for i in range(0,k-1)])
    goal = sum([i for i in range(n,n-k+1,-1)])

    for i, j in zip(range(k-1,n+1), range(n-k+1,-1,-1)):
        start += i
        goal  += j
        cnt = (goal-start+1)%N
        ans += cnt
        ans %= N

    print(ans)
main()

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

res = 0
for i in range(k,n+1):
  ma = a[n] - a[n-i]
  mi = a[i-1]
  res += ma - mi + 1
  
res += 1
res %= 10 ** 9 + 7
print(res)

Solution (Python):
n,k=map(int,input().split())
d,u=0,10**1000
ans=0
while d<u:
    d=(k*(k-1))//2
    u=(2*k*n-k**2+k)//2
    ans+=u-d+1
    k+=1
print(ans%(10**9+7))

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

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

if __name__ == '__main__':
    main()

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

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

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

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

min_val = 0
max_val = n
p = 1

for i in range(n + 1):
    
    if i + 1 >= k:
        ans += max_val - min_val + 1
        ans = ans % MOD
    min_val += p
    max_val += n - p
    p += 1

print(ans)

Solution (Python):
N,K=map(int,input().split())
b=0
c=0
ans=0

for i in range(0,K):
    b+=i
    c+=(N-i)
ans=c-b+1


for i in range(K,N+1):
    b+=i
    c+=N-i
    ans+=c-b+1

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

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

tmp = [0 for _ in range(10 ** 5 * 3 + 1)]
for i in range(10 ** 5 * 3):
    tmp[i + 1] = tmp[i] + (i + 1)

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

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

Solution (Python):
from itertools import accumulate
N,K = map(int,input().split())
acc = list(accumulate(range(N+1), lambda x,y:x+y))
ans = 0
mod = 10**9+7
for i in range(K, N+1):
    r = acc[N] - acc[N-i]
    l = acc[i-1]
    ans = (ans+r-l+1) % mod
ans += 1
print(ans % mod)

Solution (Python):
MODINT = 1000000007
n,k = map(int,input().split())
prod = [0]*(n+1)

for i in range(1,n+1):
    prod[i] = prod[i-1]+i

ans = 0
for s in range(k-1,n+1):
    L = prod[s]
    R = prod[n] - prod[n-s] + (n-s)
    
    ans += R-L+1
    ans %= MODINT
print(ans)

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

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

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

Ans = 0

for m in range(K,N+2): 
    
    

    
    maxi = m*(N-m+1 + N)/2

    
    mini = m*(0 + m-1)/2

    Ans += int(maxi - mini + 1)
    Ans %= mod
    
print(Ans)

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

def ksum(n):
    return n*(n+1)//2

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

print(ans)

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

for k in range(K, N + 2):
    count += end - start + 1
    count %= 1000000007
    start += k
    end += (N-k)
    
print(count)

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
print(ans%(10**9+7))

Solution (Python):
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

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

print(int(ans))

Solution (Python):








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

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

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

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

a = (n-k+2)*(((k+n+1)*(n+1))+2)//2
b = (((n+1)*(n+2)))*(2*n+3)//6
c = (((k-1)*k))*(2*k-1)//6

print((a-b+c)%(10**9+7))

Solution (Python):
n,k=[int(i) for i in input().split()]
mod=10**9+7
def part_sum(start,k):
    return k*(k+1)//2+(k*(start-1))

def count_sum(k):
    return part_sum(n-k+1,k)-part_sum(0,k)+1
ans=0
for i in range(k,n+2):
    ans+=count_sum(i)
    ans=ans%mod
print(ans)

Solution (Python):
N, K = map(int, input().split())
S = N * (N+1) // 2

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+2):
    minSum = j * (j-1) // 2
    maxSum = S - (N-j)*(N-j+1)//2
    possibleSums = maxSum - minSum + 1
    ans += possibleSums % (10**9 + 7)
ans %= (10**9 + 7)
print(ans)

Solution (Python):
N, K = [int(x) for x in input().split()]

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

print(ans)

Solution (Python):
N, K = map(int, input().split())
mod = 10 ** 9 + 7
print(((N+1)*(N*N+2*N+6)//6+(K-1)*(2*K*K-(3*N+4)*K-6)//6) % mod)

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

for i in range(k, n + 2):
    minimum = (i - 1) * i // 2
    maximum = (2 * n - i + 1) * i // 2
    cnt += maximum - minimum + 1
    cnt %= 10 ** 9 + 7

print(cnt)

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

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

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


if '__main__' == __name__:
    resolve()

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

ans = 0
all_sum = N*(N+1)/2

mod = 10**9+7

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




print(ans%mod)

Solution (Python):
from itertools import accumulate


n,k = list(map(int, input().split()))
cumsum   = list(accumulate(range(n+1)))
cumsum_r = list(accumulate(range(n+1)[::-1]))

MOD = 10**9 + 7
ans = 0
for i in range(k, n+2):
    _min, _max = cumsum[i-1], cumsum_r[i-1]
    ans = (ans + _max - _min + 1) % MOD

print(ans)

Solution (Python):
from math import factorial
n, k = [int(i) for i in input().split()]
mod = 10 ** 9 + 7

def s(n, m=0): 
    global mod
    return (n * (n+1) // 2 - (n-m) * (n-m+1) // 2) % mod

sm = 0
for i in range(k, n+1):
    sm = (sm + s(n, i) - s(i-1, i-1) + 1) % mod

print((sm+1) % mod)

Solution (Python):


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

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

Solution (Python):
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():
    n,k = map(int, input().split())
    ans = 0
    mn = mx = 0
    for i in range(n+1):
        j = n-i
        mn += i
        mx += j
        if i+1 >= k:
            ans += mx-mn+1
    print(ans%(10**9+7))

if __name__=="__main__":
    main()

Solution (Python):

def sm(i):
    tmpp = 0
    for j in range(i):
        tmpp += j
    return tmpp,j

def bi(i,N):
    tmpp = 0
    for j in range(i):
        tmpp += N-j

    return tmpp,N-j

def main():
    N,K = map(int,input().split())
    ans = 0
    
    for i in range(K,N+2,1):
        if i == K:
            small,numsmall = sm(i)
            big,numbig = bi(i,N)
            
        else:
            small += numsmall+1
            numsmall += 1
            big += numbig - 1
            numbig -= 1
        ans += big - small + 1

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

print(main())

Solution (Python):
N, K = [int(_) for _ in input().split()]

s = 0
e = 0
ans = 0

MOD = 10 ** 9 + 7

for i in range(N+1):
    s += i 
    e += N - i 
    if i + 1 >= K:
        ans += e - s + 1
        ans %= MOD
print(ans)

Solution (Python):

import sys

input = sys.stdin.readline
mod = 1000000007


def ST():
    return input().rstrip()


def I():
    return int(input())


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


def LI():
    return list(MI())


N, K = MI()
MAX = sum(range(N - K + 2, N + 1))
MIN = sum(range(0, K - 1))

ans = 0

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

print(ans % mod)

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

ans = 0
mod = 10**9+7
for i in range(K,N+2):
    if i*2 > N+1:
      
      ans += (N+1-i)*i+1 % mod
    else:
      
      ans += (N-i+1)*i+1 % mod
print(ans%mod)

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

mod = pow(10, 9) + 7

a = list(range(n+1))

def cumulative_sum(array):
    ret = []
    for index, a in enumerate(array):
        if index != 0:
            ret.append(ret[-1] + a)
        else:
            ret.append(a)
    return ret

a_cumulative_sum = cumulative_sum(a)
a_rev_cumulative_sum = cumulative_sum(a[::-1])

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

ans %= mod
print(ans)

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

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

ans = 0
for n in range(K, N + 2):
    mn = s[n-1] - s[0]
    mx = s[N] - s[max(N-n, 0)]
    count = mx - mn + 1
    ans += count
    ans %= MOD
print(ans)

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

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

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

N,K=map(int,input().split())
ans=0
ans+=N-K+2
ans+=(N+1)*(N+1+K)*(N-K+2)//2
ans%=MOD
ans-=(N+1)*(N+2)*(2*N+3)//6
ans%=MOD
ans+=K*(K-1)*(2*K-1)//6
ans%=MOD
print(ans)

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

Solution (Python):
N, K = map(int, input().split())
min_val = 0
max_val = 0
for i in range(K):
    max_val += N - i
    min_val += i



ans = 0
mod = 10 ** 9 + 7
for i in range(K, N + 2):
    ans += max_val - min_val + 1
    ans %= mod
    min_val += i
    max_val += N - i
print(ans)

Solution (Python):
def main():
  N, K = map(int, input().split())
  N = N + 1
  A=[n for n in range(N)]
  S=[0]*(N+1)
  for a in A:
    S[a+1]+=S[a]+a
  ans=0
  for k in range(K, N+1):
    maxS, minS=S[-1], S[k]
    offset=S[-k-1]
    ans+=(maxS - offset) - minS + 1
  print(ans%(1000000007))
  
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):
  a0=(i*(i-1))//2
  an=i*n-a0
  ans+=an-a0+1

print(ans%mod)

Solution (Python):
mod=10**9+7
x=[0]+[0]
for i in range(1,2*10**5+10):
  x.append((x[-1]+i)%mod)

ans=0


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


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

Solution (Python):
n,k=map(int,input().split())
L=list(range(n+1))

cnt=0
ans=0

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


for i in range(k,n+2):
    cnt+=calc(i)
    cnt%=(10**9+7)
    

print(cnt)

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

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

Solution (Python):
nn, kk = list(map(int,input().split()))

sum = 0
for i in range(kk, nn+2):
    min = (0+i-1)*i/2
    max = (nn+nn-i+1)*i/2
    sum += (max-min)+1

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

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

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

mod =10**9+7
sum = 0
min = 0
max = 0

for k in range(1,n+2):
    min += k-1
    max += n-(k-1)

    if k >= m:
        sum = (sum + max-min+1) % mod
print(sum)

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

ans = 0

for p in range(k, n+2):
    minimum = p * (p-1) // 2  
    maximum = p * (2*n - p + 1) // 2  
    ans += maximum - minimum + 1
    ans %= mod

print(ans)

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

if __name__ == "__main__":
    main()

Solution (Python):
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) % (10**9 + 7))

Solution (Python):
N, K = map(int, input().split())
M = 10**9 + 7
A = [0 for _ in range(N+1)]
RA = [0 for _ in range(N+1)]
for i in range(1, N+1):
    A[i] = A[i-1] + i

RA[0] = N
for j in range(1, N+1):
    RA[j] = N-j + RA[j-1]

ans = 0


for k in range(K, N+2):
    minv = A[k-1]
    maxv = RA[k-1]
    ans += ((maxv - minv) + 1)%M
    ans %= M
    

print(ans)

Solution (Python):
def solve():
    N,K = [int(i) for i in input().split()]
    ans = 0
    mod = 10**9 + 7
    for M in range(K, N+2):
        min_sum = (M-1) * M // 2
        max_sum = (2*N-(M-1)) * M // 2
        cnt = max_sum - min_sum + 1
        ans += cnt
        ans %= mod
    print(ans)

if __name__ == "__main__":
    solve()

Solution (Python):

import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]









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

Solution (Python):
from scipy.special import comb
n, k = map(int, input().split())
num, ans = 0, 0

for i in range(n+1):
    num += n-2*i
    if i >= k-1:
        ans += num+1
ans = ans%(10**9+7)
print(ans)

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

Solution (Python):

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

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


if __name__ == '__main__':
    main()

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

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

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

cnt = []

for i in range(k,n+2):
    cnt.append(i*n -(i-1)*i +1)
    
print(sum(cnt)%(10**9+7))

Solution (Python):
def rui_sum(n,k):
    k_lsum = (k-1)*k//2
    k_usum = k*n - (k-1)*k//2    
    return k_usum - k_lsum + 1

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

cnt = []

for i in range(k,n+2):
    cnt.append(rui_sum(n,i))
    
print(sum(cnt)%(10**9+7))

Solution (Python):
N, K = [int(i) for i in input().split()]
mod = 10**9+7
result = 0 
for i in range(K, N+2):
    min_sum = ((i-1) * i) // 2
    max_sum = ((N) * (N+1)) // 2 - ((N-i) * (N-i+1)) // 2
    result += (max_sum - min_sum + 1) % mod
print(result%mod)

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

mod = 10 ** 9 + 7
inv = pow(2, mod - 2) % mod

def calc(b, e, c):
    global mod
    global inv
    res = (e + b) % mod
    res = ((res * c) % mod ) * inv
    return res % mod

ans = 0
for i in range(k, n + 2):
    min_val = calc(0, i - 1, i)
    max_val = calc(n - i + 1, n, i)
    ans += (max_val - min_val + 1) % mod
    ans %= mod

print(ans)

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

mod = 10 ** 9 + 7
inv = pow(2, mod - 2, mod=mod)

def calc(b, e, c):
    global mod
    global inv
    res = (e + b) % mod
    res = ((res * c) % mod ) * inv
    return res % mod

ans = 0
for i in range(k, n + 2):
    min_val = calc(0, i - 1, i)
    max_val = calc(n - i + 1, n, i)
    ans += (max_val - min_val + 1) % mod
    ans %= mod

print(ans)

Solution (Python):
import sys

input=sys.stdin.buffer.readline





def RD(): return sys.stdin.read()


def II(): return int(input())


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


def MF(): return map(float,input().split())


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


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))





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

if __name__=="__main__":
	main()

Solution (Python):
import sys

input=sys.stdin.buffer.readline





def RD(): return sys.stdin.read()


def II(): return int(input())


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


def MF(): return map(float,input().split())


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


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))





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

if __name__=="__main__":
	main()

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

mod = 10 ** 9 + 7
N, K = MI()
def num(self):
    return (-2 * pow(self, 3) + 3 * N * pow(self, 2) + (3 * N + 8) * self) // 6
ans = num(N + 1) - num(K - 1)
print(ans % mod)

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

mod = 10 ** 9 + 7
N, K = MI()
def num(self):
    return (-2 * pow(self, 3) + 3 * N * pow(self, 2) + (3 * N + 8) * self) // 6
ans = num(N + 1) - num(K - 1)
print(ans % mod)

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

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

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

Solution (Python):

import collections as cl
import sys


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 main():
    n, k = MI()
    ans = 0
    ttl = n * (n + 1) / 2

    for i in range(k, n + 2):
        min_i = i * (i - 1) / 2
        max_i = ttl - (n - i) * (n - i + 1) / 2
        ans += (max_i - min_i + 1) % (10 ** 9 + 7)
        ans %= 10 ** 9 + 7

    print(int(ans))


main()