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):
import sys
import math
import copy
import heapq
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(1000000)


input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  
    fac = [0] * SIZE  
    finv = [0] * SIZE  
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    
    
    
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    
    return X.flatten().tolist()[0]

class TwoDimGrid:
    
    def __init__(self, h, w, wall="
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        
        
        
        
        

def solve():
    n, k = getList()
    rui = [0]
    for i in range(n+1):
        rui.append(rui[-1] + i)
    ans = 0
    
    for i in range(k, n+2):
        ans += rui[n+1] - rui[n+1-i] - rui[i] + 1
        
        ans %= MOD
    print(ans)
def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    
    solve()

Solution (Python):



def main():
    from itertools import accumulate
    import sys
    input = sys.stdin.readline

    n, k = map(int, input().split())
    mod = 10 ** 9 + 7
    a = list(accumulate([0] + [i for i in range(n + 1)]))
    ans = 0

    for j in range(k, n + 2):
        max_value = a[-1] - a[n + 1 - j]
        min_value = a[j]
        ans += (max_value - min_value) + 1
        ans %= mod

    print(ans % mod)


if __name__ == '__main__':
    main()

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

Solution (Python):

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

MOD = 10 ** 9 + 7
count = [0] * (N + 1)
for i in range(1, N + 1):
    count[i] += count[i - 1] + i
    count[i] %= MOD

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

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

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

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

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

Solution (Python):





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

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

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

M=[n]*(n+1)
m=[0]*(n+1)
for i in range(1,n+1):
    M[i]=M[i-1]+n-i
    m[i]=m[i-1]+i

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

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

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

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


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

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

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

print(ans%MOD)

Solution (Python):
def f(m):
    return (((N+1)*((m*(m+1))//2))%p-((m*(m+1)*(2*m+1))//6)%p+m%p)%p
p = 10**9+7
N,K = map(int,input().split())
cnt = (f(N+1)-f(K-1))%p
print(cnt)

Solution (Python):
N,K= map(int,input().split())
p=10**9+7
q=0
 
def calc(n,k):
  if k==1:
    return n+1
  else:
    maxi = k*n- k*(k-1)//2
    mini=  k*(k-1)//2
    
    return maxi-mini+1
  
ans=0
for i in range(K,N+2):
  ans = ( ans+calc(N,i) )%p
  
print(ans)

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate 

from collections import deque,defaultdict,Counter
import decimal
import re












import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
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)

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

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

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

count = 0
for i in range(k, n + 2):
  if i == k:
    tot_min = 0
    tot_max = 0
    for j in range(i):
      tot_min += j
      tot_max += n - j
  else:
    tot_min += i - 1
    tot_max += n - i + 1
  count += tot_max - tot_min + 1
count %= 10 ** 9 + 7
print(count)

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)//2)-((i*(i-1))//2)+1)%mod
print(count%mod)

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

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

n_list=list(range(n+1))

saisyou=sum(n_list[0:k])
saidai=sum(n_list[n-k+1:n+1])

ans=saidai-saisyou+1

for i in range(k+1,n+2):
    saisyou+=n_list[i-1]
    saidai+=n_list[-(i)]
    ans+=saidai-saisyou+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):
    ans += max(0, n*(n+1)//2 - (n-i)*(n+1-i)//2 - i*(i-1)//2 + 1)
    ans %= mod
print(ans)

Solution (Python):
n, k = map(int,input().split())
ans = 0
n_list = [i for i in range(n+1)]
l = sum(n_list[:k])
r = sum(n_list[len(n_list)-k:])
ans += r-l+1

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

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

Solution (Python):


def main():
    MOD = 10**9 + 7
    n, k = [int(i) for i in input().strip().split()]
    table = [0] * (n + 2)
    table[1] = 1

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

    ans = 0
    for i in range(k, n + 1):
        _min = table[i - 1]
        _max = table[n] - table[n - i]
        ans += _max - _min + 1
        ans %= MOD
    print((ans + 1) % MOD)


if __name__ == "__main__":
    main()

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

Solution (Python):
n,k = map(int,input().split())
ans = 0
num = n+1
for i in range(1,n+2):
  
  if i>=k:
    ans += num
  num += n-(2*i)
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):
  ans+=(n+1-i)*i+1
print(ans%mod)

Solution (Python):
import sys


def resolve(in_):
    mod = 1000000007  
    n, k = map(int, in_.readline().split())
    n += 1

    
    ans = 1
    
    while n > k:
        ans += (
            ((n + (n - k)) * k // 2) % mod - 
            ((1 + k - 1) * k // 2) % mod +
            1
            ) % mod
        ans %= mod
        k += 1
    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

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

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
from functools import reduce

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

a = n*(n+k+1)*(n-k+2)//2
b = n-k+2
c = -((n+2)*(n+1)*n - k*(k-1)*(k-2))//3

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

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


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

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

  print(sum_ % 1_000_000_007)


if(__name__ == '__main__'):
  main()

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

def cul(N,K):
  Ans = 0
  for i in range(N+1-K+1):
    t = (K+i-1)*(K+i)/2
    Ans += (K+i)*N - 2*t +1
  return(int(Ans%mod))

print(cul(N,K))

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

Solution (Python):
N, K = map(int, input().split())
preans = []
for n in range(K, N+2):
    MIN = (0+n-1) * n / 2
    MAX = (N + (N-n+1)) * n / 2
    preans.append(MAX - MIN+1)
    
print(int(sum(preans)%(10**9 + 7)))

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

def get_ans(i):
    ans = i*(N+1) - i**2 +1
    ans = max(0,ans)
    return ans

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

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

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

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

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

print(ans)

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

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain, product
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp



class UnionFindEx:
    def __init__(self, size):
        
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    N, K = mis()
    v = [0]
    for i in range(N+1):
        v.append(v[-1]+i)
    ans = 0
    for k in range(K, N+2):
        mi = v[k] - v[0]
        ma = v[-1] - v[-1-k]
        ans += ma - mi + 1
        ans %= N1097
    print(ans)



main()

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

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


upper = sum(range(N+1))
lower = sum(range(N+1))
answer = 1

for k in range(N, K - 1, -1):
    upper -= N - k
    lower -= max(0, k)
    answer += upper - lower + 1
    
print(answer % (10 ** 9 + 7))

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

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

mod=10**9+7
ans=0
for x in range(k,n+2):
  min_a=(0+x-1)*x//2
  max_a=(n-x+1+n)*x//2
  aa=max_a-min_a+1
  ans+=aa
  
print(ans%mod)

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

Solution (Python):
n,k=[int(i) for i in input().split()]    
m=n+2-k
a=-m*(m+1)*(2*m+1)//6
b=(n-2*k+3)*m*(m+1)//2
c=m*(-k**2+3*k+n*k-n-1)
mod=10**9+7

a=a%mod
b=b%mod
c=c%mod

ans=a+b+c

print(ans%mod)

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

for i in range(K,N+2):
  if i ==N+1:
    count+=1
  else:  
    a = (i-1)
    a = a/2
    a = a*i
    b = (N+N-(i-1))/2
    b = b*i
    count +=b-a+1
    
print(int(count%(10**9+7)))

Solution (Python):
N, K = map(int, input().split())
mod = pow(10, 9)+7
Cmax = ((N+N-K+1)*K)//2
Cmin = ((K-1)*K)//2
ans = 1
for i in range(K, N+1):
    ans = (ans+Cmax-Cmin+1)
    Cmin += i
    Cmax += (N-i)

print(ans % mod)

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

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

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

ans = 0
for s in range(k, n+2):
    l = f(0,s-1) % M
    r = f(n-s+1,n) % M
    ans += r-l+1

print(ans%M)

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


low, high = 0, 0
ans = 0

for x in range(1, N + 2):
    
    
    low += x - 1
    high += N - x + 1
    if x >= K:
        ans += (high - low + 1)
        ans %= MOD

print(ans)

Solution (Python):

import itertools
N, K = map(int, input().split())
a = [0] * (N+1)
for i in range(N+1):
  a[i] = i

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

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

  
  ans += (max_total - min_total + 1)

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

Solution (Python):






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

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

Solution (Python):
import numpy

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

cum = numpy.cumsum(range(N+1), dtype='int64')
count = 0

for i in range(K, N+1):
    min_num = cum[i-1]
    max_num = cum[-1] - cum[-i-1]

    count += (max_num - min_num + 1)
    count %= MOD

print(count + 1)

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

Solution (Python):
from itertools import accumulate

n, k = map(int, input().split())
MOD = 10 ** 9 + 7
acc = [0] + list(accumulate(range(n + 1)))

ans = 0
for i in range(k, n + 2):
    mi = acc[i]
    ma = acc[-1] - acc[-i - 1]
    ans += ma - mi + 1
    ans %= MOD

print(ans)

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

def f(n):
    s = (n*(n+1))//2
    return s


N,K = map(int,input().split())
m= 10**9+7
ln = list(range(N+1))
num = 0
for i in range(K,N+2):
    num += f(N+1)-f(N+1-i)-f(i)+1
print(num%m)

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

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

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

Solution (Python):
def su(n):
    if n < 0:
        return 0
    return n*(n+1)//2
MOD = 10 ** 9 + 7
N, K = map(int, input().split())
num = [i for i in range(N+1)]
ans = 0
su_N = su(N)
for i in range(K, N+2):
    min = su(i-1)
    max = su_N - su(N-i)
    ans += max - min + 1
    ans %= MOD
print(ans)

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

sum_pattern_num = 0

for num_cnt in range(K, N+2):
    if num_cnt == K:
        min_sum_frac = sum([i for i in range(0, K)])
        max_sum_frac = sum([i for i in range(N - K + 1, N + 1)])
    else:
        min_sum_frac = min_sum_frac + (num_cnt - 1)
        max_sum_frac = max_sum_frac + (N - num_cnt + 1)
    sum_pattern_num = \
        (sum_pattern_num + (max_sum_frac - min_sum_frac + 1)) % 1000000007

print(sum_pattern_num)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

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

    print(ans)
    return


if __name__ == '__main__':
    main()

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

mod = 1000000007

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

    ans += (num_max - num_min + 1)%mod
print(ans%mod)

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

Solution (Python):
MOD = 1000000007
n, k = map(int, input().split())
rsw = [0]*(n+2)
for i in range(1,n+2):
    rsw[i] = (rsw[i-1]+i-1)%MOD
rsw_e = [0]*(n+2)
for i in range(1,n+2):
    rsw_e[i] = (rsw_e[i-1]+n-(i-1))%MOD
res = 0
for i in range(k,n+2):
    start = rsw[i]
    end = rsw_e[i]
    res += (end-start+1)%MOD
print(res%MOD)

Solution (Python):
from itertools import accumulate
N, K = map(int, input().split())
MOD = 10**9 + 7
cum = list(accumulate([0]+ list(range(N+1))))
print((sum(cum[N+1] - cum[N+1-k] - cum[k] + 1 for k in range(K,N+2)))%MOD)

Solution (Python):
n,k = map(int, open(0).read().split())

left = right = 0
ans = 0
MOD = 10**9+7

for c,(i,j) in enumerate(zip(range(n+1), range(n,-1,-1))):
    left += i
    right += j

    if c >= k-1:
        ans += (right-left+1)
        ans %= MOD

print(ans)

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

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
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 - i + 1)) * i // 2
        res += ma - mi + 1
        res %= mod
    print(res)


if __name__ == '__main__':
    resolve()

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

Solution (Python):

n,k = map(int,input().split())
a = list(range(n))

ans = 0

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


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

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


def sum_from_to(fr, to):
    return (to - fr + 1) * (fr + to) // 2 % MOD


def main():
    input = sys.stdin.buffer.readline
    n, k = map(int, input().split())
    ans = 0
    for i in range(k, n + 2):
        ans += sum_from_to(n - i + 1, n) - sum_from_to(0, i - 1) + 1
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

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

main()

Solution (Python):
N, K =map(int, input().split())
mod = 10**9 + 7
A = int(-(N+1)*(N+2)*(2*N+3)/6)%mod
B = int((N+1)*(N+1)*(N+2)/2)%mod
C = N+1
a = int(-(K-1)*K*(2*K-1)/6)%mod
b = int((N+1)*(K-1)*K/2)%mod
c = K-1
print((A+B+C-a-b-c)%mod)

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

    
    
    

    num_sums = sum((n-j+1)*j + 1 for j in range(k, n+2)) 
    print(num_sums % (10**9 + 7))


main()

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

print(ans%M)

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

Solution (Python):
def main():
    N, K = map(int, input().split())
    MOD = 1_000_000_007
    l = 0
    r = 0
    ans = 0
    for i in range(N + 1):
        l += i
        r += N - i
        if i + 1 >= K:
            ans += r - l + 1
            ans %= MOD
    print(ans)
if __name__ == '__main__':
    main()

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

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

  sum+=(N*(N+1)//2)-((N-i)*(N-i+1)//2)-(i*(i-1)//2)+1
  sum%=(10**9+7)
print(sum%(10**9+7))

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

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

print(sum_)

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

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

Solution (Python):
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 - i*(i-1)) //2 + 1
print(ans%MOD)

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

su = 0
for i in range(k, n+2):
    co = (n+(n-i+1))*i/2 - (i-1)*i/2 + 1
    su = (su + int(co)) % (10**9 + 7)
    
print(su)

Solution (Python):

"""
Created on Sun Jul  5 00:28:02 2020

@author: Aruto Hosaka
"""


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

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

ans1 = N+1
ans1 *= N+K+1
ans1 %= mod
ans1 *= N+2-K
ans1 %= mod
ans1 *= modinv(2)
ans1 %= mod

ans2 = N+1
ans2 *= N+2
ans2 %= mod
ans2 *= 2*N+3
ans2 %= mod
ans2 *= modinv(6)
ans2 %= mod

ans3 = K-1
ans3 *= K
ans3 %= mod
ans3 *= 2*K-1
ans3 %= mod
ans3 *= modinv(6)
ans3 %= mod

ans4 = N+2-K

ans = ans1 - ans2 + ans3 + ans4
ans %= mod
print(ans)

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

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

count = 0
for i in range(k,n+2):
  min_k = i*(i-1)/2
  max_k = i*(2*n-i+1)/2
  count += max_k - min_k + 1
print(int(count % DIV))

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

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

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

Solution (Python):

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


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


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

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

    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
from numba import jit

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

tmp=[]
for i in range(n+1):
    tmp.append(i)
ary = np.array(tmp)


@jit
def lr(l,r): 
    return (l+r)*(r-l+1)//2

ans = 0
for j in range(k,n+2):
    l = lr(0, j-1)
    r = lr(n+1-j, n)
    ans += r-l+1
    ans %= 10**9+7
    
print(ans)

Solution (Python):
import numpy as np

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

ary = np.array([i for i in range(n+1)])

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

ans = 0
for j in range(k,n+2):
    l = lr(0, j-1)
    r = lr(n+1-j, n)
    ans += r-l+1
    ans %= 10**9+7
    
print(ans)

Solution (Python):
import numpy as np

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

ary = np.array([i for i in range(n+1)])


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

ans = 0
for j in range(k,n+1):
    l = lr(0, j-1)
    r = lr(n+1-j, n)
    ans += r-l+1
    
ans += 1
ans %= 10**9+7

print(ans)

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

print(ans)

Solution (Python):
import numpy as np

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

ary = np.array([i for i in range(n+1)])
cum = np.cumsum(ary)


ans = 0
for j in range(k,n+1):
    ans += (cum[-1] - cum[-j-1]) - cum[j-1] + 1
    
else:
    ans += 1
    ans %= 10**9+7

print(ans)

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