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 = [int(s) for s in input().split(" ")]
res = 0
for i in range(K, N + 2):
  res += (N - i + 1) * i + 1
  #print res, i, (N - i + 1) * i + 1
print(res % 1000000007)

Submission status: Accepted

Solution code:
from itertools import accumulate

N, K = map(int, input().split())
a = [i for i in range(N+1)]
# print(a)
b = list(accumulate(a))
# print(b)
# print(a)
mod = 10**9 + 7
ans = 0

for i in range(K, N+2):
    if i == N+1:
        end = b[N]
        start = b[i-1] - b[0]
    else:
        end = b[N] - b[N-i]
        start = b[i-1] - b[0]
    # print(end)
    # print(start)
    ans += end - start + 1
print(ans % mod)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n , k = map(int , input().split())
sum = 0
mod = 1e9+7
def func(x):
    return (2 * n - x + 1) * x / 2 - (x - 1) * x / 2 + 1
for i in range(k , n+2):
    sum = (sum + func(i)) % mod
print(int(sum))

Submission status: Accepted

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

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

ans=0
M=1000000007

S=[0]*(N+2)

for i in range(1,N+1):
    S[i+1]=S[i]+i

for i in range(K,N+2):
    U=S[N+1]-S[N-i+1]
    B=S[i]
    ans+=U-B+1
    ans%=M

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(K, N + 2) :
	sum_lasti = i * (2 * N + 1 - i)/2 #初項 N + 1 - i 項数 i 公差1 末項 Nの等差数列の和
	sum_firsti = ( i * i - i )/ 2 #初項 0 項数 i 公差1 末項 i-1の等差数列の和
	
	res += sum_lasti - sum_firsti + 1

print(int(res%1000000007))

Submission status: Accepted

Solution code:
from itertools import accumulate
mod = 10**9 + 7
N, K = map(int, input().split())
a = [i for i in range(N+1)]
b = list(accumulate(a))
#b = [0] + b
# print(b)
# print(a)
ans = 0
for i in range(K, N+2):
    if i == N+1:
        v1 = b[N]
        v2 = b[i-1] - b[0]
    else:
        v1 = b[N] - b[N-i]
        v2 = b[i-1] - b[0]
    # print(v1)
    # print(a[N-i+1:])
    # print(a[:i])
    ans += v1 - v2 + 1
print(ans % mod)

Submission status: Accepted

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

Submission status: Accepted

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

al=[0]*(n+1)
bl=[0]*(n+1)
bl[0]=n
for i in range(1,n+1):
    al[i]=i+al[i-1]
    bl[i]=(n+1-i-1)+bl[i-1]
    
ans=0
for i in range(k,n+2):
    ans+=bl[i-1]-al[i-1]+1
print(ans%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MOD = 10**9 + 7
class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

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

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

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

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

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

    __radd__ = __add__

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

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

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

def differenceOfMaximumSumAndMinimumSum(cumulative_sum, i):
    return (cumulative_sum[-1] - cumulative_sum[-i-1]) - cumulative_sum[i - 1]

def solve(N, K):
    ret = ModInt(1)
    cumulative_sum = [0] * (N + 1)
    tmp_sum = 0
    for i in range(1, N + 1):
        tmp_sum += i
        cumulative_sum[i] = tmp_sum

    for i in range(K, N + 1):
        ret += differenceOfMaximumSumAndMinimumSum(cumulative_sum, i) + 1
    return ret


if __name__ == '__main__':
    N, K = map(int, input().split())
    print(solve(N, K))

Submission status: Accepted

Solution code:
def conta_casos(n, k):
    s = 0
    for i in range(k, n+2):
        s += i*(n-i+1)+1
    print(s % (1000000000+7))

a, b = [int(x) for x in input().split()]
conta_casos(a, b)

Submission status: Accepted

Solution code:
MOD = 10**9 + 7
class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

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

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

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

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

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

    __radd__ = __add__

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

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )
def sumOfArithmeticSequence(a, b):
    return (a + b) * (b - a + 1) // 2

def solve(N, K):
    ret = ModInt(0)
    for i in range(K, N + 2):
       ret += sumOfArithmeticSequence(N - i + 1, N) - sumOfArithmeticSequence(0, i - 1) + 1
    return ret


if __name__ == '__main__':
    N, K = map(int, input().split())
    print(solve(N, K))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
cnt = [0]*(N-K+2)

cnt_all = 0
mod = 1000000007

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

for i in range(N-K+2):
    cnt_all += cnt[i]

