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())
total = 0
for l in range(k,n+2):
    total += l*n-l*(l-1)+1
print(total%1000000007)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
mod = 1000000007

def sum_(a, b):
    return int((a+b)*(b-a+1)/2)

def main():
    args = input().rstrip().split(' ')
    N, K = int(args[0]), int(args[1])
    
    Ans = 0
    for i in range(K, N+2):
        sum_b = sum_(0, i-1)
        sum_u = sum_(N-i+1, N)
        Ans += (sum_u-sum_b)+1
        Ans = Ans % mod
    print(Ans)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()

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

ans = 0
for i in range(K,N+1):
  ans += (rui[-1] - rui[-i-1]) - rui[i-1] +1
print((ans +1) %mod)

Submission status: Accepted

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

M = pow(10, 9) + 7


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

    ans = 0
    for i in range(n - k + 1 + 1):
        ans += range_sum(i, n) % M - range_sum(0, n - i) % M + 1
        ans %= M
    print(ans)


def range_sum(a, b):
    if a < 1:
        return b * (b + 1) // 2
    else:
        return b * (b + 1) // 2 - a * (a - 1) // 2


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
#from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [LI()for i in range(n)]
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()
    
n,k=MI()
def standard(a,b):
    return b*(a-b+1)+1
def ansum(a,b):
    ansum=0
    for i in range(b,a):
        ansum+=standard(a,i)
    return ansum
#print(ansum(4,2))
anslarge=n+2
if k==1:
    if n==1:
        ans=3
    else:
        ans=ansum(n,2)+n+1+anslarge
elif k==n+1:
    ans=1
elif k==n:
    ans=n+2
else:
    ans=ansum(n,k)+anslarge
print(ans%mod)

Submission status: Accepted

Solution code:
from itertools import accumulate

def main():
    N, K = map(int, input().split())
    MOD = 10 ** 9 + 7
    A = list(range(0,N+1))
    B = list(accumulate(A))
    A.reverse()
    C = list(accumulate(A))
    ans = 0
    for r in range(K, N+2):
        r -= 1
        t_max = C[r]
        t_min = B[r]
        ans += t_max - t_min + 1 
        ans %= MOD
    print(ans)





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):
    if i == 1:
        ans += N + 1
    elif i == 2:
        ans += 2*N - 1
    else:
        ans += N*i - i*(i-1) + 1
print(ans % (10**9 + 7))

Submission status: Accepted

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

N=A[0]
K=A[1]
sum_N = 0
for i in range(K,N+2):
    sum_N+=i*N-i*(i-1)+1

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

Submission status: Accepted

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

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

shou = sum(memo[:k-1])
dai = sum(memo[n-k+2:])

ans = 1
for i in range(k-1,n):
    dai += memo[-i-1]
    shou += memo[i]
    ans += dai-shou+1
    ans = ans%mod
    #print(ans)
print(ans)

Submission status: Accepted

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

min_sum = sum(range(K))
max_sum = sum(range(N + 1 - K, N + 1))
ans = 0
for i in range(K, N + 2):
    ans += max_sum - min_sum + 1
    ans %= MOD
    min_sum += i
    max_sum += (N - i)
print(ans)

Submission status: Accepted

Solution code:

import sys
import numpy as np
import itertools

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

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

m = np.arange(1,N+2)
m1 = np.arange(N+1,0,-1)

for i in range(1,len(m)):
    m[i] = (m[i] + m[i-1])%mod
    m1[i] = (m1[i] + m1[i-1])%mod

#m = np.array(list(itertools.accumulate(m)))
#m1 = np.array(list(itertools.accumulate(m1)))
#m = m % mod
#m1 = m1 % mod

ans = 0
for i in range(K-1,N+1):
    ans += m1[i] - m[i] + 1
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

n, k = map(int, input().split())
l = [0] * ((n + 1) // 2)
l[0] = n + 1
ans = 0

for i in range(1, (n + 1) // 2):
    l[i] = (l[i - 1] + (n - i * 2)) % MOD

for i in range(k, n + 1):
    if i <= (n + 1) // 2:
        ans += l[i - 1]
    else:
        ans += l[n - i]
    ans %= MOD

print((ans + 1) % MOD)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(K, N + 2):
    p = 0 + i - 1
    q = N - i + 1
    P = p * (p + 1) // 2
    Q = P + (i * q)
    ans += Q - P + 1
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
for i in range(K, N+2):
    min = 0
    max = 0
    min = (i*(i-1))//2
    max = i*N-min
    ans += max-min+1
print(ans % (10**9+7))

Submission status: Accepted

Solution code:
from sys import stdin
n,k = [int(x) for x in stdin.readline().rstrip().split()]
answer = 0
while k <= n+1:
    min = k*(k-1)//2
    max = n*(n+1)//2
    t = n+1-k
    max -= t*(t-1)//2
    answer += max-min+1
    answer %= 1000000007
    k += 1
print(answer)

Submission status: Accepted

Solution code:
import math


def comb(n, r):
    mf = math.factorial
    return mf(n) // (mf(n - r) * mf(r))


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

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

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))*i + 1
    if ans > 10**9 + 7:
        ans = ans % (10**9 + 7)

