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

lst = [i for i in range(N+1)]
rlst = [i for i in range(N,-1,-1)]

P = 10**9 + 7
rlt = 0

mini = sum(lst[:K-1])
maxi = sum(rlst[:K-1])

for i in range(N -K + 2):
  mini += lst[K+i-1]
  maxi += rlst[K+i-1]
  rlt += maxi -mini + 1
  rlt %= P
  
print(rlt)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
num = list(range(N+1))
count = 0
base_minimum = sum([i for i in num[:K]])
base_maximum = sum([i for i in num[-K:]])
count += base_maximum - base_minimum + 1

for k in range(K, N+1):
    base_minimum += num[k]
    base_maximum += num[-k-1]
    count += base_maximum - base_minimum + 1
    
print(int(count%(1e9+7)))

Submission status: Accepted

Solution code:
import numpy as np

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

cumsum = np.arange(0, N + 2).cumsum()

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

MOD = 10**9 + 7

N,K = map(int, input().split())
k = np.arange(K,N+2)
low = (k-1)*k//2
high = (N-k+1)*k + low + 1
ans = (high-low)%MOD
print(ans.sum()%MOD)

Submission status: Accepted

Solution code:

def resolve():
    MOD = 10 ** 9 + 7
    N, K = map(int, input().split())
    ans = 0
    for k in range(K, N + 2):
        min_num = k * (k - 1) // 2
        max_num = k * (N * 2 - k + 1) // 2
        add = max_num - min_num + 1
        ans = (ans + add) % MOD
    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import itertools

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

num = []
for i in range(N+1):
    num.append(i)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a=range(n+1)

max=sum(a[n+1-k:])
min=sum(a[:k])
ans=max-min+1
if n+1==k:
  print(ans)
  exit()
for i in range(k+1,n+2):
    max += a[n+1-i]
    min += a[i-1]
    ans += max-min+1
print(ans%(10**9+7))

Submission status: Accepted

Solution code:
from itertools import combinations
MOD = 10**9+7

def main():
    N, k = map(int, input().split(' '))
    count = 0

    if k > N:
        print('1')
        exit(0)
    for i in range(k,N+2):
        maxsum = (N*(N+1) - (N-(i-1))*(N-i))//2
        minsum = (i-1)*i//2
        count += maxsum - minsum + 1

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
number = N+1-K+1
W = 0
for i in range(number):
    min = (K+i)*(K+i-1)/2
    max = (K+i)*(2*N-K-i+1)/2
    W += (max-min+1)
w = W % (1000000007)
print(int(w))

Submission status: Accepted

Solution code:
MOD = 10**9+7
a = 10**6
n, k = map(int, input().split())
nums = [i for i in range(n+1)]
min_n = sum(nums[:k])
max_n = sum(nums[-k:])
res = (max_n-min_n)+1
res %= MOD
i = 0
while k+i <= n:
    min_n += nums[k+i]
    max_n += nums[-(k+i+1)]
    diff = max_n - min_n
    res += diff+1
    res %= MOD
    i += 1

print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def fact(N):
        res = {}
        tmp = N
        for i in range(2, int(N ** 0.5 + 1) + 1):
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            if cnt > 0:
                res[i] = cnt
        if tmp != 1:
            res[tmp] = 1
        if res == {}:
            res[N] = 1
        return res


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N, K = Scanner.map_int()
    ans = 0
    N += 1
    for i in range(K, N + 1):
        l = i * (i - 1) // 2
        r = N * i - ((i + 1) * i) // 2
        ans += r - l + 1
        ans %= MOD
    print(ans)


def main():
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

for k in range(K,N+2): 
    counter += k*(N-k+1) + 1


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

Submission status: Accepted

Solution code:
modprime = 10**9+7
n, k = map(int, input().split())
big_total = 0
# fix the number of selected
for z in range(k, n+2):
  min_sum = (z-1)*z//2
  max_sum = n*(n+1)//2 - (n-z)*(n-z+1)//2
  # all intermediate sums are possible
  num_sums = max_sum - min_sum + 1
  big_total = (big_total + num_sums)%modprime
