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 = list(map(int,input().split()))

counter = 0

for i in range(K, N + 2):
    S = (i ** 2 - i) / 2
    B = N * i - S
    counter += B - S + 1
    
print(int(counter) % (1000000000 + 7))

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

result = 0
x_n = n*(n+1)//2

for i in range(k, n+1):
    x_min = (i-1)*i//2
    x_max = x_n - (n-i)*(n-i+1)//2
    result += (x_max - x_min + 1)
    
result += 1
print(result%(10**9+7))

Solution (Python):
import numpy as np
N, M = map(int, input().split())
A = np.asarray(range(N+1), dtype=np.int64)
MOD = 10**9+7
S, E = (N/2) * (N+1), (N/2) * (N+1)
result = 1
for i, j in zip(range(N - M + 1), range(N, -1, -1)):
    S = S - i
    E = E - j
    
    result += (S - E + 1) % MOD
    result %= MOD
    
print(int(result))

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

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

S=0
for i in range(k,n+1):
    S+=l1[n]-l1[n-i]-(l1[i-1]-1)
S+=1

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

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


input = sys.stdin.buffer.readline
INF = 2**62-1

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


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Combination:
    def __init__(self, n, mod):

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

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n-r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.MOD



@mt
def slv(N, K):
    ans = 0
    M = 10**9 + 7
    for i in range(K, N+2):
        a = i*(i-1)//2 - 1
        b = i*(2*(N-i+1) + i-1) // 2
        ans += b - a
        ans %= M
    return ans


def main():
    N, K = read_int_n()
    print(slv(N, K))


if __name__ == '__main__':
    main()

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

for i in range(K,N+1):
    s = (N*i- i*(i-1) + 1)
    cnt += s%p
    cnt %= p
print((cnt+1)%p)

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

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

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

N, K = map(int, input().split())
A = [i for i in range(N+1)]
S = [0]*(N+2)
for i in range(1,N+2):
    S[i] = S[i-1] + A[i-1]
C = [0 for i in range(N+1)]
for i in range(N+1): 
    mx = S[N+1] - S[N-i]
    mi = S[i+1] - S[0]
    
    C[i] = mx - mi +1

ans = 0
for i in range(K-1, N+1):
    ans += C[i]
    ans %= MOD
print(ans)

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

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

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

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

counter = 0

for i in range(N + 1, K - 1, -1):
  
  m = (i * (2 * N - (i - 1)) - (i - 1) * i) / 2 + 1
  counter += int(m)

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

Solution (Python):
N,K = map(int, input().split())
mod = 10**9+7
ans = (((2*K-1)*(K-1)%mod*K%mod - (2*N+3)*(N+2)%mod*(N+1)%mod \
     + 3*(N+1)*(N+1)%mod*(N+2)%mod - 3*(N+1)*K%mod*(K-1)%mod)*pow(6,mod-2,mod) \
     + (N-K+2))%mod




print(int(ans))

Solution (Python):
n,k  = map(int,input().split())
cnt = 0
m = 10**9+7
a = [o for o in range(n+1)]
b = sorted(a,reverse = True)
for i in range(k,n+2):
    t = int((n*(n+1))/2-((i-1)*i)/2+1)
    if i < n:
        t -= int(((n-i)*(n-i+1))/2)
    cnt += t
print(cnt%m)

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

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

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


def main():
    n, k = map(int, input().split())
    sum_all = 0
    for i in range(k, n+2):
        
        
        
        sum_all += (n+1-i)*i+1
        sum_min = 0
        sum_max = 0

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


if __name__ == '__main__':
    main()

Solution (Python):
N, K = list(map(int, input().strip().split()))
M = 10**9 + 7
l = list(range(N+1))
l2 = [0]
for i in range(1, N+1):
  l2.append(l2[i-1] + l[i])

ans = 0
for i in range(K, N+1):
  
  minimum = l2[i-1]
  
  maximum = l2[-1] - l2[N-i]
  n = maximum - minimum + 1
  
  
  
  ans += n
ans += 1
print(ans % M)

