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

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

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

Solution (Python):
MOD = 1000000000+7
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)

Solution (Python):
n, k = [int(m) for m in 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
MOD = 10**9+7

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

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

ans, saidai, saisyo = 0, 0, 0
for i in range(1, N+2):
    saisyo += i-1
    saidai += N-i+1
    if i >= K:
        ans += (saidai - saisyo + 1)
    
print(ans%(10**9+7))

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
ans = 0
for k in range(K, N+2):
    mi = (k - 1) * k // 2
    ma = (N + 1) * N // 2 - (N - k) * (N - k + 1) // 2
    ans += ma - mi + 1
print(ans % mod)

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

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

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

ans, saidai, saisyo = 0, 0, 0
for i in range(1, N+2):
    saisyo += i-1
    saidai += N-i+1
    if i >= K:
        ans += (saidai - saisyo + 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):
    min = ((i-1)*i)//2
    max = ((2*n-i+1)*i)//2
    ans += max-min + 1
print(ans%mod)

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

low, high = 0, 0
ans = 0
for i in range(1, N + 2):
    low += i - 1
    high += N - i + 1

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

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

ans = 0
mod = 10**9+7
for i in range(k,n+2):
    a = i*((2*n)-i+1)/2
    b = i*(i-1)/2
    ans += (a-b+1)

print(int(ans%mod))

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

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 LLI(rows_number): return [LI() for _ in range(rows_number)]

n,k = LI()
from scipy.special import comb
ans = 0
mod = 10**9+7
l = [i for i in range(n+1)]
a = sum(l[:k])
b = sum(l[-k:])
for i in range(k,n+2):
    ans += b-a+1
    a += i
    b += n-i
print(ans%mod)

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

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

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

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

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

print(ans)

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

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

def x_sum(x):
    return (2*n-x+1)*x//2 - x*(x-1)//2 + 1

ans = 0 
for i in range(k, n+2):
    ans += x_sum(i)
ans %= 10 ** 9 + 7

print(ans)

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

def x_sum(x):
    return (2*n-x+1)*x//2 - x*(x-1)//2 + 1

ans = 0 
for i in range(k, n+2):
    ans += x_sum(i)
ans %= 10 ** 9 + 7

print(ans)

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

for k in range(K,N+1):
    large = n_list[N]-n_list[N-k]
    small = n_list[k-1]

    answer += large-small+1
answer += 1
print(answer % 1000000007)

Solution (Python):
N,K = map(int,input().split())
A = 0
while K < N +2:
    min = K/2*(K-1)
    max = K/2*(2*N-K +1)
    A += max - min + 1
    K+= 1
print(int(A % (10**9 +7) ))

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

Solution (Python):
N, K = [int(x) for x in input().split()]
Sum = 1
ans = 1
T = N + 1 - K
for t in range(T):
  Sum = (Sum + (N - 2 * t)) % 1000000007
  ans = (ans + Sum) % 1000000007
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

print(ans%mod)

Solution (Python):
n,k = map(int, input().split())
lis = [i for i in range(n+1)]
rui = [0]*(n+2)
tmp = 0
for j in range(n+1):
    tmp += lis[j]

    rui[j+1] += tmp

ans = 0
for l in range(k,n+2):
    ans += rui[n+1]-rui[n-l+1]-rui[l] +1
ans %= 1000000007
print(ans)

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

Solution (Python):
N,K = [int(i) for i in input().split()]
result = 0
value = 1000000007

def nums_every_k(n,k):
    first_num = (k*(k-1))/2
    last_num = k*(2*n-k+1)/2
    numbers = last_num - first_num + 1
    return numbers
    
for k in range(K,N+2):
    result += nums_every_k(N,k)

result = result%value
print(int(result))

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

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

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

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

Solution (Python):
def main():
    MOD = 1000000007
    N, K = map(int, input().split())
    L, R = list(range(N + 1)), list(range(N + 1))[::-1]
    for i in range(N):
        L[i + 1] += L[i]
        R[i + 1] += R[i]
    ans = 0
    for i in range(K - 1, N + 1):
        ans = (ans + R[i] - L[i] + 1) % MOD
    print(ans)


if __name__ == '__main__':
    main()

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

total = 0
mod = 10**9+7
s = [0]
for i in range(0, N+1):
    s.append(s[-1] + i)

for i in range(K, N+2):
    total = (total + ((s[-1]-s[-(i+1)]) - s[i] + 1)) % mod
print(total)

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

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

my_code_D()

Solution (Python):
import sys
from collections import Counter

lines = 1
inp = list()

for _ in range(lines):
    inp.append(sys.stdin.readline().strip())


nk = inp[0].split()
n = int(nk[0])
k = int(nk[1])









i = 1
sigma = 0
while i <= k - 2:
    sigma += i
    i += 1


result = 0
i = k


while k <= i <= n + 1:
    sigma += i - 1
    result += i * n - 2 * sigma + 1
    i += 1


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

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

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


ans=0
for i in range(n+1):
  ans+=z[i]
print(int(ans%(10**9+7)))

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

for i in range(k, n+2):
  min = int(i * (i - 1) / 2) 
  max = int(i * (2 * n - i + 1) / 2)
  cnt += max - min + 1

print(cnt % mod)

Solution (Python):
n,k=map(int,input().split())
s=0
pre=[]
m=10**9+7
for i in range(n+1):
    s+=i
    pre.append(s)
ans=0

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

Solution (Python):
n,k=map(int,input().split())
ans=0
mod=10**9+7
sum_=[0]
for i in range(n):
    sum_.append(sum_[-1]+(i+1))
for i in range(k-1,n+1):
    ans+=(i+1)*n-sum_[i]-(sum_[i]-1)
    ans=ans%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):
