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

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

print(sum)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
start = sum(range(0,K-1))
ans = 0

for i in range(N-K+2):
    n = K+i
    start = n*(n-1)//2
    saidai = (n*(2*N - n + 1)//2)
    ans += saidai - start + 1
print(ans % ((10**9)+7))

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
first = sum(list(range(K)))
end = sum(list(range(N, N-K, -1)))
for i in range(K, N+2):
  if i != K:
    first += (i-1)
    end += (N-i+1)
  ans += (end - first + 1)

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

Submission status: Accepted

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

MOD = 1000000007  # type: int


def solve(N: int, K: int):
    import itertools
    import numpy as np
    candidate = 0
    ls = list(range(0, N+1))
    ls_cumsum = np.cumsum(ls)
    ls_cumsum_re = np.cumsum(ls[::-1])
    for k in range(K, N+1):
        ls_min, ls_max = ls_cumsum[k-1], ls_cumsum_re[k-1]
        candidate += ls_max - ls_min + 1
    print((candidate+1) % MOD)

# 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:
import numpy as np

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

sums = np.zeros(n // 2 + n % 2 + 1, dtype=np.uint32)

mod = int(1e9 + 7)

ans = 0

for i in range(len(sums)):
    sums[i] = (((2 * n - i + 1) * i) // 2 - (i * (i - 1)) // 2 + 1) % mod

for i in range(k, n + 2, 1):
    if i > (n // 2 + n % 2):
        ans += sums[n + 2 - (i + 1)]
        ans %= mod
    else:
        ans += sums[i]
        ans %= mod

print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

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

    MOD = 10**9 + 7

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

def C(N, p):
  min_p = p * (p - 1) // 2
  max_p = p * (2 * N - p + 1) // 2
  return max_p - min_p + 1

ans = 0

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
MOD=10**9+7
A=[0]
for i in range(1,N+1):
    A.append(A[i-1]+i)
B=[N]
for i in range(N):
    B.append(B[i]+N-(1+i))

ans=0
for i in range(N-K+2):
    k=i+K-1
    ans+=B[k]-A[k]+1
    ans=ans%MOD
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):
  i %= mod
  add = i*(N+1) - i**2 +1 
  add %= mod
  ans += add

ans %= mod
print(ans)

Submission status: Accepted

Solution code:
import sys
mod = 7 + 10 ** 9

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    ans = 0
    for k in range(K, N + 2):
        minSum = (0 + k - 1) * k // 2
        maxSum = (N - k + 1 + N) * k // 2
        ans += (maxSum - minSum + 1) % mod
        ans %= mod
    print(ans)
    


    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split()]
cnt=0
for i in range(K,N+2):
    minval=(i-1)*(i)//2
    maxval=i*(N+1)-i*(i+1)//2
    cnt+=maxval-minval+1
    #print("i,max,min,cnt={},{},{},{}".format(i,minval,maxval,cnt))
print(cnt%1000000007)

Submission status: Accepted

Solution code:
# 整数複数個
N, k = map(int, input().split())

l=10**9+7
ans=0

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

print(ans)

Submission status: Accepted

Solution code:
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N, K = lr()
    MOD = pow(10, 9)+7
    ans = 0
    for i in range(K, N+2):
        ans += i*(N-i+1)+1
        ans %= MOD
    print(ans)
resolve()

Submission status: Accepted

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

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

import math
import numpy as np
r=0
n1=n+1
for ii in np.arange(k,n1+1):
    """print(n+1,ii,permutations_count(n1, ii))
    r+=permutations_count(n1, ii)"""
    r+=((2*n1-ii+1)*ii)/2-((ii+1)*ii)/2+1
print(int(r)%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

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

nums = [i for i in range(N + 1)]
total = 0


mini = sum(nums[0:K])
maxx = sum(nums[-K:])


for i in range(K, N + 1):
    total += maxx - mini + 1

    index = i + 1
    
    if (i == N):
        break
    else:
        mini += nums[index-1]
        maxx += nums[-index]

total += 1

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


print(ans)

Submission status: Accepted

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

    def nkr(x,y):
        low = (y-1)*y // 2
        high = ( x*(x+1) - (x-y)*(x-y+1) ) // 2
        return max(high - low,0) + 1

    ans = 0
    for i in range(k,n+2):
        ans += nkr(n,i)
    print(ans % mod)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
MOD = 10**9+7

N, K = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7

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

print(ans % MOD)

Submission status: Accepted

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

ans = 0

for i in range(K, N + 2):
    i_sum_min = i * (i - 1) // 2
    i_sum_max = N * i - i_sum_min
    ans += (i_sum_max - i_sum_min) + 1
    ans %= MOD

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(K, N+2):
    mini = (i-1)*(i)//2 
    maxi = (N-i+1) * i + (i-1)*(i)//2
    
    tmp = maxi - mini + 1
    res = (res+tmp) % MOD

print(res)

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

MOD = 10**9+7
n,k = get_all_int()

ans = 0

for m in range(k, n+2):
    # m個選ぶ最小値
    a = (m-1) * m // 2

    # m個選ぶ最大値
    b = (n+(n-m+1)) * m // 2
    
    ans += b-a+1

print(ans % MOD)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MOD = 10**9+7


def end(b):
    num = 0
    for i in range(n, n-b, -1):
        num += i
    return num

n, k = map(int, input().split())
ans = 0
for i in range(k, n+2):
    s = (i-1) * i // 2
    e = (2*n-i+1) * i // 2
    #print(s, e)
    cnt = e-s+1
    ans = ans + cnt
    ans %= MOD
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

A = [i for i in range(N+1)]
tmp = sum(A[-K:]) - sum(A[:K]) + 1
ans = tmp

for i in range(K+1,N+2):
    tmp += A[-i] - A[i-1]
    ans += tmp
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

MOD = int(1e9) + 7
sum = 0
for i in range(K, N + 2):
    sum += (N - i + 1) * i + 1
    sum %= MOD
    # print(i, (N - i + 1) * i + 1)

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
list=input().split(" ")
N=int(list[0])
K=int(list[1])

def sum_to_N(start,goal):
    return int((start+goal)*(goal-start+1)/2)

count=0
for i in range(K,N+2):
    count+=sum_to_N(N-i+1,N) - sum_to_N(0,i-1) + 1
    

print(count%1000000007)

Submission status: Accepted

Solution code:
MOD = 10**9 + 7

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

inv2 = pow(2, MOD-2, MOD)
nums = []
for i in range(N+3):
    num = i*(i+1)%MOD*inv2%MOD
    nums.append(num)
nums.append(0)
#print('nums:', nums)

ans = 0
for i in range(K, N+2):
    mn = nums[i-1]
    mx = nums[N] - nums[N-i]
    ans += mx-mn+1
    ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
li = [i for i in range(0,n+1)]
#print(li)
#[0,1, 2, 3]
tmp = 0
def exc(n):
    return (n)*(n+1)//2

for i in range(k,n+2):
    #print(i,li[n-i+1:],li[:i],sum(li[n-i+1:]) - sum(li[:i]))
    #tmp += sum(li[n-i+1:]) - sum(li[:i]) + 1
    mi = exc(i-1)
    ma = exc(n) - exc(n-i)
    #print(i,mi,ma,ma - mi + 1)
    tmp += ma - mi + 1
print(tmp%(10**9+7))

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
  count = count % (10**9 + 7)

print(count)

Submission status: Accepted

Solution code:
def main():
    n,k=map(int,input().split())
    ans=0
    maxi=sum(range(n-k+1,n+1))
    mini=sum(range(0,k))
    for i in range(k,n+2):
        tmp=maxi-mini+1
        ans=(ans+tmp)%(1e+9+7)
        maxi+=n-i
        mini+=i
    print(int(ans))
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0
for i in range(N+1-K):
    nowk = K+i
    min_k = nowk*(nowk-1)//2
    max_k = (2*N-nowk-1)*nowk//2
    ans += (max_k-min_k+1)%mod
    ans %= mod
print(ans)

Submission status: Accepted

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

MOD=10**9+7

sm=0
tmp=0
b=1
for i in range(1,N+2):
    if i!=0:
        b=(b-2*(i-1))%MOD
    else:
        b=1
    #print(b)
    val=(i*N+b)%MOD
    sm=(sm+val)%MOD
    if i<K:
        tmp=(tmp+val)%MOD
#print(sm)
#print(tmp)
ans=(sm-tmp)%MOD
print(ans%MOD)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
N, K = (int(i) for i in input().split())  

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

Submission status: Accepted

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

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

print(d_sum_of_large_numbers())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
p = 10**9+7

def sum_num(n, k):
    ans = 0
    while k <= n+1:
        # print(k, k*n-k*(k-1)+1)
        ans += k*n-k*(k-1)+1
        ans = ans%p
        k += 1
    print(ans)

n, k = [int(i) for i in input().split()]
sum_num(n, k)

Submission status: Accepted

Solution code:
from math import factorial

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

ans = 0
j = 0
a = N + 2 - K
for i in range(0, N+1):
    n = min(N + 1 - i, a)
    ans -= i * n % M
for i in range(N, 0, -1):
    j = N - i
    n = min(N + 1 - j, a)
    ans += i * n % M
print((ans + N + 2 - K) % M)

Submission status: Accepted

Solution code:
t=list(map(int,input().split(' ')))
n=t[0] ; k=t[1]
x=0
for i in range(k,n+2):
    p=i*(2*n-(i-1))/2
    q=i*(i-1)/2
    x+=(p-q+1)
print(int(x)%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def f(n, k):
    c = 0
    for i in range(k, n + 2):
        d = i*(n - i) + i * (i + 1) // 2 - i * (i - 1) // 2 + 1
        c = (c + d) % int(1e9 + 7)
    return c

print(f(*map(int, input().split())))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
n=[i for i in range(N+1)]
mod=10**9+7

min_value=[0]*(N+1)
max_value=[0]*(N+1)
min_value[0]=0
max_value[0]=N
for i in range(1,N+1):
  min_value[i]=min_value[i-1]+n[i]
  max_value[i]=max_value[i-1]+n[-(i+1)]

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

Submission status: Accepted

Solution code:
from copy import deepcopy
n,k=map(int,input().split())
mod=10**9+7
accum=[0]*(n+1)
for i in range(n):
  accum[i+1]+=accum[i]+i+1
accumrev=deepcopy(accum)
accumrev=accumrev[::-1]+[0]
accum=[0]+accum
#print(accumrev)
#print(accum)
ans=0
for i in range(k,n+2):
  ans+=accumrev[0]-accumrev[i]-accum[i]+1
  ans%=mod
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
head = 0
foot = 0
ans = 0
for i in range(1, N+2):
    head += i-1
    foot += N - (i-1)
    if i >= K:
        ans = (ans + foot - head + 1) % 1000000007
    # print(i, head, foot, ans)
print(ans)

Submission status: Accepted

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

min_ = sum([i for i in range(K)])
max_ = sum([i for i in range(N, N - K, -1)])

right = K - 1
left = N - (K - 1)

cnt = 0
for k in range(K, N + 2):
    cnt += max_ - min_ + 1

    right += 1
    left -= 1

    min_ += right
    max_ += left

print(cnt % MOD)

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)

s = 0

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

print(s%(1000000007))

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

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

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

ans %= MOD
print(ans)

Submission status: Accepted

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

###
# main
if(__name__ == '__main__'):
    # input
    n, k = map(int, input().split(" "))

    num = 0
    for pick in range(k, n+2):
        tgt = (pick * (n-pick+1) + 1)
        num += tgt % (10**9 + 7)
        num %= 10**9 + 7
    
    print(num)

# else:
    # do nothing

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

lst = [0]*(N+2)
lst[1] = N+1
mi = [0]*(N+2)
ma = [0]*(N+2)
ma[1] = N
for i in range(2,N+2):
    mi[i] = mi[i-1]+i-1
    ma[i] = ma[i-1]+N+1-i
    lst[i] = (ma[i]-mi[i]+1)

print(sum(lst[K::])%mod)

Submission status: Accepted

Solution code:
from math import ceil
N, K = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 0
n = m = 0
for i in range(1, N + 2):
    n += N + 1 - i
    m += i - 1
    if i >= K:
        ans += n - m + 1
        ans %= mod
print(ans)

Submission status: Accepted

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

LOW, HIGH = 0, N
ans = 0

if 1 >= K:
    ans += (HIGH - LOW + 1)

for i in range(2, N + 2):
    LOW += i - 1
    HIGH += N - i + 1
    LOW %= MOD
    HIGH %= MOD
    if i >= K:
        ans += (HIGH - LOW + 1)
        ans %= MOD

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

MOD = 1000000007  # type: int


def solve(N: int, K: int):
    sum = 0
    for k in range(K, N + 2):
        sum += k * (N - k + 1) + 1
    
    print(sum % MOD)
    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:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


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

    MOD = 10**9 + 7

    s = 0
    for i in range(k, n + 2):
        a = ((i - 1) * i) // 2
        s = (s + (n * i) - (2 * a) + 1) % MOD

    print(s)


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


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    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())
MAX=2*(10**5)+1
P=10**9+7
"""A=[i for i in range(MAX)]
B=[0 for i in range(MAX)]
P=10**9+7
A[1]=1
print(len(A))
for i in range(1,MAX-1):
    A[i+1]=(A[i]*(i+1))%P
B[-1]=A[-1]
for i in range(0,MAX-1):
    B[MAX-i-2]=(B[MAX-i-1]*pow(MAX-i-1,P-2,P))%P"""

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

Submission status: Accepted

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

# まずKこちょうどを選ぶとして，Kこの選び方はN_C_K通り，これについて実際の和を計算して同じものを省いていくととてつもなくめんどくさい
count=0
for i in range(K,N+1+1):
    count+=1
    yoyu=N-i
    count += (N+1-i)*i % (10**9+7)
    count %= (10**9+7)
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
#mint
class ModInt:
    def __init__(self, x):
        self.x = x % mod
    
    def __str__(self):
        return str(self.x)
    
    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

    __radd__ = __add__
        
    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

    def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
    def __rtruediv(self, other):
        if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod))