Solution (Python):
N, K = [int(INPUT) for INPUT in input().strip().split(' ')]

total_num = 0

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

print(int(total_num % (1e9+7)))

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



N,K = LI()

min_ = 0
for i in range(K):
    min_ += i

max_ = 0
for i in range(K):
    max_ += N-i

ans = max_-min_+1
last_max = max_
for i in range(K+1,N+2):
    min_ += i-1
    max_ += N-i+1
    ans += max_-min_+1
    ans %= mod

print(ans)

Solution (Python):
LL = 10**9+7
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)

print(ans%LL)

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

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

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

left = 0
right = 0
A = []
for k in range(0, N+1):
    left += k
    right += N - k
    A.append((right - left + 1) % (10 ** 9 + 7))


print(sum(A[K-1:]) % (10 ** 9 + 7))

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

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

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

Solution (Python):

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

for i in range(k,n+2):
    mini = 0.5 * i * (i - 1)
    maxi = 0.5 * n * (n + 1) - 0.5 * (n - i) * (n - i + 1)
    dif = maxi - mini + 1
    count += dif

count = count % (10 ** 9 + 7)
print("{}".format(int(count)))

Solution (Python):
from collections import defaultdict

n, m = list(map(int, input().split()))

def func(x):
    res = 0
    res += -1/6 * x * (x + 1)* (2*x + 1)+ (n + 1) * 1/2 * x * (x + 1) + x
    return int(res)

print(int((func(n + 1) - func(m - 1)) % (10 ** 9 + 7)))

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

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

ans += end - begin + 1

for i in range(k + 1, n + 2):
    begin += a
    end += b
    a += 1
    b -= 1
    ans += end - begin + 1

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

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

Solution (Python):
import numpy as np

MOD = 10**9 + 7

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

n = N+1
ans = 0
a = np.arange(n)
l = np.cumsum(a)
r = np.cumsum(a[::-1])[::-1]
l %= MOD
r %= MOD
for i in range(k, n+1):
    ans += r[-i] - l[i-1] +1
    ans %= MOD
print(ans)

Solution (Python):
import math


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


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


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

ans = 0
M = N + 1 - K

MOD = 10**9+7

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


print(ans % MOD)

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

Solution (Python):
N,K =map(int,input().split())
def tasu(n,m):
    return((n-m+1)*m+m*(m+1)/2)

answer = 0
for i in range(K,N+2):
    maxsum = tasu(N,i)
    minsum = tasu(i-1,i)
    answer += maxsum-minsum+1
    answer = answer%(10**9+7)
print(int(answer))

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

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

print(ans)

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

S=[0]*(N+1)
for i in range(1,N+1):
    S[i]=S[i-1]+A[i]

for k in range(K,N+1):
    MIN=S[k-1]
    MAX=S[N]-S[N-k]
    ans+=(MAX-MIN+1)%mod
    ans%=mod
print(ans+1)

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

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
n,k = iim()
ans = 0
mod = 1000000007
for i in range(k,n+2):
    ans += n*(n+1)//2 - i*(i-1)//2 - (n-i)*(n-i+1)//2 + 1
    ans = ans%mod

print(ans)

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


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

print(sum % (1000000000 + 7))

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

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

Solution (Python):


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

ans = 0
buttom = 0
for i in range(k):
    buttom += n - i

top = 0
for i in range(k):
    top += i

_max = 0
for i in range(n+1):
    _max += n - i

_MOD = 10**9+7

for i in range(k, n+1+1):
    ans += buttom - top + 1
    buttom = min(_max, buttom+n-i)
    top += i
    ans = ans % _MOD

print(ans)

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

Solution (Python):
def f(i,j):
    return max(0, j*(i-j)+1)

jon = 10**9+7
N, K = [int(i) for i in input().split()]

i = N + 1
print(sum(f(i,j) for j in range(N+2-K)) % jon)

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

Solution (Python):
import math

n,k = (int(x) for x in input().split())
ans = 0
a = n*(k-1)
b = (k-1)*(k-2)//2

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

