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 itertools import accumulate

mod = 10**9 + 7

n, k = map(int, input().split())
a = list(accumulate(range(0, n+2)))

ans = 0
for m in range(k, n+2):
    min_num = a[m] - a[0]
    max_num = a[-1] - a[-(m+1)]
    ans += (max_num - min_num) + 1
print(ans % mod)

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

count = 0
for m in range(K, N+2):
    
    ans = m * N - (m * (m - 1) - 1)
    
    if ans > 0:
        count += ans

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

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

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

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

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


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(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True



def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret



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

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

    print(ans % 1000000007)
    
resolve()

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

x = 10 ** 9 + 7


answer = 0



for k in range(N+1, K-1, -1):
    
    min_a = k * (k-1) // 2
    max_a = k * (2*N - k + 1) // 2
    
    
    num = max_a - min_a + 1
    
    answer = (answer + (num % x))%x 
print(answer)

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] = list(map(int, input().split()))
answer = 0
for i in range(K, N+2):
    S_min = i*(i-1)/2
    S_max = (2*N-i+1) * i/2
    answer += S_max - S_min +1
answer %= 7+10**9
print(int(answer))

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

Solution (Python):
X = list(map(int, input().split()))
N = int(X[0])
K = int(X[1])

S = 0

for i in range(K,N+2):
  Min = (i-1)*i/2
  Max = (N-i+N+1)*i/2

  S+=(Max-Min+1)
  
print(int(S%(pow(10,9)+7)))

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

if __name__ == '__main__':
    main()

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

Solution (Python):

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

print((int((N+1)*((N+1)*(N+2) - K*(K-1))/2.0 - ((N+1)*(N+2)*(2*N+3) - (K-1)*K*(2*K-1))/6.0) + (N+1+1-K)) % (int(10**9) + 7))

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

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

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

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

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

Solution (Python):
import numpy as np
A=list(input().split())
N=int(A[0])
K=int(A[1])

from math import factorial

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


print((np.sum(t)%(10**9+7)))

Solution (Python):
def main():
    N, K = map(int, input().split())
    N += 1
    n = 0
    for i in range(K, N+1):
        n = n + i*(N-i)+1
    print(n%1000000007)
main()

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

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

Solution (Python):
N,K = map(int,input().split())
lis = []
for k in range(K,N+2):
    lis.append((N-k+1)*k+1)

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

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

MOD = 10**9 + 7

data = []
for i in range(n+1):
  data.append(i)

ans = 0


sum_data = [0] * (n + 1)
for i in range(1, n + 1): 
  sum_data[i] = sum_data[i - 1] + i




for i in range(k, (n+1) + 1): 
  
  min_ = sum_data[i-1]

  
  if n+1 - i - 1 == -1:
    max_ = sum_data[-1]
    
  else:
    max_ = sum_data[-1] - sum_data[n+1 - i - 1]
    

  diff = (max_ - min_ + 1)
  ans += diff

print(ans % MOD)

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

mod = 10 ** 9 + 7
num = n * (n + 1) // 2 + 2
ans = 0
for i in range(k, n + 2):
    left = (0 + (i - 1)) * i // 2
    right = ((n - (i - 1)) + n) * i // 2
    ans += (right - left) + 1
    ans %= mod

print(ans)

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

ans=0

for i in range(K,N+2):
  a=(i*(i-1))/2
  b=((N*2-i+1)*i)/2
  ans=int((ans+b-a+1)%1000000007)

print(ans)

Solution (Python):
import sys

input = sys.stdin.readline
MOD = 1000000007

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


res = 0

if N < K:
    print(1)
    exit()

_min=0
_max=0
for i in range(K):
    _min += i
    _max += (N-i)

res = 0

for i in range(K,N+2):
    if i != K:
       _min+=i-1
       _max+=(N+1 -i)

    
    
    res +=(_max-_min+1)

print(res%MOD)

