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


from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


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

    MOD = 10**9 + 7

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

    print(s)




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


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

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



if __name__ == "__main__":
    main()

Solution (Python):
def calc(x):
    smallest = x * (x - 1) // 2
    largest = smallest + (N - x + 1) * x
    return largest - smallest + 1


N, K = map(int, input().split())
M = 10 ** 9 + 7
res = 0
for x in range(K, N + 2):
    res = (res + calc(x)) % M

print(res)

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

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


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

sum = 0
for i in range(K,N+2):
    sum += numK(N,i)

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

Solution (Python):
def div_with_mod(x, y, mod):
    
    return x*pow(y, mod - 2, mod)


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

    s = 0
    s_1 = 0
    a = []
    b = 0
    ans = 0
    for i in range(N+1):
        b += i
        a.append(b)

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


if __name__ == "__main__":
    solve()

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

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

Solution (Python):
n,k=map(int,input().split())
count=0
for i in range(n+2):
    if i<k:
        continue
    elif i>=k:
        mini=i*(i-1)//2
        a=n*(n+1)//2
        b=(n-i)*(n-i+1)//2
        maxi=a-b
        total=maxi-mini+1
        count+=total
ans=count%(10**9+7)
print(ans)

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

MOD = 10**9+7
class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value += Mint.get_value(other)
        if self.value >= MOD: self.value -= MOD
        return self
    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value -= Mint.get_value(other)
        if self.value < 0: self.value += MOD
        return self
    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj
    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self
    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self
    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj
    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