print(ans)

Submission status: Accepted

Solution code:
def solve():
    MOD = 10 ** 9 + 7
    N, K = map(int,input().split())
    mn = sum(list(range(K)))
    mx = sum(list(range(N,N-K,-1)))

    cnt = 0
    for i in range(K,N+2):
        if i != K:
            mn += i-1 % MOD
            mx += N-(i-1) % MOD
        cnt += mx % MOD - mn % MOD + 1 % MOD

    print(cnt % MOD)

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

ans = ((k-1)/6)*(2*k**2 + (-3*n-4)*k -6 ) + ( n**3 + 3*n**2 + 8*n)/6
print((math.ceil(ans)+1) % (10**9 + 7))

Submission status: Accepted

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

ans = 0
for i in range(K, N+2): # K個以上、N+1以下選ぶ
    minSum = (i-1)*i//2
    maxSum = (2*N+1-i)*i//2
    cnt = maxSum - minSum + 1
    # ans += (minSum + maxSum) * cnt // 2
    # ans += (tmp_mod * cnt * i) % MOD
    ans += cnt
    ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

N, K = read_ints()

# 選ぶ数kが異なれば絶対和は異なる
# k個選ぶときに何通りあるか？
# 和としてありえるものの個数
# k個選ぶときにありえる通りの数はsum(0..(k-1))からsum((N-1)..N)1づつ出てくる
ans = 0
for k in ra(K, N + 2):
    tmp = ((N + N - (k - 1)) * k // 2) - ((0 + k - 1) * k // 2) + 1
    # print(tmp)
    ans += tmp
    ans %= MOD
print(ans)

Submission status: Accepted

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

ans = 0
s = sum(range(K-1))
for i in range(K, N+2):
    s += i - 1
    max_add = N * i - s
    min_add = s
    ans += max_add - min_add + 1

print(ans % (1000000007))

Submission status: Accepted

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

sum_list = [i*(n-i+1)+1 for i in range(1,n+2)]

print(sum(sum_list[k-1::])%(10**9+7))

Submission status: Accepted

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

b = (n + 1)*(n**2 + 2*n + 6)
a = m*(2*m**2 - 3*m*(n + 2) + 3*n - 2)

ans = (a + b)//6+1
ans = ans % 1000000007
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N, K = (int(x) for x in input().split())
sum = 0
for i in range(K, N+2):
    j = i*N - (i-1)*i + 1
    if j > 0:
        sum = sum + j
print(sum % 1000000007)

Submission status: Accepted

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

prev = 1
for k in range(1, N+1):
    prev = prev - (k-1) + N - (k-1)
    if k >= K:
        ans += prev
        ans %= mod


print(ans % mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
mod = 10**9+7
l = [i for i in range(n+1)]
rl = [i for i in range(n,-1,-1)]
suml = [0]*(n+1)
suml[0] = l[0]
for i in range(n):
    suml[i+1] = suml[i] + l[i+1]
sumrl = [0]*(n+1)
sumrl[0] = rl[0]
for i in range(n):
    sumrl[i+1] = sumrl[i] + rl[i+1]
cnt = 0
for m in range(k,n+2):
    max_m = sumrl[m-1]
    min_m = suml[m-1]
    cnt += max_m-min_m+1
print(cnt%mod)

Submission status: Accepted

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

Submission status: Accepted

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

@author: black
"""


N, K = map(int, input().split())
List = [n for n in range(N)]

total = 1
for k in range(K, N+1):
    total += N*k-(k-1)*k+1
    total = total%(10**9+7)
print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n, k = map(int, input().split())
    n += 1
    sum_ = 0
    sums = [0]

    for i in range(1, n):
        sums.append(sums[-1] + i)

    for i in range(k, n + 1):
        if i == n:
            sum_ += 1
            continue
        up = (sums[-1] - sums[-i - 1])
        low = sums[i - 1]
        tmp = up - low + 1
        sum_ += tmp

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

Submission status: Accepted

Solution code:
MOD = 10**9 + 7
def mySum(a, b):
    return (a + b) * (b - a + 1) // 2 % MOD

N, K = list(map(int, input().split()))
l = mySum(N-K+1, N) - mySum(0, K-1) + 1
res = l
for i in range(K, N+1):
    l = l - i + (N-i)
    res += l
    res %= MOD
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def LI():return list(map(int,input().split()))
n,k=LI()
mod=10**9+7
ans=0
for kk in range(k,n+1+1):
    tmp=n*kk-(kk-1)*kk+1
    ans+=(tmp%mod)
print(ans%mod)

Submission status: Accepted

Solution code:
from sys import stdin

[N, K] = [int(x) for x in stdin.readline().rstrip().split()]
#この場合、10^100は無視しても大丈夫ではない
#足した個数によって10^100の桁の数が変わるので、問題が単純になる。
#これ少し考えればわかるけれど、
#0, 1, 2, ..., N からK個足してできる数は
#最小の値 0+1+2+...+K-1
#最大の値 N-K+1 + N-K+2 + ...+ N
#の間の任意の整数をとりうる。
#したがって、
# # (2N-K+1)*K/2 - (K-1)*K/2 + 1をK~Nについて計算すればよろしい

num_sum = 0
waru = 10**9+7
for i in range(K, N+2):
    num_sum += (2*N - i + 1)*i/2 - (i-1)*i/2 + 1
    #print(i,num_sum)
    num_sum = num_sum%waru

print(int(num_sum))

Submission status: Accepted

Solution code:
from sys import stdin
import sys

# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
N, K = [int(x) for x in stdin.readline().rstrip().split()]
# print(N, K)
ans = 0
# min = 0
for i in range(K, N+2):
    # print(i)
    min = 0
    max = 0
    min = (i*(i-1))//2
    max = i*N-min
    # print(min, max)
    # min = 0
    # max = 0
    # for k in range(i):
    #     min += k
    #     max += N-k
    # print(min, max)
    ans += max-min+1
print(ans%(10**9+7))

Submission status: Accepted

Solution code:
"""
NTC here
"""
 

#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase

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

def main():
    T = 1
    while T:
        md = 10**9+7
        T-=1
        n, k = lin()
        ans = [0]*(n+1)

        l, h = 0, n
        s1, s2 = 0, n
        for i in range(n+1):
            ans[i]+=s2-s1+1
            l+=1
            h-=1
            s1+=l
            s2+=h
        print(sum(ans[k-1:])%md) 
        # print(ans)
        








# region fastio

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

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

def calc_k(k):
  return k*n - k*(k-1) + 1


m = 10**9+7
ans = 0

for i in range(k, n+2):
  ans += calc_k(i)%m
  
print(ans%m)

Submission status: Accepted

Solution code:
import math
import queue

def readInt():
	return int(input())

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

def readChars():
	return input().split()



x = readInts()
n = x[0]
k = x[1]

def ts(l):
	return int((l*(l-1))/2)

def ts2(l):
	return int(l*(n+n-(l-1))/2)


#for i in range(k,n):
#	for j in range(0,n-i+1):
#iは個数

#a = range(0+1,n+n-1 +1) #2
#b = range(0+1+2,n+n-1+n-2 +1) #3

s = 0

for i in range(k,n+2):
	#x = range(ts(i),ts2(i)+1)
	#print(ts2(i)+1-ts(i))
	#print(x)
	s += ts2(i)+1-ts(i)

print(s%(1000000007))

Submission status: Accepted

Solution code:
# python 3.8.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
from math import gcd
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def lcm(a,b):return (a*b) // gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')
def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,K = imn()

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

ans = 0
for i in range(K, N+2):
    if i == 1:
        min_v = 0
        max_v = N
    else:
        min_v = i*(i-1)//2
        max_v = c[i-1]
    ans += max_v-min_v+1
print(ans%MOD)

Submission status: Accepted

Solution code:
def main():
    n,k=map(int,input().split())
    mod=10**9+7
    if n-k==-1:
        print(1)
    else:
        ans=(n+2*k)*(n-k+1)*(n-k+2)//6+n-k+2
        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):
    ans += i * (N - i + 1) + 1
    ans %= 1000000007
print(ans)

Submission status: Accepted

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

MOD = 10**9 + 7

s = [0 for _ in range(n+2)]
v = 0
for i in range(n+2):
    v += i
    s[i] = v

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
mod = 1000000007

maxNum = 0
minNum = 0

for i in range(k):
    maxNum += n - i
    minNum += i

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

b=[0]
c=[a[-1]]
for i in range(1,n+1):
    b.append(i+b[i-1])
    c.append(c[i-1]+(n-i))


if n+1==k:
    print(1)
else:
    s=0
    for i in range(k-1,n+1):
        s+=abs(b[i]-c[i])+1
    print(s%1000000007)

Submission status: Accepted

Solution code:
import sys
import numpy as np

#n=int(sys.stdin.readline())
n,k=map(int,sys.stdin.readline().split())
#a=np.array(sys.stdin.readline().split(),dtype='int64')
#a=np.array([sys.stdin.readline().split() for i in range(n)],dtype='int64')

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

print(ans%(mod))

Submission status: Accepted

Solution code:
import sys
from collections import deque
input = lambda: sys.stdin.readline().rstrip()
ints = lambda: list(map(int, input().split()))
mod = 10**9+7
n,k = ints()
def f(x,N):
    a = 2*x**2
    c = 3*N
    b = c*x
    return int(x*(-a+b+c+8)/6)

print((f(n+1,n)-f(k-1,n))%mod)

Submission status: Accepted

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

Submission status: Accepted

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

MOD = 10**9 + 7
sum = 0
for j in range(K, N+1):
    MIN = j * (j-1) // 2
    MAX = (N+1)*N//2 - (N+1-j)*(N-j)//2
    # print(MAX, MIN)
    sum += MAX - MIN + 1
    
print(sum % MOD + 1)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
mod = 10**9 + 7

n,k = map(int,input().split()) # n:0~nまでの数 k:選ぶ最低個数

sum_num = 0
for i in range(k,n+2):
  max_num = int(i*(n+n-i+1)/2)
  min_num = int(i*(i-1)/2)

  sum_num = (sum_num + (max_num-min_num + 1)) % mod

print(sum_num)

Submission status: Accepted

Solution code:
# D - Sum of Large Numbers
import numpy as np

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

r = np.cumsum(np.arange(n+1))
rr = np.cumsum(np.arange(n+1)[::-1])

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if k == n + 1:
    print(1)
else:
    ans = 1
    mod = 10**9 + 7
    left = sum(l[:k])
    right = sum(lr[:k])
    # print(left)
    # print(right)
    for i in range(n - k + 1):
        ans += right - left + 1
        ans %= mod
        left += l[k + i]
        right += lr[k + i]
    print(ans)

Submission status: Accepted

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

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

N += 1
MOD = 10**9+7
#%%
ans = 0
for i in range(K,N+1):
    p = (2*N-i-1)*i//2
    m = (i-1)*i//2
    ans += p-m+1
    ans %= MOD

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


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

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

Submission status: Accepted

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

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

max_val = int(sum(point[-K:]))
min_val = int(sum(point[:K]))
count = int(max_val - min_val + 1)%1000000007

for i in range(K, N+1):
    max_val = max_val + point[-i-1]
    min_val = min_val + point[i]
    count += int(max_val - min_val + 1)%1000000007 
print(int(count)%1000000007)

Submission status: Accepted

Solution code:
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))

n, k = load_list()

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

cnt = 0

lowd = [i for i in range(0, n+1)]
for i in range(1, n+1):
    lowd[i] = lowd[i-1] + lowd[i]
highd = [i for i in range(0, n+1)]
for i in range(n-1, -1, -1):
    highd[i] = highd[i] + highd[i+1]

for i in range(k, n+2):
    low = lowd[i-1]
    high = highd[n+1-i]
    cnt += high - low + 1

print(int(cnt % (math.pow(10, 9) + 7)))

Submission status: Accepted

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

def sumf(NN,X):
    return (NN+1)*0.5*X*(X+1) - X*(X+1)*(2*X+1)/6 + X

print(int(sumf(N,N+1) - sumf(N,K-1)) % 1000000007)

Submission status: Accepted

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

Submission status: Accepted

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

S=0
for x in range(K,N+2):
  max=(N*(N+1)-(N-x)*(N-x+1))//2
  min=x*(x-1)//2
  S=S+(max-min+1)
S=S%(10**9+7)
print(S)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
mod = 10**9 + 7
from collections import defaultdict
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input().rstrip()))
def inlt():
    return(list(map(int,input().rstrip().split())))
def insr():
    s = input().rstrip()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().rstrip().split()))
################################################################
n,m = invr()
left = 0
right = 0
l_a = 0
r_a = n

for i in range(m):
    left += l_a
    right += r_a
    l_a += 1
    r_a -= 1
#print(left,right)
ans = right - left + 1
while m <= n :
    left += l_a
    right += r_a
    l_a += 1
    r_a -= 1
    ans += (right - left + 1)%mod
    ans = ans%mod
    m += 1
print(ans)  
#print(n - s if s <= n else -1)
#print('No')
#print()

Submission status: Accepted

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

counter = 0

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


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