Problem:
 Score : 400 points    Problem Statement We have N+1 integers: 10^{100} , 10^{100}+1 , ..., 10^{100}+N .  We will choose K or more of these integers. Find the number of possible values of the sum of the chosen numbers, modulo (10^9+7) .      Constraints  1 \leq N \leq 2\times 10^5  1 \leq K \leq N+1  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  K       Output Print the number of possible values of the sum, modulo (10^9+7) .        Sample Input 1 3 2      Sample Output 1 10  The sum can take 10 values, as follows:   (10^{100})+(10^{100}+1)=2\times 10^{100}+1  (10^{100})+(10^{100}+2)=2\times 10^{100}+2  (10^{100})+(10^{100}+3)=(10^{100}+1)+(10^{100}+2)=2\times 10^{100}+3  (10^{100}+1)+(10^{100}+3)=2\times 10^{100}+4  (10^{100}+2)+(10^{100}+3)=2\times 10^{100}+5  (10^{100})+(10^{100}+1)+(10^{100}+2)=3\times 10^{100}+3  (10^{100})+(10^{100}+1)+(10^{100}+3)=3\times 10^{100}+4  (10^{100})+(10^{100}+2)+(10^{100}+3)=3\times 10^{100}+5  (10^{100}+1)+(10^{100}+2)+(10^{100}+3)=3\times 10^{100}+6  (10^{100})+(10^{100}+1)+(10^{100}+2)+(10^{100}+3)=4\times 10^{100}+6        Sample Input 2 200000 200001      Sample Output 2 1  We must choose all of the integers, so the sum can take just 1 value.       Sample Input 3 141421 35623      Sample Output 3 220280457

Solution (Python):
import sys
import math
from collections import deque
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def I(): 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 LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h,w): return [[i for j in range(w)] for k in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)

MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline

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

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

def ssum(i):
    return i*(i+1)//2

ans = 0
for i in range(k, n+2):
    l,m = ssum(i-1), ssum(n)-ssum(n-i)
    ans += (m - l + 1)
    ans %= mod

print(ans)

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

MOD = 10**9+7


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


def main():
    n, k = map(int, input().split())

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


main()

Solution (Python):
n,k=map(int,input().split())
if k>n:
    print(1)
else:
    r=0
    s=0
    sum=0
    for i in range(k):
        r=(r+i)%1000000007
  
        s=(s+n-i)%1000000007
   
    for j in range(k,n+2):
        sum=(sum+s-r+1)%1000000007
 
        r=(r+j)%1000000007
 
        s=(s+n-j)%1000000007
 
    print(sum)

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

MOD = 10 ** 9 + 7


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


ans = 0
for i in range(K, N + 2):
    left = f(0, i - 1) % MOD
    right = f(N - i + 1, N) % MOD
    ans += (right - left + 1) % MOD
print(ans % MOD)

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

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

Solution (Python):
NK = list(map(int, input().split()))
N = NK[0]; K = NK[1]
 
result = 0
for i in range(K,N+2):
    result += i*(N-i+1) +1
    result = result%1000000007
 
print(result)

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

def return_wa(n,a):
  g = 1/2 * n * (n+1)
  a = 1/2 * a * (a-1)
  return int(g -a)
  
    
z = 10**9 + 7    
ans = 0    

for i in range(k,n+2):
      seki = return_wa(n,n+1-i)  - sum_wa(i-1) + 1
      seki = seki % z 
      ans += seki
      
print(ans%z)

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *




























def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007




def main():
	N,K = inputMap()

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

	dekki_min = [0]
	for i in dekki_tmp:
		dekki_min.append(dekki_min[-1] + i)
	dekki_min = dekki_min[2:]
	

	dekki_tmp = dekki_tmp[::-1]

	dekki_max = [0]
	for i in dekki_tmp:
		dekki_max.append(dekki_max[-1] + i)
	dekki_max = dekki_max[2:]
	

	ans = 0
	if K == 1:
		ans += N
	for i in range(K,N+2):
		mins = dekki_min[i-2]
		maxs = dekki_max[i-2]

		ans = (ans + maxs - mins + 1) % mod
		

	print(ans)





def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y



def H(n, r, mod=10**9+7):
	
	
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        
        
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

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

mod = 10**9+7
res = 1
l = K*(K-1)//2
r = l+(N-K+1)*K
for i in range(K, N+1):
    res += r-l+1
    res %= mod
    l += i
    r += N-i
print(res)

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

ans = 0

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

l_sum = sum(n[:K])
r_sum = sum(n[-K:])

l = K
r = N-K

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

Solution (Python):
import itertools

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

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

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

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

ans = 0

for i in range(n - k + 2):
    ans += (2 * n - k - i + 1) * (k + i) / 2 - (k + i - 1) * (k + i) / 2 + 1
    ans %= 1e9 + 7