print(big_total)

Submission status: Accepted

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

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

    ans += maxx - mini + 1
    ans %= MOD

print(int(ans))

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
MOD = 10**9+7
s = 1
for k in range(K,N+1):
    t = (N+1-k)*k+1
    # print(t)
    s += t
    s = s%MOD
print(s)

Submission status: Accepted

Solution code:
import sys
n, k = [int(i) for i in sys.stdin.readline().split()]
MOD = 10**9 + 7
_sum = 0
for i in range(k,n+2):
    _sum += ((n + (n-i+1)) * i // 2) - ((i-1) * i) // 2 + 1
    _sum %= MOD
print(_sum)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = [i for i in range(n+1)]
mod = 10**9+7
ans = 0
for i in range(k, n+2):
  L = i * (i - 1) / 2
  R = n * i - i * (i - 1) / 2
  ans += R - L + 1
  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 = (i-1)*i//2
  ans += n*i-2*a+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**2 - i)//2
  MAX = n*i - MIN
  ans += MAX - MIN + 1
  
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):
  L = (i-1)*i / 2  #初項0,末項l,項数iの等差数列の和
  H = ((n-i)+(n+1))*i //2 #初項a,末項l,項数iの等差数列の和
  ans += H - L + 1
  ans %= MOD
print(int(ans))

Submission status: Accepted

Solution code:
n,k = list(map(int, input().split()))
ans = 0
sum_n = (n+1)*n/2

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

Submission status: Accepted

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

#k ... n の値を取りうる. mとする。
# 和としてあり得るものは、
# m*(2*0+(m-1))/2 ~ m*(2*n+(m-1)*-1)/2 までの値を取りうる
# よって
# m*(2*n+(m-1)*-1)/2 - m*(2*0+(m-1))/2 + 1 通りがありうる。
# 
# mはk~nまでとりうるので
ans=0
for m in range(k,n+1):
    ans+= (m*(2*n+(m-1)*-1)/2 - m*(2*0+(m-1))/2 + 1 )
print(int((ans+1)%(10**9+7)))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
mod = 10**9+7
from itertools import accumulate
lis = list(accumulate([0]+[i for i in range(N+1)]))
ans = 0
for k in range(K, N+2):
    MIN = lis[k]
    MAX = lis[-1]-lis[-1-k]
    ans += (MAX-MIN+1)
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
MOD = pow(10,9)+7
ans = 0
for i in range(K,N+2): #KからN+1
  MAX = i*(2*N-i+1)//2
  MIN = i*(i-1)//2
  #print(i,MIN,MAX)
  ans += (MAX-MIN+1)%MOD
print(ans%MOD)

Submission status: Accepted

Solution code:
import numpy as np

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

a = np.arange(n+1, dtype='int')

b = np.cumsum(a)

s = 0

for i in range(k, n+1):
	s += (b[n] - b[n-i]) - b[i-1] + 1
	s = s % 1000000007

s += 1
s = s % 1000000007
print(s)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
# ln = []
# for n in range(N + 1):
#     ln.append(n)
s = 0
f = N * (N + 1) / 2
for k in range(K,N + 2):
    # mx = sum(ln[N - k + 1:N + 1])
    # mn = sum(ln[0:k]) - 1
    mx = int(f - (N - k) * (N - k + 1) / 2)
    mn = int((k - 1) * k / 2) - 1
    m = mx - mn
    s += m
    s = s % (10 ** 9 + 7)
print(s)

Submission status: Accepted

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

MOD = 10 ** 9 + 7

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#D
from collections import deque
N,K = map(int,input().split())
numbers = [i for i in range(0,N+1)]
large  = deque([N])
small = deque([0])
for i in range(1,N+1):
    large.append(large[-1]+numbers[-i-1])
    small.append(small[-1]+numbers[i])

