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())
LARGE = 10 ** 9 + 7
total = 0
for n in range(K, N + 2):
    total = (total + (N + 1 - n) * n + 1) % LARGE
print(total)

Submission status: Accepted

Solution code:
# D - Sum of Large Numbers
from itertools import accumulate


def main():
    N, K = map(int, input().split())
    MOD = 10 ** 9 + 7
    cumsum_left = tuple(accumulate(range(N + 1)))
    cumsum_right = tuple(accumulate(range(N + 1)[::-1]))
    total = sum(r - l + 1 for l, r in zip(cumsum_left[K - 1 :], cumsum_right[K - 1 :]))
    total %= MOD
    print(total)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# D - Sum of Large Numbers
from itertools import accumulate


def main():
    N, K = map(int, input().split())
    MOD = 10 ** 9 + 7
    cumsum_left = tuple(accumulate(range(N + 1)))
    cumsum_right = tuple(accumulate(reversed(range(N + 1))))
    total = sum(r - l + 1 for l, r in zip(cumsum_left[K - 1 :], cumsum_right[K - 1 :]))
    total %= MOD
    print(total)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# D - Sum of Large Numbers
from itertools import accumulate


def main():
    N, K = map(int, input().split())
    cumsum_left = tuple(accumulate(range(N + 1)))
    cumsum_right = tuple(accumulate(reversed(range(N + 1))))
    total = 0
    MOD = 10 ** 9 + 7
    for l, r in zip(cumsum_left[K - 1 :], cumsum_right[K - 1 :]):
        total += r - l + 1
        total %= MOD
    print(total)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def dif_mm(a,b):
    f_min=(a-1)*a/2
    f_max=(2*b-a+1)*a/2
    return int(f_max-f_min+1)
N,K=map(int,input().split())
mod=10**9 + 7
ans=0
for i in range(K,N+2):
    ans+=dif_mm(i,N)
    ans%=mod
print(ans)

Submission status: Accepted

Solution code:

MOD = 1E9+7
N, K = list(map(int, input().split()))
ans = 0
for k in range(K, N+2):
    first = k * (k-1) / 2
    second = k * (2 * N - k + 1) / 2
    add = second - first + 1
    ans = (ans + add) % MOD

print(int(ans))

Submission status: Accepted

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

#n,k = 3, 2

res = 0

for k in range(K, n+2):
  first = k * (k-1) / 2
  last = (2 * n - k + 1) * k / 2
  res += (last - first + 1) 
print(int(res%(10**9+7)))

Submission status: Accepted

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

A = [i for i in range(N+1)]
A_rev = sorted(A, reverse=True)
ans = 0
dp = {'max':sum(A_rev[0:K]), 'min':sum(A[0:K])}
ans += dp['max'] - dp['min'] + 1
for i in range(K, N+1):
    dp['max'] += A_rev[i]
    dp['min'] += A[i]
    ans += dp['max'] - dp['min'] + 1
print(ans%d)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
line= list(map(int,input().split()))
N = line[0]
K = line[1]
#0~Nの連続した整数から
#K個以上(N+1)個以下だけ選ぶ
answer = 0
for i in range (K,N+2):
    minit = i*(i-1)/2
    maximum = (2*N-i+1)*i/2
    
    num = maximum-minit+1
    answer += num
 
if answer >=(10**9+7):
    print(int(answer%(10**9+7)))
    
else:
    print(int(answer))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

li=list(range(N+1))
count=0

#print(li)
for i in range(M,N+2):
    small=(i*(i-1))//2
    large=small+li[-i]*i
    count+=large-small+1

print(count%(pow(10,9)+7))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ANS_TABLE = [0] * (N + 1)
TMP_MIN = sum([i for i in range(0, K)])
TMP_MAX = sum([i for i in range(N, N - K, -1)])
TMP_UP = K
TMP_LOW = N - K

for i in range(K, N + 1):
    ANS_TABLE[i] = TMP_MAX - TMP_MIN + 1
    TMP_MAX += TMP_LOW
    TMP_MIN += TMP_UP
    TMP_UP += 1
    TMP_LOW -= 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
