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

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

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


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


if __name__ == '__main__':
    main()

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

Solution (Python):







a, b = map(int, input().split())

if a+1 == b:
    print(1)
else:
    res_count_list = []

    min_before = 0
    max_before = 0
    for i in range(b, a+2):
        if min_before == 0 and max_before == 0:
            min_before = sum(range(i))
            max_before = sum(range(a, a-i, -1))
        else:
            min_before = min_before + i - 1
            max_before = max_before + a - i + 1
        
        
        
        res_count_list.append(max_before - min_before + 1)

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

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

resolve()

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

Solution (Python):
N,K=map(int, input().split())
ans=0
mod=10**9+7
for i in range(K,N+2):
    if i==K:
        MIN=sum(list(range(0,K)))%mod
        MAX=sum(list(range(N,N-K,-1)))%mod
    else:
        MIN+=(i-1)%mod
        MAX+=(N+1-i)%mod
    ans+=(MAX-MIN+1)%mod
    ans%=mod

print(ans)

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

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

print(ans)

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

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

print(ans)

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

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


def main():
    N, K = (int(i) for i in input().split())
    ans = 0
    for i in range(K, N+2):
        lower = (i-1)*i//2
        upper = N*(N+1)//2 - (N-i)*(N-i+1)//2
        ans += upper - lower + 1
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

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

DIVIDER = 1000000007

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

ans = 0
for cnt in range(K, N + 2):
    val_min = (tab_sum[cnt] - tab_sum[0]) % DIVIDER
    val_max = (tab_sum[-1] - tab_sum[-1 - cnt]) % DIVIDER
    
    ans = (ans + (val_max - val_min + 1)) % DIVIDER

print(ans)

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

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

print (ans)

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


def main():
    n, k = map(int, input().split())
    answer = 0
    mod = 10 ** 9 + 7
    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=map(int,input().split())
mod=10**9+7
ans=0
for kk in range(k,n+2):
  mi=kk*(kk-1)//2
  ma=n*(n+1)//2-(n-kk)*(n-kk+1)//2
  ans+=ma-mi+1
  ans%=mod
print(ans)

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

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

print(ans)

Solution (Python):
import sys
mod = 7 + 10 ** 9

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    ans = 0
    for k in range(K, N + 2):
        minS = (k - 1) * k // 2
        maxS = (N - k + 1 + N) * k // 2
        ans += (maxS - minS + 1)
        ans %= mod

    print(ans) 

    return 0

if __name__ == "__main__":
    solve()

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

count_sum = 1

for k in range(K,N+1):
    count_sum += k*(N-k+1)+1
    
print(int((count_sum)%(1e9 + 7)))

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

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

ans = 0

for i in range(k, n + 2):
    mn = i * (i - 1) // 2
    mx = (n * 2 - i + 1) * i // 2
    ans += mx - mn + 1
    ans = 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):
    
    maxim = (n + n - i + 1) * i // 2
    minim = (i - 1) * i // 2
    ans += (maxim - minim + 1)
    
ans %= MOD
print(ans)

Solution (Python):

from sys import stdin

MOD = int(1e9 + 7)


def solve(tc):
    n, k = map(int, stdin.readline().split())

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

        ans += hi-lo+1
        ans %= MOD
    print(ans)


tcs = 1
LOCAL_TEST = not __debug__
if LOCAL_TEST:
    infile = __file__.split('.')[0] + "-test.in"
    stdin = open(infile, 'r')
    tcs = int(stdin.readline().strip())

tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1

Solution (Python):


from functools import reduce
from operator import add
import sys