def main():
    N,K=MI()
    N+=1
    ans = ModInt(0)
    for k in range(K,N+1):
        ans += k*(N-k)+1
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from math import pi
# import bisect
# from collections import deque

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
 
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')
INF = 10 ** 18
MOD = 10**9+7

# def ncr(n, r, p): 
#     # initialize numerator 
#     # and denominator 
#     num = den = 1 
#     for i in range(r): 
#         num = (num * (n - i)) % p 
#         den = (den * (i + 1)) % p 
#     return (num * pow(den,  
#             p - 2, p)) % p 
  
n,k=  Ri()
n+=1
pre = [0]*(n)
for i in range(n):
    if i==0:
        pre[i] = i
    else:
        pre[i] = pre[i-1]+i
suf = [0]*(n)
for i in range(n-1,-1,-1):
    if i ==n-1:
        suf[i] = n-1
    else:
        suf[i] = suf[i+1]+i
summ = 0
for i in range(k,n+1):
    dif =suf[n-i]-pre[i-1]+1
    # print(dif)
    summ+=dif
    summ = summ%MOD
print(summ)

Submission status: Accepted

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

Submission status: Accepted

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

starts=list(range(n+1))
ends=list(reversed(list(range(n+1))))

init_starts=sum(starts[0:k-1])
init_ends=sum(ends[0:k-1])

