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:
from itertools import accumulate

def resolve():
    n,k = map(int, input().split())
    ans = 0
    mod = 10**9+7
    dp = [i for i in range(n+1)]
    acc = [0] + list(accumulate(dp))
    for i in range(k-1, n+1):
        r = acc[-1] - acc[n-i]
        l = acc[i+1]
        ans = (ans + r - l + 1) % mod
    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
L=[]
for i in range(N+1):
    L.append(i)
count=0
Mod=10**9+7
for i in range(K-1,N+1):
    mi=(i)*(i+1)//2
    ma=(N)*(N+1)//2-(N-i)*(N-i-1)//2
    count+=(ma-mi+1)%Mod
print(count%Mod)

Submission status: Accepted

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

MOD = 10 ** 9 + 7

ans = 0
num = 0

for i in range(1, n + 2):
  num += (i - 1)
  if i >= k:
    # print(num, i, i * n - 2 * num + 1)
    ans += max(i * n - 2 * num + 1, 1) 
    ans = ans % MOD

print(ans)

Submission status: Accepted

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

MOD = 1000000007  # type: int


def solve(N: int, K: int):
    result = 0
    for i in range(0, N-K+2):
        s = (K + i) * (2 * N - K - i + 1) // 2 - (K + i) * (K + i - 1) // 2 + 1
        result += s
    print(result%(10**9+7))
    return


# Generated by 1.1.6 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:
# from math import pi
# a = int(input())
# # a = [int(i) for i in input().split()]

# print(2*pi*a)

n, k = [int(i) for i in input().split()]
res = 0
for i in range(k, n + 2):
    res += (2 * n - 2 * i + 2) * i // 2 + 1


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)


def main():
    N, K = map(int, input().split())

    num = 0
    min_sum = sum(range(0, K))
    max_sum = sum(range(N + 1 - K ,N + 1))

    for i in range(N + 2 - K):
        num += max_sum - min_sum + 1
        max_sum += N - K - i
        min_sum += K + i

    D = 10 ** 9 + 7
    print(num % D)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# Problem D - Sum of Large Numbers

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

# initialization
up_list = [i for i in range(N+1)] # 昇順リスト
up_sums = [0]*(N+1)
for i in range(N+1):
    if i==0:
        up_sums[i] = up_list[i]
    else:
        up_sums[i] = up_sums[i-1] + up_list[i]
down_list = [i for i in range(N, -1, -1)] # 降順リスト
down_sums = [0]*(N+1)
for i in range(N+1):
    if i==0:
        down_sums[i] = down_list[i]
    else:
        down_sums[i] = down_sums[i-1] + down_list[i]
ans = 0
MOD = 10**9 + 7

# count
tmp_k = K
while tmp_k<=(N+1):
    test_up = up_sums[tmp_k-1]
    test_down = down_sums[tmp_k-1]
    tmp = (test_down - test_up + 1)%MOD
    ans += tmp
    ans = ans % MOD
    tmp_k += 1

# output
print(ans)

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
x = [i for i in range(n+1)]

left, right = [x[0]], [x[-1]]
for i in range(1, n+1):
    left.append(left[i-1] + x[i])
    right.append(right[i-1] + x[-(i+1)])

total = 0
for i in range(k-1, n+1):
    total += right[i] - left[i] + 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
N,K=nm()

mod=10**9+7
ans=0

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

print(int(ans%mod))

Submission status: Accepted

Solution code:
n, k = [int(x) for x in input().split(" ")]

p = 1000000007

sum = 0

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

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
mod = 10**9+7

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

if ans >= mod:
    print(ans%mod)
else:
    print(ans)

Submission status: Accepted

Solution code:


n, k = [0] * 2

mod = 10**9 + 7

def format_input(filename = None):
	global n, k
	if filename == None:
		n, k = list(map(int, input().split()))

	elif filename == '__random__':
		from random import randint as rng
		n = rng(1, 2 * 10**5)
		k = rng(1, n+1)
		print(n, k)

def get_answer():
	answer = ((n+1) * (n+2)) // 2 * n + ((n+1) * (n+2)) // 2 - ((n+1) * (n+2) * (2*n+3)) // 6 + (n+1)
	answer -= (k * (k-1)) // 2 * n + (k * (k-1)) // 2 - (k * (k-1) * (2*k-1)) // 6 + (k-1)
	answer %= mod
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)

Submission status: Accepted

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

sums = [0 for i in range(n+1)]
MOD = 1000000007

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

ans += n-k+1

for i in range(n+1):
    ans -= (n-i)*min(i,n-k+1)
    ans += MOD
    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+1)*i+1
print(ans%1000000007)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7

def main():
    N, K = map(int, readline().rstrip().split())
    ans = 0
    for k in range(K, N+2):
        mi = ((k-1) * k) // 2
        ma = (N * (N + 1)) // 2 - ((N-k) * (N-k+1)) // 2
        ans += (ma - mi + 1) % MOD

    print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

M = 10**9+7

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

print(ans%M)

Submission status: Accepted

Solution code:

# coding: utf-8
import sys
# import collections

