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

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

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

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

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

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

print(ans)

Solution (Python):
from sys import stdin


def get_result(data):
    N, K = data
    mod = 10**9+7
    e_val = [i for i in range(N+1)]
    
    e_cumsum = [0]
    for i in range(N+1):
        e_cumsum.append(e_cumsum[i] + e_val[i])
    ans = 0
    for r in range(K, N+2):
        min_val = e_cumsum[r]
        max_val = e_cumsum[N+1] - e_cumsum[N+1-r]
        ans += (max_val - min_val + 1) % mod
    return ans % mod


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)

Solution (Python):

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

    increments = []

    for i in range(N+1):
        increments.append(i)

    accumulation = [0]*(N+2)
    accumulationReverse = [0]*(N+2)

    for i in range(0, N+1):
        accumulation[i+1] = accumulation[i] + increments[i]
        accumulationReverse[i+1] = accumulationReverse[i] + increments[N-i]

    ans = 0

    for i in range(K, N+2):
        ans += accumulationReverse[i]-accumulation[i] + 1

    print(ans % mod)


if __name__ == "__main__":
    solve()

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


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

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy


from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd

sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

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

if __name__ == "__main__":
    main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    from math import factorial
    mod = 10**9 + 7
    N, K = map(int, input().split())
    ans = 0
    for i in range(K, N+2):
        ans += i * ((2 * N + 1) - i) // 2 - i * (i - 1) // 2 + 1 
        ans %= mod
    print(ans%mod)


if __name__ == '__main__':
    main()

Solution (Python):
s = input().split()
N = int(s[0])
K=int(s[1])
MOD = 1000000007
res=0
M = N+1
L = K-1
res = M*(M*M+5)/6 + L*(L*L*2+L*3-5-M*(L+1)*3)/6
print(int(res%MOD))

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

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

print(counter)

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

Solution (Python):
n,k = map(int,input().split())
a = [i for i in range(n)]
cnt = 0
for m in range(k,n+2):
    amin = (m*(m-1))/2
    amax = (n*(n+1))/2 - (n-m)*(n-m+1)/2
    cnt += amax-amin+1
print(int(cnt%(1e9+7)))

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

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