l = list()
for i in range(K,N+2):
    min = i*(i - 1)/2
    max = (2*N - i + 1)*i /2
    cases = max - min + 1
    l.append(cases)
print(int(sum(l)) % (10**9 + 7))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split( ))
ans = 0
#個数で10**100以上の桁の値が一意
#それ未満の桁の値の個数下界から上界が1きざみ
for i in range(k,n+2):
    ans += i*(2*n-i+1)//2-i*(i-1)//2+1
print(ans%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from typing import NoReturn


def my_sum(start: int, end: int):
    if start < 0:
        return my_sum(1 - start, end)
    elif start > 1:
        return my_sum(1, end) - my_sum(1, start - 1)
    else:
        return end * (end + 1) // 2


def main() -> NoReturn:
    n, k = map(int, input().split())  # type: int, int

    p: int = 10 ** 9 + 7

    answer = 0

    for i in range(k, n + 2):
        min_val: int = my_sum(0, i - 1)
        max_val: int = my_sum(n - i + 1 , n)
        answer += max_val - min_val + 1

    print(answer % p)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
S = 0
w = 0
for k in range(K,N+2):
    s = 0
    if k-1 == 0:
        s = N+1
    else:
        w = int(k*(k-1)/2)
        s = k*N - 2*w +1
    S += s
print(S%(10**9+7))

Submission status: Accepted

Solution code:
#!/usr/bin/python3

M = 1000000007

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

c = ((6 * n - 6 * k + 12 + 3 * (n + 1) * (k + n + 1) * (n - k + 2) - (n + 1) * (n + 2) * (2 * n + 3) + k * (k - 1) * (2 * k - 1)) // 6) % M

print(c)

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

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

Submission status: Accepted

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

l = [i for i in range(n+1)]

mod = 10**9 + 7

cnt = 0

for i in range(k,n+2):
    mi = i*(i-1) // 2
    ma = i*(2*n-i+1) // 2
    #print('min:',min)
    #print('max:',max)
    cnt += ma - mi + 1
print(cnt % mod)

Submission status: Accepted

Solution code:
from itertools import combinations
N, K = map(int, input().split())
nums = [0 for _ in range(N + 1)]
for i in range(N + 1):
    if i == 0:
        nums[i] = 0
    else:
        nums[i] = nums[i - 1] + i
# print(nums)
if N + 1 == K:
    print(1)
else:
    count = 1
    for i in range(K, N + 1):
        # iは組み合わせに使うかず
        # 2,3,4
        min_nums = nums[i - 1]
        max_nums = nums[N] - nums[N - i]
        # print(i, nums[:i], min_nums, nums[N + 1 - i:N + 1], max_nums)
        # print(i, max_nums - min_nums + 1)
        count += max_nums - min_nums + 1

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

def solve(N, K, MOD=10**9+7):
    s = list(range(N+2))
    for i in range(1, N+2):
        s[i] = s[i-1] + i
        s[i] %= MOD

    ans = 0
    for k in range(N+1, K-1, -1):
        # [a, b]
        b = s[N+1] - s[N+1-k]
        b %= MOD
        a = s[k] - s[0]
        a %= MOD
        ans += (b - a + 1)
        ans %= MOD
    return ans


if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))

Submission status: Accepted

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

MOD = 10 ** 9 + 7

min_ = sum(range(K))
max_ = sum(range(N, N-K, -1))

count_ = 0

# K個以上選ぶのでKからはじめてN+1まで増やす
for i in range(K, N + 2):
    # 作れる個数
    add = max_ - min_ + 1

    min_ += i
    max_ += (N - i)

    count_ = (count_ + add ) % MOD

print(count_)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


def main():
    input = sys.stdin.readline
    n, k = map(int, input().split())
    MOD = 10**9 + 7
    answer = 0
    for i in range(k, n+2):
        mi = sigma(0, 1, i)
        ma = sigma(n, -1, i)
        answer += ma - mi + 1
    print(answer % MOD)


