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 re
import math
from collections import defaultdict
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)

alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)

def main():
    n,K=map(int,input().split())
    n+=1
    ans=0

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

Solution (Python):


n, k = map(int, input().split())
x_list = list(range(0, n + 1))
ans = 0
min_total = sum(x_list[0 : k - 1])
max_total = sum(x_list[n + 1 - (k - 1) : n + 1])
for i in range(k, n + 2):
    min_total += x_list[i - 1]
    max_total += x_list[n + 1 - i]
    ans += max_total - min_total + 1
print(ans % (10 ** 9 + 7))

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

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

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

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

print(answer % mod)

Solution (Python):
N, K = [int(v) for v in input().split()]
indexs = [i for i in range(N+1)]
mod = int(1e9) + 7

max_n = 0
min_n = 0

for i in range(K):
    max_n += indexs[N-i]
    min_n += indexs[i]

ans = (max_n-min_n+1) % mod
for k in range(K,N+1):
    max_n += indexs[N-k]
    min_n += indexs[k]
    ans = (ans + (max_n-min_n+1)) % mod

print(ans)

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

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

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

Solution (Python):
NK = list(map(int, input().split()))
N = NK[0]
K = NK[1]
sumOfAll = 0
for howManyWeChoose in range(K, N+2):
    until = int(N*(N+1)/2 - (N-howManyWeChoose)*(N-howManyWeChoose+1)/2)
    start = int(howManyWeChoose*(howManyWeChoose-1)/2)
    sumOfAll += until-start+1
print(sumOfAll%(7+10**9))

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

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

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

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


def main():
    N, K = (int(i) for i in input().split())
    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
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

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

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

cnt = 0
for k in range(K,N+2):

    t = (N-k+1)*k+1
    cnt += t
    cnt %= MOD
print(cnt)

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

MOD = 10**9+7
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 % MOD
print(int(result))

Solution (Python):
n,m = map(int,input().split())
mod = 1000000007
l = []

ans=0

for i in range(m,n+2):

    ans+=(i*(n-i+1)+1)
    ans=ans%mod

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

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



















ans = 0

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

for i in range(k, n+1):
    
    ans += ((sum_cache[n] - sum_cache[n-i]) - sum_cache[i-1] + 1) % MOD

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

print(ans%mod)

Solution (Python):
def partsum(n,k):
  ret1 = n*(n+1)/2
  ret2 = (n-k+1)*(n-k)/2
  return ret1 - ret2

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

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

    
    sub_sum = [0] * (N+2)
    for i in range(2, N+2):
        sub_sum[i] = sub_sum[i-1] + i-1
    
    for i in range(K, N+2):
        min_val = sub_sum[i]
        max_val = sub_sum[N+1] - sub_sum[N+1-i]
        ans += max_val - min_val + 1
        ans %= MOD
        
    print(ans)
if __name__ == "__main__":
    main()

Solution (Python):
def main():
    N,K = map(int,input().split())
    ans = 0
    souwa = N*(N+1)//2
    mod = 10 ** 9 + 7

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

    print(ans%mod)

if __name__ == "__main__":
    main()

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

Solution (Python):
from itertools import accumulate

MOD = 10**9 + 7
N, K = map(int, input().split())
cumsum = list(accumulate(range(N+1)))
ans = 0
for k in range(K, N+2):
    ans += (cumsum[N] - cumsum[max(N-k, 0)]) - cumsum[k-1] + 1; ans %= MOD
print(ans)

Solution (Python):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n, k = nm()

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

    print(ans % mod)
    
    
if __name__ == '__main__':
    main()

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

mod = 10 ** 9 + 7

ksum = 0
ans = 0

isum = 0
sum_list = [0 for _ in range(n+2)]
for i in range(n+2):
	isum += i  
	sum_list[i] = isum % mod


for i in range(k, n+2):
	vmax = (n * i - sum_list[i-1]) % mod
	vmin = sum_list[i-1] 
	ans += vmax - vmin + 1
	ans %= mod

print(ans)

Solution (Python):
n,k=map(int,input().split())
x=0
y=0
b=0
for i in range(0,n):
  x+=i
  y+=n-i
  b+=y-x+1
s=b+1
l=0
m=0
c=0
for j in range(0,k-1):
  l+=j
  m+=n-j
  c+=m-l+1
print((s-c)%1000000007)

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




possible = 0


def sumRange(first, last):
    count = last - first + 1
    return int((first + last) * count / 2)




for selected in range(K, (N + 1) + 1):
    
    minFraction = sumRange(0, selected - 1)

    
    maxFraction = sumRange(N - selected + 1, N)

    
    possible += maxFraction - minFraction + 1


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

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

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

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

Solution (Python):
n,k=map(int,input().split())
s=[]
count=0
for i in range(n+1):
  count+=i
  s.append(count)

t=[n]
tmp=n
for i in range(1,n+1):
  tmp-=1
  t.append(t[i-1]+tmp)


