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):
N, K = map(int, input().split())
ans = (K - N - 2) * (2 * K * K - K * (N + 2) - N * N - N - 6) // 6
print(ans % (10**9 + 7))

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

N, K = map(int, readline().split())
N = N + 1

lower = None
upper = None
answer = 0
for k in range(K, N+1):
    if lower is None:
        lower = sum(range(k))
        upper = sum(range(N-k, N))
    else:
        lower += k - 1
        upper += N - k
    answer += (upper - lower + 1)
print(answer % MOD)

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

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

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

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

ans = 0


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


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

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

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

print(ans)

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

Solution (Python):
import sys










sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
mod = 1000000007



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

    if K == N+1:
        print(1)
        return

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

    ans = ans % mod
    print(ans)


if __name__ == "__main__":
    main()

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

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

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

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

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

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

print(ans)

Solution (Python):
base = input().split()
n = int(base[0])
k = int(base[1])
ans = 0
x = []
for i in range(n+1):
    x.append(i)
y = x.copy()
y.sort(reverse = True)
for a in range(k,n+2):
    z = (n+1-a)*a
    ans += (z+1)%(10**9+7)
print(ans%(10**9+7))

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

Solution (Python):
N, K = map(int, input().split())
 
if K==N+1:
    print(1)
elif K==N:
    print(N+2)
else:
    def tousawa(shokou, makkou, kosu):
        return int((shokou+makkou)*kosu/2)
    
    ans=0
    for i in range(K,N+2):
        ans+=tousawa(N-i+1,N,i)-tousawa(0,i-1,i)+1
    print(int(ans%(10**9+7)))

Solution (Python):
def d_sum_of_large_numbers(MOD=10**9 + 7):
    N, K = [int(i) for i in input().split()]
    return (N + 2 - K) * (N**2 + (K + 1) * N - 2 * K**2 + 2 * K + 6) // 6 % MOD

print(d_sum_of_large_numbers())

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

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

B=[i for i in range(n+1)]
for i in reversed(range(n)):
    B[i]+=B[i+1]

for i in range(k,n+2):
    ans+=B[-i]-A[i-1]+1
print(ans%(10**9+7))

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

Solution (Python):
N, K = map(int, input().split())
print((N-K+2)*((N-K+1)*(N+2*K)+6)//6%(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-1):
  a += j
  b += n-j
for i in range(k-1, n+1):
  a += i
  b += n-i
  ans = (ans+b-a+1)%p
print(ans)

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = LI()
    ans = 0
    mi = 0
    ma = n+1
    m = n*(n+1) >> 1
    for i in range(1,n+2):
        if i >= k:
            ans += ma-mi
            ans %= mod
        mi += i
        ma += n-i
        mi %= mod
        ma %= mod
    print(ans)
    return


if __name__ == "__main__":
    solve()

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

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

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


def main():
    n, k = map(int, input().split())
    mod = 10 ** 9 + 7
    answer = 1  
    max_num = sum_from_1_to_n(n)
    for i in range(k, n + 1):
        answer += max_num - sum_from_1_to_n(n - i) - sum_from_1_to_n(i - 1) + 1
        answer %= mod
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):




import numpy as np
from itertools import accumulate


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

n = range(N+1)


if K > N:
    print(1)
    exit(0)

combi = np.array(range(N+1-(K-1)))+K
S = 0

minsum = list(accumulate(n))

maxsum = list(accumulate(n[::-1]))

for c in combi:
    
    
    min_num = (minsum[c-1]-1) % 1000000007
    max_num = maxsum[c-1] % 1000000007
    
    if (max_num-min_num) < 0:
        S += ((max_num-min_num) + 1000000007)
    else:
        S += (max_num-min_num)
    S %= 1000000007
print(S)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))
def inpl_str():
    '''
    一行に複数の文字
    '''
    return list(input().split())

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

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

dp=[[0]*2 for i in range(n+1)] 
mod=10**9+7

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

mod=10**9+7

ksum=0
for kk in range(k-1,n+1):
    ksum=(ksum+dp[kk][1]-dp[kk][0]+1)%mod
print(ksum)

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

Solution (Python):
def d():
    n, k = map(int, input().split())
    combination = [0] * (n+2)
    min = [0] * (n+2)
    max = [0] * (n+2)
    

    
    
    
    for i in range(1, n+2):
        max[i] = max[i-1] + n+1-i
        min[i] = min[i-1] + i-1
        combination[i] = max[i] - min[i] + 1
        
        

    mod = 10**9 + 7
    print(sum(combination[k:n+2]) % mod)



if __name__ == "__main__":
    d()

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

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

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

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

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

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

print(ans)

Solution (Python):
from itertools import accumulate

mod = 10 ** 9 + 7

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