N, K = map(int, input().split())

ans = 0
MOD = 10**9 + 7


def sum(a, b):
    return (b - a + 1) * (a + b) // 2


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

print(ans % MOD)

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

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

Solution (Python):


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

Solution (Python):

















mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,k = readInts()
    
    
    
    
    
    
    
    
    
    def calc(a):
        sml = (0 + a-1) * a // 2
        lar = sml + a * (n-a+1)
        return lar - sml + 1
    ans = 0
    for i in range(k,n+2):
        ans += calc(i)%mod
    print(ans%mod)
if __name__ == '__main__':
  main()

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

for i in range(k, n+2):
  
  s_min = i * (i-1) // 2
  
  s_max = (n+1) * n // 2 - (n-i+1) * (n-i) // 2
  
  s_count = s_max - s_min + 1
  
  ans = (ans + s_count) % div

print(ans)

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

mod = int(1e9+7)


upper = 0
for i in reversed(range(N+1-K,N+1)):
    upper += i
upper_point = N-K

lower = 0
for i in range(K):
    lower += i
lower_point = K
ans = 0

for i in range(K,N+2):
    
    
    ans += upper - lower + 1
    upper += upper_point
    lower += lower_point

    upper_point -= 1
    lower_point += 1

print(ans%mod)

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

Solution (Python):








n,k = [int(x) for x in input().split()]
count=0
mod = 10**9+7
for i in range(k,n+2):
    mink=int(i*(i-1)/2)
    maxk=int(i*(2*n-i+1)/2)
    count+=maxk - mink + 1

print(count%mod)

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

mod = int(1e9+7)


upper = 0
for i in reversed(range(N+1-K,N+1)):
    upper += i
upper_point = N-K

lower = 0
for i in range(K):
    lower += i
lower_point = K
ans = 0

for i in range(K,N+2):
    
    
    ans += upper - lower + 1
    upper += upper_point
    lower += lower_point

    upper_point -= 1
    lower_point += 1

print(ans%mod)

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




'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

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

r=[]
mi=0
ma=0
su=range(n+1)
for i in range(n+1):
    mi+=su[i]
    ma+=su[::-1][i]
    r.append(ma-mi+1)

ans=0
for i in range(k-1,n+1):
    
    ans+=r[i]
print(ans%(1000000007))

Solution (Python):
n,k = map(int,input().split())
s = [i for i in range(n+1)]
a = [0]*(n+1)
b = [0]*(n+1)
t = n+1-k
for i in range(0,n+1):
    if i < t+1:
        a[-(i+1)] = (i+1)*s[-(i+1)]
        b[-(i+1)] = (i+1)*s[i]
        c = i+1
    else:
        a[-(i+1)] = c*s[-(i+1)]
        b[-(i+1)] = c*s[i]
