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(' '))
ans = n*(-k*(k-1)//2+(n+2)*(n+1)//2) + k*(k-1)*(2*k-1)//6 - k*(k-1)//2 - (n+1)*(n+2)*(2*n+3)//6 + (n+1)*(n+2)//2 + n-k+2
print(ans%(pow(10,9)+7))

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

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

sum_num = 0
for i in range(k,n+2):
  max_num = int(i*(n+n-i+1)/2)
  min_num = int(i*(i-1)/2)

  sum_num = (sum_num + (max_num-min_num + 1)) % mod

print(sum_num)

Solution (Python):

import numpy as np

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

r = np.cumsum(np.arange(n+1))
rr = np.cumsum(np.arange(n+1)[::-1])

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

print(ans)

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

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

for i in range(k,n+2):
  tot+=n+2-i+(i-1)*(n+1-i)
  
print(str(tot%1000000007))

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

if k == n + 1:
    print(1)
else:
    ans = 1
    mod = 10**9 + 7
    left = sum(l[:k])
    right = sum(lr[:k])
    
    
    for i in range(n - k + 1):
        ans += right - left + 1
        ans %= mod
        left += l[k + i]
        right += lr[k + i]
    print(ans)

Solution (Python):

import sys

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

N += 1
MOD = 10**9+7

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

print(ans)

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

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

Solution (Python):



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

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

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

point = [int(i) for i in range(N+1)]
count = 0

max_val = int(sum(point[-K:]))
min_val = int(sum(point[:K]))
count = int(max_val - min_val + 1)%1000000007

for i in range(K, N+1):
    max_val = max_val + point[-i-1]
    min_val = min_val + point[i]
    count += int(max_val - min_val + 1)%1000000007 
print(int(count)%1000000007)

Solution (Python):
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))

n, k = load_list()

N = [i for i in range(0, n+1)]

cnt = 0

lowd = [i for i in range(0, n+1)]
for i in range(1, n+1):
    lowd[i] = lowd[i-1] + lowd[i]
highd = [i for i in range(0, n+1)]
for i in range(n-1, -1, -1):
    highd[i] = highd[i] + highd[i+1]

for i in range(k, n+2):
    low = lowd[i-1]
    high = highd[n+1-i]
    cnt += high - low + 1

print(int(cnt % (math.pow(10, 9) + 7)))

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

def sumf(NN,X):
    return (NN+1)*0.5*X*(X+1) - X*(X+1)*(2*X+1)/6 + X

print(int(sumf(N,N+1) - sumf(N,K-1)) % 1000000007)

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

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

S=0
for x in range(K,N+2):
  max=(N*(N+1)-(N-x)*(N-x+1))//2
  min=x*(x-1)//2
  S=S+(max-min+1)
S=S%(10**9+7)
print(S)

Solution (Python):
n,k = (int(x) for x in input().split())
res = 0
for i in range(k,n+2):
    base = n*i -(i*(i-1)) +1
    res = res+ base
resu = res%1000000007
print(resu)

Solution (Python):
mod = 10**9 + 7
from collections import defaultdict

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

n,m = invr()
left = 0
right = 0
l_a = 0
r_a = n

for i in range(m):
    left += l_a
    right += r_a
    l_a += 1
    r_a -= 1

ans = right - left + 1
while m <= n :
    left += l_a
    right += r_a
    l_a += 1
    r_a -= 1
    ans += (right - left + 1)%mod
    ans = ans%mod
    m += 1
print(ans)

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

counter = 0

for i in range(k, n+2):
    min_sum = i * (i-1) / 2
    max_sum = i * (n + (n - i + 1)) / 2
    
    counter += (max_sum - min_sum + 1) % (10**9 + 7)


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

Solution (Python):
from itertools import accumulate

def resolve():
    n,k = map(int, input().split())
    ans = 0
    mod = 10**9+7
    dp = [i for i in range(n+1)]
    acc = [0] + list(accumulate(dp))
    for i in range(k-1, n+1):
        r = acc[-1] - acc[n-i]
        l = acc[i+1]
        ans = (ans + r - l + 1) % mod
    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
N,K=map(int,input().split())
L=[]
for i in range(N+1):
    L.append(i)