ans=0
for i in range(k-1,n+1):
  ans+=t[i]-s[i]+1
  ans%=(10**9+7)

print(ans)

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

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

Solution (Python):
import sys

input = sys.stdin.readline

P = 10 ** 9 + 7


def main():
    N, K = map(int, input().split())

    ans = 0
    for k in reversed(range(1, (N+1)+1)):
        a = (N + (N-k+1))*k//2
        b = k*(k-1)//2
        ans += a - b + 1
        ans %= P

        if k == K :
            break

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n, m = map(int, input().split())
sum = 0

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

Solution (Python):

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

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

BigNum = 10 ** 9 + 7

total = 0
for k in range(K, N+2):
    kosu = k * N - k * (k - 1) + 1
    total += kosu % BigNum
print(total % BigNum)

Solution (Python):
def main(N, K):
    def sumN(x):
        return int(x * (x + 1) * 0.5)
    ans = sum([sumN(N) - sumN(N - k) - sumN(k - 1) + 1 for k in range(K, N + 2)])
    print(ans%(10**9+7))



if __name__ == '__main__':
    N, K = list(map(int, input().split()))
    main(N, K)

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):
from itertools import accumulate
N, K = map(int, input().split())
S = [0] + list(accumulate(range(N+2)))
M = 10**9 + 7
ans = 0
for i in range(K, N+2):
    ans += S[N+2] - S[N+2-i] - S[i+1] + 1
    ans %= M
print(ans)

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

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

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

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

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

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

print(ans)

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

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

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