print(int(ans))

Solution (Python):
n,k=map(int,input().split());print(((n+2*k)*(~n+k)-6)*(k-n-2)//6%(10**9+7))

Solution (Python):
n,k=map(int,input().split());print(((n+2*k)*(~n+k)-6)*(k-n-2)//6%(10**9+7))

Solution (Python):
n,k=map(int,input().split())
print(((n+2*k)*(~n+k)-6)*(k-n-2)//6%(10**9+7))

Solution (Python):
n,k=map(int,input().split());print(((n+2*k)*(~n+k)-6)*(k-n-2)//6%(10**9+7))

Solution (Python):
n,k=map(int,input().split());print(((n+2*k)*(~n+k)-6)*(k-n-2)//6%(10**9+7))

Solution (Python):
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('d1.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    M = 10 ** 9 + 7
    N, K = read_int_list()
    res = 0
    for i in range(K, N + 2):
      d = (i - 1) * i // 2
      f = i * N - d
      res += f - d + 1
      res = res % M
    print(res)


main()

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

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

Solution (Python):
from sys import stdin, stdout
import math
import bisect
import queue

N, K = map(int, stdin.readline().strip().split())

ans = 0

for l in range(K, N + 2):
    fi = ((-1 + l) * l) // 2
    se = ((N + (N - l + 1)) * l) // 2
    ans += se - fi + 1
    ans %= 1000000007
    
stdout.writelines(str(ans) + '\n')

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

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

resolve()

Solution (Python):
N, K = map(int, input().split())
MAX = 10 ** 9 + 7
 
res = 0
 
def calc_sum(l, r):
  return ((l+r) * (r-l+1)) // 2
 
for i in range(K, N+2):
  low = calc_sum(0,i-1)
  high = calc_sum(N-i+1,N)
  res = (res + (high-low+1)) % MAX
 
print(res)

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

Solution (Python):
from sys import stdin, setrecursionlimit, stdout

from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def lsi():
    x=list(stdin.readline())
    x.pop()
    return x
def si(): return stdin.readline()
mod=1000000007


def solve(k):
    l=(k*(k-1))//2
    u=(n*(n+1))//2-((n-k)*(n-k+1))//2
    return u-l+1

n, k=mi()
s=0
while k<=n+1:
    s+=solve(k)
    if s>=mod:
        s%=mod
    k+=1
print(s)

Solution (Python):

def return_number(n, k):
    return n * k - k*k + k + 1


il1 = input().split()
N = int(il1[0])
K = int(il1[1])

answer = 0
mod = 10**9 +7

for k in range(K, N+2):
    num  = return_number(N, k)
    answer = answer + num

print(answer%mod)

Solution (Python):





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

    ans = 0
    for n in range(K, N+2):
        ans += n*(N-n+1) + 1
    
    return ans % q


print(main())

Solution (Python):
from itertools import permutations, combinations

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

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

for i in range(N+1):
    h += _list[i]
    cnt += 1
    l += cnt
    if i >= K-1:
        ans += h - l + 1
        
print(ans%(10**9 + 7))

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

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

print(ans)

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

Solution (Python):
N,K = map(int,input().split())
 
s = 0
 
for i in range(K,N+2):
  s += i*N +1 - i*(i -1)

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

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

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

Narr = []
for i in range(0, N + 1):
    Narr.append(i)
S = []
S.append(0)
for i in range(1, N + 2):
    S.insert(i, Narr[i - 1] + S[i - 1])

sum = 0
mod = pow(10, 9) + 7
last = len(S) - 1
for i in range(K, N + 2):
    sum += S[last] - S[last - i] - S[i] + 1

print(sum % mod)

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

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())
MOD_BY = 7 +10**9











ans = 0

for i in range(K,N+2):
    comb_min = (0+i-1)*i//2 
    comb_max = (N+N-i+1)*i//2 
    
    comb_num = comb_max - comb_min + 1
    ans += comb_num
    ans %= MOD_BY
    
print(ans)

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

cusum = [0] * (L + 1)

for i in range(L):
  cusum[i + 1] = cusum[i] + (i + 1)
  
total = 0

for k in range(K, L + 1):
  total += (cusum[L] - cusum[L - k]) - cusum[k] + 1

print(total % P)

Solution (Python):
n,k=map(int,input().split())
left=right=ways=0
for i in range(n+1):
  left += i
  right += n-i
  if i >= k -1:
    ways += max(right -left +1, 0)
print(int(ways%(1e9+7)))

Solution (Python):
def f(n,k):
  return (n+1)*(n+k+1)*(n-k+2)//2+k*(k-1)*(2*k-1)//6-(n+1)*(n+2)*(2*n+3)//6+n-k+2

n,k=map(int,input().split())
print(f(n,k)%1000000007)

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

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

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

Solution (Python):
N, K = map(int, input().split())
cnt = []
minimum = sum([i for i in range(K-1)])
maximum = sum([i for i in range(N-(K-2), N+1)])

for n in range(K-1, N+1):
    minimum += n
    maximum += (N-n)
    diff = maximum - minimum +1
    cnt.append(diff)
ans = sum(cnt) % (10**9+7)
print(ans)

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

ans = 0
for i in range(K, N+2):
    minima = i*(i-1)//2
    maxima = i*(2*N-i+1)//2
    ans += maxima-minima+1
    ans %= 10**9 +7
    
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

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

def main():
  N, K = map(int, input().split())
  MOD = 1000000007

  ans = 0
  for i in range(K,N+2):
    min_n = sum(0, i-1)
    max_n = sum(N+1-i, N)
    ans += (max_n-min_n+1)
  print(ans%MOD)

if __name__ == '__main__':
    main()

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

def main():
  t=0
  for k in range(K,N+2):
    s=k*~-k//2
    m=k*(2*N-k+1)//2
    t=(t+m-s+1)%MOD

  print(t%MOD)

main()

Solution (Python):
import sys 
import math
try:
	sys.stdin = open('input.txt', 'r') 
	sys.stdout = open('output.txt', 'w')
except:
	pass

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

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

M=N+1

A=-M*(M+1)*(2*M+1)//6+(N+1)*M*(M+1)//2+M

M=K-1

B=-M*(M+1)*(2*M+1)//6+(N+1)*M*(M+1)//2+M


print((A-B)%(10**9+7))

Solution (Python):
n, k=map(int, input().split())
mod=10**9 +7
def calc(num):
    small=num*(num-1)//2
    large=num*(2*n -num+1)//2
    return large-small+1

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

print(ans)

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

sum_left = list(range(N+1))
sum_right = list(range(N+1))[::-1]

for i in range(1, N+1):
    sum_left[i] += sum_left[i-1]

for i in range(1, N+1):
    sum_right[i] += sum_right[i-1]

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

print(ans)

Solution (Python):
def sigma(x, d):
    if d == 1:
        return x * (x + 1) // 2
    if d == 2:
        return x * (x + 1) * (2 * x + 1) // 6


def calc(x):
    return -sigma(x, 2) + (n + 1) * sigma(x, 1) + x




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

print((calc(n + 1) - calc(k - 1)) % p)

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


for i in range(K,N+2):
    mini=i*(i-1)//2
    maxi=i*N-mini
    ans=ans+(maxi-mini+1)
print(ans%(10**9+7))

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

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

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

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

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

Solution (Python):
n, k = map(int, input().split())
if n < k:
    print(1)
    exit(0)

MOD = pow(10, 9) + 7
count = 0
while n+1 >= k:
    minv = k * (k-1) // 2
    maxv = ((n+1) * n // 2) - ((n-k) * (n-k+1) // 2)

    count += (maxv - minv + 1)
    count %= MOD
    k += 1

print(count)

Solution (Python):
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
INF=10**9+7
ans=0
for i in range(k,n+2):
    a=i*(i-1)//2
    b=(2*n-i+1)*i//2
    temp=b-a+1
    ans=(ans+temp)%INF
print(ans)

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

def min_sum(k):
  return int(k*(k-1)/2)

def max_sum(n,k):
  return int((n+n-k+1)*k/2)

def main():
  N,K = [int(x) for x in input().split()]
  ans = 0
  for k in range(K,N+2):
    ans += max_sum(N,k) - min_sum(k) + 1

  print(ans%mod)

if __name__ == "__main__":
    main()
    pass

Solution (Python):
n,k=map(int,input().split())
print(((n+2-k)*(k*n-k*k+k)+(n+2-k)*(n+1-k)*(n+1-2*k)//2-(n-k+1)*(n-k+2)*(2*n-2*k+3)//6+(n+2-k))%1000000007)

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

Solution (Python):
n,k = [int(e) for e in input().split()]

count = 0

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


mod = 10**9+7
print(int(count%mod))

Solution (Python):
from collections import  deque
import sys
import bisect
import math
import itertools
from queue import deque
from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)

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

print(ans % mod)

Solution (Python):
from collections import  deque
import sys
import bisect
import math
import itertools
from queue import deque
from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)

N, K = inp_list()
ans = 0
for k in range(K, N + 2):
    
    M = ( N * (N + 1) // 2 - (N - k) * (N + 1 - k) // 2 ) % mod
    m = k * (k - 1) // 2 % mod
    ans += (M - m + 1) % mod

print(ans % mod)

Solution (Python):
from collections import  deque
import sys
import bisect
import math
import itertools
from queue import deque
from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)

N, K = inp_list()
ans = 0
for k in range(K, N + 2):
    
    M = ( N * (N + 1) - (N - k) * (N + 1 - k) ) // 2
    m = k * (k - 1) // 2
    ans += (M - m + 1) % mod

print(ans % mod)

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

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

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

ans = 0

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

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

Solution (Python):
from itertools import accumulate

N, K = map(int, input().split())
a = [i for i in range(N+1)]

b = list(accumulate(a))


mod = 10**9 + 7
ans = 0

for i in range(K, N+2):
    if i == N+1:
        end = b[N]
        start = b[i-1] - b[0]
    else:
        end = b[N] - b[N-i]
        start = b[i-1] - b[0]
    
    
    ans += end - start + 1
print(ans % mod)

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

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

print(ans)

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

Solution (Python):


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

ans=0
M=1000000007

S=[0]*(N+2)

for i in range(1,N+1):
    S[i+1]=S[i]+i

for i in range(K,N+2):
    U=S[N+1]-S[N-i+1]
    B=S[i]
    ans+=U-B+1
    ans%=M

print(ans)

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

Solution (Python):
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 
	sum_firsti = ( i * i - i )/ 2 
	
	res += sum_lasti - sum_firsti + 1

print(int(res%1000000007))

Solution (Python):
from itertools import accumulate
mod = 10**9 + 7
N, K = map(int, input().split())
a = [i for i in range(N+1)]
b = list(accumulate(a))



ans = 0
for i in range(K, N+2):
    if i == N+1:
        v1 = b[N]
        v2 = b[i-1] - b[0]
    else:
        v1 = b[N] - b[N-i]
        v2 = b[i-1] - b[0]
    
    
    
    ans += v1 - v2 + 1
print(ans % mod)

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

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

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

Solution (Python):
MOD = 10**9 + 7
class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x) if isinstance(other, ModInt) else
            ModInt(other - self.x)
        )

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )

def differenceOfMaximumSumAndMinimumSum(cumulative_sum, i):
    return (cumulative_sum[-1] - cumulative_sum[-i-1]) - cumulative_sum[i - 1]

def solve(N, K):
    ret = ModInt(1)
    cumulative_sum = [0] * (N + 1)
    tmp_sum = 0
    for i in range(1, N + 1):
        tmp_sum += i
        cumulative_sum[i] = tmp_sum

    for i in range(K, N + 1):
        ret += differenceOfMaximumSumAndMinimumSum(cumulative_sum, i) + 1
    return ret


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

Solution (Python):
def conta_casos(n, k):
    s = 0
    for i in range(k, n+2):
        s += i*(n-i+1)+1
    print(s % (1000000000+7))

a, b = [int(x) for x in input().split()]
conta_casos(a, b)

Solution (Python):
MOD = 10**9 + 7
class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x) if isinstance(other, ModInt) else
            ModInt(other - self.x)
        )

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )
def sumOfArithmeticSequence(a, b):
    return (a + b) * (b - a + 1) // 2