def sigma(a, d, n):
    return (2*a+(n-1)*d)*n//2


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 0
for j in range(k, n + 2):
    small = cum[j]
    big = cum[n + 1] - cum[n - j + 1]
    ans += big - small + 1
    ans %= mod

print(ans % mod)

Submission status: Accepted

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

for i in range(K, N+2):
    # i個選ぶ時
    #print('i=', i, end='')
    # max = N-i+1 + ... + N
    max = (N-i+1+N)*i // 2
    #print(' max=', max, end='')
    
    # min = 0+1+ ... + i-1
    min = (0 + i-1)*i // 2
    count += max-(min-1)
    #print(' min=', min)

print(count % mod)

Submission status: Accepted

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

Submission status: Accepted

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

mod = 10**9+7
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
mod = 10**9+7
N,K = [int(x) for x in stdin.readline().rstrip().split()]
l = np.cumsum(range(0,N+1))
r = np.cumsum(range(N,-1,-1))
ans = 0
for k in range(K,N+2):
    ans += (r[k-1] - l[k-1] + 1)
    ans %= mod
print(ans%mod)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int,input().split())

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

Submission status: Accepted

Solution code:
t = input().split( )
n = int(t[0])
k = int(t[1])

mod = int(1e9+7)

x = int((k-1)*k*(2*k-1)/6)
y = int((n+1)*(n+2)*(2*n+3)/6)
z = int((n+1)*(n+k+1)*(n-k+2)/2)
w = int(n-k+2)

print(int((x-y+z+w)%mod))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
def readInt():
    return list(map(int,input().split()))
n, k = readInt()
ans = 0
# l = [int(x) for x in range(n+1)]
for i in range(k,n+2):
    smallest = (i-1)*i /2
    largest = n*(n+1)/2 - (n-i)*(n-i+1)/2
    ans += int(largest - smallest + 1)
    ans %= 10**9 + 7
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):
    x=(n*(n+1)//2)%mod-((n-i)*(n-i+1)//2)%mod
    y=(i*(i-1)//2)%mod
    ans+=(x-y+1)%mod
    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):
	l = (i - 1) * i // 2
	r = (2 * N - i + 1) * i // 2
	ans += r - l + 1
	ans %= mod

print(ans)

Submission status: Accepted

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

_mod = 10 ** 9 + 7

ans = 0

#init
min0 = sum(range(0,k))
max0 = sum(range(n + 1 - k, n + 1))
cnt = max0 - min0 + 1
ans = cnt

for i in range(k+1 , n + 2):
#    min0 = min0 + i - 1
#    max0 = max0 + (n + 1 - i)
#    cnt  = max0 + (n + 1 - i) - (min0 + i - 1) + 1
    cnt = cnt + (n + 1 - i) - (i - 1)    
    ans += cnt % _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):
    ans += i*(N+1-i)+1
print(ans%mod)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
# 整数の入力
n, k = map(int, input().split())
# 計算
count = 0
max = 0
min = 0

for i in range(k):
    min += i
    max += n-i
# print(min, max)
for i in range(k, n+2):
    count += max - min + 1
    min += i
    max += n-i
    # print(count)
    # print(min, max)

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

Submission status: Accepted

Solution code:
def main():
    mod = 1000000007
    n, k = (int(x) for x in input().split())
    l = (i for i in range(n + 1))  # おまけの小さい部分，でも大事

    # 累積和を計算しておく，前からと後ろから。
    former = 0
    acm = tuple((former:= former + i) for i in range(n + 1))
    former = 0
    acm_rev = tuple((former:= former + i) for i in range(n, -1, -1))

    ans = 0
    # 選ぶ数の数で分ける。でかい部分は無視して，
    # 最小値と最大値が分かれば取りうる値も分かる。
    for j in range(k-1, n + 1):
        ans += acm_rev[j] - acm[j] + 1
        ans %= mod
    return ans