count=0
Mod=10**9+7
for i in range(K-1,N+1):
    mi=(i)*(i+1)//2
    ma=(N)*(N+1)//2-(N-i)*(N-i-1)//2
    count+=(ma-mi+1)%Mod
print(count%Mod)

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

MOD = 10 ** 9 + 7

ans = 0
num = 0

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

print(ans)

Solution (Python):

import sys

MOD = 1000000007  


def solve(N: int, K: int):
    result = 0
    for i in range(0, N-K+2):
        s = (K + i) * (2 * N - K - i + 1) // 2 - (K + i) * (K + i - 1) // 2 + 1
        result += s
    print(result%(10**9+7))
    return



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

if __name__ == '__main__':
    main()

Solution (Python):






n, k = [int(i) for i in input().split()]
res = 0
for i in range(k, n + 2):
    res += (2 * n - 2 * i + 2) * i // 2 + 1


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

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

Solution (Python):
import sys
sys.setrecursionlimit(10000000)


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

    num = 0
    min_sum = sum(range(0, K))
    max_sum = sum(range(N + 1 - K ,N + 1))

    for i in range(N + 2 - K):
        num += max_sum - min_sum + 1
        max_sum += N - K - i
        min_sum += K + i

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



if __name__ == '__main__':
    main()

Solution (Python):



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


up_list = [i for i in range(N+1)] 
up_sums = [0]*(N+1)
for i in range(N+1):
    if i==0:
        up_sums[i] = up_list[i]
    else:
        up_sums[i] = up_sums[i-1] + up_list[i]
down_list = [i for i in range(N, -1, -1)] 
down_sums = [0]*(N+1)
for i in range(N+1):
    if i==0:
        down_sums[i] = down_list[i]
    else:
        down_sums[i] = down_sums[i-1] + down_list[i]
ans = 0
MOD = 10**9 + 7


tmp_k = K
while tmp_k<=(N+1):
    test_up = up_sums[tmp_k-1]
    test_down = down_sums[tmp_k-1]
    tmp = (test_down - test_up + 1)%MOD
    ans += tmp
    ans = ans % MOD
    tmp_k += 1


print(ans)

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

left, right = [x[0]], [x[-1]]
for i in range(1, n+1):
    left.append(left[i-1] + x[i])
    right.append(right[i-1] + x[-(i+1)])

total = 0
for i in range(k-1, n+1):
    total += right[i] - left[i] + 1

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

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

Solution (Python):
import sys
import itertools
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
N,K=nm()

mod=10**9+7
ans=0

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

print(int(ans%mod))

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

p = 1000000007

sum = 0

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

print(sum)

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

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

ans = 0
mod = 10**9+7

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

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

Solution (Python):


n, k = [0] * 2

mod = 10**9 + 7

def format_input(filename = None):
	global n, k
	if filename == None:
		n, k = list(map(int, input().split()))

	elif filename == '__random__':
		from random import randint as rng
		n = rng(1, 2 * 10**5)
		k = rng(1, n+1)
		print(n, k)

def get_answer():
	answer = ((n+1) * (n+2)) // 2 * n + ((n+1) * (n+2)) // 2 - ((n+1) * (n+2) * (2*n+3)) // 6 + (n+1)
	answer -= (k * (k-1)) // 2 * n + (k * (k-1)) // 2 - (k * (k-1) * (2*k-1)) // 6 + (k-1)
	answer %= mod
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)

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

sums = [0 for i in range(n+1)]
MOD = 1000000007

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

ans += n-k+1

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

print(ans)

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%1000000007)

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

def main():
    N, K = map(int, readline().rstrip().split())
    ans = 0
    for k in range(K, N+2):
        mi = ((k-1) * k) // 2
        ma = (N * (N + 1)) // 2 - ((N-k) * (N-k+1)) // 2
        ans += (ma - mi + 1) % MOD

    print(ans % MOD)


if __name__ == '__main__':
    main()

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

M = 10**9+7

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

print(ans%M)

Solution (Python):


import sys








"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        
        
        
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

    def lcm(self, x, y):
        return (x * y) // self.gcd(x, y)


"""ここからメインコード"""


def main():
    
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    
    
    
    
    
    n, k = ip.IL()
    ans = 0
    for i in range(k-1, n+1):
        
        a= ((n - i + n) * (i + 1) / 2)
        b = ((0 + i) * (i + 1) /2)
        
        ans +=  a - b + 1
    print(int(ans) % (10 ** 9 + 7))

