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:
#!/usr/bin/python3
# -*- coding: utf-8 -*-


import numpy as np
from itertools import accumulate


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

n = range(N+1)
# print((n + 10**100)%(10**9+7))

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

combi = np.array(range(N+1-(K-1)))+K
S = 0

minsum = list(accumulate(n))

maxsum = list(accumulate(n[::-1]))

for c in combi:
    # S += len(set(np.sum(np.array(list(itertools.combinations(n, c))),axis=1)))
    # itertools.combinations(n, c)
    min_num = (minsum[c-1]-1) % 1000000007
    max_num = maxsum[c-1] % 1000000007
    # print(min_num, max_num)
    if (max_num-min_num) < 0:
        S += ((max_num-min_num) + 1000000007)
    else:
        S += (max_num-min_num)
    S %= 1000000007
print(S)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))
def inpl_str():
    '''
    一行に複数の文字
    '''
    return list(input().split())

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

Submission status: Accepted

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

dp=[[0]*2 for i in range(n+1)] 
mod=10**9+7

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

mod=10**9+7

ksum=0
for kk in range(k-1,n+1):
    ksum=(ksum+dp[kk][1]-dp[kk][0]+1)%mod
print(ksum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def d():
    n, k = map(int, input().split())
    combination = [0] * (n+2)
    min = [0] * (n+2)
    max = [0] * (n+2)
    # print(min, max)

    # i個選ぶ場合、その合計値のパターン: 最大値〜最小値が1つずつ生成できるからそれ
    # min: 0, 1, 2, ..., i-1
    # max: n, n-1, n-2, ..., n+1-i
    for i in range(1, n+2):
        max[i] = max[i-1] + n+1-i
        min[i] = min[i-1] + i-1
        combination[i] = max[i] - min[i] + 1
        # print('i, min_i, max_i, cmb_i', i, min[i], max[i], combination[i])
        # print(min, max)

    mod = 10**9 + 7
    print(sum(combination[k:n+2]) % mod)


##########
if __name__ == "__main__":
    d()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0
for a in range(k, n+2):
    smallest = a*(a-1)//2
    largest = smallest + a*(n-a+1)
    ans += largest - smallest + 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 = [0] + list(accumulate(range(N + 1)))
B = [0] + list(accumulate(reversed(range(N + 1))))

print(sum(b - a + 1 for a, b in zip(A[K:], B[K:])) % mod)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
mod=10**9+7
l=[i for i in range(n+1)]
mi=sum(l[:k])
ma=sum(l[n+1-k:])
ans=(ans+ma-mi+1)%mod
for i in range(k+1,n+2):
    mi+=l[i-1]
    ma+=l[-i]
    ans=(ans+ma-mi+1)%mod
print(ans)

Submission status: Accepted

Solution code:
def usirowa(n, x):
    return x*(2*n - x + 1) // 2

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

cnt = 0
for i in range(k, n+2):
    cnt += usirowa(n, i) - i*(i - 1) // 2 + 1

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
mod=10**9+7
l=[i for i in range(n+1)]
mi=sum(l[:k])
ma=sum(l[n+1-k:])
ans=(ans+(ma-mi+1))%(10**9+7)
for i in range(k+1,n+2):
    mi+=l[i-1]
    ma+=l[-i]
    ans=(ans+(ma-mi+1))%(10**9+7)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import itertools

# スペース区切りの整数の入力
N, K = map(int, input().split())
# 文字列の入力
#s = input()
#print(s[0:K-1]+s[K-1].lower()+s[K:N])

#list = []
#for i in range(N+1):
#    list.append(i)

#print(list)

#print(range(N+1))

ans=0

i=K
while(i<=N+1):
    #print("i:"+str(i))
    #comb=combinationListRecursive(list, i)
    #comb = list(itertools.combinations(range(N+1), i))
    #print(comb)
    #tmp=[]
    #min=0
    #max=0
    #j=0
    #while(j<=i-1):
        #min = min+j
        #max = max+(N-j)
        #j=j+1
    max=((N-i+1+N)*i)/2
    min=((0+i-1)*i)/2
    #print("max:"+str(max))
    #print("min:"+str(min))
    #print("diff:"+str(max-min+1))
    ans=ans+(max-min)+1

    i=i+1


print(int(ans)%1000000007)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
#l = [i for i in range(n+1)]
ans = 0

for i in range(k,n+2):
#  MIN = sum(l[:i])
  MIN = i*(i-1)/2
  MAX = (n+1-i+n)*i/2
  ans +=(MAX-MIN+1)
  
print(int(ans%(10**9+7)))

Submission status: Accepted

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


#例）n=4
#10**100+0、10**100+1、10**100+2、10**100+3、10**100+4
#組み合わせる数をkkとすると
#kk=1
#10*100+（0+1+2+3+4)
#kk=2
#2*10**100 +(1+2+3+4+5+6+7)  ※1は小さいほうの組み合わせ0+1、7は大きいほうの組み合わせ3+4
#kk=3
#3*10**100 +(3+4+5+6+7+8+9) ※3は0+1+2、9は2+3+4
#kk=4
#4*10**100 +(6+7+8+9+10) 
#kk=5
#5*10**100 +(10)

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

result=0

mod=10**9+7


for i in range(k-1,n+1):
    #print(i)
    result=(result+upSum[i]-underSum[i]+1)%mod

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy
N, K  = map(int, input().split(' '))
right = 0
s = 0
for i in range(K, N+2):
    mi = (i-1)*i/2
    ma = (2*N-i+1)*i/2
    s += (ma - mi) + 1
print(int(s%(1e9+7)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def coun(n,r):
    return n*r+1+r-r**2

def sigma(func,frm,too):
    result=0
    for i in range(frm,too+2):
        #print(i)
        result=result+func(too,i)
        #print(result)
    print(result%mod)

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

sigma(coun,k,n)

Submission status: Accepted

Solution code:
def mul(a,b):
    mod=10**9+7 
    return ((a%mod)*(b%mod))%mod
def solve(n,k):
    mod=10**9+7
    i=n-k+2
    s=0
    for j in range(k,n+2):
        #print("Hello")
        s=(s%mod+mul(i-1,j)+1)%mod
        i-=1
    return s
n,k=map(int,input().split())
mod=10**9+7
print(solve(n,k)%mod)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
wa = [0]
for i in range(1,N+1):
    wa.append(wa[i-1] + i)
def func(k):
    a = wa[N] - wa[N-k] #12
    b = wa[k-1] #3
    #print(k,a,b,a-b+1)
    return a - b + 1
if N<K:
    print(1)
else:
    ans = 1
    for i in range(K,N+1):
        ans = (ans+func(i))%(10**9+7)
    print(ans)

Submission status: Accepted

Solution code:
class Ruisekiwa:
    def __init__(self,lst):
        s = 0
        self.r = [0]
        for i,_ in enumerate(lst):
            self.r.append(s+lst[i])
            s += lst[i]

    def query(self,a,b):
        #リスト内の半開区間[a,b)の総和
        return self.r[b] - self.r[a]

def main():
    mod = 10**9+7
    n,k = map(int,input().split())
    num_lst = list(range(n+1))
    ruisekiwa = Ruisekiwa(num_lst)
    answer = 0
    for i in range(k,n+2):
        mx = ruisekiwa.query(n-i+1,n+1)
        mn = ruisekiwa.query(0,i)
        #print(num_lst[:i],num_lst[-i:],mn,mx)
        answer += mx - mn + 1
        answer %= mod

    print(answer)




if __name__ == '__main__':
    main()

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 += k*(N-k+1)+1
print(ans%mod)

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
Cseq = [i for i in range(N+1)]
CCseq = [0]
for i in range(1,N+1):
    CCseq.append(Cseq[i] + CCseq[-1])
ans = 1
for i in range(K,N+1):
    ans += CCseq[-1]-CCseq[len(CCseq)-1-i]-CCseq[i-1]+1
print(ans % (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):
    l = i*(i-1)//2 
    r = i*(n-i+1+n)//2
    ans = (ans + r-l+1)%mod

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MOD = 10**9+7

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

min_list = [sum([i for i in range(K)])]
for i in range(K, N+1):
    min_list.append((min_list[-1]+i) % MOD)

max_list = [sum([N-i for i in range(K)])]
for i in range(K, N+1):
    max_list.append((max_list[-1]+N-i) % MOD)


count = 0
for i in range(len(min_list)):
    count = (count+(max_list[i]-min_list[i]+1)) % MOD

print((count) % MOD)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

n_li = list(range(n+1))

ans = 0

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

    ans += q - p + 1
    ans %= MOD
    k += 1

print(int(ans))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def MI(): return map(int, sys.stdin.readline().split())
if __name__ == "__main__":
    N, K = MI()
    result = 0
    mod = 10**9+7
    if N+1 == K:
        print(1)
    else:
        for i in range(K, N+2):
            result += i*(N-i+1)+1
        print(result%mod)

Submission status: Accepted

Solution code:
import sys
n,k = map(int,sys.stdin.buffer.read().split())
mod = 10**9+7
print(((n**3+3*n**2+8*n+2*(k-1)**3-8*(k-1)-3*(k-1)**2*n-3*(k-1)*n)//6+1) % mod)

Submission status: Accepted

Solution code:
# n= int(input())
# import math
# s =input()
n,k = map(int, input().split())
# a = list(map(int, input().split()))
# a,b = map(str, input().split())
# ab = [list(map(int,input().split())) for _ in range(n)]

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

Submission status: Accepted

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

Submission status: Accepted

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

calc = lambda x: x * (N-x+1) + 1

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

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

Submission status: Accepted

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


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

print(int(ans%1000000007))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
from scipy.special import comb

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

MOD = 10**9 + 7
ans = 0
lis = list(range(0,N+1))

for i in range(K,N+1+1):
    start = (i-1)*i//2
    end = N*i - start
    if end<=start:
        start,end = end,start
    num = end - start +1
    ans += num
ans %= MOD
print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
def sum2(nums):
    res = 0
    for num in nums:
        res += num
        res %= 1000000007
    return res
print(sum2(1 + l * (n + 1 - l) for l in range(k, n + 2)))

Submission status: Accepted

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

n_li = list(range(n+1))

ans = 0

while(k <= n+1):
    p = (k - 1) * k / 2
    q = ((n + n - k + 1) * k) / 2

    ans += q - p + 1
    ans %= MOD
    k += 1

print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

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

MOD = 10 ** 9 + 7

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

res = 0
for a in range(k, n + 2):
	res += calc(a)
	res %= MOD

print(res)

Submission status: Accepted

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

def calc(i):
    minv = i * (i-1) // 2
    maxv = minv + i * (N - i + 1)
    return maxv-minv+1

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

ans = 0
for i in range(K,N+1):
    min = acc[i-1]
    max = acc[N] - acc[N-i]
    ans += max - min + 1
    
MOD = 10**9+7
print(ans%MOD+1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

    n_li = list(range(n+1))

    ans = 0

    while(k <= n+1):
        p = (k - 1) * k / 2
        q = ((n + n - k + 1) * k) / 2

        ans += q - p + 1
        ans %= MOD
        k += 1

    print(int(ans))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

l = 0
u = 0
du = n
dl = 0
ans = 0

for i in range(n+1):
    l += dl
    u += du
    if i+1 >= k:
        ans += u-l+1
        ans %= 1000000007
    du -= 1
    dl += 1
assert(l == u)
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
#互いに素なa,bについて、a*x+b*y=1の一つの解
N,K=map(int,input().split())
mod=10**9+7

mx=0
mi=0
ans=0
for k in range(N+1):
    mx+=N-k
    mi+=k
    if k>=K-1:
        ans+=mx-mi+1

print(ans%mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = list(map(int,input().split()))
ans=0
s1=0
s2=0

for i in range(k-1):
    s1+=i
    s2+=n-i
#print(s1,s2)

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

class abc_163:
    
    def __init__(self):
        pass
    
    def A(self):
        r=int(input())
        print(2*math.pi*r)
    
    def B(self):
        NM=list(map(int,input().split()))
        A=list(map(int,input().split()))
        
        if NM[0]-sum(A)>=0:print(NM[0]-sum(A))
        else:print("-1")
    
    def C(self):
        N=int(input())
        A=list(map(int,input().split()))
        ans_list=[0]*(N+1)
        
        for i in range(N-1):ans_list[A[i]] +=1
        for i in range(1,N+1):print(ans_list[i])
        
    def D(self):
        NK=list(map(int,input().split()))
        
        data_list=[i for i in range(NK[0]+1)]
        reverse_data_list=sorted(data_list, reverse=True)
        
        #累積和格納リスト
        min_sum_data_list=[0]*(NK[0]+1)
        max_sum_data_list=[0]*(NK[0]+1)
        
        #初期値設定
        min_sum_data_list[0]=data_list[0]
        max_sum_data_list[0]=reverse_data_list[0]
        ans_data=0
        
        #累積和の計算
        for i in range(1,NK[0]+1):
            min_sum_data_list[i]+=min_sum_data_list[i-1]+data_list[i] % (pow(10,9)+7)
            max_sum_data_list[i]+=max_sum_data_list[i-1]+reverse_data_list[i] % (pow(10,9)+7)
       
        for i in range(NK[1]-1,NK[0]+1):
            ans_data+=(max_sum_data_list[i]-min_sum_data_list[i]+1) % (pow(10,9)+7)
            
        print(ans_data % (pow(10,9)+7))    
            
    
if __name__=='__main__':
    obj=abc_163()
    obj.D()

Submission status: Accepted

Solution code:
# int(input()) # 入力が1つ
from collections import defaultdict
n, k = map(int, input().split()) # 入力が複数
# [int(i) for i in input().split()] # 配列で数字
mod = 10 ** 9 + 7
cum = [0] + [i for i in range(n + 1)]
for i in range(n + 1):
    cum[i + 1] += cum[i]

ans = 0
for i in range(k, n + 2):
    MIN = cum[i]
    MAX = cum[n + 1] - cum[n + 1 - i]
    ans += (MAX - MIN + 1) % mod
print(ans % mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
X=N-K+1
Y=1
if X==0:
    print(Y)
else:
    Y=(N-K+2)*(N-K+2)*(K-1)+(N-2*K+3)*(N-K+2)*(N-K+3)/2-(N-K+2)*(N-K+3)*(2*N-2*K+5)/6+N-K+2
    print(int(Y%(1000000007)))

Submission status: Accepted

Solution code:
import math  # noqa
import bisect  # noqa
import queue  # noqa


if __name__ == '__main__':
    N, K = map(int, input().split())

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

    print(ans)

Submission status: Accepted

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

ma = sum([n-int(x) for x in range(k)])
mi = sum([int(x) for x in range(k)])

ans = ma-mi+1
for i in range(1,n-k+2):
    mi += k+i-1
    ma += n-k+1-i
    ans += ma - mi + 1

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

Submission status: Accepted

Solution code:
MOD = 10**9 + 7

class ModInt:
    def __init__(self, x):
        if isinstance(x, ModInt):
            self.value = x.value
        else:
            self.value = x % MOD
            if self.value < 0:
                self.value += MOD
    
    def get_mod(self):
        return MOD
    
    # str関数を使用したとき
    def __str__(self):
        return str(self.value)
    
    def __int__(self):
        return self.value
    
    __index__ = __int__
    
    # print関数を使用したとき
    __repr__ = __str__

    ## 四則演算
    def __add__(self, other):
        return ModInt(self.value + ModInt(other).value)
    
    def __sub__(self, other):
        return ModInt(self.value - ModInt(other).value)

    def __mul__(self, other):
        return ModInt(self.value * ModInt(other).value)
    
    def __truediv__(self, other):
        # a * a^(p - 2) ≡ 1 (mod p) 逆元から求める
        return ModInt(self.value * pow(ModInt(other).value, MOD - 2, MOD))

    # 累乗
    def __pow__(self, other):
        return ModInt(pow(self.value, ModInt(other).value, MOD))

    ## 四則演算の順序
    __radd__ = __add__

    def __rsub__(self, other):
        return ModInt(other - self.value)
    
    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return ModInt(other * pow(self.value, MOD - 2, MOD))

    def __rfloordiv__(self, other):
        return ModInt(other // self.value)
    
    # 累乗の順序
    def __rpow__(self, other):
        return ModInt(pow(other, self.value, MOD))
    
    ## 不等号
    def __lt__(self, other):
        return self.value < ModInt(other).value
    
    def __gt__(self, other):
        return self.value > ModInt(other).value

    def __le__(self, other):
        return self.value <= ModInt(other).value
    
    def __ge__(self, other):
        return self.value >= ModInt(other).value
    
    def __eq__(self, other):
        return self.value == ModInt(other).value
    
    def __ne__(self, other):
        return self.value != ModInt(other).value
    
    ## in-place 演算子(+=, -=, *=, /=)
    def __iadd__(self, other):
        self.value += ModInt(other).value
        if self.value >= MOD:
            self.value -= MOD
        return self.value
    
    def __isub__(self, other):
        self.value -= ModInt(other).value
        if self.value < 0:
            self.value += MOD
        return self.value
    
    def __imul__(self, other):
        self.value = ModInt(self.value * ModInt(other).value)
        return self.value

    def __itruediv__(self, other):
        self.value = ModInt(self.value * pow(ModInt(other).value, MOD - 2, MOD))
        return self.value
    
    # 逆元
    def modinv(self):
        return ModInt(pow(self.value, MOD - 2, MOD))
    
N, K = map(ModInt, map(int, input().split()))

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

print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline                                
def I(): return list(map(int,inp().split()))
m=10**9+7

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline                                
def I(): return list(map(int,inp().split()))
m=10**9+7

n,k=I()
ans=1 ;a=[]
for i in range(k,n+1):
    ans+=i*(n-i+1)+1
    ans%=m
    a.append(k*(n-i+1)+1)
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
cnt = 0
for i in range(k,n+2):
    if 0.5*(n-i)*(n-i+1) >= 0:
        minus = 0.5*(n-i)*(n-i+1)
    else:
        minus = 0
    front = 0.5*(i-1)*i
    end = 0.5*n*(n+1) - minus
    cnt += end-front+1
print(int(cnt%(10**9+7)))

Submission status: Accepted

Solution code:
MOD = 10**9 + 7
n, k = map(int, input().split())
ans = 0
for i in range(k, n+2):
    mn = (0+(i-1))*i*0.5
    mx = (n+(n-(i-1)))*i*0.5
    ans += mx - mn + 1

print(int(ans%MOD))

Submission status: Accepted

Solution code:
import math  # noqa
import bisect  # noqa
import queue  # noqa


if __name__ == '__main__':
    N, K = map(int, input().split())

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

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

    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from itertools import permutations
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)
MOD = pow(10, 9) + 7

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

l = range(0, N + 1)
sum_ = sum(l)
if K > N:
    print(1)
    sys.exit()

ans = 0
for i, k in enumerate(range(K, N + 2), 0):
    small = (i - 1) * i // 2
    large = (2 * N - i + 1) * i // 2
    acc = large - small + 1
    acc %= MOD
    ans += acc
    #break
print(ans % MOD)