def calc(n, k):
  return (2*n-k+1) * (k // 2) if k % 2 == 0 else (2*n-k+1) * (k // 2) + (n + (n-k+1)) // 2

def choose(n, k):
  x1 = calc(n, k)
  x2 = calc(k-1, k)
  return (x1 - x2 + 1) % mod

res = 0
for i in range(k, n+2):
  a = choose(n, i)
  res += a
  res %= mod

print(res)

Solution (Python):
a,b=map(int,input().split())
ans=0
sums=a*(a+1)//2
for i in range(a-b+2):
    c=b+i
    minsum=c*(c-1)//2
    maxsum=sums-(a-c)*(a-c+1)//2
    ans+=maxsum-minsum+1
print(ans%(pow(10,9)+7))

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

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


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

Solution (Python):
N, K = map(int, input().split())
MOD = 1000000007
small = 0
large = 0
res = 0

for i in range(K-1):
  small += i
  large += N-i

for i in range(K, N+2):
  small += i-1
  large += N - i +1
  gap = large - small +1
  res += gap

print(res%MOD)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop
import numpy as np

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

N, K = map(int, input().split())
k = np.arange(K, N + 2, dtype=np.int64)

low = k * (k - 1) // 2
high = N * k - low
cnt = high - low + 1
print(sum(cnt) % MOD)

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

nowmin=0
nowmax=n

for i in range(n+1):
    if i>=k-1:
        ans+=mx-mn+1
        ans%=(10**9+7)
    nowmin+=1
    nowmax-=1
    mn+=nowmin
    mx+=nowmax
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
print(ans%mod)

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

    acmN = [0]
    for n in range(N+1):
        if n == 0:
            acmN.append(0)
        else:
            acmN.append(n + acmN[n])

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

        print(ans % MOD)

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

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

l = (sum(range(K)), sum(range(N-K+1, N+1)))
a, b = l
ans = (1 + abs(a - b)) % mod
for k in range(K, N+1):
    a, b = l
    a, b = a + k, b + N - k
    l = (a, b)
    ans = (ans + (1 + abs(a - b)) % mod) % mod
        
print(ans)

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

ans = 0
lower = 0
upper = 0
cnt = 0
p = 1000000007

for i in range(K,N+2):
  lower = i*(i-1)/2
  upper = i*(2*N-i+1)/2
  cnt += (upper - lower + 1) % p
  
ans = cnt % p
print(int(ans))

Solution (Python):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
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


def main():
    N, K = MAP()
    N += 1

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


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

Solution (Python):



def solve(*args: str) -> str:
    n, k = map(int, args[0].split())
    ret = 1
    p = 10**9+7
    for i in range(k, n+1):
        ret += (n+(n-i+1))*i//2
        ret -= (i*(i-1)//2-1)
        ret %= p

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

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

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

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

l = 0
u = 0
du = n
dl = 0
ans = 0
for i in range(n+1):
    l += dl
    u += du
    if i+1 >= k:
        ans += u-l+1
        ans %= 1000000007
    du -= 1
    dl += 1
assert(l == u)
print(ans)

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

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

    print(ans % mod)

Solution (Python):


import numpy as np

import itertools



N, K = map(int, input().split())
l = [i for i in range(N+1)]

count = 0
if K == N+1:
    max_sum = np.sum(l[1:])
elif K == 1:
    max_sum = 0
else:
    max_sum = np.sum(l[-K+1:])

if K == 1:
    min_sum = 0
else:
    min_sum = np.sum(l[:K-1])





for k in range(K,N+2):
    max_sum += l[-k]
    min_sum += l[k-1]
    
    count += (max_sum-min_sum+1)%((10**9)+7)
    
print(count%((10**9)+7))

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

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

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

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

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

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 itertools

n, k = map(int,input().split())
ans = 0
li = list(range(n+1))

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

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

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

print(int(((N*(N+1)*(N+2) - K*(K-1)*(3*N-2*K+4))/6 + N - K + 2)%1000000007))

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

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

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

Solution (Python):
def sum_left(n):
    return int(n*(n+1)/2)

def sum_right(n,k):
    return int(n*(n+1)/2 - (n-k)*(n-k+1)/2)

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

mod = 10**9+7

cnt = 0
for i in range(K, N+2):
    cnt = (cnt - sum_left(i) +sum_right(N+1, i) + 1) % mod

print(cnt)

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


def answer(N:int,K:int) -> int:
    l = [i for i in range(N+1)]
    counter = 0
    for i in range(K,N+2):
        counter += i*(N - i + 1) + 1

    return counter % (10**9 + 7)



def main():
    N,K = map(int,input().split())
    
    print(answer(N,K))

if __name__ == '__main__':
   main()

Solution (Python):
import sys
from pprint import pprint

N, K = map(int, sys.stdin.readline().strip().split())
ans = 0
for i in range(K, N + 2):
    sum_min = i * (i - 1) // 2
    sum_max = i * N - i * (i - 1) // 2
    ans += sum_max - sum_min + 1
    
    ans %= 10**9 + 7

print(ans)

Solution (Python):

"""
@author: H_Hoshigi
"""


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

if __name__ == "__main__":
    main()

Solution (Python):
N, K = map(int, input().split())
x = 1000000007
 
A = N * (N * (N + 1) - K * (K - 1)) // 2
B = (N * (N + 1) * (2 * N + 1) - K * (K - 1) * (2 * K - 1)) // 6
C = N - K + 2
D = (N * (N + 1) - K * (K - 1)) // 2

Ans = (A - B + C + D) % x
 
print(Ans)

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

Solution (Python):
import sys,collections as cl,bisect as bs,math
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans
mod = 10**9+7 
N = 10**5 * 2 + 1
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
def p(n,r):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n,k = m()

dp = [0 for i in range(n+1)]
dp[0] = n+1
co = 0
if k-1 == 0:
    co += dp[0]
for i in range(1,n+1):
    dp[i] = dp[i-1] + (n - 2*i)
    dp[i] %= mod
    if i >= k-1:
        co += dp[i]
        co %= mod

print(co)

Solution (Python):
N, K = map(int, input().split())
box = [n for n in range(N+1)]
MOD = int(1e9) + 7
ans = 0


bubu = []
bubu.append(box[0])
for el in range(N+1):
    if el == 0:
        continue
    else:
        bubu.append(bubu[el - 1] + box[el])

rbubu = []
rbubu.append(box[-1])
for el in reversed(range(N+1)):
    if el == N:
        continue
    else:
        rbubu.append(rbubu[-1] + box[el])

for i in range(K, N+2):
    temp = (rbubu[i-1] - bubu[i-1] + 1) % MOD
    ans += temp
    ans = ans % MOD

print(ans)

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

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

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

Solution (Python):

from sys import stdin
from operator import itemgetter
from collections import deque
from collections import Counter
import math
import pprint
from functools import reduce


def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def combination(m,n):
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))


N, K= [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
go = 0

for i in range(K,N+2):
    ans_= (i*(N-i+1) + 1) % 1000000007
    ans += ans_
    go += 1
    

print(ans%1000000007)

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

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

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

Solution (Python):
def LI(): return list(map(int,input().split()))

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

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


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


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False



def main():
    N, K = MI()
    ans = 0

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

    print(ans % MOD)


if __name__ == '__main__':
    main()

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

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

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

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

mod = 10 ** 9 + 7

mi = 0
ma = N
mii = 1
maa = N - 1
su = 0
for i in range(1,N+2):
    if i >= K:
        su += ma - mi + 1
        su %= mod
    mi += mii
    mii += 1
    ma += maa
    maa -= 1

print(su)

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

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

c = 0

for l in range(k, n+2):
    c += l*(2*n + 1 - l)/2 - l*(l - 1)/2 + 1
    c %= 10**9+7

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

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

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

print(count)

Solution (Python):
N,k=map(int,input().split())
n=N+1
a1=-(n**3-k**3)*2
a2=-(n**2+k**2)*3
a3=-(n-k)*1
A=(a1+a2+a3)//6
B=n*(n+k)*(n-k+1)//2
C=(n-k+1)
print ((A+B+C)%(10**9+7))