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



def input_int():
    return int(input())



def int1(x):
    return int(x) - 1



def input_to_int_map():
    return map(int, input().split())



def input_to_int_tuple():
    return tuple(map(int, input().split()))



def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


MOD = 10 ** 9 + 7


from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


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

    all_n = n + 1
    ret = 0
    all_list_sum = [0]
    pre = 0
    for i in range(0, all_n):
        all_list_sum.append(i + pre)
        pre = i + pre

    for choice_cnt in range(k, all_n + 1):
        ret = (ret + (all_list_sum[n + 1] - all_list_sum[n + 1 - choice_cnt] - all_list_sum[choice_cnt] + 1)) % MOD

    return ret


if __name__ == "__main__":
    print(main())

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

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

Solution (Python):
MOD = 1000000007

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

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

print(ans)

Solution (Python):
def solve():
    N, K = map(int, input().split())
    cs = [0] * (N + 1)
    for i in range(1, N + 1):
        cs[i] = cs[i - 1] + i
    
    ans = 0
    for i in range(K, N + 2):
        if i == N + 1:
            ans += 1
        else:
            mn = cs[i - 1]
            mx = cs[-1] - cs[-1 - i]
            ans += mx - mn + 1
        
        ans = ans % (10**9 + 7)
    print(ans)


if __name__ == '__main__':
    solve()

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

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

ans=0

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

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

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

sum = 0

for j in range(K,M+2):
    temp = j*(M-j+1) + 1
    if temp > (10**9 + 7):
        temp = temp%(10**9 + 7)
    sum += temp
if sum > 10**9+7:
    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 += int((N)*(N+1)/2 - (N-i)*(N-i+1)/2 - (i-1)*i/2 + 1)

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

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

if __name__ == '__main__':
    main()

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

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

Solution (Python):
n,k=map(int, input().split())
x=0
a=list(range(0,n+1))
aa=list(range(1,n+2))
mod=10**9+7
from itertools import accumulate
A=list(accumulate(a))
for i in range(k-1,n+1):
    x+=(2*A[i]-1)%mod
    x%=mod
print(((sum(aa[k-1:])%mod*n)-x+mod)%mod)

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

if __name__ == '__main__':
    main()

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

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

print(ans)