Solution (Python):
a = list(map(int,input().split()))
ans=0
min=0
max=0
for i in range(a[1]):
    min +=i
    max +=a[0]-i
    minx=i-1
    maxx=a[0]-i-1
ans=max-min+1
for i in range(a[1]+1,a[0]+2):
    minx +=1
    min += minx
    maxx += -1
    max +=maxx
    ans=(ans+max-min+1)%(10**9+7)
print(ans)

Solution (Python):
n, k = map(int, input().split())
ans=0
while k <= n+1:
  ans += k*(n-k+1)+1
  k+=1
print(ans%(10**9+7))

Solution (Python):


import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, k = map(int, sys.stdin.readline().split())
    if k > n:
        print(1)
    else:
        ans = 0
        for i in range(k, n+2):
            i = i - 1
            l = ((i * (i + 1)) // 2)%mod
            r = ((n*(n+1))//2 - ((n-i)*(n-i-1))//2) % mod
            ans += ((r-l)+1) % mod
        print(ans % mod)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()

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

MOD = 10 ** 9 + 7

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

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

print(ans)

Solution (Python):
def summ(n, nn=0):
  nn = max(nn, 0)
  return n*(n+1)/2 - nn*(nn+1)/2

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

a = 1
for i in range(k, n + 1):
  mmin = summ(i - 1)
  mmax = summ(n, n - i)
  m = mmax - mmin + 1
  a += m

k = 10**9 + 7
print(int(a%k))

Solution (Python):
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N, K = rl()

import itertools

def f(n, k):
    return k*(n-k) + 1

N += 1
ans = 0
for k in range(K, N+1):
    ans = (ans + f(N, k)) % mod
print(ans)

Solution (Python):


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


def check(n,k):
    sum_min = (k-1)*k/2
    sum_max = n*(n+1)/2 - (n-k)*(n-k+1)/2
    
    sum_pattern = sum_max - sum_min + 1
    return sum_pattern


cnt = 0
for i in range(K,N+1):
    c = check(N,i)
    cnt = (cnt + c) % (10**9+7)
    
print(int(cnt+1))

Solution (Python):

def solve():
    
    
    total_comb = 0
    for i in range(k, n+2):
        total_comb = (total_comb + i * (n - i + 1) + 1) % (10**9 + 7)
    print(total_comb)
    return



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

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

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

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

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

Solution (Python):

"""
@author: H_Hoshigi
"""
def f(N, k):
    return  -(k*(k+1)*(2*k+1))//6 + (N+1) * (k*(k+1))//2 + k
def main():
    N, K = map(int, input().split())
    
    
    
    
    counter = f(N, N+1) - f(N, K-1)
    print(counter%(1000000007))

if __name__ == "__main__":
    main()

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

def cumsum(s):
    n = len(s)
    cs = [0] * (n+1)
    for i in range(n):
        cs[i+1] = cs[i] + s[i]
    return cs

s = list(range(n))
cs = cumsum(s)
ans = 0

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

print(ans)

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


if k==n+1:
  print(1)
  exit(0)

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

count=0
for i in range(k,n+2):
  if n-i<0:
    we=l[-1]-l[i-1]+1
  else:
    we=l[-1]-l[i-1]-l[n-i]+1
  count+=we
  
print(count%(10**9+7))

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

count = 0

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

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

Solution (Python):
N, K = map(int, input().split())
l = []
cmin = 0
cmax = 0
for i in range(K, N+2):
  cmin = 0
  cmax = 0
  cmin = i * (i-1) / 2
  cmax = (2*N - i + 1) * i / 2
  dif = cmax - cmin + 1
  l.append(dif)
print(int(sum(l)%(10**9 + 7)))

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

mod=10**9+7

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

  sigma1=(i-1)*i//2
  sigma2=(n-i)*(n-i+1)//2
  sigma3=n*(n+1)//2


  ans+=sigma3-sigma2-sigma1+1
  ans%=mod
print(ans)

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

tmp = sum(range(k-1))

ans = 0
for x in range(k, n+2):
  ans += x*n + 1
  if x >= 2:
      tmp += x-1
      ans -= 2*tmp
  ans %= mod

print(ans)

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

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

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

r = 1

for i in range(K, N+1):
	up = S[N]-S[N-i]
	low = S[i-1]
	r = (r+(up-low+1))%mod

print(r)

Solution (Python):
from math import factorial

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

ans=0
i=K
while i<=N+1:

    mni=i*(i+1)//2
    mxi=i*(2*N-i+3)//2
    ans+=mxi-mni+1
    i+=1

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

Solution (Python):
n , k = input().split()
n = int(n)
k = int(k)
lmin = list(range(0, k - 1))
lmax = list(range(n - k + 2, n + 1))
min = sum(lmin)
max = sum(lmax)

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

print(int(ans % (1e9 + 7)))

Solution (Python):
N, K = map(int, input().split())
R = range(K, N + 2)
A = []
for i in R:
    s_max = (N + (N - i + 1)) * i / 2
    s_min = (i - 1) * i / 2
    n = s_max - s_min + 1
    A.append(n)
S = int(sum(A))
print(S % (10 ** 9 + 7))

Solution (Python):

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


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

print(answer % mod)

Solution (Python):
from itertools import accumulate
import sys

mod = 10 ** 9 + 7

N, K = map(int, sys.stdin.readline().rstrip().split())
if K == N + 1:
    print(1)
    sys.exit()

l = list(accumulate(range(N + 1)))

ans = 0
for k in range(K, N + 2):
    if k == N + 1:
        ans += 1
    else:
        ans += k * N - (2 * l[k-1]) + 1

if ans >= mod:
    print(ans % mod)
else:
    print(ans)

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

s_rev = [0] * (N + 2)
for i in range(N, -1, -1):
    s_rev[N - i + 1] = s_rev[N - i] + i

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

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

print(ans%1000000007)

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

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

c = []
for i in range(K, N+2, 1):
  minimum = 1 / 2 * (i - 1) * i
  maximum = 1 / 2 * N * (N + 1) - 1 / 2 * (N - i) * (N - i + 1)
  c.append(int(maximum - minimum + 1))
else:
  answer = 0
  for i in c:
  	answer += i
  else:
  	print(answer % (10 ** 9 + 7))

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

Solution (Python):
import sys
p = 1000000007
N,K = map(int,input().split())
su = 0
if N < K:
    print(1)
    sys.exit()
for i in range(K,N+2):
    su += (i + (N-i)*i+1)
  
  
print(su%p)

Solution (Python):
N,K=map(int,input().split())
mod=pow(10,9)+7
numbers=[a for a in range(0,N+1)]
z=sorted(numbers,reverse=True)
NN=[]
b=0
for a in numbers:
    b+=a
    NN.append(b)
c=0
SS=[]
for a in z:
    c+=a
    SS.append(c)
if N+1==K:
    print(1)
else:
    answer=1
    for a in range(K,N+1):
        kotae=SS[a-1]-NN[a-1]+1
        answer+=kotae
        answer=answer%mod
    print(answer%mod)

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

mod = 10**9+7

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

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

    res = (res+ma-mi+1)%mod

print(res)

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

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())
mod = 10 ** 9 + 7
premin = 0
premax = 0
ans = 0
list = [i for i in range(n + 1)]
for x in range(n + 1):
    premin += list[x]
    premax += list[n - x]
    if x < k - 1: continue
    ans += (premax - premin + 1)
    if ans >= mod: ans %= mod
print(ans)

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

        ans += (x - y + 1)%MOD
        ans %= MOD
        x += n - i
        x %= MOD
        y += i
        y %= MOD

    print(ans)

if __name__ == "__main__":
    main()

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

Solution (Python):
def nA(n, k):
    minimum = n*(n-1)//2
    maximum = n*k - minimum
    res = maximum-minimum+1

    return n*k - n*(n-1) + 1
    
    


NK = input().split()
N = int(NK[0])
K = int(NK[1])


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

res = res % 1000000007

print(res)

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

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

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

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

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

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

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

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
N,K = map(int,input().split(' '))
u = 10**9+7

M = (N+1)*N//2

LIMIT = 0
ANS = 0



for i in range(K,N+2):
    m_LIMIT = (0+(i-1))*i//2
    M_LIMIT = (N+(N-(i-1)))*i//2
    ANS += (M_LIMIT-m_LIMIT)+1
    ANS %= u
print(ANS)

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

def sm(mn :int, mx :int) -> int:
    n = mx - (mn - 1)
    return int((mx + mn) * (n / 2))

cnt = 0
for i in range(k, n+2):
    mn, mx = sm(0, i-1), sm(n-(i-1), n)
    cnt += mx - (mn-1)
    cnt = cnt % BASE
print(cnt)

Solution (Python):
n, k = map(int, input().split())
mod = 10 ** 9 + 7
ans = [None] * (n - k + 2)
ans[0] = ((n - k + 1 + n) * k // 2) - ((0 + k - 1) * k // 2) + 1

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

print(sum(ans) % mod)

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

DP=[0]*(n+2)
DP[0]=1
point=n
n=n+1

for i in range(1,n+1):
    DP[i]=DP[i-1]+point
    point -=2
print(sum(DP[k:])%mod)

Solution (Python):

mod = pow(10, 9)+7
N, K = map(int, input().split())
sum = 0
for i in range(K, N+2):
    sum = sum+i*(2*N+1-i)/2.0 - 1/2.0*i*(i-1)+1
    sum = sum % mod

print(int(sum))

Solution (Python):
import itertools

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

MOD = 1000000007

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

print(int(ans)%MOD)

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

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

ans=0

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

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

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

M = 10**9 + 7

cnt = 1

a = 0
b = N
c = 0

for i in range(N - K + 1):
    cnt += b - a + 1
    c += 1
    a += c
    b += N - c


print(cnt % M)

Solution (Python):
MOD = 10**9 + 7
N, K = [int(s) for s in input().split()]
cnt = 0
for i in range(K, N + 2):
    if i != N + 1:
        cnt += i * ((N + 1) - i) + 1
    else:
        cnt += 1
    cnt %= MOD

print(cnt)

Solution (Python):


from pprint import pprint
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline

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




b_list = range(N + 1)

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

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

Solution (Python):
import numpy as np

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

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

print(int(int(sum)%(1e9+7)))

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

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

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

lst = [i for i in range(N+1)]
lst1 = lst[::-1]

ans = 0
mod = 10**9+7
tmp = sum(lst[:K-1])
tmp1 = sum(lst1[:K-1])

for i in range(K-1, N+1):
    tmp += lst[i]
    tmp1 += lst1[i]
    ans += (tmp1-tmp+1)
print(ans%mod)

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

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

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

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

Solution (Python):
from scipy.special import comb

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

'''
n += 1
an = comb(n, k, exact=True)
ans = an
for i in range(k,n):
    an=an*(n-i)//(i+1)
    ans += an
    ans %= (10**9+7)

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

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

Solution (Python):
from math import factorial

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

N += 1

ans = 0
head = sum(range(K-1))
tail = sum(range(N-K+1,N))

for i in range(K,N+1):
    head+=i-1
    tail+=N-i
    ans += tail - head +1

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

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



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

print(ans%mod)

Solution (Python):
import math
mod = 10**9 +7
def cmb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N,K = map(int,input().split())
f = cmb(N+1,K)
mi = K*(K-1)//2
ma = K*(2*N-K+1)//2
s = 0
while N -K +2> 0:
    mi = K*(K-1)//2
    ma = K*(2*N-K+1)//2
    s += ma - mi +1
    K +=1
print(s%mod)

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

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

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

mod = 10 ** 9 + 7
ans = 0

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

    first = (n * (n + 1) // 2) % mod
    second = ((n - i) * (n - i + 1) // 2) % mod
    n_max = (first - second) % mod

    add = (n_max - n_min + 1) % mod
    ans = (ans + add) % mod

print(ans)

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

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

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

Solution (Python):
n,k = (int(x) for x in input().split())
M = 10**9+7
s = 0

for i in range(n+2-k):
    ad = 1 + (n+1-k-i)*(k+i)
    s += ad


        
print(s%M)