if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

ret = 0

for i in range(k, n+2):
    min_val = i * (i - 1) // 2
    max_val = (n * (n + 1) // 2) - ((n - i) * (n - i + 1) // 2)
    ret += (max_val - min_val) + 1

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

Submission status: Accepted

Solution code:
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

N, K = mapint_inp()
MOD = 10**9+7

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

print(ans%MOD)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!python3

MOD = int(1e9 + 7)

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


def main():
    ans = 0
    s = N * (N + 1) // 2
    for i in range(K, N + 2):
        a = i * (i - 1) // 2
        b = s - (N - i) * (N - i + 1) // 2
        ans = (ans + b - a + 1) % MOD

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
mod = 1000000007

N,K = map(int, input().split(sep=" "))
#選ぶ個数が違えば絶対その和は違うだろう
sum = 0
for i in range(K,N+2,1):
    Min = (((i+1)*i)/2)%mod
    Max = (i*(N+2)-((i+1)*i)/2)%mod
    sum = (sum + Max - Min +1)%mod 
print(int(sum))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, k = [int(m) for m in input().split()]
mod = 10 ** 9 + 7

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

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())  # 0~NのN+1個の数字, K個以上選んで出来上がる数
ans = 0
MOD = 10**9+7
# 出来上がる数字の幅を考える
for k in range(K, N+2):  # K~N+1までループを回す
  upper = k*(2*N-(k-1))//2
  lower = k*(k-1)//2
  ans += upper - lower + 1
  ans %= MOD
print(ans)

Submission status: Accepted

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

ans, saidai, saisyo = 0, 0, 0
for i in range(1, N+2):
    saisyo += i-1
    saidai += N-i+1
    if i >= K:
        ans += (saidai - saisyo + 1)
    
print(ans%(10**9+7))

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

Submission status: Accepted

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

count = 0
lower = (k - 1) * (k - 2) // 2
upper = (k - 1) * (2 * n - k + 2) // 2
for i in range(k, n + 2):
  lower += i - 1
  upper += n - i + 1
  count = (count + upper - lower + 1) % mod
print(count)

Submission status: Accepted

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

ans, saidai, saisyo = 0, 0, 0
for i in range(1, N+2):
    saisyo += i-1
    saidai += N-i+1
    if i >= K:
        ans += (saidai - saisyo + 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(k, n+2):
    min = ((i-1)*i)//2
    max = ((2*n-i+1)*i)//2
    ans += max-min + 1
print(ans%mod)

Submission status: Accepted

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

low, high = 0, 0
ans = 0
for i in range(1, N + 2):
    low += i - 1
    high += N - i + 1

    if i >= K:
        ans += (high - low + 1)
        ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, k = map(int, input().split())
# 選ぶ数が違う時絶対に違う
# 1..N の中で和が同じにならない組み合わせを引いたらいい
# 解説AC  k ... n+1 について最大、最小をとってその間は全部作れる
ans = 0
mod = 10 ** 9 + 7
for i in range(k, n + 2):
    mi = (i - 1) * i // 2
    ma = (2 * n - i + 1) * i // 2
    # print(i, (ma - mi + 1))
    ans += (ma - mi + 1) % mod
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):
    a = i*((2*n)-i+1)/2
    b = i*(i-1)/2
    ans += (a-b+1)

print(int(ans%mod))

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]

n,k = LI()
from scipy.special import comb
ans = 0
mod = 10**9+7
l = [i for i in range(n+1)]
a = sum(l[:k])
b = sum(l[-k:])
for i in range(k,n+2):
    ans += b-a+1
    a += i
    b += n-i
print(ans%mod)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ans = 0
for t in range(k, n+2):
    pattern = t * (n+1-t) + 1 % mod
    ans = (ans + pattern) % mod

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def x_sum(x):
    return (2*n-x+1)*x//2 - x*(x-1)//2 + 1

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

print(ans)

Submission status: Accepted

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

def x_sum(x):
    return (2*n-x+1)*x//2 - x*(x-1)//2 + 1

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