mod = 10**9+7

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
Max = [0]
Min = [0]
for i in range(1, N+2):
  Max.append(N-i+1+Max[i-1])
  Min.append(i-1+Min[i-1])
A = [mx-mn+1 for mx,mn in zip(Max,Min)]
B =[0]
for i in range(N+1):
  B.append(B[i]+A[i+1])
print((B[N+1]-B[K-1])%(10**9+7))

Submission status: Accepted

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

for right in range(1, N+2):
    S[right] = S[right-1] + A[right-1]

total = S[N+1]
ans = 0
for left in range(N+2):
    total -= A[max(left-1, 0)]
    if (N+1) - left >= K:
        ans += (total - S[(N+1)-left] + 1) % mod

print(ans % mod)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
MOD = 10**9+7
res = 0
curmin,curmax = 0, N
mini,maxi = 1, N-1
for i in range(1,N+2):
  if i == N+1:
    # print(1)
    res += 1
  else:
    if i >= K:
      # print(curmin,curmax)
      res = (res + curmax - curmin + 1) % MOD
    curmin += mini
    curmax += maxi
    mini += 1
    maxi -= 1

print(res % MOD)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

l = [0] * (n+2)
minv = 0
maxv = n

#print(l)
for i in range(1, n+2):
  #print(i)
  l[i] = maxv - minv + 1
  minv += i
  maxv += (n-i)

for i in range(k, n+2):
  ans = (ans + l[i]) % (10**9 + 7)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, k = map(int, input().split())
    nums = [i for i in range(n+1)]
    sums = [0]
    ans = 0
    x = 10**9 + 7
    for i in range(n):
        sums.append(nums[i+1]+sums[i])
    for j in range(k, len(nums)+1):
        if j == len(nums):
            ans += 1
        else:
            ans += sums[-1] - sums[-(1+j)] - sums[j-1] + 1
    print(ans%x)   

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def _sum(l, r):
  return (l+r)*(r-l+1)//2
  

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#N,K入力
n,k= map(int,input().split())

ans = 0

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

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
mo = 10 ** 9 + 7
ans = 0
def calc(t):
    u = (0 + t - 1) * t // 2
    v = (n + n - t + 1) * t // 2
    return v - u + 1
for i in range(k, n + 2):
    ans = (ans + calc(i)) % mo
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
mod = 10**9 + 7
count = 0
for n in range(K, N+2):
  maxSum = (n*(N + N-n+1))//2
  minSum = (n*(n-1))//2
  count += maxSum - minSum + 1
  count %= mod

print(count)

Submission status: Accepted

Solution code:
import sys
import copy
from collections import deque
stdin = sys.stdin

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n,k = na()

if n==k-1:
    print(1)
    exit(0)

prev_min = sum([i for i in range(k)])
prev_max = sum([i for i in range(n, n-k, -1)])
prev_num_min = k-1
prev_num_max = n-k+1
cnt = 0
for i in range(n-k+2):
    # print("{} {}".format(prev_min, prev_max))
    cnt += prev_max-prev_min+1
    cnt %= mod
    
    prev_num_min += 1
    prev_num_max -= 1
    prev_min += prev_num_min
    prev_max += prev_num_max

print(cnt)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,k = nm()

MOD = 10**9+7
ans = 0

for kk in range(k,n+2):
  # print()
  aa = (n-kk+n+1)*kk//2
  bb = (0+kk-1)*kk//2
  # print(aa)
  # print(bb)
  a=aa-bb
  # print(a)
  ans+=a+1%MOD

print(ans%MOD)

Submission status: Accepted

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

Submission status: Accepted

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

#取る個数が違った場合、その和は絶対同じ数にならない。
#n個とるとしたら最低値(lowest)は下(0)からn-1まで、最大値(highest)は上(N-0)からN-(n-1)までの和
#最小値から最大値は連続的にすべての値をとる。
#ただし、n=K~Nであるのでここはfor文

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

