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):
MOD = 10**9+7
class mint:
    def __init__(self, x):
        self.x = x % MOD if isinstance(x, int) else int(x) % MOD
    def __str__(self):
        return str(self.x)
    __repr__ = __str__
    def __iadd__(self, other):
        self.x += other.x if isinstance(other, mint) else other
        self.x -= MOD if self.x >= MOD else 0
        return self
    def __isub__(self, other):
        self.x += MOD-other.x if isinstance(other, mint) else MOD-other
        self.x -= MOD if self.x >= MOD else 0
        return self
    def __imul__(self, other):
        self.x *= other.x if isinstance(other, mint) else other
        self.x %= MOD
        return self
    def __imod__(self, other):
        self.x %= other.x if isinstance(other, mint) else other
        self.x %= MOD
        return self
    def __add__(self, other):
        return (
            mint(self.x + other.x) if isinstance(other, mint) else
            mint(self.x + other)
        )
    def __sub__(self, other):
        return (
            mint(self.x - other.x) if isinstance(other, mint) else
            mint(self.x - other)
        )
    def __mul__(self, other):
        return (
            mint(self.x * other.x) if isinstance(other, mint) else
            mint(self.x * other)
        )
    def __mod__(self, other):
        return (
            mint(self.x % other.x) if isinstance(other, mint) else
            mint(self.x % other)
        )
    def __truediv__(self, other):
        return (
            mint(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, mint) else
            mint(self.x * pow(other, MOD - 2, MOD))
        )
    def __pow__(self, other):
        return (
            mint(pow(self.x, other.x, MOD)) if isinstance(other, mint) else
            mint(pow(self.x, other, MOD))
        )
    __radd__ = __add__
    def __rsub__(self, other):
        return (
            mint(other.x - self.x) if isinstance(other, mint) else
            mint(other - self.x)
        )
    __rmul__ = __mul__
    def __rmod__(self, other):
        return (
            mint(other.x % self.x) if isinstance(other, mint) else
            mint(other % self.x)
        )
    def __rtruediv__(self, other):
        return (
            mint(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, mint) else
            mint(other * pow(self.x, MOD - 2, MOD))
        )
    def __rpow__(self, other):
        return (
            mint(pow(other.x, self.x, MOD)) if isinstance(other, mint) else
            mint(pow(other, self.x, MOD))
        )

def sumarray(a,b):
    res=b*(b+1)//2
    res-=a*(a-1)//2
    return mint(res)

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


ans=mint(0)

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

print(ans)

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

print(ans)

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())
mod = pow(10,9)+7
ans = 0
D = [0]
for i in range(N+1):
    D.append(D[i]+i)
for k in range(K,N+2):
    ans += (D[N+1]-D[N+1-k]-D[k]+1)%mod
print(ans%mod)

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

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

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

def main():
    mod=10**9+7
    N,K=MI()
    ans=0
    S=[0]*(N+2)
    for i in range(N+1):
        S[i+1]=S[i]+(i)
    
    
    for i in range(K,N+2):
        m=S[i]
        M=S[-1]-S[-1-i]
        ans+=(M-m+1)%mod
        ans%=mod
    print(ans)
        

main()

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

res = 0

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

print(res)

Solution (Python):
[N,K] = list(map(int,input().split()))
out = 0
for i in range(K,N+2):
    L = (i-1)*i//2
    R = N*i-L
    P = (R-L+1)
    out += P
    out = out%(10**9+7)
print(out)

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

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


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

print(ans)

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

mod = 10**9+7

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

A = [0]
for i in range(1, N+1):
    A.append((A[-1]+i)%mod)

ans = 0
for k in range(K, N+2):
    if k == N+1:
        ans = (ans + 1)%mod
    else:
        ans = (ans + (A[-1]-A[-k-1]) - A[k-1] + 1) % mod
print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def f(st, en):
    n = en - st + 1
    return n * (st + en) // 2