Solution (Python):
MOD = 10**9 + 7
n,k = map(int,input().split())
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):
if __name__ == '__main__':
    n, k = map(int, input().split())
    num = [0] * (n + 1)
    for i in range(1, n + 1):
        num[i] = num[i - 1] + i
    num.append(num[-1])
    ans = 0
    for i in range(k, n + 2):
        max_num = num[n] - num[max(0, n - i)]
        min_num = num[i - 1]
        ans += max_num - min_num + 1
        ans %= (10 ** 9 + 7)
    print(ans)

Solution (Python):
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N, K = read_ints()
    
    
    
    total = 0
    prefix = sum(range(K))
    suffix = sum(range(N, N-K, -1))
    modulo = 10**9+7
    for k in range(K, N+2):
        total = (total+(suffix-prefix+1))%modulo
        prefix = (prefix+k)%modulo
        suffix = (suffix+N-k)%modulo
    return total


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

Solution (Python):

import sys

MOD = 1000000007  


def solve(N: int, K: int):
    ct = 0
    for k in range(K, N+2):
        ct += int((N + N - k + 1) * k / 2 - (k - 1) * k / 2 + 1) % MOD

    print(ct % MOD)
    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):
n,k = map(int, input().split(' '))
result = 0

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

print(int(result))

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

Solution (Python):

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



mod=10**9+7
total=0

for m in range(k,n+2):
    add=m*(n-m+1)+1
    total=(total+add)%mod
print(total)

Solution (Python):
import numpy as np

s = list(map(int, input().split()))
N,K = s[0],s[1]
ans = 0
n = 10**9 + 7

"""
if K==2:
    min = (0+K-1)*K/2
    max = (N-K+1+N)*K/2
elif K==3:
    min = (0+K-1)*K/2
    max = (N-K+1+N)*K/2
else:
    min = (0+K-1)*K/2
    max = (N-K+1+N)*K/2
"""

def num(x, N):
    y = -x**2 + (N+1)*x +1
    return y



ans = num(K,N)
for i in range(1,N-K+2):
    if ans >= n:
        ans = ans % n
    ans += num(K+i,N)

print(ans)

Solution (Python):


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












def sum_num(l,r): 
    result = (l+r) * (r-l+1)/2
    return result

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

ans=0
for s in range(K,N+2):
    L = sum_num(0,s-1)
    R = sum_num(N-s+1,N)
    ans += R - L + 1

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

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

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

mod = 10 ** 9 + 7

sum = 0

for i in range(k, n + 2):
    
    min_value = int(i * (i - 1) / 2)
    max_value = int(i * (2 * n - i + 1) / 2)
    
    sum += max_value - min_value + 1

print(sum % mod)

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

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

min_lis = [0] * (N + 2)
max_lis = [0] * (N + 2)

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

answer = 0
for k in range(K, N + 2):
    answer += max_lis[k] - min_lis[k] + 1
print(answer % MOD)

Solution (Python):
nk = input()
nk = nk.split()
[n,k] = nk
n, k = int(n), int(k)
ans = 0
for s in range(k, n + 2):
    temp = s*(n-s+1) + 1
    ans += temp
    if(ans > 1000000007):
        ans = ans % 1000000007
print(ans)

Solution (Python):
a, b = map(int, input().split())
MOD = 10 ** 9 + 7
n = [0] * (a + 1)

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

ans = 0
for k in range(b - 1, a + 1):

    ans = (ans + (n[a] - n[max(0, a - k - 1)]) - n[k] + 1) % MOD

print(ans)

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    mod=10**9+7
    N,K=map(int,readline().split())
    A=list(range(N+1))
    s1=A[:]
    s2=A[:]
    for i in range(1,N+1):
        s1[i]+=s1[i-1]
    for i in range(N-1,-1,-1):
        s2[i]+=s2[i+1]
    
    res=0
    for l in  range(K-1,N+1):
        a=s2[N-l]-s1[l]+1
        res+=a
        res%=mod
    print(res)