sums=0
for i in range(k-1,n+1):
    init_starts+=starts[i]
    init_ends+=ends[i]
    sums+=init_ends-init_starts+1
    sums%=mod
print(sums)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
#print(cmb(10,2))
counter = 0
mod = 10**9 + 7
for x in range(k, n+1):
    num = (x * n) - (x * (x - 1)) + 1
    counter += num
    counter %= mod
else:
    counter += 1
    counter %= mod
print(counter)

Submission status: Accepted

Solution code:
import numpy as np
if __name__ == "__main__":
    # 入力パターン．
    # 要素の数がわかっているパターン
    ### a b
    N, K = map(int, input().split())
    nums = np.array(range(N+1))
    a = np.cumsum(nums)
    b = np.cumsum(nums[::-1])
    #print(a)
    #print(b)
    ans = 0
    for k in range(K, N+1+1):
        #print("k:{}, b:{}, a:{}".format(k, b[k-1], a[k-1]))
        #print(b[k-1] - a[k-1] + 1)
        ans += b[k-1] - a[k-1] + 1
    print(ans % (10**9+7))

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest

def resolve():
    n, k = map(int, input().split())
    ans = 0
    div = 10 ** 9 + 7
    for i in range(k, n + 2):
        tmp = 0
        # if (2 * n - i + 1) * i / 2 < (i - 1) * i / 2:
        #     break
        if i == n + 1:
            ans += 1
        else:
            ans += (2 * n - i + 1) * i / 2 - (i - 1) * i / 2 + 1

    print(int(ans % div))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3 2"""
        output = """10"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """200000 200001"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """141421 35623"""
        output = """220280457"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()