print(ans)

Submission status: Accepted

Solution code:
N, K= map(int, input().split())
answer = 0
n_list = [0]*(N+1)
n_list[0] = 0
for i in range(1,N+1):
    n_list[i] = n_list[i-1]+i

for k in range(K,N+1):
    large = n_list[N]-n_list[N-k]
    small = n_list[k-1]

    answer += large-small+1
answer += 1
print(answer % 1000000007)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
A = 0
while K < N +2:
    min = K/2*(K-1)
    max = K/2*(2*N-K +1)
    A += max - min + 1
    K+= 1
print(int(A % (10**9 +7) ))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = [int(x) for x in input().split()]
Sum = 1
ans = 1
T = N + 1 - K
for t in range(T):
  Sum = (Sum + (N - 2 * t)) % 1000000007
  ans = (ans + Sum) % 1000000007
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):
    ans += i*(n-i+1) + 1

print(ans%mod)

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
lis = [i for i in range(n+1)]
rui = [0]*(n+2)
tmp = 0
for j in range(n+1):
    tmp += lis[j]

    rui[j+1] += tmp

ans = 0
for l in range(k,n+2):
    ans += rui[n+1]-rui[n-l+1]-rui[l] +1
ans %= 1000000007
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = [int(i) for i in input().split()]
result = 0
value = 1000000007

def nums_every_k(n,k):
    first_num = (k*(k-1))/2
    last_num = k*(2*n-k+1)/2
    numbers = last_num - first_num + 1
    return numbers
    
for k in range(K,N+2):
    result += nums_every_k(N,k)

result = result%value
print(int(result))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())  # 0~NのN+1個の整数, K個以上選ぶ, 注意 ; 3, 5 と 1, 3, 4は別物になる。0と5, 2と3 を選んだパターンは同じになる

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    MOD = 1000000007
    N, K = map(int, input().split())
    L, R = list(range(N + 1)), list(range(N + 1))[::-1]
    for i in range(N):
        L[i + 1] += L[i]
        R[i + 1] += R[i]
    ans = 0
    for i in range(K - 1, N + 1):
        ans = (ans + R[i] - L[i] + 1) % MOD
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

total = 0
mod = 10**9+7
s = [0]
for i in range(0, N+1):
    s.append(s[-1] + i)

for i in range(K, N+2):
    total = (total + ((s[-1]-s[-(i+1)]) - s[i] + 1)) % mod
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

my_code_D()

Submission status: Accepted

Solution code:
import sys
from collections import Counter

lines = 1
inp = list()

for _ in range(lines):
    inp.append(sys.stdin.readline().strip())


nk = inp[0].split()
n = int(nk[0])
k = int(nk[1])

# def sigma(_m, _n, func, s=0):
#     if _m > _n:
#         return s
#     return sigma(_m+1, n, func, s + func(_m))
#
#
# sigma = sigma(1, k-2, lambda x: x)

i = 1
sigma = 0
while i <= k - 2:
    sigma += i
    i += 1


result = 0
i = k


while k <= i <= n + 1:
    sigma += i - 1
    result += i * n - 2 * sigma + 1
    i += 1


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

Submission status: Accepted

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

for i in range(k-1,n+1):#i+1こ選んだ場合
  #zにi+1個選んだ場合の和の組み合わせを格納。
  z[i]=(2*n-i)*(i+1)/2-i*(i+1)/2+1

#z[i]にはkとしてi+1個選んだ場合の和の数が格納(1=<k<=n+1) 
ans=0
for i in range(n+1):
  ans+=z[i]
print(int(ans%(10**9+7)))

Submission status: Accepted

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

for i in range(k, n+2):
  min = int(i * (i - 1) / 2) #等差数列の和
  max = int(i * (2 * n - i + 1) / 2)
  cnt += max - min + 1

print(cnt % mod)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
s=0
pre=[]
m=10**9+7
for i in range(n+1):
    s+=i
    pre.append(s)
ans=0