main()

Solution (Python):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
t1 = n-k+2
t2 = (n+1)*(n+k+1)*(n-k+2)//2
t3 = ((n+2)*(n+1)*(2*n+3)-(k-1)*k*(2*k-1))//6
ddprint(t1)
ddprint(t2)
ddprint(t3)
print((t1+t2-t3)%R)

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

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

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

print(ans%mod)

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

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

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007



def main():
	
	n, k = IN()
	
	kk=0
	for i in range(k-1):
		kk += i
		kk %= mod
		
	bb=0
	for i in range(k-1):
		bb += (n )- i
		bb %= mod
	cc=0
	
	
	for i in range(k, n+2):
		bb += (n + 1) - i
		bb %= mod
		kk += i-1
		kk %= mod
		cc += (bb - kk + 1)
		cc%= mod 
		
	print(cc)
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

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

mod = 10 ** 9 + 7

ans = 0
n = ((N * (N+1)) // 2) % mod
for i in range(K,N+2):
    if i == N+1:
        ans += 1
        continue
    t = (((N-i) * (N+1-i)) // 2) % mod
    ans +=  (n - t + 1) % mod
    ans -= (((i-1) * i)//2) % mod 
    ans %= mod

print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import itertools

n, k = map(int, readline().split())
memo = [i for i in range(n + 1)]
cumsum = list(itertools.accumulate(memo))
mod = 10 ** 9 + 7
if n < k:
    print(1)
    exit()
ans = 1
for i in range(k - 1, n):
    ans += (cumsum[-1] - cumsum[n - i - 1]) - cumsum[i]
    ans += 1
    ans %= mod
print(ans % mod)

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

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

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

Solution (Python):

from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product
import math

s = input().split()
p = [int(w) for w in s] 

N = p[0]
K = p[1]



A = (N+1) * (N+2) * N / 6
B = K * (K-1) * (2*K - 3*N - 4) / 6
C = N - K + 2
ans = int(A+B+C) 

print(ans % 1000000007)

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

count = 0
for i in range(k, n+2):
    mn = (i - 1) * i / 2
    mx = (2 * n - i + 1) * i / 2
    count += mx - mn + 1
print(int(count % 1000000007))

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

MM = 10**9 +7

for i in range(K,K+a):
  start = int( ( (i)*(i-1)/2 ) % MM )
  fin = int( ( (N+(N-1)-i)*(i)/2+1 ) % MM )
  ans = int( ( ans + (fin - start) ) % MM )

ans += 1
print(ans)

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

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

print(ans%mod)

Solution (Python):
N , K =map(int,input().split())
MOD=10**9+7
ans=0
if N<K:
    print(1)
else:
    tmp_low = sum(range(K))
    tmp_high = sum(range(N-K+1,N+1))
    r=tmp_high-tmp_low+1
    ans+=r
    ans%=MOD
    for sel in range(K+1,N+2):
        tmp_low += sel-1
        tmp_high += N-sel+1
        r= tmp_high-tmp_low+1
        ans+=r
        ans%=MOD
    print(ans%MOD)

Solution (Python):



 
import sys
import math



 

fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile


mod=1000000007
 

def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 

t=1
for tt in range(t):
    
    n,k= map(int, sys.stdin.readline().split(' '))
    ans=0
    for i in range(k,n+2):
        x=(i*(i-1))//2
        y=n*i
        y-=(i*(i-1))//2
        ans+=(y-x+1)
        ans%=mod

        
    print(ans)
    
    
    

if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

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

Solution (Python):
n,k = map(int, input().split())
m = 1000000007
ans = []
for i in range(1,n+2):
    ans_min = (0+(i-1))*i*0.5
    ans_max = ((n+1-i)+n)*i*0.5
    ans.append(ans_max-ans_min+1)

ans_wa = [ans[0]]
for i in range(1,n+1):
    ans_wa.append(ans_wa[i-1]+ans[i])

if (k>=2):
    print(int((ans_wa[n]-ans_wa[k-2])%m))
else:
    print(int(ans_wa[n]%m))

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

Solution (Python):
import collections
import math
import operator as op
from functools import reduce
from collections import Counter
import numpy as np
import math
import bisect
import heapq

MOD = 1000000007

def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def main():
    N, K = get_inputs(int)

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

N,K = map(int, input().split())
MOD = 10**9+7
def count(N, K):
    min =K*(K-1)/2
    max = (N-K+1)*K+min
    count_num = max-min+1
    K = K +1
    while K <=N+1:
        min = min + K-1
        max = max + N-K+1
        count_num = count_num + max-min+1
        K=K+1
    return count_num

print(int(count(N,K)%MOD))

Solution (Python):


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

    def total(mn, mx):
        """mnからmxまでの和を返す"""
        n = mx-mn+1
        ret = int((mn+mx)*n/2)
        return ret%MOD

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

    print(int(ans))


if __name__ == "__main__":
    solve()

Solution (Python):
n, k = map(int, input().split())
lis = [n+1]
l = n+1
mod = 10**9+7
for i in range(2, n+2):
    new_l = (l + n -2*i + 2) %mod
    lis.append(new_l)
    l = new_l
s = 0
for i in lis:
    s += i
    s %= mod
s_2 = 0
for i in range(k-1):
    s_2 += lis[i]
    s_2 %= mod
ans = (s- s_2)%mod
if ans < 0:
    ans += mod
print(ans)

Solution (Python):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
mod =10**9+7
def solver(k,n):
    ans=int((k*(2*n-k+1)-k*(k-1))/2)+1
    ans=ans%mod
    return ans 
def do():
    sol=0
    n,k=INTM()
    for i in range(k,n+1):
        sol+=solver(i,n)
        sol=sol%mod
        
    print(sol+1)
        
if __name__ == '__main__':
    do()

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

cnt=[0]*(n+2-k)
for i in range(n+2-k):
    imin=int((i+k-1)*(i+k)/2)
    imax=int((2*n-i-k+1)*(i+k)/2)
    
    num=imax-imin+1
    cnt[i]=num
print(sum(cnt)%(10**9+7))

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

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

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

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

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

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

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

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

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

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

print(sum_ % MOD)

Solution (Python):




import sys
input = sys.stdin.readline



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

    mod = 10 ** 9 + 7

    res = 0

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

    print(res)



main()

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

if N + 1 == K:
    print(1)
    sys.exit(0)

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

print(ans)

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

fac = [1] * m
finv = [1] * m
inv = [1] * m


def COMinit():
    for i in range(2, m):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod


def COM(n, k):
    if n < 0 or k < 0 or n < k:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


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

Solution (Python):
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,k=n1()

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

Solution (Python):

from sys import stdin
import sys


def nextLine(): return next(stdin)
def nextStrList(): return nextLine().split()
def nextIntList(): return [int(_) for _ in nextStrList()]


m=10**9+7
def s2(n):
	v=(n*(n+1)//2)*(2*n+1)//3
	v%=m
	return v

def s(n):
	v= n*(n+1)//2
	v%=m
	return v 

def main():
	n,k=nextIntList()
	
	ss=-(s2(n)-s2(k-2))+(n-1)*(s(n)-s(k-2))+(((n+1)*(n-(k-2)))%m)
	ss%=m
	print(ss)







		
	
if __name__=="__main__":
	main()

Solution (Python):
n,k = map(int,input().split())
"""
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
"""
mod = 10**9+7 
"""
N = 2*10**5
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 )
"""
ans = 0

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

print(ans)

Solution (Python):
import math
n,k = map(int, input().split())
mod = 10**9+7
ans = 0
array = [i for i in range(n+1)]
first_sum = sum(array[:k])
latter_sum = sum(array[-k:])
for i in range(k,n+1):
    ans += (latter_sum - first_sum) + 1
    first_sum += array[i]
    latter_sum += array[-(i+1)]
    ans %= mod
ans += 1
print(ans % mod)

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

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

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

Solution (Python):

import sys
from itertools import accumulate

MOD = 1000000007  

def solve(N: int, K: int):
    a = list(range(0,N+1))

    left_a = list(accumulate(a))
    right_a = list(accumulate(a[::-1]))

    answer = 0
    for i in range(K,N+2):
        l = left_a[i-1]
        r = right_a[i-1]
        answer += r-l+1
        answer %= MOD
    
    print(answer)
    return


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

if __name__ == '__main__':
    main()

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