Submission status: Accepted

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

def choose(n, m):   #0~nからm個選ぶ和の種類
    return (n - m + 1) * m + 1

s = 0
for i in range(k, n + 2):
    s += choose(n, i)

s %= (10**9 + 7)
print(s)

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

ans = 0
MOD = 10 ** 9 + 7 
for i in range(k, n + 2):
    low = (0 + i - 1) * i // 2
    # high = sum(j for j in range(n + 1 - i, n + 1))
    high = (n + 1 - i + n) * i // 2
    ans += (high - low + 1) % MOD
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 x in range(1, N + 2):
    low += x - 1
    high += N - x + 1

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

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
N, K = lr()
answer = 0
for i in range(K, N+2):
    low = i * (i-1) // 2
    high = i * (N+N-i+1) // 2
    answer += high - low + 1
    answer %= MOD

print(answer%MOD)

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    mod = 10**9+7
    if n - k == -1:
        print(1)
    else:
        ans = (n+2*k) * (n-k+1) * (n-k+2) // 6 + n - k + 2
        print(ans%mod)
if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = list(map(int, input().split()))
mod = int(1e9+7)
# N+1からK個をとる手法
# だけどmin - maxまで一飛ばしで作れるはずなので引き算でもとめてよい
ans = 0
for i in range(K,N+2):
  ans = (ans + i * (N+1-i) + 1) % mod
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(n, k):
    ans = 0
    mod = int(1e9 + 7)
    for i in range(k, n + 2):
        lb = (i - 1) * i // 2
        ub = (n + n - i + 1) * i // 2
        ans += ub - lb + 1
        ans %= mod
        # print(ub-lb+1, ub, lb, i)
    return ans


def main():
    # print(solve(3, 2))
    # print(solve(200000, 200001))
    # print(solve(141421, 35623))
    print(solve(*[int(v) for v in input().split()]))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

num = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def sum_of(n):
    return n * (n - 1) // 2

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

for i in range(K, N + 2):
    mini = sum_of(i)
    maxi = sum_of(N + 1) - sum_of(N - i + 1)
    ans += (maxi - mini + 1)

print(ans % mod)

Submission status: Accepted

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

MOD = (10**9) + 7


def dSum(s, e):
    s -= 1
    _s = s * (s + 1) // 2
    _e = e * (e + 1) // 2
    return _e - _s


ans = 0
for i in range(k, n + 1):
    # _sum = dSum(n - i - 1, n) - dSum(0, i - 1) + 1
    ans += dSum(i, n) - dSum(0, n - i) + 1

print((ans + 1) % MOD)

Submission status: Accepted

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

n = n+1
mod = 10**9+7

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

    ans = (ans + m2 - m1 + 1) % 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:
MOD = 10**9 + 7
N, K = map(int, input().split())
cusum = [0]
for i in range(1, N+1):
    cusum += [cusum[-1] + i]
ans = 0
for k in range(K, N+1):
    ans += (cusum[N]-cusum[N-k]-cusum[k-1] + 1)
    ans %= MOD
print((ans+1)%MOD)

Submission status: Accepted

Solution code:
import sys
# from collections import defaultdict
# from collections import Counter
# from queue import Queue
# sys.setrecursionlimit(2000000)

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

MOD = 1000000007

def main():
    # N = int(input())

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

    # sum of 0~i
    s = 0
    comm_sum = [0]
    for i in range(1, N+1):
        s += i
        comm_sum.append(s)

    # sys.stderr.write('{}\n'.format(comm_sum))

    ans = 0
    for k in range(K, N+1 + 1):
        if k == N + 1:
            ans = (ans + 1) % MOD
            continue
        max_a = comm_sum[N] - comm_sum[N - k]
        min_a = comm_sum[k - 1]
        diff = max_a - min_a + 1
        ans = (ans + diff) % MOD
        # sys.stderr.write('k = {}\n'.format(k))
        # sys.stderr.write('{}\n'.format(min_a))
        # sys.stderr.write('{}\n'.format(max_a))
        # sys.stderr.write('{}\n'.format(diff))
        # sys.stderr.write('--\n')

    print(ans)

    return 0

