Problem:
 Score : 400 points    Problem Statement We have N+1 integers: 10^{100} , 10^{100}+1 , ..., 10^{100}+N .  We will choose K or more of these integers. Find the number of possible values of the sum of the chosen numbers, modulo (10^9+7) .      Constraints  1 \leq N \leq 2\times 10^5  1 \leq K \leq N+1  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  K       Output Print the number of possible values of the sum, modulo (10^9+7) .        Sample Input 1 3 2      Sample Output 1 10  The sum can take 10 values, as follows:   (10^{100})+(10^{100}+1)=2\times 10^{100}+1  (10^{100})+(10^{100}+2)=2\times 10^{100}+2  (10^{100})+(10^{100}+3)=(10^{100}+1)+(10^{100}+2)=2\times 10^{100}+3  (10^{100}+1)+(10^{100}+3)=2\times 10^{100}+4  (10^{100}+2)+(10^{100}+3)=2\times 10^{100}+5  (10^{100})+(10^{100}+1)+(10^{100}+2)=3\times 10^{100}+3  (10^{100})+(10^{100}+1)+(10^{100}+3)=3\times 10^{100}+4  (10^{100})+(10^{100}+2)+(10^{100}+3)=3\times 10^{100}+5  (10^{100}+1)+(10^{100}+2)+(10^{100}+3)=3\times 10^{100}+6  (10^{100})+(10^{100}+1)+(10^{100}+2)+(10^{100}+3)=4\times 10^{100}+6        Sample Input 2 200000 200001      Sample Output 2 1  We must choose all of the integers, so the sum can take just 1 value.       Sample Input 3 141421 35623      Sample Output 3 220280457

Solution (Python):

MOD = 1000000007

def solve(n,k):
	ans = (n*k - k*k + 1)%MOD
	return ans

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

n +=1 

output = 0

for i in range(k,n+1):
	output = (output + solve(n,i))%MOD
print(output)

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


lst = [None for i in range(n+1)]
for i in range(n+1):
    lst[i]=i

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