ans = 0
mod = (10**9)+7
for i in range(K, N+2):
    min_sum = S(i-1)
    max_sum = S(N) - S(N-(i))
    ans += max_sum - min_sum + 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):
    num = ((n*(n+1)-(n-i+1)*(n-i)-(i-1)*i)//2+1)%mod
    ans = (ans+num)%mod

print(ans)

Solution (Python):
n, k = map(int, input().split())
ans = 0
for i in range(k, n+2):
    a = 0.5*i*(i-1)
    b = 0.5*n*(n+1)-0.5*(n-i)*(n-i+1)
    ans += int(b-a+1)

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

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

z=0

zz = ((N-K+1)+N)*K//2 - (0+(K-1))*K//2 + 1
zz = zz % mod

for x in range(K+1, N+3):

  z = (z + zz) % mod
  zz += (N-x+1) - (x-1)
  zz = zz % mod

print(z)

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

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

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

a = [0] * (n + 1)
for i in range(n + 1):
    temp = (n * 2 - i) * (i + 1) // 2 - i * (i + 1) // 2 + 1
    a[i] = temp % mod
b = a[k - 1:]
print(sum(b) % mod)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

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

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

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

print(int(fin))

Solution (Python):
'''
「異なる個数を選んで足した場合、それらが一致することは絶対にない」
N=5, k=3のとき、最小の数 3 から、最大の数 12 まで「連続する整数を作ることができる」
k 個足してできる最小の整数を求める (a とする)
k 個足してできる最大の整数を求める (b とする)
出来上がる整数は b−a+1 個である
'''
N, k = map(int, input().split())
ans = 0
MOD = 10**9+7
for i in range(k, N+2):
  minNum = i*(i-1)//2 
  maxNum = i*(2*N-i+1)//2 
  ans += maxNum - minNum + 1
print(ans%MOD)

Solution (Python):
import sys


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

MOD = 10**9 + 7
a = [i for i in range(n+1)]

ans = 0
for i in range(k, n+2):
    first = i * (a[0] + a[i-1]) / 2
    last = i * (a[-i] + a[-1]) / 2
    ans += last - first + 1
print(int(ans%MOD))

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

def main():
   N, K = map(int, input().split()) 
   NUM = [i for i in range(N+1)]
   LOWER = 0
   UPPER = 0
   CNT = 0
   for j in range(K):
       LOWER += NUM[j]
       UPPER += NUM[N-j]
   for i in range(N+1):
       if i + K >= N+1:
           CNT += 1
           break
       CNT += UPPER -LOWER + 1
       LOWER += NUM[K+i]
       UPPER += NUM[N-(K+i)]
   print(CNT%((10**9)+7))

if __name__ == '__main__':
    main()

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

Solution (Python):



import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    md = 10**9+7
    mx, mi, ret = 0, 0, 0
    for k in range(1, N+2):
        mx += N-k+1
        mi += k-1
        ret += ((mx - mi + 1)*(k>=K))%md
    print(ret%md)

if __name__ == '__main__':
    main()

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

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



for i in range(k,n+2):
    min_wa=r[i]
    max_wa=l[i]
    ans+=max_wa-min_wa+1
    
print(ans%INF)

Solution (Python):
def main():

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

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


    mini = sum(nums[0:K])
    maxx = sum(nums[-K:])


    for i in range(K, N + 1):
        total += maxx - mini + 1

        index = i + 1
        
        if (i == N):
            break
        else:
            mini += nums[index-1]
            maxx += nums[-index]

    total += 1
    ans = total % (10 ** 9 + 7)

    print(ans)

if __name__ == '__main__':
    main()

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

Sum = 0

for i in range(K, (N + 1) + 1):
    a = (((N - (i - 1)) + N) * i // 2) - ((i - 1) * i // 2) + 1
    
    Sum = (Sum + a) % 1000000007

print(Sum)

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

L = N + 1  

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

cusum = [0] * (L + 1)

for i in range(L):
  cusum[i + 1] = cusum[i] + table[i]

while K <= L:
  
  count += (cusum[L] - cusum[L - K]) - cusum[K] + 1
  count %= P
  K += 1

print(count)

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

S = [0]*(N+1)
S[0] = 0
for n in range(1,N+1):
    S[n] = S[n-1]+n

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

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

Solution (Python):

import sys
from collections import Counter
from itertools import permutations, combinations
from fractions import gcd
from math import ceil, floor
import bisect
sys.setrecursionlimit(10 ** 6)

def input():
    return sys.stdin.readline()[:-1]

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

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

if __name__ == '__main__':
    main()

Solution (Python):
n,k=map(int,input().split())
p=10**9+7
def S(x):
    return (x*(x-1))//2
c=n
ans=[c+1]+[0]*n
for i in range(1,n+1):
    c=(c+(n-i))%p
    ans[i]=(c-S(i+1)+1)%p
print(sum(ans[k-1:])%p)

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

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

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

for k in range(K, N + 2):
    p = tot[k]
    q = tot[-1] - tot[-(1 + k)]
    ans += q - p + 1
    ans %= MOD

print(ans)

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

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


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

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

print(answer)

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


dxdy=((1,0),(0,1))

def pin(type=int):
    return map(type,input().rstrip().split())



def resolve():
    N,K=pin()
    sita=0
    ue=N
    
    ans=0
    for k in range(1,N+2):
        if k>=K:ans=(ans+(ue-sita+1))%1000000007
        sita+=k;ue+=N-k
    print(ans)
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 2"""
        output = """10"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """200000 200001"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """141421 35623"""
        output = """220280457"""
        self.assertIO(input, output)


if __name__ == "__main__":
    

    

    resolve()

Solution (Python):
n, k = map(int, input().split())
mod = 10 ** 9 + 7
ans = 1
for i in range(k, n+1):
    ans += i*n - i*(i-1) + 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):
  maxV = (N + (N - k + 1)) * k // 2
  minV = ((k - 1) * k) // 2
  ans += (maxV - minV + 1)
  ans %= DIV
  
print(ans)

Solution (Python):
n, k = map(int, input().split())
lst = list(range(0, n + 1))
reversed_lst = list(reversed(lst))
mod = 10 ** 9 + 7

min_lst = sum(lst[:k])
max_lst = sum(reversed_lst[:k])
ans = max_lst - min_lst + 1

while k <= n:
    min_lst += lst[k]
    max_lst += reversed_lst[k]
    ans += max_lst - min_lst + 1
    k += 1
    
print(ans % mod)

Solution (Python):
a=input().split()
N=int(a[0])
K=int(a[1])
count=int((1/2)*N*(N+1)*(N+1)-(N*(N+1)*(2*N+1))/6+N-(1/2)*(N+1)*K*(K-1)+(K*(K-1)*(2*K-1))/6-(K-1)+1)
print(count%(10**9+7))

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

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

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

MOD = 10**9+7
cnt = 0

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

print(cnt)

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

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

MOD = 10 ** 9 + 7


def calc(i):
    init = i * (i + 1) // 2
    last = init + (N - i + 1) * i
    return last - init + 1


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

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

pattern = 0

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

print(pattern)

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



def in_int():
    return (int(input()))


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


def in_str():
    s = input()
    return (list(s[:len(s) - 1]))


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

mod = 7 + 10**9

n, k = in_ints()

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


print(ans)

Solution (Python):
N, K = map(int, input().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())
ans = 0
mod = 10**9+7
for i in range(k,n+2):
  min = (i**2-i)//2
  max = (2*n-i+1)*i//2
  ans += max-min+1
print(ans%mod)

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

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

ans = 0
mx = 0
mn = 0

for i in range(N+1):
  mx += N-i
  mn += i
  if i + 1 >= K:
    ans += (mx - mn + 1) % INF

print(ans % INF)

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

cnt = 0
buf2_min = 0
buf2_max = 0
buf_max = 0
buf_min = 0

for j in range(k):
    buf2_max += n - j
    buf2_min += j

buf_max = n - k + 1
buf_min = k - 1

for i in range(n - k + 2):
    cnt += buf2_max - buf2_min + 1
    buf_max -= 1
    buf_min += 1
    buf2_max += buf_max
    buf2_min += buf_min
cnt  = cnt % (10**9 + 7)

print(cnt)

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

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

ans = 0
mx = 0
mn = 0
for i in range(N+1):
  s = 0
  mx += N-i
  mn += i
  if i + 1 >= K:
    ans += (mx - mn + 1) % INF

print(ans % INF)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n, k = map(int,input().split())
    res = 0
    for i in range(k, n + 1):
        
        
        low = (0 + (i - 1)) * i // 2
        high = (n + (n - i + 1)) * i // 2
        res += high - low + 1
        res %= MOD
    res += 1
    res %= MOD
    print(res)
resolve()

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

solution()

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

Solution (Python):
import itertools

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


















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

print(int(result))

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

solution()

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

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

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

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

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

Solution (Python):
n, k = map(int, input().split())
MOD = 1e9+7

def s(i,n):
    s1 = (2 * i * i)
    s2 = (3 * n * (i+1)) 
    s3 = 8

    d = (s2 + s3 - s1)

    ans = ( int((i * d)/6 + 0.5) )
    
    return ans

ans = int(s(n+1,n) - s(k-1,n)) % MOD
if ans < 0:
    ans += MOD

print(int(ans))

Solution (Python):



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

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

for i in range(1, len(accum)):
    accum[i] += accum[i-1] 
accum = [0] + accum

backs = [i for i in range(N,-1,-1)]
cnt = [0] * (N+1)

tmp = 0
for i in range(N+1):
    tmp += backs[i]
    cnt[i] = tmp + 1 - accum[i]

ans = 0
for num in cnt[K-1:]:
    ans += num
    ans %= MOD

print(ans)

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

Solution (Python):
import itertools
import math
from functools import reduce

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

pattern = 0

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

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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

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

Solution (Python):
import heapq
import math
import random
import sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, namedtuple, UserDict
from functools import cmp_to_key, lru_cache, reduce
from itertools import (chain, combinations, combinations_with_replacement,
                       permutations, product)

sys.setrecursionlimit(10**6+1)
write = sys.stdout.write


MOD = 10**9 + 7


if __name__ == "__main__":
    n, k = map(int, input().split())
    head = sum(i for i in range(k))
    tail = sum(n-i for i in range(k))
    ans = tail - head + 1
    for i in range(k, n+1):
        head += i
        tail += n - i
        ans += tail - head + 1
        ans %= MOD
    print(ans)

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

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

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

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



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

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
ans = 0

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

Solution (Python):
from math import comb as c
a,b=map(int,input().split())
print(((c(a+2,2)+1)*(a+2-b)-c(a+3-b,3)-c(a+3,3)+c(b+1,3))%(10**9+7))

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

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

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

mod = 10 ** 9 + 7
ans = 0

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

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

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

print(ans%mod)

Solution (Python):
n,k=map(int,input().split())
print(((n**3+3*n*n+3*n*k+8*n-3*n*k*k+2*k**3-2*k)//6-k*k+2)%(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) % (10 ** 9 + 7)


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

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

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

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

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

if K > N:
    print(1)
    exit()

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

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


res = (res + 1) % (10 ** 9 + 7)

print(res)

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

mod = 10**9 + 7
n_list = [0]*(n+1)
for i in range(n+1):
    n_list[i] = (10**100 + i) % mod

s = [0]*(n+1)
s[0] = n_list[0]

for i in range(1, n+1):
    s[i] = (s[i-1] + n_list[i]) % mod


count = 0
for i in range(k, n+1):
    min_sum = s[i-1] % mod
    max_sum = (s[n] - s[n-i]) % mod
    m = (max_sum - min_sum) + 1 % mod
    count += m
count += 1  
print(count % mod)

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

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

mo = 1000000007

ans = 0

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

print(ans)

Solution (Python):

N, K = map(int, input().split())
ans = 0
mod = 10**9 + 7
vmin = 0
vmax = 0
L = [i for i in range(N+1)]
for i in range(N+1):
    vmin += L[i]
    vmax += L[-1-i]
    if i < K-1:
        continue
    ans += max(0, vmax - vmin+1)
    ans %= mod
print(ans)

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

N,K = map(int,input().split())
s = 0
for k in range(K, N+2):
	s = (s + N*k - k*k + k + 1) % MOD
print(s)

Solution (Python):
import math

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

b=0

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

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

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

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

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

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

print(ans % MOD)

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

ans = 0

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

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

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    a = [i for i in range(N+1)]
    s = [0] * (N+2)
    for i in range(N+1):
        s[i+1] = s[i] + a[i]
    ans = 0
    MOD = 10**9+7
    for i in range(K, N+2):
        ans += (s[-1]-s[-i-1]-s[i]+1) % MOD
    print(ans % MOD)
if __name__ == "__main__":
    main()

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

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

min_sum = 0
max_sum = 0
under_K = 0
ans = 0
for i in range(N+1):
    min_sum += i
    max_sum += N - i
    if i < K - 1:
        under_K += max_sum - min_sum + 1
    ans += max_sum - min_sum + 1
    
print((ans - under_K) % (10**9+7))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline

MOD = 10 ** 9 + 7


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


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

    ans = 0
    b = sum_up_to_n(N)
    for i in range(K, N + 2):
        a = sum_up_to_n(i - 1)
        aa = sum_up_to_n(N - i)
        ans += (b - aa) - a + 1
        ans = ans % MOD

    print(ans)


if __name__ == '__main__':
    main()

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

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

    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):

import numpy as np
import itertools
import time
n, k = list(map(int, input().split()))
MOD = 10 ** 9 + 7
result = 0
for x in range(k, n + 2):

    
    min_value = x*(x-1)//2
    max_value = (n + n-x+1)*x//2
    
    result += max_value - min_value + 1
print(int(result) % MOD)

Solution (Python):
a,b=map(int,input().split())
wa=lambda a,b:(a+b)*(b-a+1)//2
print(sum([wa(a+2-i,a+1)-wa(0,i)+1for i in range(b,a+2)])%(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 += int(n*(n+1)/2 - (n-i)*(n - i + 1)/2 - (i-1)*i/2 + 1)
 
print(ans%mod)

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