def main():
    N, K = map(int, input().split(' '))
    sys.setrecursionlimit(N + 50)

    C = 1
    for i in range(K, N + 1):
        C += (N * (N + 1) // 2 - (N - i) * (N - i + 1) // 2) \
            - ((i * (i - 1)) // 2) \
            + 1
    print(C % 1000000007)


if __name__ == '__main__':
    main()

Solution (Python):
n,k=map(int,input().strip().split())
ans=0
while(k<=n):
    max=(n+n-k+1)*k//2
    min=(0+k-1)*k//2
    ans=ans+max-min+1
    k=k+1
ans=(ans+1)%1000000007
print(ans)

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

print(s% 1000000007)

Solution (Python):
import math

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


mod = 10 ** 9 + 7

ans = 0
min_v = sum(ary[0:(k - 1)])
max_v = sum(ary[(n + 1 - (k - 1)):])

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

print(ans)

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

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

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

n, k = [int(x) for x in input().split()]
a = [int(x) for x in range(n + 1)]
a_rev = a[::-1]
mod = 10**9 + 7

left = sum(a[:k])
right = sum(a_rev[:k])

ans = right - left + 1

for i in range(k, n + 2):
    if i > n:
        break
    left += a[i]
    right += a_rev[i]
    ans += right - left + 1
    ans %= mod

print(ans)

Solution (Python):
def rangesum(n, k):
    return k * n + (k - 1) * k // 2

def calc(N, K):
    x = 0
    for i in range(K, N + 2):
        x += rangesum(N + 1 - i, i) - rangesum(0, i) + 1
    return x % (10 ** 9 + 7)


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

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

input = sys.stdin.readline


def solve():
    N, K = map(int, input().split())
    answer = 0
    for k in range(K, N + 2):
        answer += k * (N - k + 1) + 1
    return answer % (10 ** 9 + 7)


if __name__ == '__main__':
    answer = solve()
    print(answer)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]




n,k=mii()

arr = [i for i in range(0,n+1)]
lenarr = len(arr)

S = [0]
for i in range(0, lenarr):
    S.append(S[i] + arr[i])

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

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

Solution (Python):
def input_1line_number():
    return map(int, input().split())

def sum_of_equal_number_sequence(first_term, difference, number_of_terms):
    return (2*first_term + (number_of_terms-1)*difference) * number_of_terms // 2

def mod_number():
    return 10**9+7

def main():
    n, k = input_1line_number()

    answer = 0

    for i in range(k, n+2):
        number_of_fractions = sum_of_equal_number_sequence(n-i+1, 1, i) - sum_of_equal_number_sequence(0, 1, i) + 1
        answer += number_of_fractions

    answer %= mod_number()

    print(answer)

if __name__ == "__main__":
    main()

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

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

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

for i in range(K,N+1):
    s+= (tousa(N-i+1, N) - tousa(0, i-1) + 1)

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

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

Ans = [0]*(N+2)
Sum_Ans = 0

def solution(N,K,Ans,Sum_Ans):
    for i in range(K,N+2):
        
        
        Ans[i] = i*(N - i + 1) + 1
        
        Sum_Ans += Ans[i]
    
    print(Sum_Ans%(10**9 + 7))

solution(N,K,Ans,Sum_Ans)

Solution (Python):
def main():
    import sys
    import itertools

    input = sys.stdin.readline

    n, k = map(int, input().split())
    l = list(range(0, n + 1))
    l_1 = list(itertools.accumulate(l))
    ans = 0
    for i in range(k, n + 2):
        if i == n + 1:
            ans += 1
        else:
            mini = l_1[i - 1]
            maxi = l_1[-1] - l_1[-i - 1]
            ans += (maxi - mini + 1)
    print(ans % (10 ** 9 + 7))

if __name__ == "__main__":
    main()

Solution (Python):



DATA = """
141421 35623
""".split("\n")

def get_debug_line():
	for i in DATA:
		yield i

if 1:
	get_line = input
else:
	get_line = get_debug_line().__next__
	get_line()

MOD = 10**9 + 7

N, M = [int(i) for i in get_line().strip().split(" ")]

minV = (0 + M-1) * M // 2
maxV = (N-M+1 + N) * M // 2


count = 0
for i in range(M, N+2):
    count += (maxV - minV + 1)
    
    minV += i
    maxV += (N-i)
print (count%MOD)

Solution (Python):

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



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

	
	
	
	
	
	

	iResult = iResult + i * (n - i + 1) + 1

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

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

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

if __name__ == '__main__':
    solve()

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

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

mod = 10**9+7
ans = 0

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

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

ans = 0
min_x, max_x = 0, 0
for i in range(N+1):
    min_x += i
    max_x += N-i
    if i+1 < K: continue
    ans += max_x - min_x + 1
    ans %= mod

print(ans)

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

n_min = sum([i for i in range(0, k-1)])
n_max = sum([n - i for i in range(0, k-1)])

for i in range(k-1, n+1):
  n_min += i
  n_max += n - i
  ans += n_max - n_min + 1
    
print(ans % mod)

Solution (Python):
import sys
import itertools
flatten = itertools.chain.from_iterable
input = sys.stdin.readline


def inp():
    return int(input())


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


N, K = inpl()

ss = list(range(0, N + 3))
for i in range(1, N + 3):
    ss[i] += ss[i - 1]

mod = 10**9 + 7

ans = 0
for k in range(K, N + 2):
    L = ss[k]
    R = ss[N + 1] - ss[N + 1 - k]
    ans += (R - L + 1)
    ans %= mod

print(ans)

Solution (Python):
if __name__ == '__main__':
	N, K = map(int, input().split())
	ans = 0
	P = 10**9 + 7
	for k in range(K,N+2):
		minimum = k * (k-1) // 2
		maximum = (2*N - k + 1) * k / 2
		v = maximum - minimum + 1
		ans += v%P

	print(int(ans%P))

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

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

res = 0

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

res = res % mod

print(res)

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


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


def sum_arithmetic_seq(a, d, n):
    ans = n*(2*a+(n-1)*d)//2
    return ans


n, k = map(int, input().split())
ans = 0
for i in range(k, n+2):
    tmp = sum_arithmetic_seq(n-i+1,1,i) - sum_arithmetic_seq(0,1,i) + 1
    ans += tmp % NUM
print(ans % NUM)

Solution (Python):
if __name__ == "__main__":
    
    
    N, K = map(int, input().split(" "))

    total_num = 0
    for k in range(K, N+2):
        
        sum_max = int(k*(2*N - k + 1) / 2)
        
        sum_min = int(k*(k-1) / 2)
        
        total_num += sum_max - sum_min + 1
        total_num %= 1000000007
    
    print(total_num)

Solution (Python):


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

ans = 0
for i in range(k, n+2):
    mini = (0+(i-1))*i/2
    maxi = ((n)+(n-i+1))*i/2
    ans += maxi-mini+1
    
print(int(ans%z))

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

res = 0

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

  mini = int(k*(k-1)/2)
  maxi = int(k*(2*N-k+1)/2)

    
  res = (res + (maxi-mini+1)) % (10**9+7)

  
print(res)

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

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

ans=0

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

print(ans)

Solution (Python):

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

l = range(n+1)

c = 0

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

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

Solution (Python):
import math
n, k = map(int, input().split())
mod = 1000000007
m = math.ceil((n+1)/2)

def makeTable(n):
    fac = [n+1]
    
    for i in range(1, m):
        fac.append(fac[i-1]+(n-i)-i)
    return fac

def answer(fac):
    ans = 0
    for i in range(k-1, n):
        if (i < m):
            ans = ans + fac[i]
        else:
            ans = ans + fac[n-1-i]
    ans = ans + 1
    return ans

fac = makeTable(n)
print(answer(fac) % mod)

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

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

def calc_ans(AR,i):
	max = AR*(AR-1)/2 - (AR-i)*(AR-i-1)/2
	min = i*(i-1)/2
	return max - min +1

for i in range(k, AR+1):
	ans += calc_ans(AR,i)

print(int(ans % mod))

Solution (Python):
import sys
read = sys.stdin.readline
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 10 ** 9 + 7

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

k = np.arange(K, N + 2, dtype=np.int64)
low = (k - 1) * k // 2
high = N * k - low
cnt = high - low + 1
print(cnt.sum() % MOD)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 10 ** 9 + 7

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

k = np.arange(K, N + 2, dtype=np.int64)
low = (k - 1) * k // 2
high = N * k - low
cnt = high - low + 1
print(cnt.sum() % MOD)

Solution (Python):

import numpy as np

n, k = map(int, input().split())
MOD = int(1e9+7)
rem = (10*100)%MOD 
ans = 0 

for i in range(k, n+2):
    if i == k:
        minimum = np.arange(i).sum()
        maximum = np.arange(n, n-i, -1).sum()
    else:
        minimum += i-1 
        maximum += n-i+1
    ans += (maximum-minimum+1)%MOD

print(ans%MOD)

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

Solution (Python):
N = [int(e) for e in input().split()]
nums = []
u = 10**9 + 7
t = 0
s = 0
Min =0
Max =0
for i in range(0,N[1]):
    Min += i
    t = i+1
    Max += N[0] - i
    s = N[0] - i -1
ans = Max - Min + 1
for k in range(N[1]+1,N[0]+2):
    Min += t
    t += 1
    Max += s
    s -= 1
    ans += Max - Min + 1
print(ans%u)

Solution (Python):
import math

def fac(x):
    if x<=1:
        return 1
    s=1
    for i in range(1,x+1):
        s=s*i
    return s
def com(m,n):
    return fac(m)/(fac(n)*fac(m-n))


temps=input().split()
n=int(temps[0])
m=int(temps[1])
sum=0
for i in range(m,n+2):
    min=int((i-1)*i/2)
    max=int((2*n-i+1)*i/2)
    sum=sum+max-min+1
print(int(sum%(math.pow(10,9)+7)))

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

total = 0
for i in range(K, N + 2):
  maximum = (N - i + 1 + N) * i / 2
  minimum = (i - 1) * i / 2
  count = maximum - minimum + 1
  total += (count % mod)
  
print(int(total % mod))

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

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

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

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

print(ans)

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

mod = 10**9+7 

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

print(int(res%mod))

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

mod = 10**9+7 

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

print(int(res%mod))

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

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

    wa=max-min+wa+1


wa=wa+1
wa=wa%(10**9+7)
print(int(wa))

Solution (Python):
a, b = map(int, input().split())
mod = pow(10,9) + 7

def cal(a,i):
  min = i*(i-1)/2
  max = a*(a-1)/2 - (a-i)*(a-i-1)/2
  return max - min + 1

count = 0
for i in range(a-b+2):
  count += cal(a+1,i+b)
print(int(count % mod))

Solution (Python):


import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, k = na()
    ans = 0
    for s in range(k, n+2):
        mmin = (0+s-1)*s//2
        mmax = (n-s+1+n)*s//2
        ans += mmax - mmin + 1
        
    print(ans%(10**9+7))

if __name__ == "__main__":
    main()

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

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

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

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

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

Solution (Python):

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






N = N+1


def minmax(N,K):
    
    
    return (N-K)*K+1


Ans = 0
for i in range(K,N+1):
    Ans = Ans + minmax(N,i)


mod = 1000000007
Ans = Ans % mod

print(Ans)

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

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

print(cnt)

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

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


print(result%1000000007)

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

print(ans)

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

print(ans)

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

Solution (Python):
import numpy as np

n, k = map(int, input().split())
MOD = 10 ** 9 + 7
ref = np.array(list(range(n + 1)), dtype='int64')

max_sum = np.sum(ref[-k + 1:])
min_sum = np.sum(ref[:k - 1])
if k == 1:
    max_sum = min_sum = 0
ans = 0

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

print(ans)

Solution (Python):
import numpy as np

n, k = map(int, input().split())
MOD = 10 ** 9 + 7
ref = np.array(list(range(n + 1)), dtype='int64')

ans = 0

for i in range(k, n + 2):
    min_sum = (ref[i - 1] * (ref[i - 1] + 1)) // 2
    max_sum = (n + ref[-i]) * (n - ref[-i] + 1) // 2
    ans += max_sum - min_sum + 1
    ans %= MOD

print(ans)

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

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

Solution (Python):
MOD = 10**9 + 7
def solve(n, k):
    v = list(range(n+1))
    l = [0] * (n+1)
    u = [0] * (n+1)
    u[0] = n
    for i in range(1, n+1):
        l[i] = l[i-1] + v[i]
    for i in range(1, n+1):
        u[i] = u[i-1] + v[n-i]
    return sum((u[i] - l[i] + 1)for i in range(k-1, n+1)) % MOD

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
    sum_min = ((0 + k - 1) * k) / 2

    
    
    total += int(sum_max - sum_min + 1)

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

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

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

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

print(ans)

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

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

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

Solution (Python):
def i1str():
    return input()


def istrs(n=None):
    if n is None:
        return input().split()
    a = []
    for _ in range(n):
        a.append(istrs())
    return a


def i1num():
    return int(input())


def inums(n=None):
    if n is None:
        return list(map(int, input().split()))
    a = []
    for _ in range(n):
        a.append(inums())
    return a


def ostrs(l, sp=" "):
    print(sp.join(l))


def onums(l, sp=" "):
    print(sp.join(map(str, l)))


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


if __name__ == "__main__":
    n, k = inums()
    print(solve(n, k))

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




MOD = int(10 ** 9 + 7)

la = list(range(N + 1))

def counter(k):
    
    
    
    

    
    
    

    
    
    
    ft = (k - 1) * k // 2
    fl = (N + 1) * N // 2 - (N - k + 1) * (N - k) // 2

    
    
    return fl - ft + 1

count = 0
for k in range(K, N + 2):
    ans_k = counter(k)
    count = (count + ans_k) % MOD
print(count)

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

Solution (Python):
n,k = map(int,input().split())
from itertools import accumulate
a = [i for i in range(n+1)]
b = [i for i in reversed(range(n+1))]

ac_a = list(accumulate(a))
ac_b = list(accumulate(b))
ans = 0

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

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

Solution (Python):
import time
startTimeProblem=time.time()

import fileinput, sys, itertools, functools

import math
from bisect import *
from heapq import *
from collections import *

def lcm(a, b):  
    return (a*b)/gcd(a, b)

class InputHelper:
    def __init__(self):
        self.myinput = fileinput.input()

    def isLocal(self):
        return not fileinput.isstdin()

    def int(self):
        return int(self.myinput.readline().rstrip())

    def ints(self):
        return [int(_) for _ in self.myinput.readline().rstrip().split()]

    def str(self):
        return self.myinput.readline().rstrip()

    def strs(self):
        return [_ for _ in self.myinput.readline().rstrip().split()]

class OutputHelper:
    def int(self, a):
        print(a)    

    def ints(self, a):  
        print(" ".join([str(_) for _ in a]))
    
    def intsNL(self, a):
        for _ in a:
            print(_)
    
    def str(self, s):
        print(s)

    def strs(self, s):
        print(" ".join([_ for _ in s]))

    def strsNL(self, s):
        for st in s:
            print(st)

class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None

In = InputHelper()
Out = OutputHelper()



N, K = In.ints()
MOD = 10**9+7

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

Out.int(ans)



if len(sys.argv)>2 and sys.argv[2]=="TIMEIT":
    fin = (time.time()-startTimeProblem)*1000
    print("{:.2f}".format(fin) + "ms")

Solution (Python):
import math

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

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

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

print(ans)