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:
n, k = map(int, input().split())
mod = 10 ** 9 + 7

ans = 0
c = 0   #combination
l = 0
h = 0
for i in range(1, n+2): #O(n)
    l += i - 1
    h += n + 1 - i
    c = (h - l + 1) % mod
    if i >= k:
        ans = (ans + c) % mod
    else:
        pass
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N, K = [int(item) for item in input().split()]

    res = 0

    for i in range(K, N+2):
        a = (i-1)*i//2
        c = N-i
        b = N*(N+1)//2 - c*(c+1)//2
        # print(a, b)
        res += b - a +1

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
input_str = input()

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

result = k * n - k * (k+1) + 2 * k + 1

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

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

Submission status: Accepted

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

cnt = 0
for i in range( K, N + 2 ):
    a = ( N * ( N + 1 ) // 2  - ( N - i  ) * ( N - i + 1 ) // 2 - i * ( i - 1 ) // 2 + 1 ) 
    cnt += a
    cnt %= limit 
print( cnt )

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)]
DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)]
from itertools import accumulate as acc
MOD = 10**9+7

def main():
    n, k = MII()
    cnt = 0
    dd = [i for i in range(n+1)]
    dd_a = list(acc(dd))
    dd_b = list(acc(dd[::-1]))
    for i in range(k-1,len(dd_a)):
        cnt += dd_b[i]-(dd_a[i]-1)
    print(cnt%MOD)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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 = 1

def count(i, N):
	if i == 1:
		return N+1
	else:
		return (N*(N+1)/2 - (N-i)*(N-i+1)/2) - (i-1)*i/2 + 1


for i in range(K, N+1):
	ans += count(i, N)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

goukei = 0
for j in range(k,n+2):
    goukei += ((2*n-j+1)*(j)/2) - ((j-1)*j/2) + 1
    
print(int(goukei % (1e9 + 7)))

Submission status: Accepted

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

sums = 0
for K in range(k, (n+1)+1):
  sums += 1 + (n - K + 1) * K
  
answer = sums % (10**9 + 7)
print(int(answer))

Submission status: Accepted

Solution code:
def main():
    MOD = 10 ** 9 + 7
    n, k = map(int, input().split())
    a = list(range(n + 1))
    x = a.copy()
    y = a.copy()
    ans = 0
    for i in range(1, n+1):
        x[i] = a[i] + x[i-1]

    for i in range(n-1, -1, -1):
        y[i] = a[i] + y[i+1]

    for j in range(k-1, n+1):
        ans += y[-j-1] - x[j] + 1
    return ans%MOD


print(main())

Submission status: Accepted

Solution code:
a,b=(int(x) for x in input().split())
z=0
while b<=a+1:z=(z+(a-b+1)*b+1)%int(1e9+7);b+=1
print(z)

Submission status: Accepted

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

MOD = 10 ** 9 + 7

upper_list = [0] * (N + 1)
upper_list[0] = N
lower_list = [0] * (N + 1)
lower_list[0] = 0
ans_list = [0] * (N + 1)


for i in range(1, N + 1):
    lower_list[i] = lower_list[i - 1] + i
    upper_list[i] = upper_list[i - 1] + (N - i)

for i in range(N + 1):
    ans_list[i] = (upper_list[i] - lower_list[i] + 1) % MOD

ans = print(sum(ans_list[K - 1:]) % MOD)

Submission status: Accepted

Solution code:
N, K = [int(i.strip()) for i in input().split(' ')]
MOD = 10 **9 + 7
count = 0
for i in range(K,N+2):
    MIN = i * (i-1)/2
    MAX = N * i -MIN
    c = MAX -MIN + 1
    count += int(c)

print(count%MOD)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s = [0 for i in range(N+2)]
mod = 10**9+7
#s[i]:i個選んだ時の総和
for k in range(N+2):
    a = (k-1)*k/2
    b = (N+N-k+1)*k/2
    s[k] = b-a+1

#ss[i+1]:i個までの個数の総和
ss = [0 for i in range(N+2)]
for i in range(N+1):
    ss[i+1] = ss[i] + s[i] 

ans = int(ss[N+1]-ss[K]) % mod  
print(ans+1)