print(ans)

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,k = map(int,input().split())
class InverseTable:
    __slots__ = ['In', 'fac', 'Ifac']

    def __init__(self, mod, maxnum):
        self.In = [0, 1]; self.fac = [1, 1]; self.Ifac = [1, 1]
        for i in range( 2, maxnum + 1 ):
            self.In.append( ( -self.In[mod % i] * (mod//i) ) % mod )
            self.fac.append( ( self.fac[-1] * i ) % mod )
            self.Ifac.append( (self.Ifac[-1] * self.In[-1]) % mod )
        
    def cmb(self, n, r):
        if ( r<0 or r>n ): return 0
        r = min(r, n-r)
        return self.fac[n] * self.Ifac[r] * self.Ifac[n-r] % mod
    
    def per(self, n, r):
        if ( r<0 or r>n ): return 0
        return self.fac[n] * self.Ifac[n-r] % mod

invt = InverseTable(mod, 10**6)


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

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

def rsq(L, R):
    return T(R) - T(L - 1)

n, k = [int(x) for x in input().split()]
ans = 0
for i in range(k, n + 2):
    ans += rsq(n - i + 1, n) - rsq(0, i - 1) + 1
    ans %= 10**9 + 7
print(ans)

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

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

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

kari = list()
count = 0
for i in range(2*10**5+1):
    count += i
    kari.append(count)
    
amount = 0
mod = 10**9+7
if K > N:
    print(1)
else:
    for i in range(K, N+2):
        if N-i >= 0:
            max_count = kari[N] - kari[N-i]
        else:
            max_count = kari[N]
        min_count = kari[i-1]
        count = max_count - min_count + 1 
        amount += count % mod
    print(amount%mod)

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

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

acc_min = []
acc_max = []
s_min = 0
s_max = 0
for i in range(n + 1):
    s_min += i
    acc_min.append(s_min % mod)
    s_max += n - i
    acc_max.append(s_max % mod)
ans = 0
for i in range(k, n + 2):
    ans = (ans + acc_max[i - 1] - acc_min[i - 1] + 1) % mod
print(ans)

Solution (Python):










import math
import numpy as np
import statistics
import string
import sys
from array import array
from collections import deque
from functools import wraps
import time

def intinput():
    return int(input())
def listintinput():
    return list(map(int, input().split()))
def splitintinput():
    return map(int, input().split())
def factorialsurplus(x, y, z):  
    ret = 1
    for i in range(x, y + 1):
        ret = (ret * i) % z
    return (ret)
def isprime(x):
    if x == 1:
        return False
    if x == 2:
        return True
    sq = int(math.sqrt(x))
    for i in range(2,sq+1):
        if x % i == 0:
            return False
    return True
def hcfnaive(a,b):
    if(b==0):
        return a
    else:
        return hcfnaive(b,a%b)

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

print(ans)

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

MAX = sum([i for i in range(n-k+1, n+1)[::-1]])
MIN = sum([i for i in range(k)])

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

print(ans)

Solution (Python):

import sys

MOD = 1000000007  


def powm(a, n, m):
    if a == 1 or n == 0:
        return 1
    if n % 2 == 0:
        s = powm(a, n // 2, m)
        return s * s % m
    else:
        return a * powm(a, n - 1, m) % m

def solve(N: int, K: int):
    
    sumMinus = 0
    lastMinimum = 0
    lastMaximum = 0
    for i in range(1,N+2):
        lastMinimum += i-1
        lastMaximum += N-(i-1)
        
        if i >= K:
            count = lastMaximum-lastMinimum+1
            sumMinus= (sumMinus+count)%MOD
            
    print(sumMinus)
    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())

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

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

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


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

if __name__ == '__main__':
    main()

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

ma = 0
mi = 0
ans = 0

for i in range(K):
  ma = (ma + N - i) % MOD
  mi = (mi + i) % MOD

t = ma - mi + 1
while t < 0:
  t += MOD

ans = (ans + t) % MOD

for i in range(K, N + 1):
  ma = (ma + N - i) % MOD
  mi = (mi + i) % MOD
  t = ma - mi + 1
  while t < 0:
    t += MOD
  ans = (ans + t) % MOD

print(ans)

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

Solution (Python):


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

def mymult(i):
    if i%2==0:
        a=i//2
        return a*(i-1)
    else:
        a=(i-1)//2
        return a*i

def mymult2(n,i):
    tmp=n*2-i+1
    if tmp%2==0:
        a=tmp//2
        return a*i
    else:
        a=i//2
        return tmp*a

ans=0
for i in range(k,n+2):
    minim=mymult(i)
    maxim=mymult2(n,i)
    ans=ans+(maxim-minim)+1

print(ans%1000000007)

Solution (Python):
import sys
import socket

hostnames = ['N551J', 'F551C', 'X553M']
input_file = 'd1.in'




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


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


M = 10 ** 9 + 7
def solve():
    n, k = read_int_list()
    res = 0
    for i in range(k, n + 2):
        start = i * (i - 1) // 2
        stop = i * (n + n - i + 1) // 2
        res += stop - start + 1
        res %= M
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import accumulate
n,k = list(map(int, input().split()))
a = list(range(0,n+1))
bleft = list(accumulate(a))
bright = list(accumulate(reversed(a)))
ans = 0
mo = 10**9 + 7
for i in range(k-1,n+1):
    ans = (ans + bright[i] - bleft[i] + 1) % mo

print(ans)

Solution (Python):
mod = 10**9 + 7
base = 10**100 % mod

n,k = map(int,input().split())
A = [base + i for i in range(n+1)]

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

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

Solution (Python):


n, k = map(int, input().split())
ans = 0
l = list(range(n))
s = n*(n+1)//2
m = 10**9+7

for i in range(n-k+2): 
    
    ans += ((s - (n-(i+k))*(n-(i+k)+1)//2) - (i+k-1)*(i+k)//2 +1)
    if ans > m:
        ans = ans % m
print(ans)

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]




N, K = mi()
ma = mi = 0
mod = 10**9+7
for i in range(K-1):
    ma += N-i
    mi += i
ans = 0


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

Solution (Python):
import sys
from itertools import accumulate

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

N, K = map(int, read().split())
mod = 10 ** 9 + 7
answer = 0
cnt = list(accumulate(range(N + 1)))
for i in range(K, N + 1):
    tmp = cnt[N] - cnt[N - i] - cnt[i] + 1
    answer = (answer + cnt[N] - cnt[N - i] - cnt[i - 1] + 1) % mod

answer += 1
print(answer)

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

Solution (Python):
def do(a, d, n, l):
    return (n*(a+l) // 2)

n, k = map(int, input().split())
maxnum = n + 1
res = 0
mod = 10**9 + 7

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

    r = do(n+1 - i, 1, i,     n)
    

    
    res += r-l+1
    res %= mod
print(res)

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

    low = []
    lowtotal = 0
    high = []
    hightotal = 0
    for i in range(N+1):
        lowtotal += i
        low.append(lowtotal)
        hightotal += N-i
        high.append(hightotal)

    ans = 0
    for l, h in zip(low[K-1:], high[K-1:]):
        cnt = h-l+1
        ans += cnt
        ans %= MOD
    print(ans)
main()

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

a = 10 ** 9 + 7
ans = 0
small = 0
big = 0
for i in range(0 , k):
    big += n - i
    small += i
    
for i in range(k, n + 1):
    ans += big - small + 1
    big += n - i
    small += i

print((ans + 1) % a)

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

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

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

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

Solution (Python):
N, K = map(int, input().split())
sumR = 0
for i in range(K, N+2):
    front = i*(2*N + 2 - i + 1)/2
    rear = i*(i+1)/2
    number = front - rear + 1


    sumR += number
print (int(sumR%(1000000007)))

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

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

ans = 0
for k in range(K, N + 2):
    min_s = (k - 1) * k // 2
    max_s = (N + N - k + 1) * k // 2
    ans += max_s - min_s + 1
    ans %= MOD
print(ans)

Solution (Python):
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)

N,K=nm()

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

print(ans)

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

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

count  = 0

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

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

Solution (Python):
import sys

sys.setrecursionlimit(1000000)


def solve(N, K):
    M = 10 ** 9 + 7
    pre = []
    post = []
    s = 0
    for i in range(N + 1):
        s += i
        pre.append(s)

    s = 0
    for i in range(N, -1, -1):
        s += i
        post.append(s)
    post = post[::-1]

    ans = 0
    for i in range(K, N + 2):
        a = post[N + 1 - i] - pre[i - 1] + 1
        ans += a
        ans %= M
    return ans


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

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

Solution (Python):


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

    cnt = 0
    min_ = 0
    max_ = 0

    for i in range(1, n+2):
        min_ += i - 1
        max_ += n - i + 1

        if i >= k:
            cnt += max_ - min_ + 1
            cnt %= 10 ** 9 + 7

    print(cnt)


if __name__ == '__main__':
    main()

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

for i in range(k, n+2):
    high = (arr[-i] + arr[-1]) * i // 2
    low = (arr[0] + arr[i-1]) * i // 2
    ans += (high - low + 1) % MOD
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 += ((2*N-i+1)*i//2-i*(i-1)//2+1) % mod
print(ans%mod)

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

Solution (Python):


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

modulus = 10 ** 9 + 7

s = 0

for m in range(k, n + 2):
    s += (m * (n - m + 1) + 1) % modulus  

print(s % modulus)

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

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

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

Solution (Python):
n, k = map(int, input().split())
mod = int(1e9+7)
fans = 0
for x in range(k, n + 2):
    mm = (k-1) * k / 2
    
    minv = (((x-1) * x) % mod * pow(2, mod-2, mod)) % mod
    
    maxv = ((n * (n+1)) % mod * pow(2, mod-2, mod)) % mod
    
    mmm = (((n-x) * (n-x+1)) % mod * pow(2, mod-2, mod)) % mod
    maxv = maxv - mmm
    while maxv < 0:
        maxv += mod
    fans = (fans + maxv - (minv-1))%mod
while fans < 0:
    fans += mod
print(fans)

Solution (Python):
N, K =map(int, input().split())
mod = 10**9 + 7
A = int(-(N+1)*(N+2)*(2*N+3)/6)%mod
B = int((N+1)*(N+1)*(N+2)/2)%mod
C = N+1
a = int(-(K-1)*K*(2*K-1)/6)%mod
b = int((N+1)*(K-1)*K/2)%mod
c = K-1
print((A+B+C-a-b-c)%mod)

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

print(ans)

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

cum = [0]
for x in range(1, N+1):
    cum.append(cum[-1]+x)

ans = 0
for k in range(K, N+2):
    ans += (cum[N] - cum[max(0,N-k)]) - cum[k-1] + 1
    ans %= MOD

print(ans)

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

print(ans%mod)

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

Solution (Python):
N, K = map(int, input().split())
S1 = 0
S2 = 0
for k in range(1, N+1):
    S1 += k*N - k*(k-1) +1
    S1 %= 10**9 + 7
for k in range(1, K):
    S2 += k*N - k*(k-1) +1
    S2 %= 10**9 + 7
    
S = S1 - S2 + 1
S %= 10**9 +7

print(S)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline

MOD = 10 ** 9 + 7


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

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import math
import fractions
import collections
import itertools
from collections import deque
N,K=map(int,input().split())
cnt=0
p=10**9+7
for i in range(K,N+2):
    cnt=(cnt+((N-i+1)*i)+1)%p
    
print(cnt)

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

ans = 0

lst = [int(i) for i in range(N + 1)]
internal = 1
for i in range(N + 1):
    internal += lst[N - i] - lst[i]
    if i + 1 >= K:
        ans += internal
        ans = ans % mod

print(ans)

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

Solution (Python):
def calc(n):
    return n * (n - 1) // 2


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


if __name__ == '__main__':
    resolve()

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

Solution (Python):

import sys
import math
import fractions
import bisect
import queue
import heapq
import collections
import itertools
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint=====================================
N, K = map(int, input().split())
N, M = map(int, input().split())
A, B = map(int, input().split())

H, W = map(int, input().split())

L, R = map(int, input().split())

1行のstring=================================
S, T = input().split()

1行の整数配列================================
P = list(map(int,input().split()))

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
D = list(map(int,input().split()))

L = list(map(int,input().split()))
R = list(map(int,input().split()))

T = list(map(int,input().split()))

改行あり整数==================================
X = []
Y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    X.append(x1)
    Y.append(y1)

A = []
for i in range(N):
    a=int(input())
    A.append(a)

Pair = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    Pair.append((x1, y1))
    
2次元整数配列=====================================
A = []
for i in range(N):
    tmp = list(map(int,input().split()))
    A.append(tmp)


N行M列の初期化====================================
dp = [[VAL] * RETU for i in range(GYO)]

'''


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

ans = 0

for i in range(K, N+2):

    lim = ((N  + N + 1 - i) * i) // 2 
    m = ((i - 1)         * i) // 2 

    ans += lim - m + 1
    ans %= MOD

print(ans)

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

Solution (Python):
import bisect,sys
import math
from collections import deque

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac =fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV
        
    return CONV()



sys.setrecursionlimit(200005)


def main():
    N,K= isRaw()
    first = pow(10, 100, DIV)
    ans = 1
    dadd = 1
    for n in range(N+1-K):
        dadd+=N-2*n
        ans+=dadd
        ans=ans%DIV
    return ans%DIV

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

Solution (Python):

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


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

print(ans%mod)

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

    cuptable = list(range(N+1))
    rcuptable = list(range(N+1))
    rcuptable.reverse()
    for i in range(1,len(cuptable)):
        rcuptable[i]+=rcuptable[i-1]
        cuptable[i]+=cuptable[i-1]
    mod=10**9+7
    ans = 0
    for i in range(K-1,len(cuptable)):
        mn = cuptable[i]
        mx = rcuptable[i]
        ans += mx-mn +1
        ans %= mod
    
    print(ans)


if __name__ == "__main__":
    resolve()

Solution (Python):

import sys
from itertools import accumulate
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9+7

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

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

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

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

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

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

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

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

N, K = map(int, readline().split())
P = 10 ** 9 + 7
ans = 0
for a in range(K, N + 2):
    ans += (N - a + 1) * a + 1
    ans %= P

print(ans)

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

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

Solution (Python):
def fur(n, r, mod=10**9+7):
    work = (n-r+1)*r + 1
    return work%mod

N, K = map(int, input().split())
result = 0
mod = 10**9 + 7
for k in range(K, N+2):
    result += fur(N, k)
    result %= mod
print(result%mod)

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

sample = list(range(n+1))

count = 0
current = sum(sample[-k:])-sum(sample[:k])+1

for i in range(k,n+2):
    
    
    count += current
    current = current - i + (n+1-i) - 1

print(count%1000000007)

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

Solution (Python):
def main():
    mod=1000000007
    n,k=map(int,input().split())
    ans=0
    for i in range(k,n+2):
        l=i*(i+1)//2
        r=i*(2*n-i+3)//2
        ans+=r-l+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 += i*(2*n-i+1)//2 - i*(i-1)//2 + 1
    ans %= mod
print(ans)

Solution (Python):
from functools import reduce
n,k = map(int,input().split())
n += 1
mod = 10 ** 9 + 7
ans = 0
lis = [i for i in range(n)]
left = [0]
right = [lis[-1]]
for i in range(1,n):
    left.append(left[-1]+i)
for i in range(n-2,-1,-1):
    right.append(right[-1]+i)
for i in range(k-1,n):
  
    ans += max(0,right[i]-left[i]+1)%mod
    ans %= mod
  
print(ans)

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

ans=0

L=[i+1 for i in range(N+1)]


l=L[::-1]

RUI=[L[0]]
for i in range(1,len(L)):
    RUI.append(RUI[-1]+L[i])

rui=[l[0]]
for i in range(1,len(l)):
    rui.append(rui[-1]+l[i])


ans=0
for i in range(N+1):
    I=N+1-i
    if I<M:
        break
    ans+=(rui[I-1]-RUI[I-1]+1)
    ans%=mod
print(ans)

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




def culc():
    global N
    global K
    global P

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

print(culc())

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