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

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

count = 0

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

print(int(count))

Solution (Python):
def input_one_number():
    return int(input())

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

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

mod = 10**9+7

N,K = input_multiple_number()

ans = 0

for i in range(N+1+1):
	if i < K:
		continue

	ans += ((N-i+1+N)*i//2-(0+i-1)*i//2+1)

print(ans%mod)

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

print(ans)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 15
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

x = pow(10, 100, mod)
ans = 0
n, k = LI()
for i in range(k, n + 2):
    ans += (n - (i - 1)) * i + 1
    ans %= mod

print(ans)

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

Solution (Python):
import sys
N, K = map(int, sys.stdin.readline().split())
cnt = 0
while K <= N+1:
  cnt += (2*N-K+1)*K//2 - (K-1)*K//2 + 1
  K += 1
print(cnt%(10**9+7))

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

ans = 0
NUM = 1000000007
for k in range(K, N+2):
    s_min = k * (k - 1) / 2
    s_max = k * (2 * N - k + 1) / 2
    c = (s_max - s_min) + 1
    ans += c
    ans %= NUM
print(int(ans))

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


if __name__ == '__main__':
    main()

Solution (Python):
n, k = 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
print(ans%(10**9+7))

Solution (Python):
import itertools

NN = 202020
MOD = 10**9+7

INF = float("inf")

n, k = map(int, input().split())
psum = list(itertools.accumulate([i for i in range(n+1)]))
rsum = list(itertools.accumulate([i for i in reversed(range(n+1))]))



ans = 0
for i in range(k, n+2):
    ans = (ans + rsum[i-1] - psum[i-1] + 1)%MOD
    
print(ans)

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

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

mod = 10**9 + 7
ans = 0

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

print(ans)

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

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

inv2 = pow(2, MOD-2, MOD)
nums = []
for i in range(N+3):
    num = i*(i+1)%MOD*inv2%MOD
    nums.append(num)
nums.append(0)


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

print(ans)

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

n,k = map(int, input().split())
count = 0
for i in range(n+1-k+1):
    j = k+i
    count += (((2*n-(j-1))*(j)//2 - (j-1)*(j)//2) + 1)
    count = count % mod
print(count)

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

for i in range(k,n+2):
    ma = dp[-1] - dp[len(dp)-i-1]
    mi = dp[i - 1]
    if i == n + 1:ma = dp[-1]
    ans += (ma - mi + 1) % mod
    ans %= mod
print(ans)

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

s = list(range(N + 1))
cumsum = [0] * (N + 1)
for i in range(1, N + 1):
    cumsum[i] = cumsum[i - 1] + s[i]

MOD = 10 ** 9 + 7
ans = 1
for k in range(K, N + 1):
    ans += (cumsum[-1] - cumsum[-k - 1]) - cumsum[k - 1] + 1
print(ans % MOD)

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

p = 10 ** 9 + 7
s = 0


for r in range(k, n + 2):
    min_val = (r - 1) * r // 2
    max_val = (n - r + 1 + n) * r // 2
    s += (max_val - min_val + 1)
    s %= p

print(s)

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

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

print(pattern)

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


ans = 0
for num_add in range(k, n+2):
	min_res = (0 + num_add-1) * num_add // 2
	max_res = (n-num_add+1 + n) * num_add // 2
	ans += (max_res - min_res + 1) % MODULO
	ans %= MODULO
	

print(ans)

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

print(ans%mod)

Solution (Python):

import sys

MOD = 1000000007  


def solve(N: int, K: int):
    s = 0
    for i in range(K, N+2):
        p = i*(N-i+1) + 1
        s += p
        s %= MOD
    print(s)
    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):
p=10**9+7
n,k=map(int,input().split())

ans=[0]*(n+2)
ans[0]=1

for i in range(1,n+2):
    mae=(i-1)*i//2
    usiro=(n*2-i+1)*i//2
    ans[i]=usiro-mae+1

kotae=0
for i in range(k,n+2):
    kotae+=ans[i]%p




kotae%=p
print(kotae)

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

def num_sum(i):
  return ((n+(n-i+1))*i//2)-((i-1)*i//2)+1

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

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

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

print(cnt)

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

print(s)

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

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

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

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

print(ans)

Solution (Python):


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

mod = 10 ** 9 + 7

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

print(ans)

Solution (Python):

''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    mod = 10**9 + 7
    n, k = _ia()

    ret = 0
    for ki in range(k, n+2):
        mi = (ki * (ki-1))//2
        ma = ((2*n-ki+1)*ki)//2
        ret += (ma-mi+1)
        ret %= mod
    return ret


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

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,k = na()
mod = 10**9+7

ans = 0

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

print(ans%mod)

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

MOD = 10**9+7
ans = 0

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

print(ans)

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

max_sum = 0
min_sum = 0


ans = 0
for i in range(0, N+1):
    max_sum += N-i
    min_sum += i 
    if i >= K-1:
        ans += (max_sum - min_sum + 1) % MOD
print(ans%MOD)

Solution (Python):

import sys
input = sys.stdin.readline
MOD = 10**9 + 7

n, k = map(int, input().split())
ans = 0
for i in range(n + 1):
    if i + 1 < k:
        continue
    diff = (2*n - i) * (i + 1) // 2 - i * (i + 1) // 2 + 1
    ans += diff 
    ans %= MOD
print(ans)

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

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

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

cnt = 0
for i in range(K, N + 2):
    a = S[i]
    b = S[N + 1] - S[N + 1 - i]
    cnt += b - a + 1
    cnt %= MOD

print(cnt)

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

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

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

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

print(ans)

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

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

for i in range(K,N+1):
    min += X[i]
    max += X[-1 * (i+1)]
    ans += max - min + 1
    ans %= mod
    
print(ans)

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

Solution (Python):
import sys, math
def input(): return sys.stdin.readline().strip()
mod = 10**9 + 7

def main():
    N, K = map(int, input().split())
    ans = 0
    for i in range(K, N + 2):
        val = N * i - i * (i - 1) + 1
        
        ans += val
        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+=(n+(n-i+1))*i//2-(i-1)*i//2+1
	ans%=mod
print(ans)

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

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

Solution (Python):


def submit():
    n, k = map(int, input().split())
    modp = 10 ** 9 + 7
    
    ans = 0
    for cur_k in range(k, n + 2):
        minsum = cur_k * (cur_k - 1) // 2
        maxsum = cur_k * (2 * n - cur_k + 1) // 2
        ans += maxsum - minsum + 1
        ans %= modp

    print(ans)


submit()

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

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

MOD = 10 ** 9 + 7

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

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


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

print(ans)

Solution (Python):
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


MOD = 10 ** 9 + 7


def main():
    N, K = map(int, input().split())
    ans = 0
    for k in range(K, N + 2):
        m = k * (k - 1) // 2
        M = k * (2 * N - k + 1) // 2
        a = (M - m + 1) % MOD
        ans += a
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

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

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

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

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

ans = 0

for i in range(k, n+2):
    M = i * (2*n+1-i) // 2
    m = i * (i-1) // 2
    ans += (M - m + 1) % p

print(ans % p)

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

Solution (Python):
n,k = map(int,input().split())
a = [i for i in range(n+1)]
b = []
x = 0
for i in range(n+1):
    x += i
    b.append(x)
MOD = 10**9 + 7

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

Solution (Python):



M = 1e+9 + 7


def main():
  N, K = map(int, input().split())
  count = 0
  minval = 0
  maxval = 0

  for i in range(1, N + 2):
    minval += i
    maxval += N - i + 2

    if i >= K:
      count = int((count + maxval - minval + 1) % M)

  print(count)


if __name__ == '__main__':
  main()

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

MOD = 10**9+7

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

Solution (Python):
import bisect
import collections
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62


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


def llmi(n):
    return [lmi() for _ in range(n)]


N, K = lmi()

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

ans = 0
for k in range(K, N + 2):
    
    max_val = _sum[-1] - _sum[max(0,N  - k)]
    min_val = _sum[k - 1]
    
    ans += max_val - min_val + 1
print(ans%ACMOD)

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

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

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

ans = 0
over = 0
down = 0
for i in range(N+1):
    over +=  N  - i
    down += i
    if i >= K-1:
        ans += over - down + 1
print(ans % (10 ** 9 + 7))

Solution (Python):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()
  ans=0
  for i in range(k,n+2):
    mn=i*(0+i-1)//2
    mx=i*(n-i+1+n)//2
    
    ans+=mx-mn+1
    ans%=mod

  return ans


print(main())

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

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

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

retval=0
min=sum(nums[:K])
max=sum(nums[-K:])

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

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

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

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

ans = 0
pre,suf = 0,0
for i in range(1,n+2):
    pre += i-1
    suf += n+1-i

    if i >= k:
        ans += suf-pre+1
        ans %= MOD

print(ans)

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

l = 0
ll = 0
r = n
rr = n

ans = 0
for i in range(1, n+2):
    
    if i >= k:
        ans = (ans + r-l+1) % mod
    ll += 1
    rr -= 1
    l += ll
    r += rr
    

print(ans)

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

MOD = 10**9 + 7
ans = 0

for c in range(k, n + 2):
  m = c * (c - 1) // 2
  M = c * (2 * (n + 1) - c - 1) // 2
  ans += M - m + 1
  ans %= MOD

print(ans)

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

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

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

MOD = 10 ** 9 + 7

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

print (ans)

Solution (Python):
MOD = int(1e9+7)


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


if __name__ == "__main__":
    main()

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

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

MOD = 10**9 + 7
MAX = n + 10
fact = [1] * (MAX + 1)  
finv = [1] * (MAX + 1)  
iinv = [1] * (MAX + 1)  
for i in range(2, MAX + 1):
    fact[i] = fact[i - 1] * i % MOD
    iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * iinv[i] % MOD


def comb(n: int, k: int) -> int:
    if n < k or n < 0 or k < 0:
        return 0
    return (fact[n] * finv[k] % MOD) * finv[n - k] % MOD


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

print(ans)

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

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict

con = 10 ** 9 + 7

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


def main():
	N, K = getlist()
	A = [0] * (N + 2)
	for i in range(1, N + 2):
		A[i] = i * (N - (i - 1)) + 1

	
	ans = 0
	for i in range(K, N + 2):
		ans += A[i]

	ans %= con
	print(ans)

if __name__ == '__main__':
	main()

Solution (Python):
from math import *
from collections import *
mod = 10**9 + 7
test = 1

for __ in range(test):
	n,k = map(int,input().split())
	mins = 0
	maxs = 0
	for i in range(k):
		mins += i
		maxs += n-i
		mins %= mod
		maxs %= mod
	ans = (maxs-mins+1)%mod
	if(ans < 0): ans += mod
	for i in range(k,n+1):
		mins += i
		maxs += n-i
		mins %= mod
		maxs %= mod
		ans = (ans+maxs-mins+1)%mod
		if(ans < 0): ans += mod
	print(ans)

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


main()

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

if __name__ == "__main__":
    main()

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


def sum_up_to(i,j) :
    MOD = int(1e9+7)
    return (( (i+j)*(j-i+1) )//2 ) % MOD

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

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

Solution (Python):
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N, K = read_values()
    
    res = 0
    for k in range(K, N + 2):
        res += (k * (N - k + 1) + 1) % mod
        res %= mod
    print(res)


if __name__ == "__main__":
    main()

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k = list(map(int, readline().split()))

    ans = 0
    s_min = 0
    s_max = 0

    for i in range(k - 1):
        s_min += i
        s_max += (n - i)

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

    print(ans)


if __name__ == '__main__':
    main()

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

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

    ans = (ans + (maxValue - minValue + 1)) % (10 ** 9 + 7)

print(int(ans))

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N, K = Scanner.map_int()
    ans = 0
    for i in range(K, N + 2):
        a = (i * (i - 1)) // 2
        b = N * i - a
        ans += b - a + 1
        ans %= MOD
    print(ans)


def main():
    
    solve()


if __name__ == "__main__":
    main()

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() 

def main():
    n,k = na()
    ans = 0
    mod = pow(10,9)+7
    for i in range(k,n+2):
        sum_min = i*(i-1)//2
        sum_max = i*(2*n-i+1)//2
        
        ans += (sum_max - sum_min + 1)
        ans %= mod
    print(ans%mod)
    return
if __name__ == '__main__':
    main()

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

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

Solution (Python):
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json

import bisect
import sys
import math
import bisect
from functools import lru_cache

sys.setrecursionlimit(10 ** 8)

MOD = 10 ** 9 + 7
INF = 10 ** 17


def main():
    
    N, K = [int(a) for a in input().split()]
    

    res = 0

    for k in range(K, N + 2):
        minv = k * (k + 1) // 2
        maxv = minv + (N + 1 - k) * k
        t = maxv - minv + 1
        res = (res + t) % MOD

    print(res)

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    


if __name__ == "__main__":
    main()

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

Solution (Python):

def inputlist(): return [int(k) for k in input().split()]

N,K = inputlist()
mod = 10**9+7
li = [int(i) for i in range(N+1)]
suma = [0]*(N+1)
for i in range(1,N+1):
    suma[i] = suma[i-1]+li[i]
ans = 0
for i in range(K,N+1):
    m = suma[i-1]
    M = suma[-1] - suma[-(i+1)]
    ans += M-m+1
    ans %= mod
ans +=1
ans %= mod
print(ans)

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

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

Solution (Python):


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

fst = 0
lst = N
ans = 0
mod = 10**9+7

for i in range(1,K):
    fst += i
    lst += N-i


for i in range(K,N+2):
    ans += lst-fst+1
    ans %= mod
    fst += i
    lst += N-i
    
print(ans)

Solution (Python):
import itertools

N, K = map(int, input().split())
MOD = 10**9 + 7
a = [i for i in range(N+1)]

ma = list(itertools.accumulate(a))
Ma = list(itertools.accumulate(a[::-1]))

ans = 1
for k in range(K, N+1):
    m = ma[k-1]
    M = Ma[k-1]
    ans += (M - m + 1) % MOD
    ans %= MOD

print(ans)

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

Solution (Python):
n,k=[int(_) for _ in input().split()]
mod=10**9+7
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
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*(2*N-i+1)//2
    ans -= i*(i-1)//2
    ans += 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//2 - i*(i-1)//2 + 1
    ans %= mod

print(ans)

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

print(ans)

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

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

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

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

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*(2*n-i+1)//2 - (i-1)*i//2 + 1
    ans %= mod

print(ans)