for i in range(k,n+1):
    mn=pre[i-1]
    mx=(pre[n]-pre[n-i])
    ans+=(mx-mn+1)
print((ans+1)%m)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
mod=10**9+7
sum_=[0]
for i in range(n):
    sum_.append(sum_[-1]+(i+1))
for i in range(k-1,n+1):
    ans+=(i+1)*n-sum_[i]-(sum_[i]-1)
    ans=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 -i**2 +i +1
print(ans%(10**9 + 7))

Submission status: Accepted

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

ans = 0
MOD = 10**9 + 7


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


for i in range(K, N + 2):
    min = sum(0, i - 1)
    max = sum(N - (i - 1), N)
    ans += max - min + 1

print(ans % MOD)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n,k=map(int,input().split())
ans=0
for i in range(k,n+2):
 ans+=(n*(n+1))//2-max(0,(k+1-i)*(k-i)//2)-i*(i-1)//2+1
 #print((n*(n+1))//2-max(0,(k+1-i)*(k-i+2)//2))
 ans%=10**9+7
 #print(ans)
print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,k = readInts()
    # n = 0,1,2,3,4
    # k以上、選ぶ数をaとすると、最小の和の数と、最大の和の数っていうのが分かる
    # その選びかたは、k = 2 だとすると、
    # 最小の和の数は、0+1 = 1 (2番目まで)
    # 最大の和の数は、4+3 = 7 (n+1番目からn番目まで)
    # ということは、1,2,3,4,5,6,7の7通りあるので、
    # 7 - 1 + 1 = 7 という風に出すことが出来る
    # という感じで、各kに対してfor文を回してあげればいい
    # 和の数は、初項 + 末尾 ) * 項数 // 2 で求めれる
    def calc(a):
        sml = (0 + a-1) * a // 2
        lar = sml + a * (n-a+1)
        return lar - sml + 1
    ans = 0
    for i in range(k,n+2):
        ans += calc(i)%mod
    print(ans%mod)
if __name__ == '__main__':
  main()

Submission status: Accepted

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

for i in range(k, n+2):
  # 最小の和: 0 -> i-1 まで
  s_min = i * (i-1) // 2
  # 最大の和: n-i+1 -> n まで
  s_max = (n+1) * n // 2 - (n-i+1) * (n-i) // 2
  # とりうる個数
  s_count = s_max - s_min + 1
  # 答えに追加
  ans = (ans + s_count) % div

print(ans)

Submission status: Accepted

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

mod = int(1e9+7)

##O(K)
upper = 0
for i in reversed(range(N+1-K,N+1)):
    upper += i
upper_point = N-K
##O(K)
lower = 0
for i in range(K):
    lower += i
lower_point = K
ans = 0

for i in range(K,N+2):
    ##print("N:",i,upper-lower+1)
    
    ans += upper - lower + 1
    upper += upper_point
    lower += lower_point

    upper_point -= 1
    lower_point += 1

print(ans%mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 10**100の桁とそれ以外で分けて考える。
# 10**100の桁はk個選ぶと必ずk*10*100となるので無視
# 0~Nからk個選んだ場合の合計値が何個あるか数える
# 合計値のパターンは最小値から最大値まで連続した値となる
# N=3,K=2の場合、合計値パターンは5パターン：1(最小値),2,3,4,5(最大値)
# k番目の最小値は0,1,2,…k-1 = k*(k-1)/2
# k番目の最大値はn-k+1,n-k+2,n-k+3,…,n = k*(2n-k+1)/2

n,k = [int(x) for x in input().split()]
count=0
mod = 10**9+7
for i in range(k,n+2):
    mink=int(i*(i-1)/2)
    maxk=int(i*(2*n-i+1)/2)
    count+=maxk - mink + 1

print(count%mod)

Submission status: Accepted

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

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

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

r=[]
mi=0
ma=0
su=range(n+1)
for i in range(n+1):
    mi+=su[i]
    ma+=su[::-1][i]
    r.append(ma-mi+1)

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