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

MOD = 1000000007  


def solve(N: int, K: int):
    def f(k):
        return ((N * k) % MOD - (k * k) % MOD + k + 1) % MOD
    ans = 1
    for k in range(K, N+1):
        ans = (ans + f(k)) % MOD
    return ans



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    print(solve(N, K))

if __name__ == '__main__':
    main()

Solution (Python):

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

MOD = 10**9+7


def sumrange(x, y):
    ret = (x+y) * ((y-x+1)//2) 
    if (y-x+1)%2 == 1:
        ret += x+(y-x)//2
    return ret % MOD

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


print(ans)

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

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

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

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

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

print(result)

Solution (Python):
class Combination:
    def __init__(self, size, mod=10**9 + 7):
        self.size = size + 2
        self.mod = mod
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % self.mod
            self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % self.mod

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

    def nhr(self, n, r):  
        return self.ncr(n + r - 1, n - 1)

    def factN(self, n):
        if n < 0:
            return 0
        return self.fact[n]

N, K = map(int, input().split())
MOD = 10**9 + 7
S = N * (N + 1) // 2

ans = 1
for d in range(N + 1):
    if N - d < K:
        break
    mx = S - (d * (d + 1) // 2)
    mi = max(0, (N - d - 1) * ((N - d - 1) + 1) // 2)
    ans += (mx - mi + 1) % MOD
    ans %= MOD
print(ans)

Solution (Python):
n, k = map(int, input().split())
a = [i for i in range(n+1)]
a.reverse()
s = 0
l = k-1
c = sum(a[:k])
for i in range(k,n+2):
	
	s += c - (i-1)*i//2 + 1
	s %= 10**9+7
	l += 1
	if l >= n+1:
		break
	c += a[l]
print (s)

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

Solution (Python):
def num(k):
    n = (N)*(N+1)//2%inf - (N-k)*(N-k+1)//2%inf - k*(k-1)//2%inf +1
    return n

N,K = map(int,input().split())
inf = 10**9+7
ans = 0
for k in range(K,N+2):
    ans += num(k)%inf

print(ans%inf)

Solution (Python):

import sys

MOD = 1000000007  


def solve(N: int, K: int):
    res = 0
    r = 1000000007
    for k in range(K, N+2):
        
        res += (sigma(N-k+2, N+1) - sigma(1, k) + 1)
        res %= r

    print(res)


def sigma(left, right):
    return (right - left + 1) * (left + right) // 2


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    solve(N, K)


if __name__ == '__main__':
    main()

Solution (Python):
mod = 10**9+7
n,k = [int(x) for x in input().strip().split()]
res=0
for j in range(k,n+2):
    mn = (j-1)*j//2
    mx = j*(2*n-j+1)//2
    res = (res%mod+(mx-mn+1)%mod)%mod

print(res%mod)

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

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

    ans = 0
    low = sum(range(K - 1))
    high = sum(range(N - K + 2, N + 1))
    for take in range(K, N + 2):
        low += take - 1
        high += N - (take - 1)
        ans = (ans + high - low + 1) % MOD
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import heapq
from collections import defaultdict, deque
from math import ceil, factorial, gcd
from itertools import accumulate
import sys
import bisect
import numpy as np

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

si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
lmii = lambda: list(map(int, input().split()))
smii = lambda: sorted(map(int, input().split()))



N, K = mii()

num = [x for x in range(N+1)]


acc = list(accumulate(num))

ans = 0
for i in range(K, N+1):
    if i == 1:
        ans += N + 1
    else:
        tail = acc[N] - acc[N-i]
        head = acc[i-1]
        ans += tail - head + 1
    ans %= MOD

print((ans+1)%MOD)

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

        ans %= p

    print(ans)


if __name__ == '__main__':
    main()

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

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

mod = pow(10,9) +7

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

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

MOD = 10**9+7

st = int((K-1)*(K)/2)
go = int((2*N-K+1)*(K)/2)
ans = 0

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

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

MOD = 10 ** 9 + 7
count = 0
total = (N * (N + 1)) // 2
for k in range(K, N + 2):
    lo = k * (k - 1) // 2
    temp = N - k + 1
    hi = total - temp * (temp - 1) // 2
    count += hi - lo + 1
print(count % MOD)

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

left = 0
right = 0
ans = 0
MOD =10**9+7
for i in range(n+1):
	left += i
	right += n-i
	if i >= k-1:
		ans += right - left + 1
		ans %= MOD

print(ans%MOD)

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



def one_to_a_sum(a):
    return (a+1)*a//2

def a_to_b_sum(a, b):
    return one_to_a_sum(b) - one_to_a_sum(a-1)

sum_num = 0
for i in range(K, N+2):
    min_num = a_to_b_sum(0, i-1)
    max_num = a_to_b_sum(N-(i-1), N)
    sum_num = (sum_num + max_num-min_num+1) % (10**9+7)

print(sum_num)

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

print(count)

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

Solution (Python):
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

def main():
    mod = 1000000007
    n, k = map(int, input().split())
    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)

main()

Solution (Python):
N,K = map(int,input().split(' '))
num_list = list(reversed(range(N+1))) 
sum_list_reversed = [num_list[0]]
for i in range(1,N+1):
    sum_list_reversed.append(sum_list_reversed[i-1] + num_list[i])
num_list = list(range(N+1))
sum_list = [num_list[0]]
for i in range(1,N+1):
    sum_list.append(sum_list[i-1] + num_list[i])
ans = 0

for i in range(K-1,N+1):
    current_sum = sum_list_reversed[i] - (sum_list[i] -1)
    ans += current_sum
    ans = ans%(10**9+7)
print(ans)

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

for i in range(n + 2 - k):
    max_n = n * (n + 1) / 2 - (n - (k + i)) * (n + 1 - (k + i)) / 2
    min_n = (k + i) * (k + i - 1) / 2
    res = (res + max_n - min_n + 1) % 1000000007

print(int(res))

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

Solution (Python):


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

ans=0
for k in range(K,N+2):
    minc=round(k*(k-1)/2)
    maxc=round(k*(2*N-k+1)/2)
    count=maxc-minc+1
    ans+=count
    


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

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

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

Solution (Python):
n,k=list(map(int,input().split()))
od=10**9+7
s=0
e=0
ans=0
for i in range(n):
    s+=i
    e+=n-i
    if i+1<k:
        continue
    ans+=(e-s+1)%od
print((ans+1)%od)

Solution (Python):
N, K = map(int, input().split())
cnt = 0
for k in range(K, N+2):
    mn = k * (k - 1) // 2
    mx = k * (N - k + 1) + mn
    
    cnt += (mx-mn+1)

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

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

print(ans)

Solution (Python):
import sys
import os
from io import BytesIO, IOBase






'''def sieve(n):
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * p, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r'''


'''def divs(n, start=1):
    divisors = []
    for i in range(start, int(n**.5) + 1):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return len(divisors)'''


'''def divn(n, primes):
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t
    return divs_number'''


'''def flin(d, x, default=-1):
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return (default, default)
    else:
        return (left, right)'''


'''def xor1_n(n):
    d={0:n,1:1,2:n+1,3:0}
    return d[n&3]'''

def cel(n, k): return n // k + (n % k != 0)
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def prr(a, sep=' '): print(sep.join(map(str, a)))
def dd(): return defaultdict(int)
def ddl(): return defaultdict(list)
def ddd(): return defaultdict(defaultdict(int))



BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
            while True:
                    b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
                    if not b:
                            break
                    ptr = self.buffer.tell()
                    self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
            self.newlines = 0
            return self.buffer.read()

    def readline(self):
            while self.newlines == 0:
                    b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
                    self.newlines = b.count(b"\n") + (not b)
                    ptr = self.buffer.tell()
                    self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
            self.newlines -= 1
            return self.buffer.readline()

    def flush(self):
            if self.writable:
                    os.write(self._fd, self.buffer.getvalue())
                    self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
            self.buffer = FastIO(file)
            self.flush = self.buffer.flush
            self.writable = self.buffer.writable
            self.write = lambda s: self.buffer.write(s.encode("ascii"))
            self.read = lambda: self.buffer.read().decode("ascii")
            self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

from collections import defaultdict 


from math import gcd,pi











mod=10**9+7



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

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

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

    num = maxsum-minsum +1
    sum += num
    sum = sum % (10**9+7)

print(int(sum))

Solution (Python):
a=input().split(" ")
N=int(a[0])
K=int(a[1])

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

Solution (Python):



import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,k = [int(i) for i in read().split()]

a = list(range(n+1))
r = sum(a[n+1-k:])
l = sum(a[:k])

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

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

Solution (Python):
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import time
import math
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
N,K=map(int,input().split())
mod=10**9+7
"""
fac=[1,1]
for i in range(2,2*(N+1)):
    fac.append(fac[-1]*i%mod)
ifac=[pow(i,mod-2,mod) for i in fac]
def comb(a,b):
    if a<b:return(0)
    return(fac[a]*ifac[a-b]*ifac[b]%mod)
"""
c=0
for k in range(K,N+2):
    X=(N)*k - (k-1)*k//2 - (k-1)*k//2  +1
    c+=X
    
    c%=mod
print(c)

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

if __name__ == "__main__":
    main()

Solution (Python):


import sys
import math
import collections
import itertools
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N, K = LI()

k = list(range(N+1))
ans = 1
l = sum(k[0:K-1])
r = sum(k[N-K+2:])

for i in range(K-1, N):
    l += k[i]
    r += k[N-i]
    
    if  r-l < 0:
        break
    
    ans = (ans + (r-l) + 1) % MOD

print(ans)

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

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

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

print(cnt)

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

Solution (Python):
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

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

    

if __name__ == '__main__':
    main()

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

print(ans % MOD)

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

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

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

def resolve():
    p = 10**9+7

    def combMod(n, r, p):
        numer = 1
        denom = 1
        for i in range(1, r+1):
            numer = numer * (n-r+i) % p
            denom = denom * i % p
        return numer * pow(denom, p-2, p) % p

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

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

    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
n,k=map(int,input().split())
s=list(range(0,n+1))
cs=[]
mod=10**9+7
sum=0
for i in range(n+1):
	sum+=s[i]
	cs.append(sum)
cnt=0
for i in range(k,n+1):
	mini=cs[i-1]
	maxi=cs[n]-cs[n-i]
	cnt+=(maxi-mini+1)%mod
	cnt%=mod
print((cnt+1)%mod)

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

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

div = 10**9 + 7

ans = 0

top = (2*N-K+2)*(K-1) / 2
bottom = (K-1)*(K-2) / 2

for i in range(N-K+2):
    
    top += (N-K+1-i)
    bottom += (K-1+i)

    ans = (ans + top-bottom+1) % div

print(int(ans))

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

cnt = 0

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

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

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


max_num, min_select = map(int, input().split())

ans = 0
for select in range(min_select, max_num + 2):
    sum_min = (select * (select - 1)) // 2
    sum_max = max_num * select - sum_min
    ans += (sum_max - sum_min + 1) % DIV

print(ans % DIV)

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

cnt = 0
L, R = 0, 0
for i in range(k-1):
    L += i
    R += n - i

for i in range(k-1, n+1):
    L += i
    R += n - i
    cnt += R - L + 1
print(cnt%mod)

Solution (Python):
def by_k(k):
    return k*(N+2) - k*(k+1) + 1

M = 10**9+7
N, K = [int(x) for x in input().split()]
ans = 0
for k in range(K, N+2):
    ans += by_k(k)
    while ans > M:
        ans -= M
print(ans)

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

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

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

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

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

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

def sum_(a, b):
    if (a-b)%2 == 1:
        return int((b+a) * (b-a+1) / 2)
    else:
        return int((b+a) * (b-a+1) / 2)

ret = 0
for i in range(K, N+2):
    ret += sum_(N-i+1, N) - sum_(0, i-1) + 1

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

Solution (Python):
MOD = 10**9+7
def cmb(n, r):
  if r < 0 or n < r:
    return 0
  r = min(r, n - r)
  return fact[n] * factinv[r] * factinv[n-r] % MOD

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

fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N+1 + 1):
  fact.append((fact[-1] * i) % MOD)
  inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
  factinv.append((factinv[-1] * inv[-1]) % MOD)


res = 0

max_sum = 0
min_sum = 0
for i in range(K):
  max_sum += N-i
  min_sum += i

for i in range(N+1+1)[K:]:
  res += (max_sum - min_sum)+1
  max_sum += N-i
  min_sum += i

print(res%MOD)

Solution (Python):


import sys
sys.setrecursionlimit(300000)

MOD = 1000000007  

def solve(N: int, K: int):
    sums = [0] * (N + 2)
    for i in range(1, N + 2):
        sums[i] = sums[i - 1] + i
        sums[i] %= MOD

    cum = [0] * (N + 3)
    for i in range(N + 2):
        if i == 0:
            tmp = N + 1
        else:
            
            
            tmp = sums[N] - sums[max(0, N - i)]
            tmp -= sums[i - 1] - 1
        tmp %= MOD
        cum[i + 1] = cum[i] + tmp
        cum[i + 1] %= MOD
    
    ret = cum[N + 2] - cum[K]
    ret %= MOD
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    solve(N, K)

if __name__ == '__main__':
    main()

Solution (Python):



debug=0
def pront(*n):
    if debug==1:
        print(n)
        


base=10**9+7

def add(a,b):
    return (a+b)%base

def sub(a,b):
    return (a-b)%base

def multi(a,b):
    return (a*b)%base

def exp(a,b):
    x=1
    c=a
    d=b
    while d!=0:
        if d%2==1:
            x=multi(x,c)
        c=(c**2)%base
        d=d//2
    return x

def div(a,b):
    return(multi(a,exp(b,base-2)))


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


    
def fact(m,n):
    x=1
    for i in range(m,n+1):
        x=multi(x,i)
    return x
def comb(n,r):
    return div(fact(n-r+1,n),fact(1,r))

def ssum(m,n):
    x=(n)*(n+1)//2
    y=(m-1)*(m)//2
    return x-y

x=0

for i in range(K,N+2):
    
    x+=ssum(N-i+1,N)-ssum(0,i-1)+1
print(x%base)

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

lim=10**9+7
ma=n*(n+1)//2
mi=n*(n+1)//2
for i in range(n+2-k):
    
    s = (s+ma-mi+1)%lim
    ma -= i
    mi -= (n-i)
    
print(s%lim)

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()
floor = (K-1) * (K-2) // 2
limit = (N+(N-K+2)) * (K-1) // 2
answer = 0
for x in range(K, N+2):
    floor += (x-1)
    limit += N-x+1
    answer += limit - floor + 1

print(answer % MOD)

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

sum_tab = [0]
sum_tmp = 0
for i in range(N + 1):
    sum_tmp += i
    sum_tab.append(sum_tmp)

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

print(ans)

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

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

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

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

print(ans)

Solution (Python):
def main():

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

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

    return ans

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

Solution (Python):
ans=0
MOD=10**9+7
n,k=map(int,input().split())
min=0
max=n
num0=0
num1=n
for i in range(n+1):
  
  i+=1
  if i>=k:
    ans+=max-min+1
    ans=ans%MOD
  min+=num0+1
  num0+=1
  max+=num1-1
  num1-=1
print(ans)

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

N += 1
n_patterns = 0
remain_min = 0
remain_max = 0

for i in range(M-1):
    remain_min += i
    remain_max += N - 1 - i

for i in range(M-1, N):
    remain_min += i
    remain_max += N - 1 - i
    n_remain = remain_max - remain_min + 1
    n_patterns += n_remain


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

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

Solution (Python):
MOD = 10 ** 9 + 7
INF = 10 ** 12
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  itertools import permutations
from heapq import heapify,heappop,heappush

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

if __name__ =='__main__':
    main()

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

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

print(ans)

Solution (Python):
N,K = map(int,input().split())
A = []
c = 0

for i in range(N+2):
    A.append(i*(i-1)//2)

for i in range(K,N+2):
    c += A[N+1]-A[N-i+1]-A[i]+1
    
print(c%(10**9+7))

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

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

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

Solution (Python):
import numpy as np
N, K = map(int, input().split())
MOD = 10**9 + 7
arr = np.arange(0, N + 1)

_max = arr[-K:].sum()
_min = arr[:K].sum()

ans = _max - _min + 1
for k in range(K, N + 1):
    
    _max += arr[-(k + 1)]
    _min += arr[k]
    
    ans += _max - _min + 1
    ans = ans % MOD
print(ans)

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

MOD = 10**9+7

minus = sum(range(k))
plus  = sum(range(n+1-k,n+1))
count = plus - minus + 1

for i in range(k,n+1):
  plus += n-i
  minus += i
  
  count += plus - minus + 1
  count %= MOD
  
print(count)

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

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

S+=1

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

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

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

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

print(an)

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

ans = 0

s = n*(n+1)//2

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

print(ans%mod)

Solution (Python):
n,k=map(int,input().split())
MOD=10**9+7
t=[]
r=[]
for i in range(0,n+1):
    t.append(i)
for i in range(n,-1,-1):
    r.append(i)

fr=0
af=0
for i in range(0,k-1):
    fr+=t[i]
    af+=r[i]

ans=0
for i in range(k-1,n+1):
    fr+=t[i]
    
    af+=r[i]
    ans+=(af-fr+1)%MOD

print(ans%MOD)

Solution (Python):
N,K=map(int,input().split())
ruiseki=[0 for i in range(N+2)]

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

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

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

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

print(c%M)

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

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

mod = 10**9+7

cum = [i for i in range(10**6)]
def cumsum(lst): 
    res = lst[:]
    for i in range(1,len(res)):
        res[i] += res[i-1]
    return res
cum = cumsum(cum)
def cumsumdif(l,r,lst): 
    if l == 0:
        return lst[r]
    else:
        return lst[r] - lst[l-1]

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

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

print((ans+1)%mod)

Solution (Python):
n,k = map(int,input().split())
cnt = 0
for i in range(k,n+2):
    cnt += n * (n + 1) / 2 - (n - i) * (n - i + 1) / 2 - i * (i - 1) / 2 + 1
print(int(cnt % (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_start=0
    min_end=min_start+i-1
    max_end=n
    max_start=n-i+1
    min_sum=(min_end-min_start+1)*(min_end+min_start)//2
    max_sum=(max_end-max_start+1)*(max_end+max_start)//2

    ans+=max_sum-min_sum+1
    ans=ans%MOD
print(ans%MOD)

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

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

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

resolve()

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

  
mod = 10**9+7 

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

print(ans%mod)

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

if __name__ == '__main__':
  main()