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

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


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

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

Solution (Python):
def solve(n, k):
    ans = 0
    mod = int(1e9 + 7)
    for i in range(k, n + 2):
        lb = (i - 1) * i // 2
        ub = (n + n - i + 1) * i // 2
        ans += ub - lb + 1
        ans %= mod
        
    return ans


def main():
    
    
    
    print(solve(*[int(v) for v in input().split()]))


if __name__ == '__main__':
    main()

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

num = 0

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

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

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

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

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

for i in range(K, N + 2):
    mini = sum_of(i)
    maxi = sum_of(N + 1) - sum_of(N - i + 1)
    ans += (maxi - mini + 1)

print(ans % mod)

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

MOD = (10**9) + 7


def dSum(s, e):
    s -= 1
    _s = s * (s + 1) // 2
    _e = e * (e + 1) // 2
    return _e - _s


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

print((ans + 1) % MOD)

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

n = n+1
mod = 10**9+7

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

    ans = (ans + m2 - m1 + 1) % mod

print(ans)

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

ans = 0

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

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

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

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

ans = 0

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

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

Solution (Python):
import sys





import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

MOD = 1000000007

def main():
    

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

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

    

    ans = 0
    for k in range(K, N+1 + 1):
        if k == N + 1:
            ans = (ans + 1) % MOD
            continue
        max_a = comm_sum[N] - comm_sum[N - k]
        min_a = comm_sum[k - 1]
        diff = max_a - min_a + 1
        ans = (ans + diff) % MOD
        
        
        
        
        

    print(ans)

    return 0

if __name__ == '__main__':
    sys.exit(main())

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

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

    res=0

    MOD=10**9+7

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

        res+=MAX-MIN+1
        res%=MOD

    print(res%MOD)

if __name__=="__main__":
    main()

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

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

print(int(ans))

Solution (Python):
mod = 1000000007

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

memo = []

for i in range(n+1):
  memo.append(i)

min_sum = [0]

for i in range(1,n+1):
  kazu = memo[i]+min_sum[i-1]
  min_sum.append(kazu)

memo.reverse()

max_sum = [memo[0]]

for i in range(1,n+1):
  kazu = memo[i]+max_sum[i-1]
  max_sum.append(kazu)

ans = 0

for i in range(k-1,n+1):
  ans += max_sum[i]-min_sum[i]+1

print(ans%mod)

Solution (Python):
N,K=map(int,input().split())
ans=0
for i in range(K,N+2):
  if i!=(N+1):
    anssub=N*(N+1)//2 -(N-i)*(N-i+1)//2 - i*(i-1)//2+1
  else:
    anssub=1
  ans+=anssub
ans=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):
    min = i*(i-1)/2
    max = (2*N-i+1)*i/2
    ans += max - min + 1
print(int(ans%mod))

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

csl=[]
sum=0
for i in range(n+1):
	sum+=i
	csl.append(sum)



cnt=0
for i in range(k,n+1):
	max=csl[n]-csl[n-i]
	min=csl[i-1]
	
	cnt+=(max-min+1)
	cnt%=(10**9+7)

print(cnt+1)

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

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

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):
def main():
    mod = 10**9 +7
    n,k = map(int,input().split())
    ans = 0
    for i in range(k,n+2):
        a = i*(i-1)//2
        b = i*(2*n-i+1)//2
        ans += (b-a+1)
    print(ans%mod)
if __name__ == '__main__':
    main()

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

res = 0
s = [i for i in range(N)]

if K == 1:
    res += N
    K = 2

if N == 0:
    print(res)
    exit(0)

res += 1
minimum = sum(s[:K - 1])
maximum = sum(s[-K + 1:])

for i in range(K, N):
    minimum += s[i]
    maximum += s[-i + 1]
    res = (res + (maximum - minimum + 1)) % (10 ** 9 + 7)

print(res)

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

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

min_ = k * (k-1) // 2
max_ = k * (2*n-k+1) // 2
ans = max_ - min_ + 1
ans = ans % (10**9+7)

if k == n+1:
    print(ans)

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

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]


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


if __name__ == "__main__":
    main()

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

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

ans = 0

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

for i in range(k, n+2):
    l = select(0, i-1)
    r = select(n-i+1, n)
    ans += (r-l+1) 
    ans %= (pow(10, 9) + 7)