if __name__=="__main__":
    main()

Solution (Python):
import numpy as np
from itertools import combinations
n,K = map(int,input().split())
num_ls = [i for i in range(n+1)]
csum_num_ls = list(np.cumsum(num_ls))
mod = 1000000007

ans = 0
for k in range(K,n+1):
    smallest = csum_num_ls[k-1]
    biggest = csum_num_ls[-1] - csum_num_ls[-k-1]
    ans_k = biggest - smallest + 1
    ans += ans_k
    ans %= mod
ans += 1
print(ans)

Solution (Python):
import numpy as np 

a = input()
N,K = np.array(a.split()).astype(int)

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

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

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

print(ans%mod)

Solution (Python):

mod = pow(10, 9) + 7

def main():
    N, K = map(int, input().split())
    ans = 0
    for k in range(K, N+2):
        
        ans += (N*(N+1))//2 - ((N-k)*(N-k+1))//2 - ((k-1)*k)//2 + 1
        ans %= mod
    print(ans%mod)


if __name__ == "__main__":
    main()

Solution (Python):
'''ika tako
選ぶ個数を固定して、それ毎に結果を足し合わせればよい。
k  個の数を選ぶとき、各項に含まれる  10^100  は除いて考えても
和の個数を求める上では問題ない。
最小値は小さい方から  k  個を足し合わせた数0+1+2+…+(k-1)
初項  0 、末項  k−1 、長さ  k  の等差数列の総和なので  
k(k−1)/2 
最大値は大きい方から  k  個を足し合わせた数(N-k+1)+…+(N-1)+N
初項  N−k+1 、末項N 、長さk  の等差数列の総和なので  
k(2N−k+1)/2 
数字は1刻みで、特に選び方に制約も無いので、最小値～最大値の間の整数は全て作れる。
'''

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):
import sys
N, K = map(int, sys.stdin.readline().split())
MOD = 10 ** 9 + 7
m = sum(range(K))
M = sum(range(N - K + 1, N + 1))
ans = (M - m + 1) % MOD
for i in range(K + 1, N + 2):
    m += i - 1
    M += N - i + 1
    p = M - m + 1
    ans += p % MOD
print(ans % MOD)

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

def counts(n,k):
    if k==1:
        return N+1
    else:
        return k*N - k*( k - 1 ) + 1

total =0
for k in range(K,N+2):
    total += int(counts(N,k))

print(total%mod)

Solution (Python):





import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string


BUFSIZE = 8192

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

def main():
   nk=list(map(int,input().split()))
   n,k=nk[0],nk[1]
   ans=0
   mod=10**9+7
   for i in range(k,max(n+2,k)):
       ans+=((n+1)*i-i*i+1)
   print (ans%mod)
if __name__ == "__main__":
    main()

Solution (Python):

n, k = map(int, input().split())
def Funmy(a, N):
    return (8+3*a*N + 3*N -2*a*a)*a/6

total =Funmy(n+1,n) -Funmy(k-1,n)
m = 7 + 10**9
output = (total)%m
print(int(output))

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

min = K*(K-1)/2
max = K*(2*N-K+1)/2


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

    sum+=(int(max-min+1))
print(sum%(10**9+7))

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

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

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

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

ans = [((i+1)*n - i*(i+1) + 1) % mod for i in range(n+1)]
print(sum(ans[k-1:])%mod)

Solution (Python):


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

mod = 10**9+7

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






print(ans % mod)

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

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

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

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

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

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

Solution (Python):
def sum_start(k):
    return (k-1) * k / 2

def sum_end(n,k):
    return sum_start(n+1) - sum_start(n-k+1)


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

total = 0
while((N + 1) >= K):
    start = sum_start(K)
    end = sum_end(N,K)
    total += end - start + 1
    K += 1

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

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

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