def main():
    N, K = LI()
    cnt = 0
    for i in range(K, N+2):
        m = f(0, i-1)
        M = f(N - (i-1), N)
        cnt += (M - m + 1)
        cnt %= mod
    print(cnt % mod)



main()

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

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

    sum_min =  (i - 1) * (i) // 2
    sum_max = i * (2*n - i - 1) // 2
    ans += sum_max - sum_min + 1
    ans %= MOD
print(ans)

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


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

Solution (Python):


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    mod = 10**9 + 7

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

    res = 0

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

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

Solution (Python):
mod = 10**9+7
mod2 = 998244353
rng = 200100
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
n,k = map(int,input().split())
ans = 0
for i in range(k,n+2):
  ans += n*(n+1)//2-(n-i)*(n-i+1)//2-i*(i-1)//2+1
  ans %= mod
print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,k = inpl()
up = [0]
down = [n]
for i in range(n):
    up.append(up[-1] + i+1)
    down.append(down[-1] +(n-i-1))
res = 0

for i in range(k-1,n+1):
    res += down[i] - up[i] + 1
    res %= mod
print(res)

Solution (Python):
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
    ans %= mod
print(ans)

Solution (Python):
import sys
from collections import *
import heapq
import math
from math import gcd
import bisect
import copy
from itertools import permutations,accumulate,combinations,product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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




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

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

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

ANS=0
for t in range(K,N+2):
    MIN=(0+0+(t-1))*t//2
    MAX=(N+N-(t-1))*t//2

    ANS+=MAX-MIN+1
    ANS%=10**9+7

print(ANS)

Solution (Python):
Q = 10**9+7
def main():
    N, K = map( int, input().split())
    m = 0
    M = 0
    for i in range(K-1):
        m += i
        M += N-i
    ans = 0
    for i in range(K-1, N+1):
        m += i
        M += N-i

        ans += M-m+1
        ans %= Q
    print(ans)
if __name__ == '__main__':
    main()

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

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

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

print(ans%mod)

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

Solution (Python):


import sys



















def main():
    mod = 1000000007                  
    inf = float('inf')
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n, k = mi()
    ans = 0
    for i in range(k, n+2):
        low = i * (i + 1) // 2
        high = i * (2 * n + 3 - i) // 2
        ans += (high-low+1) % mod
        
    print(ans % 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):
    ans += (n + n - i + 1) * i // 2 - (i - 1) * i // 2 + 1
    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):
    ans = (ans + i * (N-i+1) + 1) % mod
print(ans)

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

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

mod = 10**9+7
a = [i for i in range(n+1)]
for i in range(n):
    a[i+1] += a[i]
b = [i for i in range(n, -1, -1)]
for i in range(n):
    b[i+1] += b[i]

ans = 0
for i in range(k-1, n+1):
    ans += b[i] - a[i] + 1
    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):
	mini=(i-1)*i//2
	maxi=(2*n-i+1)*i//2
	ans+=(maxi-mini+1)%mod
	ans%=mod
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)

mod = 1000000007
INF = 110110110
_INFL = -INF * INF

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

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

Solution (Python):
def main():
    import sys
    N,K=list(map(int,sys.stdin.readline().split()))
    output=0
    for k in range(K,N+2):
        output+=(2*N-k+1)*k//2-k*(k-1)//2+1
        output%=10**9+7

    print(output)
main()

Solution (Python):






import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


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


def lcm(a, b):
    return a * b // gcd (a, b)





N,K = inputIL()

sum = 0

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

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

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

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

cnt = 0

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

Solution (Python):
from itertools import accumulate

n, k = map(int, input().split())
MOD = 10 ** 9 + 7
f_acc = [0] + list(accumulate(list(range(n + 1))))
b_acc = [0] + list(accumulate(reversed(list(range(n + 1)))))
ans = 0
for i in range(k, n + 2):
    min_ = f_acc[i]
    max_ = b_acc[i]
    ans = (ans + max_ - min_ + 1) % MOD