def solve(N, K):
    ret = ModInt(0)
    for i in range(K, N + 2):
       ret += sumOfArithmeticSequence(N - i + 1, N) - sumOfArithmeticSequence(0, i - 1) + 1
    return ret


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

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

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

Solution (Python):
N,K = map(int,input().split())
cnt = [0]*(N-K+2)

cnt_all = 0
mod = 1000000007

for i in range(K,N+2):
    cnt[i-K] = i*N - i*(i-1) + 1

for i in range(N-K+2):
    cnt_all += cnt[i]

print(cnt_all % mod)

Solution (Python):
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    ret = 0
    for k in range(K, N + 2):
        ret += (2 * N - k + 1) * k // 2 - (k - 1) * k // 2 + 1
    print(ret % MOD)


if __name__ == '__main__':
    main()

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

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

print(ans % MOD)

Solution (Python):
MOD = 10 ** 9 + 7
N, K = map(int, input().split())
ruiMin = [0] * (N + 1)
ruiMax = [((N + 1) * N) // 2] * (N + 1)

for i in range(1, N + 1):
    ruiMin[i] = ruiMin[i - 1] + i

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

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

Solution (Python):



def input_int():
    return int(input())



def int1(x):
    return int(x) - 1



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



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



def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


MOD = 10 ** 9 + 7


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


def main():
    n, k = input_to_int_map()

    all_n = n + 1
    ret = 0
    all_list_sum = [0]
    pre = 0
    for i in range(0, all_n):
        all_list_sum.append(i + pre)
        pre = i + pre

    for choice_cnt in range(k, all_n + 1):
        ret = (ret + (all_list_sum[n + 1] - all_list_sum[n + 1 - choice_cnt] - all_list_sum[choice_cnt] + 1))

    return ret % MOD


if __name__ == "__main__":
    print(main())