if __name__ == '__main__':
    sys.exit(main())

Submission status: Accepted

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

Submission status: Accepted

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

    res=0

    MOD=10**9+7

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

        res+=MAX-MIN+1
        res%=MOD

    print(res%MOD)

if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

print(int(ans))

Submission status: Accepted

Solution code:
mod = 1000000007

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

memo = []

for i in range(n+1):
  memo.append(i)

min_sum = [0]

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

memo.reverse()

max_sum = [memo[0]]

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

ans = 0

for i in range(k-1,n+1):
  ans += max_sum[i]-min_sum[i]+1

print(ans%mod)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
ans=0
for i in range(K,N+2):
  if i!=(N+1):
    anssub=N*(N+1)//2 -(N-i)*(N-i+1)//2 - i*(i-1)//2+1
  else:
    anssub=1
  ans+=anssub
ans=ans%(10**9+7)
print(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):
    min = i*(i-1)/2
    max = (2*N-i+1)*i/2
    ans += max - min + 1
print(int(ans%mod))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
# 累積和！max-min+1
csl=[]
sum=0
for i in range(n+1):
	sum+=i
	csl.append(sum)
#3 2
#[0, 1, 3, 6]
# 0 1 2 3
cnt=0
for i in range(k,n+1):
	max=csl[n]-csl[n-i]
	min=csl[i-1]
	#初めの数も含むの+1
	cnt+=(max-min+1)
	cnt%=(10**9+7)
#0~nまで全選択の+1
print(cnt+1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    mod = 10**9 +7
    n,k = 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)
    print(ans%mod)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

res = 0
s = [i for i in range(N)]

if K == 1:
    res += N
    K = 2

if N == 0:
    print(res)
    exit(0)

res += 1
minimum = sum(s[:K - 1])
maximum = sum(s[-K + 1:])

for i in range(K, N):
    minimum += s[i]
    maximum += s[-i + 1]
    res = (res + (maximum - minimum + 1)) % (10 ** 9 + 7)

print(res)

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

Submission status: Accepted

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

min_ = k * (k-1) // 2
max_ = k * (2*n-k+1) // 2
ans = max_ - min_ + 1
ans = ans % (10**9+7)

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

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

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    N, K = map(int,input().split())
    mod = 10 ** 9 + 7
    ans = 0
    for i in range(K, N + 1 + 1):
        mi = int((i - 1) * i / 2)  #ma、miは i * (10 **100)を無視した上限下限
        ma = i * N - mi
        ans += ma - mi + 1
    print(ans % mod)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

def select(l, r):
    return (l+r)*(r-l+1) // 2

for i in range(k, n+2):
    l = select(0, i-1)
    r = select(n-i+1, n)
    ans += (r-l+1) 
    ans %= (pow(10, 9) + 7)

print(ans)

Submission status: Accepted

Solution code:
import math

DEN=10**9+7
def ret_val(n):
    return n%DEN

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

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

print(ret_val(sum))

Submission status: Accepted

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

c = 0
for i in range(K, N + 2):
    min = i * (i + 1) / 2
    max = i * (N + 2 - i + N + 1) / 2
    c += max - min + 1
    c %= (1e9 + 7)
print(int(c))

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
mod = pow(10,9)+7
c = 0
cnt = 0
for i in range(K,N+1):
    temp1 = 0.5*(K+cnt)*(K+cnt-1)
    temp2 = (K+cnt)*0.5*(2*N-(K+cnt-1))
    c += temp2 - temp1 + 1
    c = c%mod
    cnt += 1
c += 1
print(int(c))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

from itertools import accumulate
s=list(accumulate(t))
s_rev=list(accumulate(t_rev))
s.append(s[-1])
s_rev.append(s_rev[-1])

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