Solution (Python):
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, K = list(map(int,_in[0].split(' ')))  
    
    cnt = 0
    for i in range(K,N+2):
        cnt += (N*(N+1)//2-(N-i)*(N-i+1)//2) - (i-1)*i//2+1
    cnt = int(cnt % (1e9+7))
    
    print(cnt)

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


def log(v):
    print(v, file=sys.stderr)


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

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

Solution (Python):
N, K = map(int, input().split())
mod = 10**9 + 7
count = 0
for n in range(K, N+2):
  maxSum = (n*(N + N-n+1))//2
  minSum = (n*(n-1))//2
  count += maxSum - minSum + 1
  count %= mod

print(count)

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

ans = 0

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

print(ans%mod+1)

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

s = 0

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

print(s)

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

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

Solution (Python):
n,k = [int(i) for i in input().split()]
mod = 10**9+7

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

Solution (Python):
def f(s, e):
    return (e-s+1)*(s+e)//2

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

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

print(ans)

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

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

m = l % (7 + 10**9)

print(m)

Solution (Python):
def abc(N, K):
    
    ans = 0
    
    
    for i in range(K, N+2):
        
        max = int(0.5*i*(N-i+1+N))
        
        min = int(0.5*i*(0+i-1))
        
        ans += max - min + 1
    
    
    if ans > 10**9 + 7:
        ans = ans % (10**9 + 7)
    return(ans)



if __name__ == "__main__":
    
    
    N, K = map(int, input().split())
    
    
    f = abc(N, K)
    
    
    print(f)

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



sum = 0
for i in range(k - 1, n + 1):
    sum = sum + max[i] - min[i] + 1
print(sum % (pow(10, 9) + 7))

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


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


print(result % mod)

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

Solution (Python):
import itertools as it

N,K = map(int, input().split())
mod = 10**9 + 7
left = it.islice(it.accumulate(reversed(range(N+1))), K-1, N+1)
right = it.islice(it.accumulate(range(N+1)), K-1, N+1)
ans = sum(map(lambda x,y: x-y+1, left, right))
print(ans%mod)

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

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

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

MOD = 10**9 + 7

result = 0
for ki in range(k, n+2):
   first = ki * (ki - 1) / 2
   final = (2*n - ki + 1) * ki / 2
   add = final - first + 1
   result = (result + add) % MOD

print(int(result))

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

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

print(ans)

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

mi = 0
ma = 0
for i in range(K-1):
    mi += i
    ma += N - i

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

print(ans)

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





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

print(ans)

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

l = [i for i in range(n+1)]

max_sum = 0
min_sum = 0
ans = 0
for i in range(n+1):
    max_sum += l[n-i]
    min_sum += l[i]
    if i+1 < k:
        continue
    
    else:
        ans += (max_sum - min_sum + 1)
        ans %= mod

print(ans)

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

Solution (Python):
nk = [int(s) for s in input().split()]
n, k = nk[0], nk[1]
tot = 0
all_sums = [0]
for i in range(1, 200001):
    all_sums.append(i+all_sums[-1])
for i in range(k, n+1):
    tot = (tot + (all_sums[n]-all_sums[n-i]) - (all_sums[i-1]) + 1)%1000000007
print(tot+1)

Solution (Python):
import itertools
import math
import numpy as np
import fractions
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
import sys
sys.setrecursionlimit(10**9)

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

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

    print(ans)

if __name__ == "__main__":
  main()

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

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

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

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

def calcu(x):
    small = (x*(x-1))/2
    large = small + x*(N-x+1)
    return large-small+1

for i in range(K, N+2):
    ans += calcu(i)
    ans %= MOD

print(int(ans))

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

ans=0

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

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

Solution (Python):
def max_sum(n,k):
    sum = 0
    for i in range(n-k+1,n+1):
        sum += i
    return sum
N,K = map(int,input().split(" "))
sum = 0
mod_num = 1000000007
for i in range(K,N+2):
    max = i*(2*N-i+1)//2
    min = i*(i-1)//2
    sum += max-min+1
    sum %= mod_num

print(sum)

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

total=0
i=k
while i<=n+1:
	total+=(n - i + 1 + n) * i / 2 - (0 + i - 1) * i / 2 + 1;
	total %= MOD
	i+=1

print(int(total))

Solution (Python):

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



mod=10**9+7
ans=0
for kval in range(k,n+2):
    mx=kval*(2*n-kval+1)//2
    mn=kval*(kval-1)//2
    add=mx-mn+1
    ans=(ans+add) % mod

print(ans)

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

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


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

Solution (Python):
from itertools import accumulate

def main():
    n,k = (int(x) for x in input().split())
    mod = 10**9 + 7
    left = tuple(accumulate(range(n+1)))
    right = tuple(accumulate(reversed(range(n+1))))
    tot = sum(r-l+1 for l, r in zip(left[k-1:], right[k-1:]))
    print(tot%mod)

if __name__ == '__main__':
    main()

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

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

print(int(ans))

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

acc = [i for i in range(N+1)]
for i in range(N): acc[i+1] += acc[i]

ans = 0
for i in range(K,N+2):
    ma = acc[-1] - acc[max(-len(acc),-1-i)]
    mi = acc[i-1]
    ans += ma - mi + 1
    ans %= 10**9+7

print(ans)

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

MOD = 10 ** 9 + 7

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

print(int(ans))

Solution (Python):
n, k = map(int, input().split())
ans = 0
mod = 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
print(ans % mod)

Solution (Python):






"""Module docstring
"""

import functools
import heapq
import itertools
import logging
import random
import string
import sys
from argparse import ArgumentParser
from collections import defaultdict, deque
from copy import deepcopy
from math import factorial
from typing import Dict, List, Optional, Set, Tuple


def solve(values: List[str], nb: int) -> Optional[int]:
    for _v in values:
        pass
    return nb


def choose_n_k(n: int, k: int) -> int:
    return factorial(n) // (factorial(k) * factorial(n - k))


MODULO = pow(10, 9) + 7


def sum_fct(n: int) -> int:
    return ((n * (n + 1)) // 2) % MODULO


def do_job():
    "Do the work"
    LOG.debug("Start working")
    
    
    N, K = map(int, input().split())
    total = sum_fct(N)
    result = 0
    for i in range(K, N + 2):
        min_sum = sum_fct(i - 1)
        max_sum = total - sum_fct(N - i)
        result = (result + max_sum - min_sum + 1) % MODULO
    print(result)


def print_output(testcase: int, result) -> None:
    "Formats and print result"
    if result is None:
        result = "IMPOSSIBLE"
    print("Case 
    
    


def configure_log(log_file: Optional[str] = None) -> None:
    "Configure the log output"
    log_formatter = logging.Formatter(
        "%(asctime)s - %(filename)s:%(lineno)d - " "%(levelname)s - %(message)s"
    )
    if log_file:
        handler = logging.FileHandler(filename=log_file)
    else:
        handler = logging.StreamHandler(sys.stdout)
    handler.setFormatter(log_formatter)
    LOG.addHandler(handler)


LOG = None

if not LOG:
    LOG = logging.getLogger("template")
    configure_log()


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    parser = ArgumentParser()
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="run as verbose mode",
    )
    args = parser.parse_args(argv)
    if args.verbose:
        LOG.setLevel(logging.DEBUG)
    do_job()
    return 0


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    sys.exit(main())


class memoized:
    """Decorator that caches a function's return value each time it is called.
    If called later with the same arguments, the cached value is returned, and
    not re-evaluated.
    """

    def __init__(self, func):
        self.func = func
        self.cache = {}

    def __call__(self, *args):
        try:
            return self.cache[args]
        except KeyError:
            value = self.func(*args)
            self.cache[args] = value
            return value
        except TypeError:
            
            
            return self.func(*args)

    def __repr__(self):
        """Return the function's docstring."""
        return self.func.__doc__

    def __get__(self, obj, objtype):
        """Support instance methods."""
        return functools.partial(self.__call__, obj)

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

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

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

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

Solution (Python):

from itertools import accumulate


def main():
    N, K = map(int, input().split())
    MOD = 10 ** 9 + 7
    cumsum_left = tuple(accumulate(range(N + 1)))
    cumsum_right = tuple(accumulate(range(N + 1)[::-1]))
    total = sum(r - l + 1 for l, r in zip(cumsum_left[K - 1 :], cumsum_right[K - 1 :]))
    total %= MOD
    print(total)


if __name__ == "__main__":
    main()

Solution (Python):

from itertools import accumulate


def main():
    N, K = map(int, input().split())
    MOD = 10 ** 9 + 7
    cumsum_left = tuple(accumulate(range(N + 1)))
    cumsum_right = tuple(accumulate(reversed(range(N + 1))))
    total = sum(r - l + 1 for l, r in zip(cumsum_left[K - 1 :], cumsum_right[K - 1 :]))
    total %= MOD
    print(total)


if __name__ == "__main__":
    main()

Solution (Python):

from itertools import accumulate


def main():
    N, K = map(int, input().split())
    cumsum_left = tuple(accumulate(range(N + 1)))
    cumsum_right = tuple(accumulate(reversed(range(N + 1))))
    total = 0
    MOD = 10 ** 9 + 7
    for l, r in zip(cumsum_left[K - 1 :], cumsum_right[K - 1 :]):
        total += r - l + 1
        total %= MOD
    print(total)


if __name__ == "__main__":
    main()

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

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

Solution (Python):

MOD = 1E9+7
N, K = list(map(int, input().split()))
ans = 0
for k in range(K, N+2):
    first = k * (k-1) / 2
    second = k * (2 * N - k + 1) / 2
    add = second - first + 1
    ans = (ans + add) % MOD

print(int(ans))

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



res = 0

for k in range(K, n+2):
  first = k * (k-1) / 2
  last = (2 * n - k + 1) * k / 2
  res += (last - first + 1) 
print(int(res%(10**9+7)))

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

A = [i for i in range(N+1)]
A_rev = sorted(A, reverse=True)
ans = 0
dp = {'max':sum(A_rev[0:K]), 'min':sum(A[0:K])}
ans += dp['max'] - dp['min'] + 1
for i in range(K, N+1):
    dp['max'] += A_rev[i]
    dp['min'] += A[i]
    ans += dp['max'] - dp['min'] + 1
print(ans%d)

Solution (Python):


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


answer = 0
for i in range (K,N+2):
    minit = i*(i-1)/2
    maximum = (2*N-i+1)*i/2
    
    num = maximum-minit+1
    answer += num
 
if answer >=(10**9+7):
    print(int(answer%(10**9+7)))
    
else:
    print(int(answer))

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

li=list(range(N+1))
count=0


for i in range(M,N+2):
    small=(i*(i-1))//2
    large=small+li[-i]*i
    count+=large-small+1

print(count%(pow(10,9)+7))

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

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

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

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

ANS_TABLE = [0] * (N + 1)
TMP_MIN = sum([i for i in range(0, K)])
TMP_MAX = sum([i for i in range(N, N - K, -1)])
TMP_UP = K
TMP_LOW = N - K

for i in range(K, N + 1):
    ANS_TABLE[i] = TMP_MAX - TMP_MIN + 1
    TMP_MAX += TMP_LOW
    TMP_MIN += TMP_UP
    TMP_UP += 1
    TMP_LOW -= 1

print((sum(ANS_TABLE) + 1) % (10 ** 9 + 7))

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

Solution (Python):
N,K = map(int,input().split())
l = list()
for i in range(K,N+2):
    min = i*(i - 1)/2
    max = (2*N - i + 1)*i /2
    cases = max - min + 1
    l.append(cases)
print(int(sum(l)) % (10**9 + 7))

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

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

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

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


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

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

Solution (Python):
from typing import NoReturn


def my_sum(start: int, end: int):
    if start < 0:
        return my_sum(1 - start, end)
    elif start > 1:
        return my_sum(1, end) - my_sum(1, start - 1)
    else:
        return end * (end + 1) // 2


def main() -> NoReturn:
    n, k = map(int, input().split())  

    p: int = 10 ** 9 + 7

    answer = 0

    for i in range(k, n + 2):
        min_val: int = my_sum(0, i - 1)
        max_val: int = my_sum(n - i + 1 , n)
        answer += max_val - min_val + 1

    print(answer % p)


if __name__ == '__main__':
    main()

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

Solution (Python):


M = 1000000007

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

c = ((6 * n - 6 * k + 12 + 3 * (n + 1) * (k + n + 1) * (n - k + 2) - (n + 1) * (n + 2) * (2 * n + 3) + k * (k - 1) * (2 * k - 1)) // 6) % M

print(c)

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

Solution (Python):

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

l = [i for i in range(n+1)]

mod = 10**9 + 7

cnt = 0

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

Solution (Python):
from itertools import combinations
N, K = map(int, input().split())
nums = [0 for _ in range(N + 1)]
for i in range(N + 1):
    if i == 0:
        nums[i] = 0
    else:
        nums[i] = nums[i - 1] + i

if N + 1 == K:
    print(1)
else:
    count = 1
    for i in range(K, N + 1):
        
        
        min_nums = nums[i - 1]
        max_nums = nums[N] - nums[N - i]
        
        
        count += max_nums - min_nums + 1

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

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

print(ans)

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

def solve(N, K, MOD=10**9+7):
    s = list(range(N+2))
    for i in range(1, N+2):
        s[i] = s[i-1] + i
        s[i] %= MOD

    ans = 0
    for k in range(N+1, K-1, -1):
        
        b = s[N+1] - s[N+1-k]
        b %= MOD
        a = s[k] - s[0]
        a %= MOD
        ans += (b - a + 1)
        ans %= MOD
    return ans


if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))

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

MOD = 10 ** 9 + 7

min_ = sum(range(K))
max_ = sum(range(N, N-K, -1))

count_ = 0


for i in range(K, N + 2):
    
    add = max_ - min_ + 1

    min_ += i
    max_ += (N - i)

    count_ = (count_ + add ) % MOD

print(count_)

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

Solution (Python):
import sys


def main():
    input = sys.stdin.readline
    n, k = map(int, input().split())
    MOD = 10**9 + 7
    answer = 0
    for i in range(k, n+2):
        mi = sigma(0, 1, i)
        ma = sigma(n, -1, i)
        answer += ma - mi + 1
    print(answer % MOD)


def sigma(a, d, n):
    return (2*a+(n-1)*d)*n//2


if __name__ == "__main__":
    main()

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

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

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

ans = 0
for j in range(k, n + 2):
    small = cum[j]
    big = cum[n + 1] - cum[n - j + 1]
    ans += big - small + 1
    ans %= mod

print(ans % mod)

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

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

print(count % mod)

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

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

mod = 10**9+7
ans = 0

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

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

Solution (Python):
from sys import stdin
import numpy as np
mod = 10**9+7
N,K = [int(x) for x in stdin.readline().rstrip().split()]
l = np.cumsum(range(0,N+1))
r = np.cumsum(range(N,-1,-1))
ans = 0
for k in range(K,N+2):
    ans += (r[k-1] - l[k-1] + 1)
    ans %= mod
print(ans%mod)

Solution (Python):

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

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

Solution (Python):
t = input().split( )
n = int(t[0])
k = int(t[1])

mod = int(1e9+7)

x = int((k-1)*k*(2*k-1)/6)
y = int((n+1)*(n+2)*(2*n+3)/6)
z = int((n+1)*(n+k+1)*(n-k+2)/2)
w = int(n-k+2)

print(int((x-y+z+w)%mod))

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

Solution (Python):
import itertools
def readInt():
    return list(map(int,input().split()))
n, k = readInt()
ans = 0

for i in range(k,n+2):
    smallest = (i-1)*i /2
    largest = n*(n+1)/2 - (n-i)*(n-i+1)/2
    ans += int(largest - smallest + 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):
    x=(n*(n+1)//2)%mod-((n-i)*(n-i+1)//2)%mod
    y=(i*(i-1)//2)%mod
    ans+=(x-y+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):
	l = (i - 1) * i // 2
	r = (2 * N - i + 1) * i // 2
	ans += r - l + 1
	ans %= mod

print(ans)

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

_mod = 10 ** 9 + 7

ans = 0


min0 = sum(range(0,k))
max0 = sum(range(n + 1 - k, n + 1))
cnt = max0 - min0 + 1
ans = cnt

for i in range(k+1 , n + 2):



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

Solution (Python):

import math

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

count = 0
max = 0
min = 0

for i in range(k):
    min += i
    max += n-i

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

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

Solution (Python):
def main():
    mod = 1000000007
    n, k = (int(x) for x in input().split())
    l = (i for i in range(n + 1))  

    
    former = 0
    acm = tuple((former:= former + i) for i in range(n + 1))
    former = 0
    acm_rev = tuple((former:= former + i) for i in range(n, -1, -1))

    ans = 0
    
    
    for j in range(k-1, n + 1):
        ans += acm_rev[j] - acm[j] + 1
        ans %= mod
    return ans


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

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

ret = 0

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

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

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

def intinp():
    return int(input())

N, K = mapint_inp()
MOD = 10**9+7

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

print(ans%MOD)

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

Solution (Python):


MOD = int(1e9 + 7)


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


def main():
    ans = 0
    s = N * (N + 1) // 2
    for i in range(K, N + 2):
        a = i * (i - 1) // 2
        b = s - (N - i) * (N - i + 1) // 2
        ans = (ans + b - a + 1) % MOD

    print(ans)


if __name__ == "__main__":
    main()