A = [0] + list(accumulate(range(N + 1)))
B = [0] + list(accumulate(reversed(range(N + 1))))

print(sum(b - a + 1 for a, b in zip(A[K:], B[K:])) % mod)

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

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

Solution (Python):
def usirowa(n, x):
    return x*(2*n - x + 1) // 2

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

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

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

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

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

Solution (Python):


import itertools


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












ans=0

i=K
while(i<=N+1):
    
    
    
    
    
    
    
    
    
        
        
        
    max=((N-i+1+N)*i)/2
    min=((0+i-1)*i)/2
    
    
    
    ans=ans+(max-min)+1

    i=i+1


print(int(ans)%1000000007)

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

ans = 0

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

  MIN = i*(i-1)/2
  MAX = (n+1-i+n)*i/2
  ans +=(MAX-MIN+1)
  
print(int(ans%(10**9+7)))

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
















underSum=[0]
upSum=[n]
for i in range(1,n+1):
    underSum.append(underSum[-1]+i)
    upSum.append(upSum[-1]+n-i)

result=0

mod=10**9+7


for i in range(k-1,n+1):
    
    result=(result+upSum[i]-underSum[i]+1)%mod

print(result)

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

Solution (Python):
import numpy
N, K  = map(int, input().split(' '))
right = 0
s = 0
for i in range(K, N+2):
    mi = (i-1)*i/2
    ma = (2*N-i+1)*i/2
    s += (ma - mi) + 1
print(int(s%(1e9+7)))

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

Solution (Python):
def coun(n,r):
    return n*r+1+r-r**2

def sigma(func,frm,too):
    result=0
    for i in range(frm,too+2):
        
        result=result+func(too,i)
        
    print(result%mod)

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

sigma(coun,k,n)

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

Solution (Python):
N,K = map(int,input().split())
wa = [0]
for i in range(1,N+1):
    wa.append(wa[i-1] + i)
def func(k):
    a = wa[N] - wa[N-k] 
    b = wa[k-1] 
    
    return a - b + 1
if N<K:
    print(1)
else:
    ans = 1
    for i in range(K,N+1):
        ans = (ans+func(i))%(10**9+7)
    print(ans)

Solution (Python):
class Ruisekiwa:
    def __init__(self,lst):
        s = 0
        self.r = [0]
        for i,_ in enumerate(lst):
            self.r.append(s+lst[i])
            s += lst[i]

    def query(self,a,b):
        
        return self.r[b] - self.r[a]

def main():
    mod = 10**9+7
    n,k = map(int,input().split())
    num_lst = list(range(n+1))
    ruisekiwa = Ruisekiwa(num_lst)
    answer = 0
    for i in range(k,n+2):
        mx = ruisekiwa.query(n-i+1,n+1)
        mn = ruisekiwa.query(0,i)
        
        answer += mx - mn + 1
        answer %= mod

    print(answer)




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):
  ans += k*(N-k+1)+1
print(ans%mod)

Solution (Python):
N,K = map(int, input().split())
Cseq = [i for i in range(N+1)]
CCseq = [0]
for i in range(1,N+1):
    CCseq.append(Cseq[i] + CCseq[-1])
ans = 1
for i in range(K,N+1):
    ans += CCseq[-1]-CCseq[len(CCseq)-1-i]-CCseq[i-1]+1
print(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):
    l = i*(i-1)//2 
    r = i*(n-i+1+n)//2
    ans = (ans + r-l+1)%mod

print(ans)

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):
MOD = 10**9+7

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

min_list = [sum([i for i in range(K)])]
for i in range(K, N+1):
    min_list.append((min_list[-1]+i) % MOD)

max_list = [sum([N-i for i in range(K)])]
for i in range(K, N+1):
    max_list.append((max_list[-1]+N-i) % MOD)


count = 0
for i in range(len(min_list)):
    count = (count+(max_list[i]-min_list[i]+1)) % MOD

print((count) % MOD)

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

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

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

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

n_li = list(range(n+1))

ans = 0

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

    ans += q - p + 1
    ans %= MOD
    k += 1

print(int(ans))

Solution (Python):
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


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

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 % (10**9+7))

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

Solution (Python):
import sys
def MI(): return map(int, sys.stdin.readline().split())
if __name__ == "__main__":
    N, K = MI()
    result = 0
    mod = 10**9+7
    if N+1 == K:
        print(1)
    else:
        for i in range(K, N+2):
            result += i*(N-i+1)+1
        print(result%mod)

