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



Sample input:
3 2


Sample output:
10

Submission status: Accepted

Solution code:
import itertools

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

def calc(i):
    small = i * (i - 1) //2
    large = i * (2 * N - i + 1) // 2
    return large - small + 1

total = 0
for i in range(K, N+2):
    total += calc(i)
    total %= mod

print(total)

Submission status: Accepted

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

Submission status: Accepted

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

list = list(range(N+1))
t = 10**9+7
result = 0

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

print(result%t)

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

MOD = 10 ** 9 + 7

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

print(counter)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
ans=0
for i in range(K,N+2):
    saidai=(N+N-i+1)*i//2
    saisyou=(i-1)*i//2
    ans+=saidai-saisyou+1

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

Submission status: Accepted

Solution code:
import itertools
import numpy as np

n, k = map(int, input().split())
l = range(n+1)
T = [0]*(n+1)
T[0] = 0
for i in range(n):
     T[i+1] = T[i] + (i+1)

count = 0
for i in list(range(k,n+1)):
    count = count + (T[n]-T[n-i]) - T[i-1] + 1
count = count + 1
print(count%(10**9+7))

Submission status: Accepted

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

low = high = 0
ans = 0
for i in range(K, N+2):
  low = i*(i-1)//2  # i個取った時の和の最小値
  high = i*(2*N - i + 1)//2  # i個取った時の和の最大値
  ans += (high - low + 1)  # i個取った時の和の場合の数
  ans %= MOD
  
print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys
    input=sys.stdin.readline
    mod=10**9+7
    n,k=map(int,input().split())
    ans=0
    for x in range(k,n+2):
        ans=(ans+x*(n-x+1)+1)%mod
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
x=0
while K<=N+1:
    x+=K*N-K**2+K+1
    K+=1
print(x%1000000007)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
#kがことなると和はことなる
t=10**9+7
sum=0
for i in range(k,n+2):
    x=(n*i-i*(i-1)+1)%t
    sum+=x

print(sum%t)

Submission status: Accepted

Solution code:
N, K = [int(a) for a in input().split()]
numbers = list(range(0, N+1))
MOD = 1000000007

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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

Submission status: Accepted

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

Submission status: Accepted

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

res = 0
for m in range(k,n+2):
    sum_min = m*(m-1)//2
    sum_max = m*(2*n-m+1)//2
    cnt = sum_max - sum_min + 1
    res += cnt
    res %= 10**9+7
print(res)

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

n,k = map(int,input().split())
ans = 0
d = [i for i in range(n+1)]
for i in range(k,n+2):
    l = (d[i-1])*(d[i-1]+1)//2
    r = (n)*(n+1)//2 - (n+1 - i-1)*(n+2-i-1)//2
    ans += r-l +1
print(ans%MOD)

Submission status: Accepted

Solution code:
# しゃくとり

mod = 10**9 + 7

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

cnt = 0
sum_ = sum(range(n + 1))
#print("sum", sum_)
#print(list(range(n + 1)))
max_ = sum(range(n - k + 1, n + 1))
min_ = sum(range(k))
for i in range(k, n+2):
    #print(max_, min_, cnt)
    cnt += max_ - min_ + 1
    cnt %= mod
    #print(cnt)
    
    if n > i + 1:
        max_ +=  n - i
    else:
        max_ = sum_
    min_ += i
print(cnt)

Submission status: Accepted

Solution code:
mod = 10**9 + 7

n,k = map(int,input().split())
tot = []
cur = 0
for i in range(n+1):
    cur += i
    tot.append(cur)

cnt = 0
for i in range(k, n+2):
    if n > i:
        max_ = tot[n] - tot[n - i]
    else:
        max_ = tot[n]
    min_ = tot[i - 1]
    cnt += max_ - min_ + 1
    cnt %= mod