ans = Mint()
for i in range(K,N+2):
    mn = Mint(i*(i-1)//2)
    mx = Mint((N+N-i+1)*i//2)
    ans += mx - mn + 1
print(ans)

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

Solution (Python):
def main():
    n, k = [int(i) for i in input().split()]
    
    mod = 1000000007
    res = 0
    for i in range(k, n+2):
        min_s = int(i*(i-1)/2)
        max_s = int(n*(n+1)/2 - (n-i)*(n-i+1)/2 )
        res += max_s - min_s + 1
        res = res % mod
    print(int(res))

if __name__ == '__main__':
    main()

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
MOD = 10 ** 9 + 7

def main():
    N, K = map(int, readline().rstrip().split())
    ans = 0
    m = (N * (N + 1)) // 2
    for k in range(K, N+2):
        mi = ((k-1) * k) // 2
        ma = m - ((N-k) * (N-k+1)) // 2
        ans += (ma - mi + 1)

    print(ans % MOD)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
a = list(map(int,input().split()))
n = a[0]
k = a[1]

count = 0


b=n+1-k+1
keisu=[0]*b
for i in range(b):
  keisu[i]=k+i


for i in keisu:
  mn = (i-1)*i/2
  mx = ((n-i+1)+n)*i/2
  count += (mx-mn+1)
  count %= (10**9+7)
  
print(int(count))

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

a = [i for i in range(n+1)]
ac = list(accumulate(a))
sa = sum(a)
cnt = 0
for i in range(k, n+2):
    if i == n+1:
        cnt += 1
        break
    cnt += sa - ac[-i-1] - ac[i-1] + 1
print(cnt%MOD)

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

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

Solution (Python):
def sum_C(n,k):
	nn=n
	max = 0
	min = 0
	sum=0
	for i in range(k):
		min += i
	for j in range(k):
		max += nn
		nn-=1
	sum += (max-min+1)%(pow(10,9)+7)

	
	
	for i in range(k,n+1,1):
		max+=n-i
		min+=i
		
		sum+=(max-min+1)%(pow(10,9)+7)
	return sum
 
 
N,K = map(int, input().split())
 
p = sum_C(N,K)
p = p%(pow(10,9)+7)
print(p)

Solution (Python):
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7

def main():
    N, K = map(int, readline().rstrip().split())
    ans = 0
    m = (N * (N + 1)) // 2
    for k in range(K, N+2):
        mi = ((k-1) * k) // 2
        ma = m - ((N-k) * (N-k+1)) // 2
        ans += (ma - mi + 1)

    print(ans % MOD)


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

N,K = map(int,input().split())
p = 10**9+7
Nlist = []
ReNlist =[]
Ans = 0
for i in range(N+1):
    Nlist.append(i)
    ReNlist.append(N-i)
Nlist = np.array(Nlist).cumsum()
ReNlist = np.array(ReNlist).cumsum()
for i in range(K,N+1):
    Ans += ReNlist[i-1]-Nlist[i-1] +1
    Ans = Ans % p
print(Ans+1)

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

Solution (Python):
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7

def main():
    N, K = map(int, readline().rstrip().split())
    ans = 0
    m = (N * (N + 1)) // 2
    for k in range(K, N+2):
        mi = ((k-1) * k) // 2
        ma = m - ((N-k) * (N-k+1)) // 2
        ans += (ma - mi + 1) % MOD

    print(ans % MOD)


if __name__ == '__main__':
    main()

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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

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

Solution (Python):
def main_function():
    from sys import stdin
    from sys import stdout
    input = stdin.readline
    print = stdout.write

    modulo = pow(10, 9) + 7
    n, k = list(map(int, input().split()))
    ans = 0
    tmp = 1
    for i in range(1, k):
        tmp -= i * 2
    for i in range(k, n + 2):
        ans += i * n + tmp
        tmp -= i * 2
        ans %= modulo
    print(f'{ans % modulo}')


if __name__ == '__main__':
    main_function()

Solution (Python):
def main():
    N, K = map(int, input().split())
    B = [0]*(N+2-K)
    full = (((N+1)*(N)) // 2)
    for n in range(K, N+2):
        mi = (n*(n-1)) // 2
        ma = full - ((N-n)*(N-n+1)//2)
        B[n-K] = ma-mi+1

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


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 += i*N - i*(i-1) + 1
    ans %= MOD

print(ans)

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


left = number[K - 1]
right = number[-K]
s_min = sum(number[0:K])
s_max = sum(number[-K:])
count = s_max - s_min + 1
for i in range(K + 1, N + 2):
    left += 1
    right -= 1
    s_min += left
    s_max += right
    count += s_max - s_min + 1
print(count % 1000000007)

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

    

    B = [0]*(N+2-K)
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    full = (((N+1)*(N)) // 2)
    for n in range(K, N+2):
        mi = (n*(n-1)) // 2
        
        ma = full - ((N-n)*(N-n+1)//2)
        
        B[n-K] = ma-mi+1
        
    print(sum(B) % (10**9 + 7))


if __name__ == '__main__':
    main()

Solution (Python):




import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

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

    mod = 10**9+7
    a=0
    z=0
    ans=0
    n+=1
    for i in range(1,n+1):
        a+=i
        z+=(n-i+1)
        cnt=z-a+1
        if i>=k:
            ans+=cnt
            ans%=mod
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

Solution (Python):
import math
n, k = map(int,input().split())
total = 0
mod = 10**9+7
max_value = (n*(n+1)) //2
for a in range(k,n+1):
    high = (max_value-(n-a)*(n-a+1)//2)
    low = (a*(a-1)) //2
    total += high - low + 1
total += 1 
print(total%mod)

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

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

Solution (Python):




import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

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

    mod = 10**9+7
    a=0
    z=0
    ans=0
    n+=1
    for i in range(1,n+1):
        a+=i
        z+=(n-i+1)
        cnt=z-a+1
        if i>=k:
            ans=(ans+cnt)%mod
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

Solution (Python):
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
MOD = 10**9 + 7

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


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

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

p = 10 ** 9 + 7
a = 10 ** 100 % p

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

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

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

result = 0
for i in range(K,N+2):
    min_number = (i - 1) * i / 2
    max_number = (N + ( N - i + 1)) * i / 2

    result += max_number - min_number + 1

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

Solution (Python):
import math

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

Z = 10**9 + 7
X = 0






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

print(math.floor((X + 1)%Z))

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

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

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

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

ans %= MOD
print(ans)

Solution (Python):
list = input().split()
N = int(list[0])
K = int(list[1])
i = K
s = 0

def sum(a,b):
    i=0
    i = (a + b)*(b - a + 1)/2
    return i

while i <= N + 1:
    
    s = s + sum(N-i+1,N) - sum(0,i-1) + 1
    i += 1
print(int(s % (10**9+7)))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, K = map(int, rl().split())
    MOD = 10 ** 9 + 7
    
    acc = [0] * (N + 1)
    for i in range(1, N + 1):
        acc[i] = (acc[i - 1] + i) % MOD
    
    ans = 0
    for i in range(K, N + 1):
        ans = (ans + acc[N] - acc[N - i] - acc[i - 1] + 1) % MOD
    ans = (ans + 1) % MOD
    print(ans)


if __name__ == '__main__':
    solve()

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

Solution (Python):
import math
import copy
import sys
import fractions


import decimal
import heapq
import collections
import itertools
import bisect



sys.setrecursionlimit(100001)







def getInputIntList():
    outputDataList = []
    inputData = input().split()
    outputDataList = [int(n) for n in inputData]

    return outputDataList


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList



MOD = 10 ** 9 + 7

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

sum_mat = [0]
for i in range(1, 2*(10**5)+3):
    sum_mat.append(sum_mat[i-1]+i)


ans = 0
for i in range(k, n + 1):
    top = sum_mat[i]
    bottom = sum_mat[i-1] - 1
    ans += (i * n - top - bottom) % MOD
    ans %= MOD

print(ans)

Solution (Python):


import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = MAP()

acc = list(range(N+2))
acc = list(accumulate(acc))

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

Solution (Python):
def rangesum(a, b=0):
    return (abs(a-b)+1) * (a+b) // 2

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

mod = 10**9+7
res = 0
for i in range(k, n+2):
    res += rangesum(n-i+1, n) - rangesum(i-1) + 1
    res %= mod

print(res)

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

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

Solution (Python):
a,b=(int(x)for x in input().split())
z=0
while b<=a+1:z=(z+(a-b+1)*b+1)%(10**9+7);b+=1
print(z)

Solution (Python):
s=list(map(int,input().split()))
mod=10**9+7
a=s[0]
b=s[1]
e=0
if b==1:
  b+=1
  e+=(a+1)
c=sum(range(0,b))
d=sum(range(a+1-b,a+1))
for i in range(b,a+2):
  if i!=b:
    c+=(i-1)
    d+=(a-i+1)
  e+=(d-c+1)
  e%=mod
print(e)

Solution (Python):
a,b=(int(x)for x in input().split())
z=0
while b<=a+1:z=(z+(a-b+1)*b+1)%(10**9+7);b+=1
print(z)

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


def g(n, k):
    return sum([f(n, ki) for ki in range(k, n + 2)])


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

Solution (Python):
MOD = 1000000007
class ModInt:
    def __init__(self, x):
        self.x = x % MOD

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

    __repr__ = __str__

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

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

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

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

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

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

    __radd__ = __add__

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

    __rmul__ = __mul__

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

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

    def __isub__(self,other):
        self.x += ModInt(MOD - other.x) if isinstance(other, ModInt) else ModInt(MOD - other)
        return self

    def __imul__(self, other):
        self.x *= other.x if isinstance(other, ModInt) else other
        self.x %= MOD
        return self
    
    def factorical(self,n):
        tmp = ModInt(1)
        for i in range(n):
            tmp *= (i+1)
        return tmp
    
    
    def modinv(self,a,m=MOD):
        b = m
        u = 1
        v = 0
        while(b):
            t = a//b
            a -= t * b
            a,b = b,a
            u -= t * v
            u,v = v,u
        return ModInt(u)

    def comb(self,n,r):
        n = int(n)
        r = int(r)
        if r > n or n < 0 or r < 0:
            return 0
        m = n+1
        n_terms = min(r, n-r)
        numerator = ModInt(1)
        denominator = ModInt(1)
        for j in range(1, n_terms + 1):
            numerator *= m - j
            denominator *= j
        return numerator * self.modinv(denominator.x)

if __name__ == "__main__":
    N, K = map(int, input().split())

    num = list()
    for i in range(N):
        num.append(i)
    
    ans = ModInt(0)
    for i in range(K, N+2):
        
        
        
        
        
        
        
        
        
        
        

        free = (N+1-i)*(i-1) + (N+1) -(i-1)
        
        ans += free
    
    print(ans)

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

Solution (Python):
Mod = 1000000007

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

res  = 0

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

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

ret = 0
for a in range(k,n+1):

	ret = (ret+(n-a+1)*a+1)%mod

ret=(ret+1)%mod
print(ret)

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

ans = 0
c = 0   
l = 0
h = 0
for i in range(1, n+2): 
    l += i - 1
    h += n + 1 - i
    c = (h - l + 1) % mod
    if i >= k:
        ans = (ans + c) % mod
    else:
        pass
print(ans)

Solution (Python):
n, k = map(int, input().split())
pos_num = []
for i in range(n+2):
    st_num = int((i*(i-1))/2)
    ed_num = int(((2*n-i+1)*i)/2)
    
    pos_num.append(ed_num-st_num+1)
print(sum(pos_num[k:])%(10**9+7))

Solution (Python):
def resolve():
    '''
    code here
    '''
    N, K = [int(item) for item in input().split()]

    res = 0

    for i in range(K, N+2):
        a = (i-1)*i//2
        c = N-i
        b = N*(N+1)//2 - c*(c+1)//2
        
        res += b - a +1

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

if __name__ == "__main__":
    resolve()

Solution (Python):
input_str = input()

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

result = k * n - k * (k+1) + 2 * k + 1

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

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

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

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

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

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

Solution (Python):
import sys

IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

INIT_VAL = 0
DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)]
DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)]
from itertools import accumulate as acc
MOD = 10**9+7

def main():
    n, k = MII()
    cnt = 0
    dd = [i for i in range(n+1)]
    dd_a = list(acc(dd))
    dd_b = list(acc(dd[::-1]))
    for i in range(k-1,len(dd_a)):
        cnt += dd_b[i]-(dd_a[i]-1)
    print(cnt%MOD)

if __name__ == '__main__':
    main()

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 = 1

def count(i, N):
	if i == 1:
		return N+1
	else:
		return (N*(N+1)/2 - (N-i)*(N-i+1)/2) - (i-1)*i/2 + 1


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

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

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

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

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

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

goukei = 0
for j in range(k,n+2):
    goukei += ((2*n-j+1)*(j)/2) - ((j-1)*j/2) + 1
    
print(int(goukei % (1e9 + 7)))

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

sums = 0
for K in range(k, (n+1)+1):
  sums += 1 + (n - K + 1) * K
  
answer = sums % (10**9 + 7)
print(int(answer))

Solution (Python):
def main():
    MOD = 10 ** 9 + 7
    n, k = map(int, input().split())
    a = list(range(n + 1))
    x = a.copy()
    y = a.copy()
    ans = 0
    for i in range(1, n+1):
        x[i] = a[i] + x[i-1]

    for i in range(n-1, -1, -1):
        y[i] = a[i] + y[i+1]

    for j in range(k-1, n+1):
        ans += y[-j-1] - x[j] + 1
    return ans%MOD


print(main())

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

Solution (Python):
a,b=(int(x) for x in input().split())
z=0
while b<=a+1:z=(z+(a-b+1)*b+1)%int(1e9+7);b+=1
print(z)

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

MOD = 10 ** 9 + 7

upper_list = [0] * (N + 1)
upper_list[0] = N
lower_list = [0] * (N + 1)
lower_list[0] = 0
ans_list = [0] * (N + 1)


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

for i in range(N + 1):
    ans_list[i] = (upper_list[i] - lower_list[i] + 1) % MOD

ans = print(sum(ans_list[K - 1:]) % MOD)

Solution (Python):
N, K = [int(i.strip()) for i in input().split(' ')]
MOD = 10 **9 + 7
count = 0
for i in range(K,N+2):
    MIN = i * (i-1)/2
    MAX = N * i -MIN
    c = MAX -MIN + 1
    count += int(c)

print(count%MOD)

Solution (Python):
N, K = map(int, input().split())
num = [0] * (N + 1)
ans = 1
for i in range(N + 1):
    num[i] += i

for k in range(K, N + 1):
    sum_min = k * (k - 1) // 2
    sum_max = k * N - k * (k - 1) // 2
    
    ans += sum_max - sum_min + 1
    
    ans %= 10**9 + 7
print(ans)

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

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

s = [0 for i in range(N+2)]
mod = 10**9+7

for k in range(N+2):
    a = (k-1)*k/2
    b = (N+N-k+1)*k/2
    s[k] = b-a+1


ss = [0 for i in range(N+2)]
for i in range(N+1):
    ss[i+1] = ss[i] + s[i] 

ans = int(ss[N+1]-ss[K]) % mod  
print(ans+1)