print(ans)

Solution (Python):
import math

DEN=10**9+7
def ret_val(n):
    return n%DEN

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

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

print(ret_val(sum))

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

c = 0
for i in range(K, N + 2):
    min = i * (i + 1) / 2
    max = i * (N + 2 - i + N + 1) / 2
    c += max - min + 1
    c %= (1e9 + 7)
print(int(c))

Solution (Python):
N,K = map(int,input().split())
mod = pow(10,9)+7
c = 0
cnt = 0
for i in range(K,N+1):
    temp1 = 0.5*(K+cnt)*(K+cnt-1)
    temp2 = (K+cnt)*0.5*(2*N-(K+cnt-1))
    c += temp2 - temp1 + 1
    c = c%mod
    cnt += 1
c += 1
print(int(c))

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

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

Solution (Python):
n,k=map(int,input().split())
t=[int(i) for i in range(n+1)]
t_rev=[0]+[int(i) for i in range(n,0,-1)]

from itertools import accumulate
s=list(accumulate(t))
s_rev=list(accumulate(t_rev))
s.append(s[-1])
s_rev.append(s_rev[-1])

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

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

print(count)

Solution (Python):

c=0
n,k=map(int,input().split(" "))
for i in range(k,n+2):
    c+=i*n-i*(i-1)+1
    while(c>=10**9+7):
        c-=10**9+7
        
print(c)

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

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

print(ans)

Solution (Python):
import math
import sys
from collections import defaultdict
input = sys.stdin.readline


def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
    
n, k = invr()


A = [i for i in range(n + 1)]

res = 0
small = sum(A[:k])
large = sum(A[-k:])
for cLen in range(k, n + 2):
	
	res = (res +  large - small + 1 ) % (10 ** 9 + 7)
	if cLen != n + 1:
		small += A[cLen]
		large += A[-cLen - 1]

print res

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

ans = 0

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

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

print(ans)

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

count = 0

for i in range(k,n+2):
    most = (2 * n - i + 3) * i // 2
    least = (i + 1) * i // 2
    cases = most - least + 1
    count += cases
    count %= (10**9+7)

print(str(int(count)))

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

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

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

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

for i in range(k, n + 2):
    maxsum = (i*(n + (n - i + 1)))//2
    minsum = (i - 1)*i//2
    ans += (maxsum - minsum + 1)%(10**9 + 7)

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

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

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

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

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

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

Solution (Python):
def f(a,l):
    return  ((a+l)*(l+1-a))//2


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

S=0

P=f(0,K-2)
Q=f(N-K+2,N)
for x in range(K,N+2):
    P+=x-1
    Q+=N+1-x

    S=(S+(Q-P+1))%M
    
print(S)

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

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

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())
 
ans = 0
mod = pow(10,9)+7
 
for k in range(K, N+2): 
  
  ans += k*((N+1-k)+N)//2 - k*(0+k-1)//2 + 1
  
print(ans % mod)

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

lst = [_ for _ in range(n+1)]
ans = 0

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

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

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

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