print(cnt_all % mod)

Submission status: Accepted

Solution code:
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans % MOD)

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7
N, K = map(int, input().split())
ruiMin = [0] * (N + 1)
ruiMax = [((N + 1) * N) // 2] * (N + 1)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


MOD = 10 ** 9 + 7


from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def main():
    n, k = input_to_int_map()

    all_n = n + 1
    ret = 0
    all_list_sum = [0]
    pre = 0
    for i in range(0, all_n):
        all_list_sum.append(i + pre)
        pre = i + pre

    for choice_cnt in range(k, all_n + 1):
        ret = (ret + (all_list_sum[n + 1] - all_list_sum[n + 1 - choice_cnt] - all_list_sum[choice_cnt] + 1))

    return ret % MOD


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

Submission status: Accepted

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

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


MOD = 10 ** 9 + 7


from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def main():
    n, k = input_to_int_map()

    all_n = n + 1
    ret = 0
    all_list_sum = [0]
    pre = 0
    for i in range(0, all_n):
        all_list_sum.append(i + pre)
        pre = i + pre

    for choice_cnt in range(k, all_n + 1):
        ret = (ret + (all_list_sum[n + 1] - all_list_sum[n + 1 - choice_cnt] - all_list_sum[choice_cnt] + 1)) % MOD

    return ret


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MOD = 1000000007

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
  ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
def solve():
    N, K = map(int, input().split())
    cs = [0] * (N + 1)
    for i in range(1, N + 1):
        cs[i] = cs[i - 1] + i
    # print(cs)
    ans = 0
    for i in range(K, N + 2):
        if i == N + 1:
            ans += 1
        else:
            mn = cs[i - 1]
            mx = cs[-1] - cs[-1 - i]
            ans += mx - mn + 1
        # print(i, mx, mn, ans)
        ans = ans % (10**9 + 7)
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

ans=0

if k==(n+1):
  print(1)

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

Submission status: Accepted

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

sum = 0

for j in range(K,M+2):
    temp = j*(M-j+1) + 1
    if temp > (10**9 + 7):
        temp = temp%(10**9 + 7)
    sum += temp
if sum > 10**9+7:
    sum = sum%(10**9+7)

print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    mod = 10**9 + 7
    ans1 = (N + 2 - K) % mod
    ans2 = ((N + 1) * (N + 1) * (N + 2) // 2 - (N + 1) * K  * (K - 1) // 2) % mod
    ans3 = ((N + 1) * (N + 2) * (2 * N + 3) // 6 - (K - 1) * K * (2 * K - 1) // 6) % mod
    ans = (ans1 + ans2 - ans3) % mod
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int, input().split())
x=0
a=list(range(0,n+1))
aa=list(range(1,n+2))
mod=10**9+7
from itertools import accumulate
A=list(accumulate(a))
for i in range(k-1,n+1):
    x+=(2*A[i]-1)%mod
    x%=mod
print(((sum(aa[k-1:])%mod*n)-x+mod)%mod)

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
mod = 1000000007
l = 0
r = N
ans = 0
for i in range(1, K):
    l += i
    r += N - i

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

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, K = list(map(int,_in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 0
    for i in range(K,N+2):
        cnt += (N*(N+1)//2-(N-i)*(N-i+1)//2) - (i-1)*i//2+1
    cnt = int(cnt % (1e9+7))
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Accepted

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


def log(v):
    print(v, file=sys.stderr)


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

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

Submission status: Accepted

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

ans = 0

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

print(ans%mod+1)

Submission status: Accepted

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

s = 0

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

print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def f(s, e):
    return (e-s+1)*(s+e)//2

N, K = map(int, input().split())
ans = 0
MOD = 10**9+7

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

print(ans)

Submission status: Accepted

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

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

m = l % (7 + 10**9)

print(m)

Submission status: Accepted

Solution code:
def abc(N, K):
    # 答えの準備
    ans = 0
    
    # 足す個数(K個足す最大値-最小値～N+1個足す最大値-最小値)
    for i in range(K, N+2):
        # i個足すときの最大値は、項数i,初項N-i+1,末項Nの階差数列の和
        max = int(0.5*i*(N-i+1+N))
        # i個足すときの最小値は、項数i,初項0,末項i-1の階差数列の和
        min = int(0.5*i*(0+i-1))
        # 最大値から最小値を引いて、個数なので最初の分1足す
        ans += max - min + 1
    
    # 答え
    if ans > 10**9 + 7:
        ans = ans % (10**9 + 7)
    return(ans)


# バッチスタート
if __name__ == "__main__":
    # 標準入力処理
    # 1行目の入力を空白で分割された2つの数値として扱う
    N, K = map(int, input().split())
    
    # 関数呼び出し
    f = abc(N, K)
    
    # 答えの出力
    print(f)

Submission status: Accepted

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

# print(min)
# print(max)
sum = 0
for i in range(k - 1, n + 1):
    sum = sum + max[i] - min[i] + 1
print(sum % (pow(10, 9) + 7))

Submission status: Accepted

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


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


print(result % mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools as it

N,K = map(int, input().split())
mod = 10**9 + 7
left = it.islice(it.accumulate(reversed(range(N+1))), K-1, N+1)
right = it.islice(it.accumulate(range(N+1)), K-1, N+1)
ans = sum(map(lambda x,y: x-y+1, left, right))
print(ans%mod)

Submission status: Accepted

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

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

Submission status: Accepted

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

MOD = 10**9 + 7

result = 0
for ki in range(k, n+2):
   first = ki * (ki - 1) / 2
   final = (2*n - ki + 1) * ki / 2
   add = final - first + 1
   result = (result + add) % MOD

print(int(result))

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
mod = 10**9+7
print( sum((n*l-l*(l-1)+1)%mod for l in range(k,n+2)) %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):
	l = (i - 1) * i // 2
	r = (2 * N - i + 1) * i // 2
	ans += (r - l + 1) % mod
	ans %= mod

print(ans)

Submission status: Accepted

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

mi = 0
ma = 0
for i in range(K-1):
    mi += i
    ma += N - i

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

print(ans)

Submission status: Accepted

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

# K個選んだときに作れる数の個数は、
# [大きいほうK個の和] - [小さいほうK個の和] + 1
# これらの総和を求める

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

print(ans)

Submission status: Accepted

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

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

max_sum = 0
min_sum = 0
ans = 0
for i in range(n+1):
    max_sum += l[n-i]
    min_sum += l[i]
    if i+1 < k:
        continue
    
    else:
        ans += (max_sum - min_sum + 1)
        ans %= mod

print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
def comb(n,k):
  s=(2*n-k+1)*k/2-k*(k-1)/2+1
  return s
l=0
for i in range(K,N+2):
  l+=comb(N,i)
print(int(l)%(10**9+7))

Submission status: Accepted

Solution code:
nk = [int(s) for s in input().split()]
n, k = nk[0], nk[1]
tot = 0
all_sums = [0]
for i in range(1, 200001):
    all_sums.append(i+all_sums[-1])
for i in range(k, n+1):
    tot = (tot + (all_sums[n]-all_sums[n-i]) - (all_sums[i-1]) + 1)%1000000007
print(tot+1)

Submission status: Accepted

Solution code:
import itertools
import math
import numpy as np
import fractions
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
import sys
sys.setrecursionlimit(10**9)

def main():
    N,K = map(int,input().split())
    p = 10**9 + 7

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

    print(ans)

if __name__ == "__main__":
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
n += 1
sum_n = sum(range(n))
ans = 0
for i in range(k, n+1):
    mi = i*(i-1) / 2
    ma = sum_n - ((n-i)*(n-i-1) / 2)
    ans += ma - mi + 1

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

Submission status: Accepted

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

def calcu(x):
    small = (x*(x-1))/2
    large = small + x*(N-x+1)
    return large-small+1

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

print(int(ans))

Submission status: Accepted

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

ans=0

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

Submission status: Accepted

Solution code:
def max_sum(n,k):
    sum = 0
    for i in range(n-k+1,n+1):
        sum += i
    return sum
N,K = map(int,input().split(" "))
sum = 0
mod_num = 1000000007
for i in range(K,N+2):
    max = i*(2*N-i+1)//2
    min = i*(i-1)//2
    sum += max-min+1
    sum %= mod_num

print(sum)

Submission status: Accepted

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

total=0
i=k
while i<=n+1:
	total+=(n - i + 1 + n) * i / 2 - (0 + i - 1) * i / 2 + 1;
	total %= MOD
	i+=1

print(int(total))

Submission status: Accepted

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

mod=10**9+7
ans=0
for kval in range(k,n+2):
    mx=kval*(2*n-kval+1)//2
    mn=kval*(kval-1)//2
    add=mx-mn+1
    ans=(ans+add) % mod

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def sum_from_1_to_n(n):
    return n * (n + 1) // 2


def main():
    n, k = map(int, input().split())
    mod = 10 ** 9 + 7
    answer = 0
    max_num = sum_from_1_to_n(n)
    for i in range(k, n + 2):
        answer += max_num - sum_from_1_to_n(n - i) - sum_from_1_to_n(i - 1) + 1
        answer %= mod
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate

def main():
    n,k = (int(x) for x in input().split())
    mod = 10**9 + 7
    left = tuple(accumulate(range(n+1)))
    right = tuple(accumulate(reversed(range(n+1))))
    tot = sum(r-l+1 for l, r in zip(left[k-1:], right[k-1:]))
    print(tot%mod)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(int(ans))

Submission status: Accepted

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

acc = [i for i in range(N+1)]
for i in range(N): acc[i+1] += acc[i]

ans = 0
for i in range(K,N+2):
    ma = acc[-1] - acc[max(-len(acc),-1-i)]
    mi = acc[i-1]
    ans += ma - mi + 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 k in range(K, N + 2):
    first = k * (k - 1) / 2
    final = (N*2-k+1) * k / 2
    add = final - first + 1
    ans = (ans + add) % MOD

print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# vim: set fileencoding=utf-8

# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation


"""Module docstring
"""

import functools
import heapq
import itertools
import logging
import random
import string
import sys
from argparse import ArgumentParser
from collections import defaultdict, deque
from copy import deepcopy
from math import factorial
from typing import Dict, List, Optional, Set, Tuple


def solve(values: List[str], nb: int) -> Optional[int]:
    for _v in values:
        pass
    return nb


def choose_n_k(n: int, k: int) -> int:
    return factorial(n) // (factorial(k) * factorial(n - k))


MODULO = pow(10, 9) + 7


def sum_fct(n: int) -> int:
    return ((n * (n + 1)) // 2) % MODULO


def do_job():
    "Do the work"
    LOG.debug("Start working")
    # first line is number of test cases
    # N = int(input())
    N, K = map(int, input().split())
    total = sum_fct(N)
    result = 0
    for i in range(K, N + 2):
        min_sum = sum_fct(i - 1)
        max_sum = total - sum_fct(N - i)
        result = (result + max_sum - min_sum + 1) % MODULO
    print(result)


def print_output(testcase: int, result) -> None:
    "Formats and print result"
    if result is None:
        result = "IMPOSSIBLE"
    print("Case #{}: {}".format(testcase + 1, result))
    # 6 digits float precision {:.6f} (6 is the default value)
    # print("Case #{}: {:f}".format(testcase + 1, result))


def configure_log(log_file: Optional[str] = None) -> None:
    "Configure the log output"
    log_formatter = logging.Formatter(
        "%(asctime)s - %(filename)s:%(lineno)d - " "%(levelname)s - %(message)s"
    )
    if log_file:
        handler = logging.FileHandler(filename=log_file)
    else:
        handler = logging.StreamHandler(sys.stdout)
    handler.setFormatter(log_formatter)
    LOG.addHandler(handler)


LOG = None
# for interactive call: do not add multiple times the handler
if not LOG:
    LOG = logging.getLogger("template")
    configure_log()


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    parser = ArgumentParser()
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="run as verbose mode",
    )
    args = parser.parse_args(argv)
    if args.verbose:
        LOG.setLevel(logging.DEBUG)
    do_job()
    return 0


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    sys.exit(main())


class memoized:
    """Decorator that caches a function's return value each time it is called.
    If called later with the same arguments, the cached value is returned, and
    not re-evaluated.
    """

    def __init__(self, func):
        self.func = func
        self.cache = {}

    def __call__(self, *args):
        try:
            return self.cache[args]
        except KeyError:
            value = self.func(*args)
            self.cache[args] = value
            return value
        except TypeError:
            # uncachable -- for instance, passing a list as an argument.
            # Better to not cache than to blow up entirely.
            return self.func(*args)

    def __repr__(self):
        """Return the function's docstring."""
        return self.func.__doc__

    def __get__(self, obj, objtype):
        """Support instance methods."""
        return functools.partial(self.__call__, obj)

Submission status: Accepted

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

ans = 0
for i in range(K,N+2):
    # 0~K-1までK個選ぶ→(K-1)K/2:最小値
    # N-(K-1)~NまでK個選ぶ→(2N-K+1)K/2:最大値
    # 最小値〜最大値までの数→最大ー最小＋１
    # K(N-K+1)+1
    ans += (i*(N-i+1)+1)%(10**9+7)

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