Submission status: Accepted

Solution code:
def touSum(a,l):
    return int(((l-a+1)*(a+l))/2)

N,K = map(int,input().split())
maxSum = touSum(1,N)
#print(maxSum)
con = 0
for i in range(K,N+1+1):
    #print(str(i)+":"+str(touSum(1,i-1))+":"+str(touSum((1+N)-i,N)))
    if touSum(1,i-1)>maxSum:
        print(con)
        break
    else:
        con += touSum((1+N)-i,N) -touSum(1,i-1)+1
print(con%(10**9+7))

Submission status: Accepted

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

# K = 1の時の最小値
wa = 0
# 場合の数の総数
souwa = 0

# 余りを求めるための大きな素数
dprime = 10**9 + 7


for k in range(1,N+2):
#     print("k:",k)
#     print("wa:",wa,"souwa:",souwa)
    # min = wa
    
    if k >= K:
        # max
        mx = N*k-wa
#         print("mx:",mx)
        souwa += (mx - wa + 1) % dprime
#     print("souwa after:",souwa)
    wa += k
        
print(souwa%dprime)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
l=list(range(K,N+2))
sum =0
for i in l:
    m=(i-1)*i/2
    p=i*N-2*m+1
    sum+=p

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

Submission status: Accepted

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

a=0
start=0
end=0

for i in range(1,N+2):
    start=start+i-1
    end=end+N-i+1

    if i >= K:
        a = (a + (end - start)+1) % (10**9+7)

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

Submission status: Accepted

Solution code:
NK = input().split()
N = int(NK[0])
K = int(NK[1])
x = 0
for i in range(N-K+2):
    a = N+1
    b = i+K
    x += (a-b)*b+1
print(x%1000000007)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def rangesum(a, b=0):
    return (abs(a-b)+1) * (a+b) // 2

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

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

print(res)

Submission status: Accepted

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

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class ModTools:
    """ 階乗たくさん使う時用のテーブル準備 """

    def __init__(self, MAX, MOD):
        """ MAX：階乗に使う数値の最大以上まで作る """
        
        MAX += 1
        self.MAX = MAX
        self.MOD = MOD
        factorial = [1] * MAX
        factorial[0] = factorial[1] = 1
        for i in range(2, MAX):
            factorial[i] = factorial[i-1] * i % MOD
        inverse = [1] * MAX
        inverse[MAX-1] = pow(factorial[MAX-1], MOD-2, MOD)
        for i in range(MAX-2, -1, -1):
            inverse[i] = inverse[i+1] * (i+1) % MOD
        self.fact = factorial
        self.inv = inverse
    
    def nCr(self, n, r):
        """ 組み合わせの数 (必要な階乗と逆元のテーブルを事前に作っておく) """

        if n < r: return 0
        r = min(r, n-r)
        numerator = self.fact[n]
        denominator = self.inv[r] * self.inv[n-r] % self.MOD
        return numerator * denominator % self.MOD

    def div(self, x, y):
        """ MOD除算 """

        return x * pow(y, self.MOD-2, self.MOD) % self.MOD

N, K = MAP()

acc = list(range(N+2))
acc = list(accumulate(acc))

mt = ModTools(N+1, MOD)
ans = 0
for i in range(K, N+2):
    cnt = (acc[N+1] - acc[N+1-i]) - acc[i] + 1
    ans += cnt
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
mod = 10 ** 9 + 7

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

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

print(rst)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
INT_MAX=10**18+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#################################################################################
n,K=INPUT()
ways=0
for k in range(K,n+2):
        ways+=(k*(2*n-k+1))//2 - ((k)*(k-1))//2 +1
print(ways%MOD)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,K = inputMap()
	N += 1

	if N == K or K == 0:
		print(1)
		sys.exit()

	ans = 0
	tmp = [tmp for tmp in range(0,N)]
	sample1 = []
	tt = 0
	for i in tmp:
		tt += i
		sample1.append(tt)

	sample2 = []
	tmp = tmp[::-1]
	tt = 0
	for i in tmp:
		tt += i
		sample2.append(tt)
	#print(sample2)

	for i in range(K,N+1):
		tmp_i = i-1
		min_int = sample1[tmp_i]
		max_int = sample2[tmp_i]

		#print("{} {}".format(min_int,max_int))

		ans += max_int-min_int+1
		ans = ans % mod

	print(ans)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
