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:
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
from fractions import gcd
from math import ceil, floor
import bisect
sys.setrecursionlimit(10 ** 6)

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

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
mod = 10**9 + 7


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

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

print(answer)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)

#const
dxdy=((1,0),(0,1))
#my functions here!
def pin(type=int):
    return map(type,input().rstrip().split())


#your code here!
def resolve():
    N,K=pin()
    sita=0
    ue=N
    #方針
    ans=0
    for k in range(1,N+2):
        if k>=K:ans=(ans+(ue-sita+1))%1000000007
        sita+=k;ue+=N-k
    print(ans)
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 2"""
        output = """10"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """200000 200001"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """141421 35623"""
        output = """220280457"""
        self.assertIO(input, output)


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

    #I wrote my code above!

    resolve()#and submit 2 atcoder!

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
lst = list(range(0, n + 1))
reversed_lst = list(reversed(lst))
mod = 10 ** 9 + 7

min_lst = sum(lst[:k])
max_lst = sum(reversed_lst[:k])
ans = max_lst - min_lst + 1

while k <= n:
    min_lst += lst[k]
    max_lst += reversed_lst[k]
    ans += max_lst - min_lst + 1
    k += 1
    
print(ans % mod)

Submission status: Accepted

Solution code:
a=input().split()
N=int(a[0])
K=int(a[1])
count=int((1/2)*N*(N+1)*(N+1)-(N*(N+1)*(2*N+1))/6+N-(1/2)*(N+1)*K*(K-1)+(K*(K-1)*(2*K-1))/6-(K-1)+1)
print(count%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
f = lambda i: (3 * n + 4 - 2 * i) * i * (i - 1) // 6 
print((n - k + 2 + f(n + 2) - f(k)) % (10**9 + 7))

Submission status: Accepted

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

MOD = 10**9+7
cnt = 0

for i in range(k, n+2):
    min_sum = i*(i-1)//2
    max_sum = i*n - i*(i-1)//2
    cnt += max_sum - min_sum + 1
    cnt = cnt % MOD

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

MOD = 10 ** 9 + 7


def calc(i):
    init = i * (i + 1) // 2
    last = init + (N - i + 1) * i
    return last - init + 1


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

Submission status: Accepted

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

pattern = 0

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

print(pattern)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


############ ---- Input Functions ---- ############
def in_int():
    return (int(input()))


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


def in_str():
    s = input()
    return (list(s[:len(s) - 1]))


def in_ints():
    return (map(int, input().split()))

mod = 7 + 10**9

n, k = in_ints()

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
mx = 0
mn = 0

for i in range(N+1):
  mx += N-i
  mn += i
  if i + 1 >= K:
    ans += (mx - mn + 1) % INF

print(ans % INF)

Submission status: Accepted

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

cnt = 0
buf2_min = 0
buf2_max = 0
buf_max = 0
buf_min = 0

for j in range(k):
    buf2_max += n - j
    buf2_min += j

buf_max = n - k + 1
buf_min = k - 1

for i in range(n - k + 2):
    cnt += buf2_max - buf2_min + 1
    buf_max -= 1
    buf_min += 1
    buf2_max += buf_max
    buf2_min += buf_min
cnt  = cnt % (10**9 + 7)

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
mx = 0
mn = 0
for i in range(N+1):
  s = 0
  mx += N-i
  mn += i
  if i + 1 >= K:
    ans += (mx - mn + 1) % INF

print(ans % INF)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n, k = map(int,input().split())
    res = 0
    for i in range(k, n + 1):
        # 最小が 0 + 1 + ... + i - 1
        # 最大が (n + 1) + n + ... + (n - i + 2)
        low = (0 + (i - 1)) * i // 2
        high = (n + (n - i + 1)) * i // 2
        res += high - low + 1
        res %= MOD
    res += 1
    res %= MOD
    print(res)
resolve()

Submission status: Accepted

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

solution()

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:
import itertools

N, K = map(int, input().split())
# dic = {}
# count = 0
# for a in range(K, N+2):
#     for i in itertools.combinations(range(1, N+2), a):
#         length = len(i)
#         sum_ = sum(i)
#         if sum_ in dic.keys():
#             if length == dic[sum_]:
#                 continue
#             else:
#                 count += 1
#                 count %= 10000000007
#         else:
#             dic[sum_] = length
#             count += 1
#             count %= 10000000007
#
# print(count)
result = 0
for i in range(K, N+2):
    a = (i-1) * i/2
    b = (2*N-i+1) * i/2
    result += b - a + 1
    result %= 1000000007

print(int(result))

Submission status: Accepted

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

solution()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def s(i,n):
    s1 = (2 * i * i)
    s2 = (3 * n * (i+1)) 
    s3 = 8

    d = (s2 + s3 - s1)

    ans = ( int((i * d)/6 + 0.5) )
    
    return ans

ans = int(s(n+1,n) - s(k-1,n)) % MOD
if ans < 0:
    ans += MOD

print(int(ans))

Submission status: Accepted

Solution code:



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

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

for i in range(1, len(accum)):
    accum[i] += accum[i-1] 
accum = [0] + accum

backs = [i for i in range(N,-1,-1)]
cnt = [0] * (N+1)

tmp = 0
for i in range(N+1):
    tmp += backs[i]
    cnt[i] = tmp + 1 - accum[i]

ans = 0
for num in cnt[K-1:]:
    ans += num
    ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
n,k = list(map(int, input().split()))
ret = 0
sum_max = sum(range(n, n-(k-1), -1))
sum_min = sum(range(0,(k-1)))
for i in range(k, n+2):
    sum_max += n-(i-1)
    sum_min += i-1
    ret += ( sum_max - (sum_min-1) )
    if (10**9+7) <= ret:
        ret = ret % (10**9+7)
print(ret)

Submission status: Accepted

Solution code:
import itertools
import math
from functools import reduce

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

pattern = 0

for i in range(k, n + 2):
    min = i * (0 + i - 1) // 2
    max = i * (n + n - i + 1) // 2
    pattern += max - min + 1
    
pattern %= 10 ** 9 + 7
    
print(pattern)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
print(sum([i * (n + 1 - i) + 1 for i in range(k, n + 2)]) % (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
from heapq import heapify, heappop, heappush

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):
    # k個足してできる最大の整数
    # 大きい順にk個選べばよい
    # N + (N - 1) + ... + (N - k + 1)
    # = (0+1+...+N) - (0+1+...+(N-k)) = B
    B = N * (N + 1) // 2 - (N - k) * (N - k + 1) // 2
    # 最小の整数は小さい順にk個選べばよい
    # 0 + 1 + ... + (k-1)
    A = (k - 1) * k // 2
    # k個足してできる整数の数
    ans += (B - A + 1)
print(ans % mod)

Submission status: Accepted

Solution code:
import heapq
import math
import random
import sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, namedtuple, UserDict
from functools import cmp_to_key, lru_cache, reduce
from itertools import (chain, combinations, combinations_with_replacement,
                       permutations, product)

sys.setrecursionlimit(10**6+1)
write = sys.stdout.write
# input = sys.stdin.buffer.readline

MOD = 10**9 + 7


if __name__ == "__main__":
    n, k = map(int, input().split())
    head = sum(i for i in range(k))
    tail = sum(n-i for i in range(k))
    ans = tail - head + 1
    for i in range(k, n+1):
        head += i
        tail += n - i
        ans += tail - head + 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 += ((2*N-i+1)-(i-1))*i//2+1%MOD
print(ans%MOD)

Submission status: Accepted

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

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

Submission status: Accepted

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

# N, K = 3, 2

ans = 0
for k in range(K, N+1+1):
    sum_min = k*(k-1)//2
    sum_max = N*k - k*(k-1)//2
    ans += sum_max - sum_min + 1

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
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
  
print(ans%mod)

Submission status: Accepted

Solution code:
from math import comb as c
a,b=map(int,input().split())
print(((c(a+2,2)+1)*(a+2-b)-c(a+3-b,3)-c(a+3,3)+c(b+1,3))%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

mod = 10 ** 9 + 7
ans = 0

for k in range(K, N + 2):
    last = k * N - k * (k - 1) // 2
    init = N + k * (k - 1) // 2
    ans += init - k * (k - 1) // 2 + 1 + (last - init)
    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 += (i * (2 * n - i + 1) / 2) - (i * (i - 1) / 2) + 1


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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
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*(k-1)//2
  x = N-k
  ma = N*(N+1)//2 - x*(x+1)//2
  ans += ma-mi+1
  ans %= mod

print(ans%mod)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K=map(int,input().split())
s = 0 #合計

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

Submission status: Accepted

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

if K > N:
    print(1)
    exit()

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

res = 0
for i in range(K, N + 1):
    res += s[N] - s[N - i] - s[i - 1] + 1

# 全部取るときも足す
res = (res + 1) % (10 ** 9 + 7)

print(res)

Submission status: Accepted

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

mod = 10**9 + 7
n_list = [0]*(n+1)
for i in range(n+1):
    n_list[i] = (10**100 + i) % mod

s = [0]*(n+1)
s[0] = n_list[0]

for i in range(1, n+1):
    s[i] = (s[i-1] + n_list[i]) % mod
#print(s)

count = 0
for i in range(k, n+1):
    min_sum = s[i-1] % mod
    max_sum = (s[n] - s[n-i]) % mod
    m = (max_sum - min_sum) + 1 % mod
    count += m
count += 1  # k=n+1の分
print(count % mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

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

mo = 1000000007

ans = 0

for i in range(K,N+2):
    mi = i*(i+1)/2
    ma = i*(i+1)/2 + i * (N+1-i)
    ans += ma - mi + 1
    ans %= mo
    ans = int(ans)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
N, K = map(int, input().split())
ans = 0
mod = 10**9 + 7
vmin = 0
vmax = 0
L = [i for i in range(N+1)]
for i in range(N+1):
    vmin += L[i]
    vmax += L[-1-i]
    if i < K-1:
        continue
    ans += max(0, vmax - vmin+1)
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
MOD = 10**9 + 7

N,K = map(int,input().split())
s = 0
for k in range(K, N+2):
	s = (s + N*k - k*k + k + 1) % MOD
print(s)

Submission status: Accepted

Solution code:
import math

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

b=0

for i in range(K,N+2):
  a=1/2*i*(N-i+1+N)-1/2*i*(i-1)+1
  
  b+=a%(10**9+7)
  
print(int(b%(10**9+7)))

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:
import sys
input = sys.stdin.readline

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

ans = 0
for i in range(K, N + 2):
    mi = (i - 1) * i // 2
    ma = (N + N - i + 1) * i // 2
    ans += (ma - mi + 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 += i * (N - i + 1) + 1

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    a = [i for i in range(N+1)]
    s = [0] * (N+2)
    for i in range(N+1):
        s[i+1] = s[i] + a[i]
    ans = 0
    MOD = 10**9+7
    for i in range(K, N+2):
        ans += (s[-1]-s[-i-1]-s[i]+1) % MOD
    print(ans % 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):
    ans=(ans+(n-i+1)*i+1)%mod
print(ans)

Submission status: Accepted

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

min_sum = 0
max_sum = 0
under_K = 0
ans = 0
for i in range(N+1):
    min_sum += i
    max_sum += N - i
    if i < K - 1:
        under_K += max_sum - min_sum + 1
    ans += max_sum - min_sum + 1
    
print((ans - under_K) % (10**9+7))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline

MOD = 10 ** 9 + 7


def sum_up_to_n(n):
    return n * (n + 1) // 2


def main():
    N, K = [int(x) for x in input().split()]

    ans = 0
    b = sum_up_to_n(N)
    for i in range(K, N + 2):
        a = sum_up_to_n(i - 1)
        aa = sum_up_to_n(N - i)
        ans += (b - aa) - a + 1
        ans = ans % MOD

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import itertools
import time
n, k = list(map(int, input().split()))
MOD = 10 ** 9 + 7
result = 0
for x in range(k, n + 2):

    # print('選ぶ数', _k)
    min_value = x*(x-1)//2
    max_value = (n + n-x+1)*x//2
    # print(min_value, max_value)
    result += max_value - min_value + 1
print(int(result) % MOD)

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
wa=lambda a,b:(a+b)*(b-a+1)//2
print(sum([wa(a+2-i,a+1)-wa(0,i)+1for i in range(b,a+2)])%(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 += int(n*(n+1)/2 - (n-i)*(n - i + 1)/2 - (i-1)*i/2 + 1)
 
print(ans%mod)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

N, K = map(int, readline().split())
N = N + 1

lower = None
upper = None
answer = 0
for k in range(K, N+1):
    if lower is None:
        lower = sum(range(k))
        upper = sum(range(N-k, N))
    else:
        lower += k - 1
        upper += N - k
    answer += (upper - lower + 1)
print(answer % MOD)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ans = 0

# i個選んだ時の数を足していく
for i in range(K,N+2):
  min_sum_num = i*(i-1)//2
  max_sum_num = N*i - (i*(i-1)//2)
  ans += max_sum_num - min_sum_num + 1


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

Submission status: Accepted

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

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

#最小の値 0+1+2+...+K-1
#最大の値 N-K+1 + N-K+2 + ...+ N
#ans = (2N-K+1)*K/2 - ((K-1)*K/2 - 1)

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
#import copy
#import math
#import numpy as np
#import itertools
#import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#import functools

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
mod = 1000000007

#read = sys.stdin.buffer.read

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

    if K == N+1:
        print(1)
        return

    #ans0 = 0
    #ans1 = 0
    ans = 0
    for k in range(K, N+2):
        maxsum0 = (k * (2 * N - k + 1)) // 2
        #maxsum1 = ((k - 1) * (2 * N - k + 2)) // 2
        #minsum0 = (k * (k + 1)) // 2
        minsum1 = ((k - 1) * k) // 2
        #ans0 += maxsum0 - minsum0 + 1
        #ans1 += maxsum1 - minsum1 + 1
        ans += maxsum0 - minsum1 + 1

    ans = ans % mod
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
base = input().split()
n = int(base[0])
k = int(base[1])
ans = 0
x = []
for i in range(n+1):
    x.append(i)
y = x.copy()
y.sort(reverse = True)
for a in range(k,n+2):
    z = (n+1-a)*a
    ans += (z+1)%(10**9+7)
print(ans%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
 
if K==N+1:
    print(1)
elif K==N:
    print(N+2)
else:
    def tousawa(shokou, makkou, kosu):
        return int((shokou+makkou)*kosu/2)
    
    ans=0
    for i in range(K,N+2):
        ans+=tousawa(N-i+1,N,i)-tousawa(0,i-1,i)+1
    print(int(ans%(10**9+7)))

Submission status: Accepted

Solution code:
def d_sum_of_large_numbers(MOD=10**9 + 7):
    N, K = [int(i) for i in input().split()]
    return (N + 2 - K) * (N**2 + (K + 1) * N - 2 * K**2 + 2 * K + 6) // 6 % MOD

print(d_sum_of_large_numbers())

Submission status: Accepted

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

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

B=[i for i in range(n+1)]
for i in reversed(range(n)):
    B[i]+=B[i+1]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = LI()
    ans = 0
    mi = 0
    ma = n+1
    m = n*(n+1) >> 1
    for i in range(1,n+2):
        if i >= k:
            ans += ma-mi
            ans %= mod
        mi += i
        ma += n-i
        mi %= mod
        ma %= mod
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

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

for i in range(k+1, n+2):
    mx += table[-i]
    mn += table[i-1]
    ans += mx - mn + 1
print(ans%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 = 1  # N = Kのとき
    max_num = sum_from_1_to_n(n)
    for i in range(k, n + 1):
        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()