Solution (Python):
import sys
n,k = map(int,sys.stdin.buffer.read().split())
mod = 10**9+7
print(((n**3+3*n**2+8*n+2*(k-1)**3-8*(k-1)-3*(k-1)**2*n-3*(k-1)*n)//6+1) % mod)

Solution (Python):



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




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

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

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

calc = lambda x: x * (N-x+1) + 1

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

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

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


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

print(int(ans%1000000007))

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

Solution (Python):











from scipy.special import comb


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

MOD = 10**9 + 7
ans = 0
lis = list(range(0,N+1))

for i in range(K,N+1+1):
    start = (i-1)*i//2
    end = N*i - start
    if end<=start:
        start,end = end,start
    num = end - start +1
    ans += num
ans %= MOD
print(ans)

Solution (Python):
n, k = map(int, input().split())
def sum2(nums):
    res = 0
    for num in nums:
        res += num
        res %= 1000000007
    return res
print(sum2(1 + l * (n + 1 - l) for l in range(k, n + 2)))

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

n_li = list(range(n+1))

ans = 0

while(k <= n+1):
    p = (k - 1) * k / 2
    q = ((n + n - k + 1) * k) / 2

    ans += q - p + 1
    ans %= MOD
    k += 1

print(int(ans))

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

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

MOD = 10 ** 9 + 7

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

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

print(res)

Solution (Python):
def coun(n,r):
    return n*r+1+r-r**2

def sigma(func,frm,too):
    result=0
    for i in range(frm,too+2):
        
        result=result+func(too,i)
        
    print(result%mod)

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

sigma(coun,k,n)

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

def calc(i):
    minv = i * (i-1) // 2
    maxv = minv + i * (N - i + 1)
    return maxv-minv+1

if __name__ == '__main__':
    resolve()

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

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

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

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

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

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

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

    n_li = list(range(n+1))

    ans = 0

    while(k <= n+1):
        p = (k - 1) * k / 2
        q = ((n + n - k + 1) * k) / 2

        ans += q - p + 1
        ans %= MOD
        k += 1

    print(int(ans))

if __name__ == '__main__':
    main()

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



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

mx=0
mi=0
ans=0
for k in range(N+1):
    mx+=N-k
    mi+=k
    if k>=K-1:
        ans+=mx-mi+1

print(ans%mod)

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

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

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

for i in range(k-1):
    s1+=i
    s2+=n-i


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

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

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

Solution (Python):
import math

class abc_163:
    
    def __init__(self):
        pass
    
    def A(self):
        r=int(input())
        print(2*math.pi*r)
    
    def B(self):
        NM=list(map(int,input().split()))
        A=list(map(int,input().split()))
        
        if NM[0]-sum(A)>=0:print(NM[0]-sum(A))
        else:print("-1")
    
    def C(self):
        N=int(input())
        A=list(map(int,input().split()))
        ans_list=[0]*(N+1)
        
        for i in range(N-1):ans_list[A[i]] +=1
        for i in range(1,N+1):print(ans_list[i])
        
    def D(self):
        NK=list(map(int,input().split()))
        
        data_list=[i for i in range(NK[0]+1)]
        reverse_data_list=sorted(data_list, reverse=True)
        
        
        min_sum_data_list=[0]*(NK[0]+1)
        max_sum_data_list=[0]*(NK[0]+1)
        
        
        min_sum_data_list[0]=data_list[0]
        max_sum_data_list[0]=reverse_data_list[0]
        ans_data=0
        
        
        for i in range(1,NK[0]+1):
            min_sum_data_list[i]+=min_sum_data_list[i-1]+data_list[i] % (pow(10,9)+7)
            max_sum_data_list[i]+=max_sum_data_list[i-1]+reverse_data_list[i] % (pow(10,9)+7)
       
        for i in range(NK[1]-1,NK[0]+1):
            ans_data+=(max_sum_data_list[i]-min_sum_data_list[i]+1) % (pow(10,9)+7)
            
        print(ans_data % (pow(10,9)+7))    
            
    
if __name__=='__main__':
    obj=abc_163()
    obj.D()

Solution (Python):

from collections import defaultdict
n, k = map(int, input().split()) 

mod = 10 ** 9 + 7
cum = [0] + [i for i in range(n + 1)]
for i in range(n + 1):
    cum[i + 1] += cum[i]

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

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

Solution (Python):
N,K=map(int,input().split())
X=N-K+1
Y=1
if X==0:
    print(Y)
else:
    Y=(N-K+2)*(N-K+2)*(K-1)+(N-2*K+3)*(N-K+2)*(N-K+3)/2-(N-K+2)*(N-K+3)*(2*N-2*K+5)/6+N-K+2
    print(int(Y%(1000000007)))

Solution (Python):
import math  
import bisect  
import queue  


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

    MOD = 1_000_000_007
    ans = 0
    for k in range(K, N + 2):
        upper = ((N + N - k + 1) * k) // 2
        lower = ((k - 1) * k) // 2
        ans += upper - lower + 1
        ans %= MOD

    print(ans)

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

ma = sum([n-int(x) for x in range(k)])
mi = sum([int(x) for x in range(k)])

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

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

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

class ModInt:
    def __init__(self, x):
        if isinstance(x, ModInt):
            self.value = x.value
        else:
            self.value = x % MOD
            if self.value < 0:
                self.value += MOD
    
    def get_mod(self):
        return MOD
    
    
    def __str__(self):
        return str(self.value)
    
    def __int__(self):
        return self.value
    
    __index__ = __int__
    
    
    __repr__ = __str__

    
    def __add__(self, other):
        return ModInt(self.value + ModInt(other).value)
    
    def __sub__(self, other):
        return ModInt(self.value - ModInt(other).value)

    def __mul__(self, other):
        return ModInt(self.value * ModInt(other).value)
    
    def __truediv__(self, other):
        
        return ModInt(self.value * pow(ModInt(other).value, MOD - 2, MOD))

    
    def __pow__(self, other):
        return ModInt(pow(self.value, ModInt(other).value, MOD))

    
    __radd__ = __add__

    def __rsub__(self, other):
        return ModInt(other - self.value)
    
    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return ModInt(other * pow(self.value, MOD - 2, MOD))

    def __rfloordiv__(self, other):
        return ModInt(other // self.value)
    
    
    def __rpow__(self, other):
        return ModInt(pow(other, self.value, MOD))
    
    
    def __lt__(self, other):
        return self.value < ModInt(other).value
    
    def __gt__(self, other):
        return self.value > ModInt(other).value

    def __le__(self, other):
        return self.value <= ModInt(other).value
    
    def __ge__(self, other):
        return self.value >= ModInt(other).value
    
    def __eq__(self, other):
        return self.value == ModInt(other).value
    
    def __ne__(self, other):
        return self.value != ModInt(other).value
    
    
    def __iadd__(self, other):
        self.value += ModInt(other).value
        if self.value >= MOD:
            self.value -= MOD
        return self.value
    
    def __isub__(self, other):
        self.value -= ModInt(other).value
        if self.value < 0:
            self.value += MOD
        return self.value
    
    def __imul__(self, other):
        self.value = ModInt(self.value * ModInt(other).value)
        return self.value

    def __itruediv__(self, other):
        self.value = ModInt(self.value * pow(ModInt(other).value, MOD - 2, MOD))
        return self.value
    
    
    def modinv(self):
        return ModInt(pow(self.value, MOD - 2, MOD))
    
N, K = map(ModInt, map(int, input().split()))

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

print(ans)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline                                
def I(): return list(map(int,inp().split()))
m=10**9+7

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

Solution (Python):
N,K = map(int,input().split())
s = 0
for i in range(K,N+2):
  a = int((2*N-i+1)*i/2)
  b = int(i*(i-1)/2)
  s += a-b+1

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

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

    ans+=r-l+1
    ans%=mod
    if ans<0:
        ans+=mod
print(ans)

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

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline                                
def I(): return list(map(int,inp().split()))
m=10**9+7

n,k=I()
ans=1 ;a=[]
for i in range(k,n+1):
    ans+=i*(n-i+1)+1
    ans%=m
    a.append(k*(n-i+1)+1)
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 itertools
N, K = map(int, input().split())
t = 0
for i in range(K,N+2):
    st = int((i*(0+i-1))/2)
    ed = int((i*(N-i+N+1))/2)
    t += (ed - st + 1)
    t %= 10**9 + 7
print(t)

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

Solution (Python):
n,k = map(int,input().split())
cnt = 0
for i in range(k,n+2):
    if 0.5*(n-i)*(n-i+1) >= 0:
        minus = 0.5*(n-i)*(n-i+1)
    else:
        minus = 0
    front = 0.5*(i-1)*i
    end = 0.5*n*(n+1) - minus
    cnt += end-front+1
print(int(cnt%(10**9+7)))

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

print(int(ans%MOD))

Solution (Python):
import math  
import bisect  
import queue  


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

    cumsum = [0 for _ in range(N + 1)]
    cumsum[0] = 0
    for i in range(1, N + 1):
        cumsum[i] = i + cumsum[i - 1]

    MOD = 1_000_000_007
    ans = 1
    for k in range(K, N + 1):
        ans += (cumsum[N] - cumsum[-(k + 1)]) - cumsum[k - 1] + 1
        ans %= MOD

    print(ans)

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

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

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

Solution (Python):
import sys
from itertools import permutations
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)
MOD = pow(10, 9) + 7

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

l = range(0, N + 1)
sum_ = sum(l)
if K > N:
    print(1)
    sys.exit()

ans = 0
for i, k in enumerate(range(K, N + 2), 0):
    small = (i - 1) * i // 2
    large = (2 * N - i + 1) * i // 2
    acc = large - small + 1
    acc %= MOD
    ans += acc
    
print(ans % MOD)