ans = 0
temp_max = 0
temp_min = 0
for i in range(1,N+2):
  temp_max += N-i+1
  temp_min += i-1
  if i  >= K:
    ans += (temp_max - temp_min + 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):
    tmpans = 0
    s1 = (0+i-1)*i//2
    s2 = (n-i+1 + n)*i//2
    tmpans = s2-s1+1
    ans = (ans+tmpans)%(10**9+7)
print(max(1,ans%(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):
  if i==K:
    MIN=sum(list(range(0,K)))
    MAX=sum(list(range(N,N-K,-1)))
  else:
    MIN+=i-1
    MAX+=N+1-i
  #print(MIN,MAX)
  ans+=(MAX-MIN+1)%mod
  ans%=mod
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
M = 10**9+7
ans = 0
for i in range(K,N+1):
    if i == K:t = sum(range(N-i+1,N+1))-sum(range(0,i))
    else: t+=N-(i-1)-(i-1)
    # print(t)
    t%=M
    ans +=t+1
    ans%=M
    # print(00,sum(range(N-i+1,N+1)),sum(range(0,i)))


print(ans+1)

Submission status: Accepted

Solution code:
'''import os
import sys
from io import BytesIO, IOBase
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")'''
#######################################################################
n,k=map(int,input().split())
l=[]
c=0
for i in range(n+1):
    c+=i
    l.append(c)
ans=0
for i in range(k,n+1):
    ans+=l[-1]-l[n-i]-l[i-1]+1
    ans=ans%1000000007
ans+=1
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
lst = list(range(0,N+1))
m = 10**9 + 7
cnt = 0
start = sum(lst[:K])
end = sum(lst[-K:])
cnt += end - start + 1
for i in range(K+1,N+2):
    start += lst[i-1] 
    end += lst[-i]
    cnt += end - start + 1
print(cnt % m)

Submission status: Accepted

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

Submission status: Accepted

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

i = K
S = 0
while i < N+1:
    S = S + (N+1-i)*i+1
    i = i + 1
S = S + 1

print(int(S%1000000007))

Submission status: Accepted

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

a = N - K + 2 + (N + 1)*(N-K+2)*(K+N+1) // 2 - ((N + 1) * (N + 2) * (2 * N + 3) - K * (K - 1) * (2 * K - 1)) // 6

print(a % 1000000007)

Submission status: Accepted

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

Submission status: Accepted

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

MOD = 10**9 + 7
def f(t):
  return (N-t+1)*t+1

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

Submission status: Accepted

Solution code:
a,b=(int(x) for x in input().split())
z=0
for i in range(b,a+2):z=(z+(a-i+1)*i+1)%(10**9+7)
print(z)

Submission status: Accepted

Solution code:
MOD = int(1e9)+7
def main():
    n, k = map(int, input().split())
    n += 1
    a = [int(i) for i in range(n)]
    s = [0]
    for i in range(n):
        s.append(s[i]+a[i])

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 19 21:27:49 2020

@author: arute
"""


from sys import stdin

import time
import numpy as np
import math



def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

############################################

# read data for n sequences.
temp = stdin.readline().split()
N = int(temp[0])
M = int(temp[1])

# すべての場合の数を計算。
probs = np.zeros(1).astype("int64")

for i,m in enumerate(range(M,N+2)):
    # 作れる最小は？
    if i == 0:
        small = np.sum(np.arange(m))
        #
        large = np.sum(np.arange(N+1-m,N+1))
    else:
        small = (small+m-1).astype("int64")
        large = (large + (N+1-m)).astype("int64")
    probs = probs + (large - small + 1)

print(int(probs%(1e9+7)))

Submission status: Accepted

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

print((ans+n-k+2)%(10**9+7))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
cnt = 1
head = 0
head_total = 0
tail = n
tail_total = 0
mod = 10**9+7
for i in range(n + 1):
    if i >= k:
        cnt += tail_total - head_total + 1
        cnt %= mod
    head_total += head
    tail_total += tail
    head += 1
    tail -= 1
print(cnt % mod)

Submission status: Accepted

Solution code:
import math
n,k = map(int,input().split())
ans = 0
def count(i):
    min_a = ((i - 1) * i )// 2
    max_a = ((n - i + 1 + n) * i) // 2
    return max_a - min_a + 1

for i in range(k,n + 2):
    ans += count(i)
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):
    tmpans = 0
    s1 = (0+i-1)*i//2
    s2 = (n-i+1 + n)*i//2
    tmpans = s2-s1+1
    ans += tmpans
print(max(1,ans%(10**9+7)))

Submission status: Accepted

Solution code:
N,K=input().split()
MOD = 1000000007
mmax = 0
mmin = 0
result = 0
for i in range(int(N)+1):
    mmin = mmin + i
    mmax = mmax + int(N) - i
    if i >= int(K) - 1:
        result = result + mmax - mmin + 1
print(result%MOD)

Submission status: Accepted

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

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

Submission status: Accepted

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

f = {0:0}
s = {0:0}

for i in range(1, 10**6):
    f[i] = (f[i-1] + i) % mod
    s[i] = (s[i-1] + pow(i, 2, mod)) % mod


def solve(n, k):
    ans = (n+1) * ((f[n+1]-f[k-1])%mod) % mod
    sub = (s[n+1] - s[k-1]) % mod
    ans = (ans - sub) % mod
    ans = (ans + n-k+2) % mod

    return ans

ans = solve(n, k)
print(ans)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce


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

Submission status: Accepted

Solution code:
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)]
DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)]
from itertools import accumulate as acc
MOD = 10**9+7

def main():
    n, k = MII()
    cnt = 0
    dd = [i for i in range(n+1)]
    # print(dd)
    dd_a = [0]
    for i in range(n+1):
        d = dd_a[i] + dd[i]
        dd_a.append(d)
    # print(dd_a)
    dd_b = [0]
    dd_r = dd[::-1]
    for i in range(n+1):
        d = dd_b[i] + dd_r[i]
        dd_b.append(d)
    # print(dd_b)
    for i in range(k,len(dd_a)):
        cnt += dd_b[i]-(dd_a[i]-1)
    print(cnt%MOD)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


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


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N, K = MI()
    ans = 0
    l = [i for i in range(N+1)]
    acc = list(accumulate(l))

    ans1 = 0

    for i in range(K, N+2):
        # a = cmb(N+1, i, MOD)
        # ans += a
        # ans %= MOD
        if i == N+1:
            mx = acc[N]
        else:
            mx = acc[N] - acc[N-i]
        mn = acc[i-1]
        # print('k', i)
        # print('=============')
        # print('mn', mn, 'mx', mx)
        # mx = sum(l[N-i+1:N+1])
        # mn = sum(l[0:i])
        # print('mn', mn, 'mx', mx)
        ans1 += mx - mn + 1
        ans1 %= MOD
        # print('=========')

    print(ans1 % MOD)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
ans=0
mod=(10**9)+7
def ABC(N,K):
    mod=(10**9)+7
    a=((K-1)*K)//2
    b=(K*(2*N-K+1))//2
    s=b-a+1
    return s%mod

for i in range(K,N+2):
    ans+=ABC(N,i)

print(ans%mod)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import deque, defaultdict, Counter
import math
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def main():
    N, K = wi()
    mod = 10 ** 9 + 7
    s = 0
    s_1 = 0
    a = []
    b = 0
    ans = 0
    for i in range(N+1):
        b += i
        a.append(b)
    for i in range(K, N+1):
        s = a[i-1]
        s_1 = a[N]-a[N-i]
        ans += s_1-s + 1
    print(ans % mod + 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K = (int(x) for x in input().split())
N1 = N + 1
K1 = K - 1
setN = (((N1*N1*(N1+1))//2) - (N1*(N1+1)*(2*N1+1)//6) + N1) % 1000000007
setK = (((N1*K1*(K1+1))//2) - (K1*(K1+1)*(2*K1+1)//6) + K1) % 1000000007
print((setN-setK)%1000000007)