ans = 0
for x in range(K, N+2, 1):
    a = (x*(x-1)//2)
    b = ((x*(2*N-x+1))//2)
    ans += b-a+1
print(ans%(10**9+7))

Solution (Python):



MOD = 10 ** 9 + 7

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

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

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

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

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

print(ans)

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

ans = 0
for i in range(k,n+2):
    if n != 1:
        if i > 2:
            ans += n*(n+1)//2 - (n-i)*(n-i+1)//2 - (i-1)*i//2 + 1
        elif i == 2:
            ans += 2 * n - 1
        elif i == 1:
            ans += n+1
    else:
        if i == 2:
            ans += 1
        elif i == 1:
            ans += 2

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    N, K = map(int, readline().split())
    p = [int(i) for i in range(N+1)]
    s = [0]
    for i in range(N+1):
        s.append(s[i]+p[i])
    ans = 0
    P = int(1e9)+7
    for k in range(K, N+2):
        ans += (s[-1]-s[-k-1])-(s[k]-s[0])+1
        ans %= P
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = lambda: sys.stdin.readline().strip("\r\n")

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

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

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

MOD = 10**9+7
Sm = 0

for k in range(K,N+2):
    m = (2*N-k+1)*k/2-k*(k-1)/2+1
    Sm = (Sm+m)%MOD

print(int(Sm))

Solution (Python):
import itertools


def main():

    N, K = map(int, input().split())
    mod = 1000000007
    s = list(itertools.accumulate(range(0, N+1)))

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
MOD = 1000000007
n,k = (int(x) for x in input().split())
ans = 0

arrow = k
left = (k - 1) * k // 2
right = n * k - k * (k - 1) // 2
while(arrow <= n + 1):
    
    ans += (right - left + 1)
    ans %= MOD
    left += arrow
    right += n - arrow
    arrow+=1

print(ans)

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

ans = 0

for i in range(k,n+2):
    mini = i*(i-1)//2
    maxa = (i*(n + n-i+1))//2
    ans += maxa - mini + 1
    ans = ans % (10**9 +7)

print(ans)

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

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

print(sum(ans[k:])%mod)

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

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

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

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

print (ans)

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

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

    ans=(ans+(max_sum-min_sum+1))%MOD
print(ans)

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

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

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

tab_sum = [0]
sum_tmp = 0
for i in range(N + 1):
    sum_tmp += i
    tab_sum.append(sum_tmp)

ans = 0
DIVIDER = 1000000007
for cnt in range(K, (N + 1) + 1):
    sum_min = tab_sum[cnt] - tab_sum[0]
    sum_max = tab_sum[-1] - tab_sum[-1 - cnt]
    
    ans = (ans + (sum_max - sum_min + 1)) % DIVIDER

print(ans)

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

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

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

cnt = 0
for k in range(K, N+2):
    mn = k*(k-1)//2
    mx = N*(N+1)//2 - (N-k)*(N-k+1)//2
    cnt += mx-mn+1
    cnt %= mod

print(cnt)

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

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

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

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

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

print(ans)

Solution (Python):
def sum_from_1(k):
    return k * (k + 1) // 2


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


if __name__ == '__main__':
    main()

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


MOD = 1000000007

s = 0

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

print(s % MOD)

Solution (Python):


import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
mod = 10**9+7
dict = {}
N,K = LI()

summax = 0 
summin = 0
ans = 0

first = K
for i in range(1,K):
	
	summax+=N-i+1
	summin+=i-1


for k in list(range(K,N+2)):
	
	summax+=N-k+1
	summin+=k-1
	ans+=summax-summin+1
	ans%=mod
	
print(ans)

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

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

Solution (Python):
from itertools import combinations


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

Solution (Python):
import sys
from collections import deque
import copy
def main():
    N, K = map(int, input().split())
    MOD = 10 ** 9 + 7
    count = 0
    while K != N+2:
        if K == 1:
            min_ = 0
        if K >= 2:
            min_ = ((K * (K-1)) / 2) % MOD
        max_ = ((N + 1) * N - (N + 1 - K) * (N - K)) / 2 % MOD
        count += max_ - min_ + 1
        count %= MOD
        K +=1
    print(int(count))
    


if __name__ == '__main__':
    main()

Solution (Python):
line=input()
n,k=map(int,line.split())
sums=0
while k!=(n+2):
     if k==1:
          mini=0
     if k>=2:
          mini=(((k)*(k-1))/2)
     maxi=( (((n+1)*(n)) - ((n+1-k)*(n-k)) )/2  )
     sums+=(maxi-mini+1)
     sums=sums%((10**9)+7)
     k+=1
print(int(sums))

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

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

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

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 range(K, N + 2):
        a = k * (k - 1) // 2
        b = k * (2 * N - (k - 1)) // 2
        ans = (ans + (b - a + 1)) % P

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n, k = map(int,input().split())
list = [i for i in range(n+1)]
ans = 0
min = sum(list[0:k-1])
max = sum(list[n+1-k+1:n+1])

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

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

Solution (Python):
mod = 10**9 + 7
max_num = 2 * 10**5 + 3
facts = [1 for i in range(max_num)]
invs = [1 for i in range(max_num)]
 
def inv(x):
    return pow(x,mod-2,mod)
 
for i in range(1,max_num):
    facts[i] = facts[i-1]*i%mod
    invs[i] = inv(facts[i])
 
def nCk(n,k):
    return facts[n]*invs[k] * invs[n-k] % mod

def nHk(n, k):
  return nCk(n-1+k, n-1)

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

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

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

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

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

Solution (Python):
from sys import stdin, setrecursionlimit


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


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Solution (Python):
from sys import stdin, setrecursionlimit


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


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Solution (Python):
from sys import stdin, setrecursionlimit


def main():
    mod = 10 ** 9 + 7
    input = stdin.buffer.readline
    n, k = map(int, input().split())

    mins = [0]
    maxs = [n]
    tmp_min = 0
    tmp_max = n
    for i in range(1, n + 1):
        tmp_min += i
        mins.append(tmp_min)
        tmp_max += n - i
        maxs.append(tmp_max)
    ans = 0
    for i in range(k - 1, n + 1):
        ans += maxs[i] - mins[i] + 1
        ans %= mod
    print(ans % mod)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

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

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

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

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

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

MOD = pow(10, 9)+7



    
    
    
    

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

print(ans%MOD)

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

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

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

mod = 10**9+7

low = [0]*(N+1)
high = [0]*(N+1)
ls = [0]*(N+1)
high[0] = N
ls[0] = high[0] - low[0] + 1

for i in range(1,N+1):
    low[i] = i + low[i-1]
    high[i] = N-i + high[i-1]
    ls[i] = high[i] - low[i] + 1

ans = 0

for i in range(K-1,N+1):
    ans = (ans + ls[i])%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 += i*(n-i+1) + 1
    ans %= mod
print(ans)

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

ans=0
max_comb=0
min_comb=0
for i in range(K,N+2):
  try:
    max_comb=rui[-1]-rui[-1-i]
  except:
    max_comb=rui[-1]
  min_comb=rui[i-1]
  ans+=max_comb-min_comb+1
  ans %= (10**9+7)
print(ans)

Solution (Python):
def solve(string):
    from itertools import accumulate
    n, k = map(int, string.split())
    *a, = accumulate(range(n + 1))
    ans, m = 0, 10**9 + 7
    for b, c in zip(a[:-k][::-1], a[k - 1:]):
        ans = (ans + a[-1] - b - c + 1) % m
    return str((ans + 1) % m)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,k=n1()
 
down=[0]*(n+1)
up=[0]*(n+1)
up[0]=n
ans=0 if k>1 else n+1
for i in range(1,n+1):
    down[i]=down[i-1]+i
    up[i]=up[i-1]+(n-i)
    if i>=k-1:
        ans+=up[i]-down[i]+1
print(ans%(10**9+7))

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

counter = 0
for k in range(K, N+1):
    counter += k * (N-k)
    counter += k+1
    counter = counter % mod

counter += 1 
counter = counter % mod

print(counter)

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

Solution (Python):
import math

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










max_num = 0
min_num = 0
result_sum = 0
for K in range(k,n+2):
    max_num = K*(2*n-K+1)/2
    min_num = (K-1)*K/2
    result_sum += max_num - min_num +1


result_before_division = result_sum

result = result_before_division % (10**9 + 7)

print(int(result))

Solution (Python):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")
MOD = 1000000007


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

    ans = 0
    sum_min = sum([i for i in range(K)])
    sum_max = sum([i for i in range(N-K+1, N+1)])
    l = K - 1
    r = N - K + 1
    while l <= N:
        ans += sum_max - sum_min + 1
        ans %= MOD
        l += 1
        r -= 1
        sum_min += l
        sum_max += r
    
    print(ans)


if __name__ == '__main__':
    main()

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

result=0

teisu=10**9+7

for i in range(K,N+2):
    a=-i**2+(N+1)*i+1
    result+=a
    result=result%teisu

print(result)

Solution (Python):
N, K = [int(_) for _ in input().split()]
cnt = []
for i in range(1, N+2):
    mini = (i - 1) * i // 2
    maxi = (N - i + 1 + N) * i // 2
    cnt.append((maxi - mini + 1))
print(sum(cnt[K-1:]) % (10**9 + 7))

Solution (Python):

import sys

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

if __name__ == '__main__':
    main()

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

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

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

    
    
    
    
    
    
    
    
    

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


main()

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