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
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')






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

def solve():
    N, K = MI()
    ans = 0
    MOD = 1000000007
    for i in range(K, N+2):
        mn = f(0, i-1)
        mx = f(N-i+1, N)
        ans = ans + mx - mn + 1
    print(ans % MOD)

if __name__ == '__main__':
    solve()

Solution (Python):
import numpy as np

n, k = map(int, input().split())
ary = np.array([i for i in range(n+1)])

cum_1 = np.cumsum(ary)
cum_2 = np.cumsum(ary[::-1])


ans = 0
for j in range(k-1,n+1):
    ans += cum_2[j] - cum_1[j] + 1
    ans %= 10**9+7

print(ans)

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

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

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

print(ans)

Solution (Python):
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

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

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

def S(a, b):
    return T(b) - T(a - 1)

def solve():
    n, k = rl()
    ans = 1
    for i in range(k, n + 1):
        lo = T(i - 1)
        hi = S(n - i + 1, n)
        ans += hi - lo + 1
        ans %= (10**9 + 7)
        

    print (ans)






mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()

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

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

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

Solution (Python):
p = 10**9+7
N,K = map(int,input().split())
a = (((N+1)*(N+2))//2)%p
a = (a*(N+1))%p
b = (((K-1)*K)//2)%p
b = (b*(N+1))%p
c = (((N+1)*(N+2)*(2*N+3))//6)%p
d = (((K-1)*K*(2*K-1))//6)%p
e = (N-K+2)%p
ans = (a-b-c+d+e)%p
print(ans)

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

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

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

for i in range(K,N+1):
    mn += i
    mx += N-i
    ans += mx - mn + 1
    ans %= MOD

print(ans%MOD)

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

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

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

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

Solution (Python):
n,k = map(int,input().split())
mod = 10**9+7
from itertools import accumulate
N = list(range(n+1))
N_acc = [0]+list(accumulate(N))
ans = 0
for i in range(k,n+2):
    ans += ((N_acc[-1]-N_acc[-i-1])-N_acc[i]+1)%mod
print(ans%mod)

Solution (Python):
import sys
from io import StringIO
import unittest
import os


sys.setrecursionlimit(999999999)



def resolve(test_def_name=""):
    n, k = map(int, input().split())

    ans = 0

    min_num = 0
    desk_list = list(reversed(range(n + 1)))

    max_num = 0
    ack_list = list(range(n + 1))

    for i in range(1, n + 1):
        min_num = (min_num + desk_list.pop()) % (pow(10, 9) + 7)
        max_num = (max_num + ack_list.pop()) % (pow(10, 9) + 7)
        if k <= i:
            ans = (ans + max_num - min_num + 1) % (pow(10, 9) + 7)

    print(ans+1)



class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3 2"""
        output = """10"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """200000 200001"""
        output = """1"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """141421 35623"""
        output = """220280457"""
        self.assertIO(test_input, output)

    
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)



if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        
        resolve()

    else:
        
        unittest.main()

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

Solution (Python):
import itertools

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

N_acum = list(itertools.accumulate(range(N+1)))
mod = 10**9+7
ans = 0
for i in range(K, N+1):
    ans += (N_acum[-1] - N_acum[-(i+1)]) - N_acum[i-1] + 1
    ans %= mod

ans = (ans+1)%mod

print(ans)

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

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

Solution (Python):
import math

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


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

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

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

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

def sum_(i, j):
    return (a[i] + a[j]) * (j - i + 1) // 2

a = [i for i in range(N + 1)]
ans = 0
for i in range(K, N + 2):
    min_ = sum_(0, i - 1)
    max_ = sum_(N - i + 1, N)
    ans += (max_ - min_ + 1)
    ans %= 10 ** 9 + 7
print(ans)

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


MOD = 10 ** 9 + 7


def calc_cumsum(l):
    cumsum = [l[0]]
    for i in l[1:]:
        cumsum.append(cumsum[-1] + i)
    return cumsum


n, k = LI()
nums = list(range(n + 1))
ans = 0
ruiseki_min = calc_cumsum(nums)
ruiseki_max = calc_cumsum(nums[::-1])
for i in range(k, n + 2):
    min_sum = ruiseki_min[i - 1]
    max_sum = ruiseki_max[i - 1]
    ans += max_sum - min_sum + 1
    ans %= MOD
print(ans)

Solution (Python):



def main():
    n, k = map(int, input().split(" "))
    
    
    
    
    
    
    
    
    
    
    max_num = sum(range(n - k + 1, n + 1))
    min_num = sum(range(k))
    c = max_num - min_num + 1
    total = c
    for i in range(k, n + 1):
        max_num += n - i
        min_num += i
        c = max_num - min_num + 1
        total += c
    print(total % 1000000007)


if __name__ == '__main__':
    main()

Solution (Python):
n,k = map(int,input().split());
kk = n-k+2
a = [0]*kk

for i in range(kk):
    ii = i + k
    p = ii*(ii-1);
    q = ii*(2*n+1-ii);
    a[i] = (q//2)-(p//2)+1;
con = 0;
for v in range(kk):
    con = (con+a[v]) % 1000000007;
    
print(con);

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

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

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

res = 0
z = n*(n+1)//2
for x in range(k, n+2):
    min_ = (x-1)*x//2
    max_ = z - (n-x)*(n+1-x)//2
    res += max_ - min_ + 1
    res %= mod

print(res)

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

A=[i for i in range(N+1)]
wa=0
N=N+1
for i in range(K,N+1):

    mi=(i*(0+(i-1)))/(2)
    ma=(i*(N-i+(N-1)))/(2)

    wa=ma-mi+1+wa


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

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

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

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

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

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


print(ans)

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

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

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




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


print(ans)

Solution (Python):
import sys 
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10 ** 9 +7
N, K = map(int, readline().split())








k = np.arange(K,N+2,dtype = np.int64)
low = k*(k-1)//2
high = k*(2*N - k + 1) //2
cnt = high-low+1
print(sum(cnt)%mod)

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

m = 1000000007

result = 0
for i in range(K, N + 2):
    
    a = (N + (N - i + 1)) * i // 2
    
    b = (0 + (i - 1)) * i // 2
    result += a - b + 1
    result %= m
print(result)

Solution (Python):
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10 ** 9 +7
N, K = map(int, readline().split())
s = [0] * (N+1)
g = [0] * (N+1)
g[0] = N % mod
for i in range(1,N+1):
    s[i] += (s[i-1] + i ) % mod
    g[i] += (g[i-1] + N - i) % mod
ans = (sum(g[K-1:]) % mod  - sum(s[K-1:]) % mod + N-K+2) % mod
print(ans)

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

Solution (Python):

NN,K = (int(x) for x in input().split())


p =10**9 + 7
seq =[i for i in range(NN+1)] 
ans =[0] *(NN+1)
st =[0]*(NN+1)
fi =[0]*(NN+1)
st[0] =sum(seq[  :K])
fi[0] =sum(seq[-K: ])
ans[0] =fi[0] -st[0] +1
if NN==1 and K==1:
    print(3)
else:
    for i in range(NN -K+1):
        st[i+1] =st[i] +seq[K+i]
        fi[i+1] =fi[i] +seq[-K-i-1]
        ans[i+1] =(fi[i+1] -st[i+1] +1)
    print(sum(ans) %p)

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

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

Solution (Python):
def main():
    n, k = list(map(int, input().split()))
    mod = 1000000007
    N = list(range(n + 1))
    mn = [0] * (n + 1)
    mx = [0] * (n + 1)
    mx[0] = n
    for i in range(1, n + 1):
        mn[i] = mn[i - 1] + N[i]
        mx[i] = mx[i - 1] + N[n - i]
    ans = 0
    for a, b in zip(mn[k - 1:], mx[k - 1:]):
        ans += b - a + 1
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    mod = 1e9 + 7
    n, k = list(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
        ans = int(ans % mod)
    print(ans)
    return


if __name__ == "__main__":
    main()

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

ans = 0


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

print(ans)

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

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

P = 10**9 + 7
rlt = 0

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

for i in range(N -K + 2):
  mini += lst[K+i-1]
  maxi += rlst[K+i-1]
  rlt += maxi -mini + 1
  rlt %= P
  
print(rlt)

Solution (Python):
N, K = map(int, input().split())
num = list(range(N+1))
count = 0
base_minimum = sum([i for i in num[:K]])
base_maximum = sum([i for i in num[-K:]])
count += base_maximum - base_minimum + 1

for k in range(K, N+1):
    base_minimum += num[k]
    base_maximum += num[-k-1]
    count += base_maximum - base_minimum + 1
    
print(int(count%(1e9+7)))

Solution (Python):
import numpy as np

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

cumsum = np.arange(0, N + 2).cumsum()

ans = 0
for k in range(K, N + 2):
    ans += cumsum[-1] - cumsum[-(k + 1)] - cumsum[k] + 1
    ans %= MOD

print(ans)

Solution (Python):
import numpy as np

MOD = 10**9 + 7

N,K = map(int, input().split())
k = np.arange(K,N+2)
low = (k-1)*k//2
high = (N-k+1)*k + low + 1
ans = (high-low)%MOD
print(ans.sum()%MOD)

Solution (Python):

def resolve():
    MOD = 10 ** 9 + 7
    N, K = map(int, input().split())
    ans = 0
    for k in range(K, N + 2):
        min_num = k * (k - 1) // 2
        max_num = k * (N * 2 - k + 1) // 2
        add = max_num - min_num + 1
        ans = (ans + add) % MOD
    print(ans)

if __name__ == "__main__":
    resolve()

Solution (Python):
import itertools

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

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

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

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

Solution (Python):
from itertools import accumulate
mod = 10**9 + 7
n, k = map(int, input().split())
arr = []
for i in range(n+1):
    arr.append(i)
ls = [0] + list(accumulate(arr))
ans = 0
for i in range(k, n+2):
    ans += (((ls[-1] - ls[-1-i]) - ls[i]) + 1)%mod
ans %= mod
print(ans)

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

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

a=range(n+1)

max=sum(a[n+1-k:])
min=sum(a[:k])
ans=max-min+1
if n+1==k:
  print(ans)
  exit()
for i in range(k+1,n+2):
    max += a[n+1-i]
    min += a[i-1]
    ans += max-min+1
print(ans%(10**9+7))

Solution (Python):
from itertools import combinations
MOD = 10**9+7

def main():
    N, k = map(int, input().split(' '))
    count = 0

    if k > N:
        print('1')
        exit(0)
    for i in range(k,N+2):
        maxsum = (N*(N+1) - (N-(i-1))*(N-i))//2
        minsum = (i-1)*i//2
        count += maxsum - minsum + 1

    print(count%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):
  min = i*(i-1)//2
  max = (n+1)*n//2 - (n+1-i)*(n-i)//2
  ans += (max - min + 1)%mod
print(ans%mod)

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)//2
    max = (n+1)*n//2 - (n+1-i)*(n-i)//2
    ans += (max - min + 1)%mod
print(ans%mod)

Solution (Python):
N,K = map(int,input().split())
number = N+1-K+1
W = 0
for i in range(number):
    min = (K+i)*(K+i-1)/2
    max = (K+i)*(2*N-K-i+1)/2
    W += (max-min+1)
w = W % (1000000007)
print(int(w))

Solution (Python):
MOD = 10**9+7
a = 10**6
n, k = map(int, input().split())
nums = [i for i in range(n+1)]
min_n = sum(nums[:k])
max_n = sum(nums[-k:])
res = (max_n-min_n)+1
res %= MOD
i = 0
while k+i <= n:
    min_n += nums[k+i]
    max_n += nums[-(k+i+1)]
    diff = max_n - min_n
    res += diff+1
    res %= MOD
    i += 1

print(res)

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def fact(N):
        res = {}
        tmp = N
        for i in range(2, int(N ** 0.5 + 1) + 1):
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            if cnt > 0:
                res[i] = cnt
        if tmp != 1:
            res[tmp] = 1
        if res == {}:
            res[N] = 1
        return res


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N, K = Scanner.map_int()
    ans = 0
    N += 1
    for i in range(K, N + 1):
        l = i * (i - 1) // 2
        r = N * i - ((i + 1) * i) // 2
        ans += r - l + 1
        ans %= MOD
    print(ans)


def main():
    
    
    
    
    
    solve()


if __name__ == "__main__":
    main()

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

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

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

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

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


print(counter%(pow(10,9)+7))

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

for z in range(k, n+2):
  min_sum = (z-1)*z//2
  max_sum = n*(n+1)//2 - (n-z)*(n-z+1)//2
  
  num_sums = max_sum - min_sum + 1
  big_total = (big_total + num_sums)%modprime
print(big_total)

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

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

    ans += maxx - mini + 1
    ans %= MOD

print(int(ans))

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

Solution (Python):
import sys
n, k = [int(i) for i in sys.stdin.readline().split()]
MOD = 10**9 + 7
_sum = 0
for i in range(k,n+2):
    _sum += ((n + (n-i+1)) * i // 2) - ((i-1) * i) // 2 + 1
    _sum %= MOD
print(_sum)

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

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

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

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

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

Solution (Python):
n,k = list(map(int, input().split()))
ans = 0
sum_n = (n+1)*n/2

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

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








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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
mod = 10**9+7
from itertools import accumulate
lis = list(accumulate([0]+[i for i in range(N+1)]))
ans = 0
for k in range(K, N+2):
    MIN = lis[k]
    MAX = lis[-1]-lis[-1-k]
    ans += (MAX-MIN+1)
    ans %= mod
print(ans)

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

Solution (Python):
import numpy as np

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

a = np.arange(n+1, dtype='int')

b = np.cumsum(a)

s = 0

for i in range(k, n+1):
	s += (b[n] - b[n-i]) - b[i-1] + 1
	s = s % 1000000007

s += 1
s = s % 1000000007
print(s)

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



s = 0
f = N * (N + 1) / 2
for k in range(K,N + 2):
    
    
    mx = int(f - (N - k) * (N - k + 1) / 2)
    mn = int((k - 1) * k / 2) - 1
    m = mx - mn
    s += m
    s = s % (10 ** 9 + 7)
print(s)

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

MOD = 10 ** 9 + 7

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

print(ans)

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

Solution (Python):

from collections import deque
N,K = map(int,input().split())
numbers = [i for i in range(0,N+1)]
large  = deque([N])
small = deque([0])
for i in range(1,N+1):
    large.append(large[-1]+numbers[-i-1])
    small.append(small[-1]+numbers[i])

mod = 10**9+7

ans = 1
for i in range(K,N+1):
    ans += (large[i-1] - small[i-1] + 1)%mod
print(ans%mod)

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

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

for right in range(1, N+2):
    S[right] = S[right-1] + A[right-1]

total = S[N+1]
ans = 0
for left in range(N+2):
    total -= A[max(left-1, 0)]
    if (N+1) - left >= K:
        ans += (total - S[(N+1)-left] + 1) % mod

print(ans % mod)

Solution (Python):
N,K = map(int,input().split())
MOD = 10**9+7
res = 0
curmin,curmax = 0, N
mini,maxi = 1, N-1
for i in range(1,N+2):
  if i == N+1:
    
    res += 1
  else:
    if i >= K:
      
      res = (res + curmax - curmin + 1) % MOD
    curmin += mini
    curmax += maxi
    mini += 1
    maxi -= 1

print(res % MOD)

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

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

ans = 0

l = [0] * (n+2)
minv = 0
maxv = n


for i in range(1, n+2):
  
  l[i] = maxv - minv + 1
  minv += i
  maxv += (n-i)

for i in range(k, n+2):
  ans = (ans + l[i]) % (10**9 + 7)

print(ans)

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

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, k = map(int, input().split())
    nums = [i for i in range(n+1)]
    sums = [0]
    ans = 0
    x = 10**9 + 7
    for i in range(n):
        sums.append(nums[i+1]+sums[i])
    for j in range(k, len(nums)+1):
        if j == len(nums):
            ans += 1
        else:
            ans += sums[-1] - sums[-(1+j)] - sums[j-1] + 1
    print(ans%x)   

if __name__ == '__main__':
    main()

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

Solution (Python):
def _sum(l, r):
  return (l+r)*(r-l+1)//2
  

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

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

Solution (Python):

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

ans = 0

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

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

Solution (Python):
n, k = map(int, input().split())
mo = 10 ** 9 + 7
ans = 0
def calc(t):
    u = (0 + t - 1) * t // 2
    v = (n + n - t + 1) * t // 2
    return v - u + 1
for i in range(k, n + 2):
    ans = (ans + calc(i)) % mo
print(ans)

Solution (Python):
N, K = map(int, input().split())
mod = 10**9 + 7
count = 0
for n in range(K, N+2):
  maxSum = (n*(N + N-n+1))//2
  minSum = (n*(n-1))//2
  count += maxSum - minSum + 1
  count %= mod

print(count)

Solution (Python):
import sys
import copy
from collections import deque
stdin = sys.stdin

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n,k = na()

if n==k-1:
    print(1)
    exit(0)

prev_min = sum([i for i in range(k)])
prev_max = sum([i for i in range(n, n-k, -1)])
prev_num_min = k-1
prev_num_max = n-k+1
cnt = 0
for i in range(n-k+2):
    
    cnt += prev_max-prev_min+1
    cnt %= mod
    
    prev_num_min += 1
    prev_num_max -= 1
    prev_min += prev_num_min
    prev_max += prev_num_max

print(cnt)

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

for k in range(K, N + 1):
    ans += (k * (N - k) + 1) % p
    ans %= p

print(ans)

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

Solution (Python):

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

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

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

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

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

Solution (Python):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,k = nm()

MOD = 10**9+7
ans = 0

for kk in range(k,n+2):
  
  aa = (n-kk+n+1)*kk//2
  bb = (0+kk-1)*kk//2
  
  
  a=aa-bb
  
  ans+=a+1%MOD

print(ans%MOD)

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

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






ans = 0
for n in range(K,N+2):
  lowest = n*(n-1) // 2
  highest = n*N - n*(n-1) // 2
  
  ans += highest - lowest + 1
  ans %= MOD
  
print(ans)

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

def choose(n, m):   
    return (n - m + 1) * m + 1

s = 0
for i in range(k, n + 2):
    s += choose(n, i)

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

Solution (Python):
import sys
import itertools

import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

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

low, high = 0, 0
ans = 0
for x in range(1, N + 2):
    low += x - 1
    high += N - x + 1

    if x >= K:
        ans += (high - low + 1)
        ans %= MOD

print(ans)

Solution (Python):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
N, K = lr()
answer = 0
for i in range(K, N+2):
    low = i * (i-1) // 2
    high = i * (N+N-i+1) // 2
    answer += high - low + 1
    answer %= MOD

print(answer%MOD)

Solution (Python):
def main():
    n, k = map(int, input().split())
    mod = 10**9+7
    if n - k == -1:
        print(1)
    else:
        ans = (n+2*k) * (n-k+1) * (n-k+2) // 6 + n - k + 2
        print(ans%mod)
if __name__=="__main__":
    main()

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