# import bisect
# import math
# import numpy as np

# from fractions import gcd

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

    def lcm(self, x, y):
        return (x * y) // self.gcd(x, y)


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    # n, m = ip.IL()
    # a = np.array(ip.IL())
    # for _ in range(m):
    #     a[np.argmax(a)] //= 2
    # print(np.sum(a))
    n, k = ip.IL()
    ans = 0
    for i in range(k-1, n+1):
        # print(i, n)
        a= ((n - i + n) * (i + 1) / 2)
        b = ((0 + i) * (i + 1) /2)
        # print(a, b)
        ans +=  a - b + 1
    print(int(ans) % (10 ** 9 + 7))

main()

Submission status: Accepted

Solution code:
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
t1 = n-k+2
t2 = (n+1)*(n+k+1)*(n-k+2)//2
t3 = ((n+2)*(n+1)*(2*n+3)-(k-1)*k*(2*k-1))//6
ddprint(t1)
ddprint(t2)
ddprint(t3)
print((t1+t2-t3)%R)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans%mod)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n, k = IN()
	#s = input()
	kk=0
	for i in range(k-1):
		kk += i
		kk %= mod
		
	bb=0
	for i in range(k-1):
		bb += (n )- i
		bb %= mod
	cc=0
	#cc += (bb - kk)%mod
	#pa((bb,kk,cc))
	for i in range(k, n+2):
		bb += (n + 1) - i
		bb %= mod
		kk += i-1
		kk %= mod
		cc += (bb - kk + 1)
		cc%= mod 
		#pa((bb,kk,cc))
	print(cc)
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

mod = 10 ** 9 + 7

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

print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import itertools

n, k = map(int, readline().split())
memo = [i for i in range(n + 1)]
cumsum = list(itertools.accumulate(memo))
mod = 10 ** 9 + 7
if n < k:
    print(1)
    exit()
ans = 1
for i in range(k - 1, n):
    ans += (cumsum[-1] - cumsum[n - i - 1]) - cumsum[i]
    ans += 1
    ans %= mod
print(ans % mod)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = [int(s) for s in input().split()]
sum = 0
for i in range(k,n+2):
    sum+= (i*(n-i+1) + 1)
print(int(sum%(1e9+7)))

Submission status: Accepted

Solution code:
## coding: UTF-8
from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product
import math

s = input().split()
p = [int(w) for w in s] #これで勝手にNまで拾ってくれます

N = p[0]
K = p[1]


#とりあえずそのまま計算
A = (N+1) * (N+2) * N / 6
B = K * (K-1) * (2*K - 3*N - 4) / 6
C = N - K + 2
ans = int(A+B+C) 
#print(ans)
print(ans % 1000000007)

Submission status: Accepted

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

count = 0
for i in range(k, n+2):
    mn = (i - 1) * i / 2
    mx = (2 * n - i + 1) * i / 2
    count += mx - mn + 1
print(int(count % 1000000007))

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
N = N+1
a = N - K
ans = 0

MM = 10**9 +7

for i in range(K,K+a):
  start = int( ( (i)*(i-1)/2 ) % MM )
  fin = int( ( (N+(N-1)-i)*(i)/2+1 ) % MM )
  ans = int( ( ans + (fin - start) ) % MM )

ans += 1
print(ans)

Submission status: Accepted

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

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

print(ans%mod)

Submission status: Accepted

Solution code:
N , K =map(int,input().split())
MOD=10**9+7
ans=0
if N<K:
    print(1)
else:
    tmp_low = sum(range(K))
    tmp_high = sum(range(N-K+1,N+1))
    r=tmp_high-tmp_low+1
    ans+=r
    ans%=MOD
    for sel in range(K+1,N+2):
        tmp_low += sel-1
        tmp_high += N-sel+1
        r= tmp_high-tmp_low+1
        ans+=r
        ans%=MOD
    print(ans%MOD)

Submission status: Accepted

Solution code:
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    #n=int(input())
    n,k= map(int, sys.stdin.readline().split(' '))
    ans=0
    for i in range(k,n+2):
        x=(i*(i-1))//2
        y=n*i
        y-=(i*(i-1))//2
        ans+=(y-x+1)
        ans%=mod

        #print(x,y)
    print(ans)
    #a=list(map(int,sys.stdin.readline().split(' ')))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
m = 1000000007
ans = []
for i in range(1,n+2):
    ans_min = (0+(i-1))*i*0.5
    ans_max = ((n+1-i)+n)*i*0.5
    ans.append(ans_max-ans_min+1)

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

if (k>=2):
    print(int((ans_wa[n]-ans_wa[k-2])%m))
else:
    print(int(ans_wa[n]%m))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
import math
import operator as op
from functools import reduce
from collections import Counter
import numpy as np
import math
import bisect
import heapq

MOD = 1000000007

def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def main():
    N, K = get_inputs(int)

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

N,K = map(int, input().split())
MOD = 10**9+7
def count(N, K):
    min =K*(K-1)/2
    max = (N-K+1)*K+min
    count_num = max-min+1
    K = K +1
    while K <=N+1:
        min = min + K-1
        max = max + N-K+1
        count_num = count_num + max-min+1
        K=K+1
    return count_num

