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-----
3 2

-----Sample Output-----
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

Difficulty: interview

Starter code:

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



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

Ans = 0

for m in range(K,N+2): # m個選ぶ m = K ~ N+1
    # 1刻みで全ての数を作ることができる
    # よって答えは、作れる数の　(最大値) - (最小値) 通りとなる

    # 最大値 = 大きい方からm個選ぶ = N-m+1 ~ N までの和
    maxi = m*(N-m+1 + N)/2

    # 最小値 = 小さい方からm個選ぶ = 0~m-1を選ぶ
    mini = m*(0 + m-1)/2

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

def N():
    return int(input())
def L():
    return list(map(int,input().split()))
def NL(n):
    return [list(map(int,input().split())) for i in range(n)]
mod = pow(10,9)+7

import numpy as np
import sys
import math
import collections

n,k = L()
n += 1
l = [i for i in range(n)]
l = np.cumsum(l)
l %= mod
sum = 1
for i in range(k,n):
    sa = l[n-1]-l[n-1-i]-l[i-1] + 1
    sum += sa
    sum %= mod
    #print(k,sa)
print(sum)

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

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

print(sm)

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)

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
# print(prod)
ans = 0
for s in range(k-1,n+1):
    L = prod[s]
    R = prod[n] - prod[n-s] + (n-s)
    # print(L,R)
    ans += R-L+1
    ans %= MODINT
print(ans)

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
#from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
import sys

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, K = na()
ans = 1
for i in range(K, N+1):
    mae = i * (i - 1) // 2
    ato = i * (N + N - i + 1) // 2
    ans += ato - mae + 1
    ans %= mod
print(ans)

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

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

print(ans%1000000007)

# https://drken1215.hatenablog.com/entry/2020/04/20/003900
# k  個足してできる最小の整数を求める (a とする)
# k 個足してできる最大の整数を求める (b とする)
# 出来上がる整数は b−a+1 個である

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

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

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

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))
  
def __starting_point():
  main()
__starting_point()

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

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

N, K = list(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))


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

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)

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)

# -*- coding: utf-8 -*-


def main():
    from itertools import accumulate
    import sys
    input = sys.stdin.readline

    n, k = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    a = list(accumulate([0] + [i for i in range(n + 1)]))
    ans = 0

    for j in range(k, n + 2):
        max_value = a[-1] - a[n + 1 - j]
        min_value = a[j]
        ans += (max_value - min_value) + 1
        ans %= mod

    print((ans % mod))


def __starting_point():
    main()

__starting_point()

N, K = list(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)))


N,K=list(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)


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)

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

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
#print(a)
res = 0
for i in range(k,n+1):
  ma = a[n] - a[n-i]
  mi = a[i-1]
  res += ma - mi + 1
  #print(i,res,ma,mi)
res += 1
res %= 10 ** 9 + 7
print(res)

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

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)

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

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

def calc(b, e, c):
    nonlocal mod
    nonlocal 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)

N, K = map(int, input().split())
big = 10**9+7
ans = 0
def sum2(begin,end):
  return (begin+end)*(end-begin+1)//2
for k in range(K,N+2):
  ans += (sum2(N+1-k+1,N+1)-sum2(1,k)+1)%big
print(ans%big)

#amari = (10**100)%(10**9+7)
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 = list(map(int,input().split()))
    ans = 0
    #loopnum = (N+1) - K + 1
    for i in range(K,N+2,1):
        if i == K:
            small,numsmall = sm(i)
            big,numbig = bi(i,N)
            #print(numsmall,numbig)
        else:
            small += numsmall+1
            numsmall += 1
            big += numbig - 1
            numbig -= 1
        ans += big - small + 1

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

print((main()))


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

M=[n]*(n+1)
m=[0]*(n+1)
for i in range(1,n+1):
    M[i]=M[i-1]+n-i
    m[i]=m[i-1]+i

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

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)

def __starting_point():
    main()
__starting_point()

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

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

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

MOD = 10 ** 9 + 7

H = 0
L = 0
for i in range(k):
    L += i
    H += (n - i)

ans = 0
a = k
b = n - k
for i in range(n+2-k):
    #print(a, b, H, L)
    ans += H - L + 1
    L += a
    H += b
    a += 1
    b -= 1
    ans %= MOD

print(ans)

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

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

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
# print(A)
# print(RA)
for k in range(K, N+2):
    minv = A[k-1]
    maxv = RA[k-1]
    ans += ((maxv - minv) + 1)%M
    ans %= M
    # print(k, (maxv-minv)+1)

print(ans)

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)

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

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)

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