ans = 0
for i in range(K,N+2):
    a = sum_lr(N-(i-1),N)
    b = sum_lr(0,i-1)
    temp = a - b + 1
    
    
    
    
    ans += temp
    ans %= MOD
print(ans)

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

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

print(sum%1000000007+1)

Solution (Python):


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

mod = 10 ** 9 + 7
ans = 0

for i in range(K, N+2):
    sum_min = i * (i - 1) / 2
    sum_max = i * (2*N - i + 1) / 2
    ans += sum_max - sum_min + 1

print(int(ans % mod))

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

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

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

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

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

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

Solution (Python):
n, k = map(int,input().split())
mod = int(1e9)+7

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

Solution (Python):
mod = 10**9 + 7
def sum(a, b):
    r = (a + b)*(b - a + 1) / 2
    return int(r)

def main():
    sum_num = 0
    N, K = list(map(int, input().split(" ")))
    for i in range(K, N+2):
        mi = sum(0, i - 1)
        ma = sum(N-i+1, N)
        sum_num += ma - mi + 1

    print(sum_num % mod)

if __name__ == "__main__":
    main()

Solution (Python):
n, k = map(int, input().split())
l = [_ for _ in range(n + 1)]

tmp_min = sum(l[0:k])
tmp_max = sum(l[-1:-k-1:-1])
x = tmp_max - tmp_min + 1

for i in range(n-k+1):
    tmp_min += l[k+i]
    tmp_max += l[-k-i-1]
    x += tmp_max - tmp_min + 1

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

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

mod = 1000000007


def sum(a, b):
    r = (a+b)*(b-a+1) / 2
    return int(r) if r < mod else int(r % mod)


res = 0
for i in range(K, N+2):
    num_l = sum(0, i-1)
    num_r = sum(N-i+1, N)
    res += (num_r - num_l + 1)

print(res % mod)

Solution (Python):
mod = 10**9 + 7
def main():
    N,K = map(int,input().split())
    ans = 0
    S = [0]
    for i in range(1,N+4):
        S.append( S[-1] + i )
    for k in range(K,N + 1):
        ans = (ans + (S[N] - S[N - k]) - S[k - 1] + 1)%mod
    print((ans+1)%mod)
    return

if __name__ == "__main__":
    main()

Solution (Python):
def q4():
    N, K = (int(i) for i in input().split())

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

    d, ans = divmod(ans, 10**9 + 7)
    print(ans)


if __name__ == '__main__':
    q4()

Solution (Python):
import math

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

mod = 10**9 +7

sn = (n*(n+1)*(n+2)/6 +n+1)% mod
sk = ((k-1)*k*(3*n-2*k+4)/6 +k-1)% mod

snk = math.floor((sn - sk)% mod)

print(snk)

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

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






val = (N * (N+1) * (N+2) - K * (K - 1) * (3 * N - 2 * K + 4)) // 6 + N + 2 - K
print(val % (10**9 + 7))

Solution (Python):
def S(k):
    R = 0
    for i in range(1, k+1):
        R += i
    return R

N, K = [int(n) for n in input().split()]













M = 10**9 + 7
B = K*N - 2*S(K-1) + 1
A = B
for k in range(K+1, N+2):
    B += N - 2*(k-1)
    A += B
print(A % M)

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

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

mod = 10**9 + 7
ans = 0
for i in range(k, n+2):
    l = f_sum(0, i-1)
    r = f_sum(n-i+1, n)
    ans += r-l+1
    
print(ans%mod)

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

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

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

MOD = 10**9 + 7
print((culc(N, N+1)-culc(N, K-1))%MOD)

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




def calc(x, N):
    a = x * (x - 1) // 2
    b = (2 * N - x + 1) * x // 2
    return b - a + 1


tot = 0
for i in range(K, N + 2):
    ans = calc(i, N)
 
    tot += ans

aa = tot % (10 ** 9 + 7)

print(aa)

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