res = sum(b)-sum(a)+t+1
print(res%(10**9+7))

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

ans = 0
for num in range(K, N+2):
    res1 = int((2*N-num+1) * num / 2) % mod
    res2 = int((num-1) * num / 2) % mod
    ans += res1 - res2 + 1
    

print(ans % mod)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

n, k = MAP()
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)

Solution (Python):
n, k = map(int, input().split())
numbers = [i for i in range(n+1)]
min = [0] * (n+1)
for i in range(n):
    min[i+1] = min[i] + numbers[i+1]
max = [0] * (n+1)
max[0] = numbers[n]
for i in range(n):
    max[i+1] = max[i] + numbers[n-i-1]
 
ans = 0
for i in range(k-1,n+1):
    ans += max[i] - min[i] + 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): 
    a = 0.5 * i * (i - 1)
    b = 0.5 * i * (2 * n - i + 1)
    ans += (b - a + 1)
print(int(ans % mod))

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

ans = 0
for i in range(K-1,N+1):
    ans += max[i] - min[i] + 1

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

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

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

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

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

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

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

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

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

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

ans = 0

for i in range(K, N + 2):
  M = (2*N - i + 3) * i // 2
  m = i * (i+1) // 2
  ans += M - m + 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):
  ans+= ((k*(2*N+1-k)//2) - (k*(k-1)//2) +1)%MOD
print(ans%MOD)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")


def solve():
    n, k = LI()
    ans = 1
    dp = [i for i in range(n + 1)]
    dp = [i for i in itertools.accumulate(dp)]
    for i in range(k, n + 1):
        ans += (dp[n] - (dp[-i - 1])) - dp[i - 1] + 1
        ans %= mod
    print(ans)
    return



if __name__ == '__main__':
    solve()

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

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

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

Solution (Python):

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

MOD = 10 ** 9 + 7

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

print(ans)

Solution (Python):

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

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

Solution (Python):
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, k = na()

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

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    res = 0
    for i in range(k, n + 2):
        mi = (i - 1) * i // 2
        ma = n * (n + 1) // 2 - (n - i) * (n - i + 1) // 2
        res += ma - mi + 1
        res %= mod

    print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7
MAX = (10 ** 5) * 2 + 2


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


def main():
    N, K = map(int, input().split())
    ans = 0
    M = N
    m = 0
    for i in range(1, N + 2):
        if i < K:
            M += N - i
            m += i
            continue
        else:
            ans += M - m + 1
            ans %= MOD
            M += N - i
            m += i

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

import sys
import numpy as np

MOD = 1000000007  





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


    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    solve(N, K)

if __name__ == '__main__':
    main()

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

def S(k):
    return (n-k+1)*k+1

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

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

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

print(ans)

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

def S(k):
    return (n-k+1)*k+1

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

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

Solution (Python):
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    k = kwargs["k"]
    
    A = [0 for i in range(n + 1)]
    A[0] = n + 1
    res = 0

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

    for i in range(n + 1):
        if i + 1 >= k:
            res += A[i] % MOD

    res %= MOD
    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    
    
    
    kwargs["n"], kwargs["k"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

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

Solution (Python):

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


def acc(x):
    return x*(x+1)//2


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

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

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

main()

Solution (Python):
def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n % 2 == 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res


def modinv(a, mod):
    return modpow(a, mod - 2, mod)


if __name__ == "__main__":
    n, k = map(int, input().split())
    m = 10 ** 9 + 7
    
    rev2 = modinv(2, m)
    rev6 = modinv(6, m)

    f = (n + 1) * ((n + 1) * (n + 2) % m - (k - 1) * k % m) % m * rev2 % m
    s = n - k + 2
    t = ((n + 1) * (n + 2) % m * (2 * n + 3) % m - (k - 1) * k % m * (2 * k - 1)% m) % m * rev6 % m

    ans = (f + s - t) % m

    print(int(ans))

Solution (Python):
n, k = map(int,input().split())
if k == n + 1:
    print(1)
else:
    mi_n = ((k-1)*k)//2
    ma_x = ((n+n-k+1)*k)//2
    ans = ma_x - mi_n + 1
    for i in range(k,n,1):
        mi_n += i
        ma_x += n - i
        ans += ma_x - mi_n + 1

    ans += 1

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

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


n=0


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

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

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

Solution (Python):

def inputlist(): return [int(k) for k in input().split()]

N,K = inputlist()
mod = 10**9+7
li = [int(i) for i in range(N+1)]
suma = [0]*(N+1)
for i in range(1,N+1):
    suma[i] = suma[i-1]+li[i]
ans = 0
for i in range(K,N+1):
    m = suma[i-1]
    M = suma[-1] - suma[-(i+1)]
    ans += M-m+1
    ans %= mod
ans +=1
ans %= mod
print(ans)

Solution (Python):
MOD = int(1e9+7)
def main():
    n,k = map(int,input().split())
    ans = 0
    for i in range(k,n+2):
        
        min_sum = i*(i-1)//2
        
        max_sum = (2*n-i+1)*(i)//2
        
        ans = (ans + (max_sum-min_sum+1))%MOD
    print(ans)
    return

if __name__ == "__main__":
    main()

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

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

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

def sum_num(n):
    return (n*(n+1))//2

for k in range(K, N+1):
    min_sum = sum_num(k-1)
    max_sum = sum_num(N) - sum_num(N-k)
    
    ans += max_sum - min_sum + 1

ans += 1
ans %= mod
print(int(ans))

Solution (Python):
from math import factorial
N, K = map(int, input().split())

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

    tmp_min = (i - 1) * i / 2
    tmp_max = (N * (N + 1) / 2) - ((N - i) * (N - i + 1) / 2)
    

    tmp = tmp_max - tmp_min + 1
    ans += tmp

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):
  ll = 0
  lr = i - 1
  rl = n-(i-1)
  rr = n
  lsum = lr*(lr+1)//2 - ll*(ll+1)//2
  rsum = rr*(rr+1)//2 - rl*(rl-1)//2
  ans += rsum - lsum + 1
  ans %= MOD
  
  
print(ans)

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

ans = 0
a = 1

for i in range(1, n + 2):
  a -= 2 * (i - 1)
  if i >= k:
    ans += (i * n + a)
    ans %= MOD
print(ans)

Solution (Python):
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


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


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
N, K = map(int, input().split())
c = 0
ans = 0
for k in range(K, N+2):
    a = k*(k-1)/2
    b = (2*N-k+1)*k/2
    c += (b-a)+1
    
print(int(c % 1000000007))

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

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

print(ans)

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

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

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

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

for i in range(K,N+2):
    sum_ans+= ((c_sum[N+1]-c_sum[N+1-i])-(c_sum[i]-c_sum[0])+1)
print(sum_ans%(10**9+7))

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

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

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

mod = 10 ** 9 + 7
ans = 0

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

print(ans % mod)

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

Solution (Python):
from sys import stdin


def get_result(data):
    N, K = data
    mod = 10**9+7
    e_val = [i for i in range(N+1)]
    
    e_cumsum = [0]
    for i in range(N+1):
        e_cumsum.append(e_cumsum[i] + e_val[i])
    ans = 0
    for r in range(K, N+2):
        min_val = e_cumsum[r]
        max_val = e_cumsum[N+1] - e_cumsum[N+1-r]
        ans += (max_val - min_val + 1) % mod
    return ans % mod


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)

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)

'''
n, k = map(int, input().split())
ans = 0
for i in range(k, n+2):
    a = 0.5*i*(i-1)
    b = 0.5*n*(n+1)-0.5*(n-i)*(n-i+1)
    ans += int(b-a+1)

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

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

m = n + 1
l = k - 1

ans = m * (m**2 + 5) // 6
ans += l * (2 * l**2 + 3 * l - 5 - 3 * m * (l + 1)) // 6
ans = ans % (10**9 + 7)

print(ans)

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

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


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

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)

Solution (Python):



line= list(map(int,input().split()))
N = line[0]
K = line[1]


answer = 0
for i in range (K,N+2):
    minit = i*(i-1)/2
    maximum = (2*N-i+1)*i/2
    
    num = maximum-minit+1
    answer += num

if answer >(10**9+7):
    print(int(answer%(10**9+7)))
    
else:
    print(int(answer))