print(int(count(N,K)%MOD))

Submission status: Accepted

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

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

    def total(mn, mx):
        """mnからmxまでの和を返す"""
        n = mx-mn+1
        ret = int((mn+mx)*n/2)
        return ret%MOD

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

    print(int(ans))


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
lis = [n+1]
l = n+1
mod = 10**9+7
for i in range(2, n+2):
    new_l = (l + n -2*i + 2) %mod
    lis.append(new_l)
    l = new_l
s = 0
for i in lis:
    s += i
    s %= mod
s_2 = 0
for i in range(k-1):
    s_2 += lis[i]
    s_2 %= mod
ans = (s- s_2)%mod
if ans < 0:
    ans += mod
print(ans)

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
mod =10**9+7
def solver(k,n):
    ans=int((k*(2*n-k+1)-k*(k-1))/2)+1
    ans=ans%mod
    return ans 
def do():
    sol=0
    n,k=INTM()
    for i in range(k,n+1):
        sol+=solver(i,n)
        sol=sol%mod
        #print(solver(i,n))
    print(sol+1)
        
if __name__ == '__main__':
    do()

Submission status: Accepted

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

cnt=[0]*(n+2-k)
for i in range(n+2-k):
    imin=int((i+k-1)*(i+k)/2)
    imax=int((2*n-i-k+1)*(i+k)/2)
    #print(imin,imax)
    num=imax-imin+1
    cnt[i]=num
print(sum(cnt)%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1
for d in range(N + 1):
    if N - d < K:
        break
    mx = S - (d * (d + 1) // 2)
    mi = max(0, (N - d - 1) * ((N - d - 1) + 1) // 2)
    ans += (mx - mi + 1) % MOD
    ans %= MOD
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split()]
MOD = 10**9 + 7

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

print(sum_ % MOD)

Submission status: Accepted

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N,K = map(int,input().split())

    mod = 10 ** 9 + 7

    res = 0

    for i in range(K,N+2):
        r = (2 * N - i + 1) * i // 2
        l = (i - 1) * i // 2
        res += r - l + 1
        res %= mod

    print(res)



main()

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

fac = [1] * m
finv = [1] * m
inv = [1] * m


def COMinit():
    for i in range(2, m):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod


def COM(n, k):
    if n < 0 or k < 0 or n < k:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod

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

Submission status: Accepted

Solution code:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,k=n1()

down=[0]*(n+1)
up=[0]*(n+1)
up[0]=n
ans=0 if k>1 else n+1
for i in range(1,n+1):
    down[i]=down[i-1]+i
    up[i]=up[i-1]+(n-i)
    if i>=k-1:
        ans+=up[i]-down[i]+1
print(ans%(10**9+7))

Submission status: Accepted

Solution code:

from sys import stdin
import sys
# sys.setrecursionlimit(10**8)

def nextLine(): return next(stdin)
def nextStrList(): return nextLine().split()
def nextIntList(): return [int(_) for _ in nextStrList()]


m=10**9+7
def s2(n):
	v=(n*(n+1)//2)*(2*n+1)//3
	v%=m
	return v

def s(n):
	v= n*(n+1)//2
	v%=m
	return v 

def main():
	n,k=nextIntList()
	
	ss=-(s2(n)-s2(k-2))+(n-1)*(s(n)-s(k-2))+(((n+1)*(n-(k-2)))%m)
	ss%=m
	print(ss)

# 	ss=0
# 	for i in range(k-1,n+1):
# 		si=(i+1)*(2*n-i)//2-(i*(i+1)//2)+1
# 		print(i, si, (i+1)*(2*n-i)//2, (i*(i+1)//2))
# 		ss+=si
# 	print(ss)
		
	
if __name__=="__main__":
	main()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
"""
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
"""
mod = 10**9+7 #出力の制限
"""
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
"""
ans = 0

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

print(ans)
#a = cmb(n,r,mod)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

MOD = 1000000007  # type: int

def solve(N: int, K: int):
    a = list(range(0,N+1))

    left_a = list(accumulate(a))
    right_a = list(accumulate(a[::-1]))

    answer = 0
    for i in range(K,N+2):
        l = left_a[i-1]
        r = right_a[i-1]
        answer += r-l+1
        answer %= MOD
    
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

MOD = 1000000007  # type: int


def solve(N: int, K: int):
    def f(k):
        return ((N * k) % MOD - (k * k) % MOD + k + 1) % MOD
    ans = 1
    for k in range(K, N+1):
        ans = (ans + f(k)) % MOD
    return ans


# Generated by 1.1.6 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
    print(solve(N, K))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

MOD = 10**9+7

# process
def sumrange(x, y):
    ret = (x+y) * ((y-x+1)//2) 
    if (y-x+1)%2 == 1:
        ret += x+(y-x)//2
    return ret % MOD

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

# output
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

result = 0
for i in range(K,N+2):
	mini = i * (i-1)//2
	maxi = i*(N-i+1+N)//2
	result += (maxi-mini+1)
	result %= mod

print(result)