print(ans)

Solution (Python):


MOD = 10 ** 9 + 7

def main():
    n, k = map(int, input().split())
    res = 0
    for l in range(k, n + 2):
        res += l * (n + 1 - l) + 1
        res %= MOD
    print(res)

if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.readline
from collections import *
from math import *

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

for i in range(K, N+2):
    c = ((2*N-i+1)*i)//2-i*(i-1)//2+1
    ans += c
    ans %= MOD

print(ans)

Solution (Python):
mod=10**9+7
n,k=map(int,input().split())
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())


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

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

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

print(ans)

Solution (Python):
import sys
input=lambda: sys.stdin.readline().rstrip()
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=(2*n-i+1)*i//2
  ans+=r-l+1
  if ans>=mod:
    ans%=mod
print(ans)

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

ans = 0
mod = 10 ** 9 + 7

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

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

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

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

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

ans = 0

left = 0
right = 0

m = 10**9+7
for i in range(k-1):
    left += i

for i in range(k-1):
    right += n-i


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

print(ans)

Solution (Python):
def examA():
    R = I()
    ans = R*2*3.141592
    print(ans)
    return

def examB():
    N, M = LI()
    A = LI()
    S = sum(A)
    if N>=S:
        ans = N-S
    else:
        ans = -1
    print(ans)
    return

def examC():
    N = I()
    A = LI()
    ans = [0]*N
    for i in range(N-2,-1,-1):
        ans[A[i]-1] +=1
    for v in ans:
        print(v)
    return

def examD():
    N, K = LI()
    S = [0]*(N+2)
    for i in range(1,N+1):
        S[i+1] = S[i] + i
    
    ans = 0
    for i in range(K,N+2):
        cur = (S[N+1] - S[N-i+1]) - (S[i] - S[0]) +1
        ans += cur
        ans %= mod
        

    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Solution (Python):
from collections import *
import sys
try: inp = raw_input
except: inp = input
def err(s):
    sys.stderr.write('{}\n'.format(s))

def ni():
    return int(inp())

def nl():
    return [int(_) for _ in inp().split()]

N, K = nl()

MOD = 10**9 + 7
s1 = sum(range(0, K))
s2 = sum(range(N - K + 1, N+1))
no = s2 - s1 + 1
for k in range(K, N+1):
    s1 += k
    s2 += N - k
    no += (s2 - s1 + 1)
print(no%MOD)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
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 LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    ans=1
    md=10**9+7
    n,k=MI()
    for a in range(k,n+1):
        ans+=(n-a+1)*a+1
        ans%=md
    print(ans)

main()

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

Solution (Python):
mod = int(1e9) + 7

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

    small = 0
    large = 0
    ans = 0
    for i in range(0, n+1):
        small += i
        large += n-i
        if i+1 >= k:
            ans = (ans + (large - small + 1)) % mod

    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

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

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


N, K = list(map(int, sys.stdin.buffer.readline().split()))


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

Solution (Python):

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

ans = 0
mi = 0
ma = 0
mod = 10**9+7
for i in range(N+2):

    if i >= K:
        ans += ma - mi + 1
        ans %= mod

    mi += i
    ma += N-i
    mi %= mod
    ma %= mod

print (ans)

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

ans = 0
mod = 10**9 + 7

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

print(ans)

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

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

Solution (Python):
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

N,K = Ints()

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):
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'

    mp=[1]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)];rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase

input=lambda: sys.stdin.readline().rstrip()

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo

show_flg=False
show_flg=True

ans=0

n,k=LI()

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


print(ans%mo)

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

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 10 ** 9 + 7

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

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

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

Solution (Python):
import sys

stdin = sys.stdin

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

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

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):
mod = 1000000007
eps = 10**-9


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

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

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


if __name__ == '__main__':
    main()

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):
MOD = 10 ** 9 + 7

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

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

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