#!/usr/bin/env python3
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 list(map(int,input().split()))
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#つまりlist[i] < x となる i の個数
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#つまりlist[i] <= x となる i の個数
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
n,k = MI()
ans = 0
for i in range(k,n+2):
    ans += i*(n-i+1)%mod + 1
print((ans%mod))


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)
#print(n_sum)

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

print((ans+1)%MOD)

n,m = list(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)


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)

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)

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)

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

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

mod = 10 ** 9 + 7
N, K = map(int, input().split())
ans = 1
def main(i):
  m = i * (i - 1) // 2
  M = m + i * (N - i + 1)
  return M - m + 1

for i in range(K, N+1):
  ans += main(i)
  
print(ans%mod)

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)

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

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

#!/usr/bin/env python3
import sys

input = sys.stdin.readline
mod = 1000000007


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


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


def MI():
    return list(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))


# 10^100のクソデカ数値がクソデカすぎるため、+0,+1..+Nが束になってもいたくも痒くもない
# なのでもはや無視していい
# 最初の例でいうと、2つ選ぶのは[0,1,2,3]からなので、和のバリエーションは最小値1~最大値5の5つ
# 3つ選ぶのは最小値3~最大値6の4つ
# 4つ選ぶのは1つ
# 毎回最大値と最小値を計算して差+1を加えてやるとできあがり
# 計算には数列の和を使う

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

ans = 1
for i in range(k, n + 1):
    # 初項0,公差1,末項i-1までの和
    min_s = i * (i - 1) // 2
    # 初項n+1-i, 公差1, 末項i-1までの和
    max_s = i * (2 * (n + 1 - i) + (i - 1)) // 2
    ans += max_s - min_s + 1
    ans %= mod
print(ans)


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

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)

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)

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

#import math
#import collections
n,k = map(int, input().split( ))
#A = list(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)

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  # 0〜(p-1)の和
    maximum = p * (2*n - p + 1) // 2  # (n-p+1)〜nの和
    ans += maximum - minimum + 1
    ans %= mod

print(ans)


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)

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)


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

from scipy.special import comb
n, k = list(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)



N,K = list(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
    ans = ans % (10**9+7)
print(ans)


N,K=map(int,input().split());f=lambda i:i*(i+1)//2;print(sum(f(N)-f(N-i)-f(i-1)+1for i in range(K,N+2))%(10**9+7))

#!/usr/bin/env python3
import sys
from itertools import chain

# import numpy as np
# from itertools import combinations as comb
# from bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter

MOD = 1000000007  # type: int
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, K = map(int, input().split())
    # N, K = input().strip()
    # N, K = int(input())
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    answer = solve(N, K)
    print(answer)


def __starting_point():
    main()

__starting_point()

N, K = list(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)))


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

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

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


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

N,K=list(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)))
 


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
    #print(i, ans)
    ans %= mod

print(ans)

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

n,k = list(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))


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

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

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

def main():
    n,k = list(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)

def __starting_point():
    main()

__starting_point()

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

N, K = map(int, input().split())
start = sum(range(K))
end = sum(range(N-K+1, N+1))
count = 0
#print(start, end)
for k in range(K, N + 2):
    count += end - start + 1
    count %= 1000000007
    start += k
    end += (N-k)
    
print(count)

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

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

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

def s(n, m=0): # m~nの総和
    nonlocal 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)

# -*- coding: utf-8 -*-
"""
Created on Sat Sep 12 19:24:24 2020

@author: liang
"""

key = 10**9 + 7
T, K = list(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)
#print(lower)
#print(higher)


# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
import numpy as np
# import heapq
# from collections import deque

# N = int(input())
# S = input()
# n, *a = map(int, open(0))
N, K = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)


# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

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

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

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):
    # print(min_val, max_val)
    if i + 1 >= k:
        ans += max_val - min_val + 1
        ans = ans % MOD
    min_val += p
    max_val += n - p
    p += 1

print(ans)


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

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)

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)

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)

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)

def __starting_point():
    solve()
__starting_point()

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)

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

#!/usr/bin/env python3
def main():
    N, K = list(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)))


def __starting_point():
    main()

__starting_point()

from itertools import accumulate

# k個選んだ時の最小値と最大値が分かれば、個数が分かる？？
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)

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

n, k = list(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)


n, k = list(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)))


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

import math
N,K=list(map(int, input().split()))

list1=list(range(N+1))
list2=[]
for i in range(K,N+2):
    min=math.floor(i*(list1[0]+list1[i-1])/2)
    max=math.floor(i*(list1[N-i+1]+list1[N])/2)
    list2.append(max-min+1)

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