ans = 0
max=0
min=0

a=[0]*(n+1)
b=[0]*(n+2)

for i in range(n+1):
    a[i]=i
    b[i+1]=a[i]+b[i]

if n>=k:
    for i in range(k,n+2):
        min=b[i]
        max=b[n+1]-b[n+1-i]
        ans=ans+max-min+1
else:
    ans=1

ans = ans % p

print(ans)

Solution (Python):
a,b=map(int,input().split(" "))

min=0
max=0
count=0

for i in range(b,a+2):
    min = int((i-1)*i/2)
    max = int((2*a-i+1)*i/2)
    count+=max-min+1
print(count%1000000007)

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

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

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

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

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

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

Solution (Python):
Z = list(map(int,input().split()))
N = Z[0]
K = Z[1]
x = int(N*(N+1)*(N+2)/6+(K-1)*K*(2*K-3*N-4)/6+N+2-K)
y = x%1000000007
print(y)

Solution (Python):



def main():
  n, k = map(int, input().split())
  n += 1
  cnt = 0
  for ik in range(k, n+1):
    cnt += ik * (n - ik) + 1
    cnt %= (10**9 + 7)
  print(cnt)

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 + 1) + 1
print(ans % MOD)

Solution (Python):
N, K = (int(x) for x in input().split())
def sumcount(l, r):
    return (l+r)*(r-l+1)//2
num = 0
for i in range(K, N+2):
  l = sumcount(0,i-1)
  r = sumcount(N-i+1,N)
  num += r-l+1
print(num%(10**9+7))

Solution (Python):


int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


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

def solve():
    n, k = MI()
    B = [i for i in range(0, n+1)]
    
    mod = 1_000_000_007

    cnt = 0
    for i in range(k, n+2):
        mn = ssum(B[0], B[i-1])
        mx = ssum(B[n-i+1], B[-1])
        
        cnt = cnt + mx - mn + 1
    print(cnt % mod)

if __name__ == '__main__':
    solve()

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

B=[0]*(N+2)
for i in range(N+1):
    B[i+1]=B[i]+A[i]

while True:
    if K>N+1:
        break
    else:
        ans+=B[-1]-B[N-K+1]-B[K]+1
        K+=1

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

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

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

a = 0

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

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

for i in range(K, N + 2):
    m = 1 / 2 * (i - 1) * i 
    M = 1 / 2 * (N + N - i + 1) * i
    if M == m:
        ans += 1
    else:
        ans += (M - m + 1)

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

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

a = [i for i in range(n+1)]  
ans = 0
mod = pow(10, 9)+7
sum_min = sum(a[:k])  
sum_max = sum(a[-k:])  
for i in range(k, n+1):
    ans += sum_max-sum_min+1
    ans %= mod
    sum_min += a[i]  
    sum_max += a[-i-1]
ans += 1  
print(ans % mod)

Solution (Python):
import sys
from itertools import combinations
sys.setrecursionlimit(10 ** 6)  
to_index = lambda x: int(x) - 1  
print_list_in_2D = lambda x: print(*x, sep="\n")  


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

def map_int_input():
    return map(int, input())

MII = map_int_input

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

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())


def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

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


def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

N, K = MII_split()

count = 0
p_min_sum = 0
p_max_sum = 0
for num_nums in range(K, N + 2):
    
    
    
    
    
    if num_nums == K:
        p_min_sum = sum(range(num_nums))
        p_max_sum = sum(range(N - num_nums + 1, N + 1))
    else:
        p_min_sum += num_nums - 1
        p_max_sum += N - num_nums + 1

    
    
    
    
    count += p_max_sum - p_min_sum + 1

    
    
    
    
    
    

print(int(count % (1e9 + 7)))

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

ans = 0

for i in range(K,N+2):
  Min = i*(i-1)/2
  Max = i*(2*N-i+1)/2
  ans += Max-Min+1
print(int(ans%Mod))

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

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