print(cnt)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,k=map(int,input().split())
    ans=0
    for x in range(k,n+2):
        ans+=(1+((n*(n+1)//2-(n-x)*(n-x+1)//2)/x-(x*(x-1)//2)/x)*x)%(10**9+7)
    print(int(ans)%(10**9+7))

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
n = [i for i in range(N+1)]
M,m = sum(n[-K:]),sum(n[:K])
c = M-m+1
for i in range(K+1,N+2):
  M += n[-i]
  m += n[i-1]
  c += (M-m+1)
print(c%(10**9+7))

Submission status: Accepted

Solution code:
import numpy as np
import functools
import math
import collections
import scipy
import fractions
import itertools

def solve():
    n, k = map(int, input().split())
    small = 0
    large = 0
    ans = 0
    mod = 10**9+7
    for i in range(0, n+1):
        small += i
        large += n-i
        if i+1 >= k:
            ans = (ans + (large - small + 1)) % mod
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
p = (10**9)+7
ans = []
for i in range(k,n+2):
    a = i*(i-1)//2
    b = i*(2*n-i+1)//2
    ans.append(b-a+1)
print(sum(ans)%p)

Submission status: Accepted

Solution code:
MOD = 10**9+7
n,k = 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

print(ans%MOD)

Submission status: Accepted

Solution code:
N,K=list(map(int,input().split()))
ans=0
for k in range(K,N+2):
  M=k*N-k*(k-1)//2
  m=k*(k-1)//2
  ans+=M-m+1

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

Submission status: Accepted

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

Submission status: Accepted

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

r = 0

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

print(int(r) % (pow(10, 9) + 7))

Submission status: Accepted

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

mod=10**9+7

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

ans+=1
print(ans)

Submission status: Accepted

Solution code:
def find(N):
    ans = [0]*(N+2)
    pre = [0]*(N+2)
    suf = [0]*(N+2)
    temp = 0
    for i in range(N+1):
        temp += i
        pre[i+1] = temp
    
    for i in range(N+1,0,-1):
        suf[i] = temp
        temp -= (N+1-i)
    
        
    
    
    for i in range(1,N+2):
        ans[i] = suf[i] - pre[i] + 1
#     print(pre)
#     print(suf)
#     print(ans)
    return ans

def find_ans(N,K):
    ans = find(N)
    real_ans = 0
    for i in range(K,N+2):
        real_ans += ans[i]
    return real_ans

N,K = list(map(int,input().strip().split()))
print(find_ans(N,K)%(10**9+7))

Submission status: Accepted

Solution code:
#ABC163d
n, k = input().split()
n = int(n)
k = int(k)

mod = 10**9 + 7
# s = (10**100%mod)*(k%mod) # 10**100*kをmod化
ips = []
for i in range(k,n+2):
    t = i*n - (i-1)*i + 1
    ips.append(t)
print(sum(ips)%mod)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect


def choice(n, k):
    #print('n, k') # debug
    #print(n, k) # debug
    max_value = ((n - k + 1) + n) * k // 2
    min_value = (0 + (k - 1)) * k // 2
    c = max_value - min_value + 1
    #print('max_value, min_value, c') # debug
    #print(max_value, min_value, c) # debug
    return c

if __name__ == '__main__':
    n, k = list(map(int, input().split()))
    ans = 0
    for kk in range(k, n + 1 + 1):
        ans += choice(n, kk)
    mod = 10 ** 9 + 7
    print(ans % mod)

    #print('\33[32m' + 'end' + '\033[0m') # debug

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
answer=0
count=N-K+2
for y in range(K,N+2):
    min=int(y*(0+y-1)/2)
    max=int(y*(N-y+1+N)/2)
    answer+=(max+1-min)
print(answer%(10**9+7))

Submission status: Accepted

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

    num = 10*100
    nums = [num + i for i in range(0, n+1)]

    # sums = []
    total = 0
    for i in range(k, n+2):
        _min = int((nums[0]+nums[i-1])*(nums[i-1]-nums[0]+1)/2)
        _max = int((nums[-i]+nums[-1])*(nums[-1]-nums[-i]+1)/2)

        total += _max - _min + 1

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import itertools
from collections import defaultdict
import collections
mod = 1000000007
n, k = map(int, input().split())

s = [i for i in range(n + 1)]
cumsum = itertools.accumulate(s)
cumsum = list(cumsum)

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

print((ans + 1) % mod)

Submission status: Accepted

Solution code:
bg=input().split()
n=int(bg[0])+1
k=int(bg[1])

s=0
for a in range(k,n+1):
  
  max=((n-a)*a)+1
  s+=max
  
print(s%((10**9)+7))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import math

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

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

print(ans)

Submission status: Accepted

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

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

mod = 10**9 + 7
count = 0

for n in range(K, N+2):
	max = sumLR(N-n+1, N)
	min = sumLR(0, n-1)
	count += max - min + 1
	count %= mod
print(count)

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    n, k = map(int, stdin.readline().split())
    mod = 10 ** 9 + 7

    ans = 0

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

    print(ans % mod)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
from itertools import accumulate
from operator import add, mul

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

l = np.arange(N+1)
L = l.tolist()
L = accumulate(L, add)
L = list(L)

rev_L = reversed(l)
rev_L = accumulate(rev_L, add)
rev_L = list(rev_L)
ans = 0

for i in range(N+2-K):
  min_sum = L[K-1+i]
  max_sum = rev_L[K-1+i]
  ans += max_sum - min_sum + 1
  q, mod = divmod(ans, 10**9+7)

print(mod)

Submission status: Accepted

Solution code:
import itertools

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

def solve(a, b):
    c = (b + a) * (b - a + 1) // 2
    return c

ans = 0
x = n
while x >= k - 1:
    a = solve(0, x)
    b = solve(n - x, n)
    ans += b - a + 1
    ans = ans % MOD
    x -= 1
print(ans)

Submission status: Accepted

Solution code:
# 選ぶ数で場合わけすれば良い

N, K = map(int, input().split())
A = list(range(N+1))
M = 10 ** 9 + 7

mini = sum(A[0:K])
most = sum(A[-K:])
# first_count = most -mini + 1
count = most - mini + 1

for i in range(K, N+1):
    most +=  A[-(i+1)]
    mini += A[i]
    count += (most- mini + 1)

print(count % M)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
x = [0]*(N+2)
x[1] = 1
ans = 0
for i in range(2,N+2):
  x[i] = i + x[i-1]
for k in range(K,N+2):
  small = x[k]
  big = x[N+1] - x[N-k+1]
  ans += big - small + 1

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

Submission status: Accepted

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

Submission status: Accepted

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

mod = 10**9+7
count = 0
for i in range(k, n+2):
  maxsum = (i*(n+n-i+1))//2 #組み合わせの最大値
  minsum = (i*(i-1))//2 # 組み合わせの最小値
  count += maxsum - minsum +1
  count %= mod 
print(count)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
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 list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,k = LI()
    r = 0
    for i in range(k,n+2):
        t = (0+(i-1)) * i // 2
        u = ((n-i+1)+n) * i // 2
        r += u - t + 1
        r %= mod

    return r


print(main())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
back = []
forward = []
a = 0
b = 0
for i in range(n + 1):
    a += i
    b += n - i
    forward.append(a)
    back.append(b)
ans = 0
for i in range(k, n + 1):
    ans += back[n - i] - forward[n - i] + 1
ans = (ans + 1) % (10 ** 9 + 7)
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')


def solve():
    n, k = MI()
    B = [i for i in range(n+1)]
    # print(B)
    mod = 1000_000_007
    def f(l, r):
        return (r + l) * (r - l + 1) // 2

    ans = 0
    for i in range(k, n+2):
        # print(B[0], B[i-1], B[n-i+1], B[-1])
        _min = f(B[0], B[i-1])
        _max = f(B[n-i+1], B[-1])
        # print('  ', _min, _max, _max - _min + 1)
        ans = (ans + _max - _min + 1) % mod
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
cnt = 0
MOD = 1000000007
for i in range(k, n+2):
    left = i*(i-1)//2
    right = i*(2*n-i+1)//2
    add = right - left + 1
    cnt = (cnt+add)%MOD
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, K: int):
    seq = list(range(N + 1))
    cumsum = [0] * (N + 2)
    for i in range(N+1):
        cumsum[i+1] = cumsum[i] + seq[i]
    c = [0] * (N + 2)
    for i in range(1, N + 2):
        #[N + 1 - i, N+1) - [0, i)
        c[i] = (cumsum[N+1] - cumsum[N+1-i] - cumsum[i] + 1) % MOD
    print(sum(c[K:]) % MOD)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
"""
B=10**100
とすると、Bが非常に大きいので、B,B+1,B+2,,,B+Nの中でK個選んだ時のKが違えば、K個の値の和は必ず違う値になる
従ってKを固定した時、1,2,3,,,Nの中でK個選んだ時の総和が何通りあるかを求めれば良い

SはK以上N+1以下の値をとるものとする
総和を最小にするには、左からS個取れば良い
min L = 0+1+2+...+S-1
総和を最大にするには、右からS個取れば良い
max R = (n-S+1)+...+n
LからRの間の数は全て作れるので、Sを固定したときに取り得る値はR-L+1通りある

左端l、右端rの公差1の等差数列の和は
(l+r)*(r-l+1)/2
"""

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
N,K = [int(i) for i in readline().split()]

ans = 0

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

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

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

Submission status: Accepted

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

num_list = list(range(n+1))
num_list2 = num_list[::-1]
MOD = 10**9 + 7

a = sum(num_list[0:k])
b = sum(num_list2[0:k])
ans = b - a + 1

for i in range(k, n+1):
    a += num_list[i]
    b += num_list2[i]
    ans += b - a + 1

print(ans%MOD)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
x=[i for i in range(n+1)]
ans=0
xmin=0
xmax=0
for i in range(len(x)):
    xmin+=x[i]
    xmax+=x[-i-1]
    if i>=k-1:
        ans+=xmax-xmin+1


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

Submission status: Accepted

Solution code:
import math
import itertools

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

all_combination = 0
for num in range(K, N + 2): # 選ぶ個数を1 から N + 1個までずらす
    min = (0 + num - 1) * num / 2
    max = (N - (num - 1) + N) * num / 2
    possiblility = (int(max) - int(min) + 1)
    all_combination += possiblility

print(all_combination % (1000000007))

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
from math import sqrt, ceil, floor
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

N, K = Is()

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

print(ans % MOD)

Submission status: Accepted

Solution code:
def main():
  mod = 10**9 + 7
  n, k = map(int, input().split(' '))
  A = list(range(n+1))
  A_rev = A[::-1]
  cumsum_A = [0]
  cumsum_A_rev = [0]
  for i in range(len(A)):
    cumsum_A.append(A[i]+cumsum_A[i])
    cumsum_A_rev.append(A_rev[i]+cumsum_A_rev[i])
  ans = 0
  
  for i in range(k, n+2):
    tmp_min = cumsum_A[i]
    tmp_max = cumsum_A_rev[i]
    ans += (tmp_max - tmp_min + 1)
  print(ans%mod)
    

if __name__ == '__main__':
  main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# D - Sum of Large Numbers

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

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

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

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

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

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

print(res)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
mod = 10**9+7
sum_min = 0
sum_max = 0
diff = 0
while K != N+2:
    sum_min = 1/2*K*(K-1)
    sum_max = 1/2*K*(2*N-K+1)
    diff += sum_max - sum_min+1
    K+= 1
diff = diff % mod
print(int(diff))

Submission status: Accepted

Solution code:
# print('input >>')
N, K = map(int,(input().split()))

MOD = 10**9+7

# print('-----output-----')
ans = 0
for n in range(K, N+2):
    max_ = n * (N-n+1 + N) // 2
    min_ = n * (0 + n-1) // 2
    # print(n, max_, min_)
    ans += max_ - (min_ -1)

print(ans % MOD)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
for i in range(k,n+2):
    mini=i*(i-1)//2
    maxi=mini+i*(n-i+1)
    ans+=int(maxi-mini+1)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

A = list(range(N+1))
ans = 1
left = A[:K]
right = A[-K:]
nextleft = left[-1]
nextright = right[0]
left = sum(A[:K])
right = sum(A[-K:])
for i in range(K, N+1):
    ans += right - left + 1
    nextleft += 1
    nextright -= 1
    left += nextleft
    right += nextright
print(ans%(10**9+7))

Submission status: Accepted

Solution code:
#D
import itertools
n, k = map(int, input().split())
max_num = min_num = 0

for i in range(k):
    max_num += n - i
    min_num += i
ans = max_num - min_num + 1

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

Submission status: Accepted

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

mod_num = 10**9 + 7
first = [i for i in range(n+1)]
last = [i for i in range(n, -1, -1)]
for i in range(1, n+1):
    first[i] += first[i-1]
    last[i] += last[i-1]

result = 0
for i in range(k-1, n+1):
    result += (last[i] - first[i] + 1)
print(result%mod_num)

Submission status: Accepted

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

Submission status: Accepted

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

mod = 10 ** 9 + 7

total = 0
for num in range (k, n + 1):
    first = num * (num - 1) // 2 # 最小の整数
    last = (2 * n - num + 1) * num // 2 # 最大の整数
    add = last - first + 1 # 整数の数
    total = (total + add) % mod

print(total + 1)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.readline
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 10 ** 9 + 7

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

k = np.arange(K, N + 2, dtype=np.int64)
low = (k - 1) * k // 2
high = N * k - low
cnt = high - low + 1
print(cnt.sum() % MOD)

Submission status: Accepted

Solution code:
# Problem D - Sum of Large Numbers

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

# initialization
mae_list = [i for i in range(N+1)]
ushiro_list = [i for i in range(N, -1, -1)]
ans = 0
MOD = 10**9 + 7

# count
for i in range(1, N+1):
    mae_list[i] += mae_list[i-1]
    ushiro_list[i] += ushiro_list[i-1]

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

# output
print(ans%MOD)

Submission status: Accepted

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

mod = 10 ** 9 + 7

ans = 0
for i in range(k, n + 2):
    # 等差数列の和 項数*(初項+末項)/2
    min = i * (0 + (i - 1)) // 2
    max = i * ((n - (i - 1)) + n)  // 2
    ans += (max - min) + 1
    ans %= mod
    
print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate

mod = 10**9 + 7

n, k = map(int, input().split())
a = list(accumulate(range(0, n+2)))

ans = 0
for m in range(k, n+2):
    min_num = a[m] - a[0]
    max_num = a[-1] - a[-(m+1)]
    ans += (max_num - min_num) + 1
print(ans % mod)

Submission status: Accepted

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

count = 0
for m in range(K, N+2):
    #print(N, m)
    ans = m * N - (m * (m - 1) - 1)
    #print(ans)
    if ans > 0:
        count += ans

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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