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:
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
#import itertools
mod = 10 ** 9 + 7
s = 0
N,K = map(int,input().split())
for i in range(K,N+2):
    Min = i*(i+1)/2
    Max = i*(2*N+3-i)/2
    s += Max - Min +1
    s = s%mod
s = int(s)
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):
    t1 = (i - 1) * i // 2
    t2 = n * (n + 1) // 2 - (n - i) * (n - i + 1) // 2
    ans += t2 - t1 + 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+2):
  ans += ( ((N+1)*N) - ((N+1-i)*(N-i)) )//2  - (i*(i-1))//2 +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):
  mn = (i-1)*i//2
  mx = (2*n-(i-1))*i//2
  ans += mx-mn+1
  ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, (input().split()))
MOD = 10**9+7
m, M = sum(list(range(K))), sum(list(range(N, N-K, -1)))
ans = (M - m + 1) % MOD

for i in range(K, N+1):
    m += i
    M += N-i
    ans = (ans + (M - m + 1) % MOD ) % MOD
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def ca(n):
    mi = n*(n+1)//2 %mod
    ma = ((N+1+N+1-n+1)*n//2) %mod
    return ma- mi +1
for k in range(K,N+2):
    ans += ca(k)
    ans %mod

print(ans%mod)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(int(ans)%mod)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

a = [0] + list(accumulate([i for i in range(n+1)]))

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

print(ans%mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
mod = 10**9+7
def main():
    N,K = map(int,input().split())
    ans = 1
    for k in range(K,N+1):
        upper = k*(N+N-k+1)//2
        lower = k*(k-1)//2
        ans += (upper-lower+1)%mod
        ans %= mod
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
M = 1000000007

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

def f(k):
    l = k * (k - 1) / 2
    r = (2 * N - k + 1) * k // 2
    return r - l + 1

s = 0
for k in range(K, N+2):
    s = (s + f(k)) % M

print(int(s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    mi, ma = 0, 0
    for i in range(K - 1):
        mi += i
        ma += N - i
    r = 0
    for i in range(K - 1, N + 1):
        mi += i
        ma += N - i
        r += ma - mi + 1

    return r % (10 ** 9 + 7)

print(main())

Submission status: Accepted

Solution code:
# ABC163

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

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

print(ans)

Submission status: Accepted

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

n, k = [int(x) for x in input().split()]
a = [int(x) for x in range(n + 1)]
a_rev = a[::-1]
mod = 10**9 + 7

left = sum(a[:k])
right = sum(a_rev[:k])

ans = right - left + 1

for i in range(k, n + 2):
    if i > n:
        break
    left += a[i]
    right += a_rev[i]
    ans += right - left + 1
    ans %= mod

print(ans)

Submission status: Accepted

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

count = 0

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

print(int(count))

Submission status: Accepted

Solution code:
def input_one_number():
    return int(input())

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

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

mod = 10**9+7

N,K = input_multiple_number()

ans = 0

for i in range(N+1+1):
	if i < K:
		continue

	ans += ((N-i+1+N)*i//2-(0+i-1)*i//2+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):
    ans = (ans + (i*N-i**2+i+1)) % mod

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 15
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

x = pow(10, 100, mod)
ans = 0
n, k = LI()
for i in range(k, n + 2):
    ans += (n - (i - 1)) * i + 1
    ans %= mod

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N, K = map(int, sys.stdin.readline().split())
cnt = 0
while K <= N+1:
  cnt += (2*N-K+1)*K//2 - (K-1)*K//2 + 1
  K += 1
print(cnt%(10**9+7))

Submission status: Accepted

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

ans = 0
NUM = 1000000007
for k in range(K, N+2):
    s_min = k * (k - 1) / 2
    s_max = k * (2 * N - k + 1) / 2
    c = (s_max - s_min) + 1
    ans += c
    ans %= NUM
print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

NN = 202020
MOD = 10**9+7
# MOD = 998244353
INF = float("inf")

n, k = map(int, input().split())
psum = list(itertools.accumulate([i for i in range(n+1)]))
rsum = list(itertools.accumulate([i for i in reversed(range(n+1))]))
# print(psum)
# print(rsum)

ans = 0
for i in range(k, n+2):
    ans = (ans + rsum[i-1] - psum[i-1] + 1)%MOD
    # print(rsum[i-1] - psum[i-1] + 1, ans)
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 * (i-1) + 1
print(ans % (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 += (i * N - i*(i-1) + 1) % mod
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
mod = 10**9+7

n,k = map(int, input().split())
count = 0
for i in range(n+1-k+1):
    j = k+i
    count += (((2*n-(j-1))*(j)//2 - (j-1)*(j)//2) + 1)
    count = count % mod
print(count)

Submission status: Accepted

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

for i in range(k,n+2):
    ma = dp[-1] - dp[len(dp)-i-1]
    mi = dp[i - 1]
    if i == n + 1:ma = dp[-1]
    ans += (ma - mi + 1) % mod
    ans %= mod
print(ans)

Submission status: Accepted

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

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

MOD = 10 ** 9 + 7
ans = 1
for k in range(K, N + 1):
    ans += (cumsum[-1] - cumsum[-k - 1]) - cumsum[k - 1] + 1
print(ans % MOD)

Submission status: Accepted

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

p = 10 ** 9 + 7
s = 0


for r in range(k, n + 2):
    min_val = (r - 1) * r // 2
    max_val = (n - r + 1 + n) * r // 2
    s += (max_val - min_val + 1)
    s %= p

print(s)

Submission status: Accepted

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

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

print(pattern)

Submission status: Accepted

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


ans = 0
for num_add in range(k, n+2):
	min_res = (0 + num_add-1) * num_add // 2
	max_res = (n-num_add+1 + n) * num_add // 2
	ans += (max_res - min_res + 1) % MODULO
	ans %= MODULO
	# print("ans", ans)

print(ans)

Submission status: Accepted

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

print(ans%mod)

Submission status: Accepted

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

MOD = 1000000007  # type: int


def solve(N: int, K: int):
    s = 0
    for i in range(K, N+2):
        p = i*(N-i+1) + 1
        s += p
        s %= MOD
    print(s)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans=[0]*(n+2)
ans[0]=1

for i in range(1,n+2):
    mae=(i-1)*i//2
    usiro=(n*2-i+1)*i//2
    ans[i]=usiro-mae+1

kotae=0
for i in range(k,n+2):
    kotae+=ans[i]%p


#print(ans)

kotae%=p
print(kotae)

Submission status: Accepted

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

def num_sum(i):
  return ((n+(n-i+1))*i//2)-((i-1)*i//2)+1

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

print(cnt)

Submission status: Accepted

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

print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

mod = 10 ** 9 + 7

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

print(ans)

Submission status: Accepted

Solution code:
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    mod = 10**9 + 7
    n, k = _ia()

    ret = 0
    for ki in range(k, n+2):
        mi = (ki * (ki-1))//2
        ma = ((2*n-ki+1)*ki)//2
        ret += (ma-mi+1)
        ret %= mod
    return ret


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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,k = na()
mod = 10**9+7

ans = 0

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

print(ans)

Submission status: Accepted

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

max_sum = 0
min_sum = 0


ans = 0
for i in range(0, N+1):
    max_sum += N-i
    min_sum += i 
    if i >= K-1:
        ans += (max_sum - min_sum + 1) % MOD
print(ans%MOD)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 10**9 + 7

n, k = map(int, input().split())
ans = 0
for i in range(n + 1):
    if i + 1 < k:
        continue
    diff = (2*n - i) * (i + 1) // 2 - i * (i + 1) // 2 + 1
    ans += diff 
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

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

S = [0] * (N + 2)
for i in range(N + 1):
    S[i + 1] = S[i] + i

cnt = 0
for i in range(K, N + 2):
    a = S[i]
    b = S[N + 1] - S[N + 1 - i]
    cnt += b - a + 1
    cnt %= MOD

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
mod = 10 ** 9 + 7
X = [i for i in range(N+1)]
min = 0
max = 0
for i in range(K):
    min += X[i]
    max += X[-1 * (i+1)]
ans = (max - min + 1) % mod
#print(min,max,ans)
for i in range(K,N+1):
    min += X[i]
    max += X[-1 * (i+1)]
    ans += max - min + 1
    ans %= mod
    #print(min,max,ans)
print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate
N, K = map(int, input().split())
MOD = 10 ** 9 + 7
acc = list(accumulate(range(N+1)))
ans = 0
for k in range(K, N+2):
    minSum = acc[k-1]
    maxSum = acc[N] - (acc[N-k] if k != N+1 else 0)
    ans += maxSum - minSum + 1
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
import sys, math
def input(): return sys.stdin.readline().strip()
mod = 10**9 + 7

def main():
    N, K = map(int, input().split())
    ans = 0
    for i in range(K, N + 2):
        val = N * i - i * (i - 1) + 1
        #print("i={}, val={}".format(i, val))
        ans += val
        ans %= mod
    print(ans)


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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:


def submit():
    n, k = map(int, input().split())
    modp = 10 ** 9 + 7
    
    ans = 0
    for cur_k in range(k, n + 2):
        minsum = cur_k * (cur_k - 1) // 2
        maxsum = cur_k * (2 * n - cur_k + 1) // 2
        ans += maxsum - minsum + 1
        ans %= modp

    print(ans)


submit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

MOD = 10 ** 9 + 7

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

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


ans = 0
for k in range(K, N + 2):
    tmp = sum_1_to_n(k - 1)
    start = tmp
    end = N * k - tmp
    # print(start, end)
    ans += end - start + 1
    ans %= MOD
    # print("ans = ", ans)

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


MOD = 10 ** 9 + 7


def main():
    N, K = map(int, input().split())
    ans = 0
    for k in range(K, N + 2):
        m = k * (k - 1) // 2
        M = k * (2 * N - k + 1) // 2
        a = (M - m + 1) % MOD
        ans += a
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

print(ans % p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
a = [i for i in range(n+1)]
b = []
x = 0
for i in range(n+1):
    x += i
    b.append(x)
MOD = 10**9 + 7

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

M = 1e+9 + 7


def main():
  N, K = map(int, input().split())
  count = 0
  minval = 0
  maxval = 0

  for i in range(1, N + 2):
    minval += i
    maxval += N - i + 2

    if i >= K:
      count = int((count + maxval - minval + 1) % M)

  print(count)


if __name__ == '__main__':
  main()

Submission status: Accepted

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

MOD = 10**9+7

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

Submission status: Accepted

Solution code:
import bisect
import collections
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62


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


def llmi(n):
    return [lmi() for _ in range(n)]


N, K = lmi()

_sum = [0]
for i in range(1, N + 1):
    _sum.append(_sum[-1] + i)
# 10**100 + k    k = 0,1,..,N
ans = 0
for k in range(K, N + 2):
    # k vals
    max_val = _sum[-1] - _sum[max(0,N  - k)]
    min_val = _sum[k - 1]
    # print(k, max_val, min_val)
    ans += max_val - min_val + 1
print(ans%ACMOD)

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 0
over = 0
down = 0
for i in range(N+1):
    over +=  N  - i
    down += i
    if i >= K-1:
        ans += over - down + 1
print(ans % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()
  ans=0
  for i in range(k,n+2):
    mn=i*(0+i-1)//2
    mx=i*(n-i+1+n)//2
    # print(mn,mx)
    ans+=mx-mn+1
    ans%=mod

  return ans

# main()
print(main())

Submission status: Accepted

Solution code:
mod=10**9+7

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

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

retval=0
min=sum(nums[:K])
max=sum(nums[-K:])

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
mod = 10 ** 9 + 7
res = 0
l = K * (K - 1) // 2
r = 0
for i in range(K):
  r += (N - i)
for i in range(K, N + 2):
  res += r - l + 1
  res %= mod
  l += i
  r += N - i
print(res)

Submission status: Accepted

Solution code:
MOD = 10**9+7

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

ans = 0
pre,suf = 0,0
for i in range(1,n+2):
    pre += i-1
    suf += n+1-i

    if i >= k:
        ans += suf-pre+1
        ans %= MOD

print(ans)

Submission status: Accepted

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

l = 0
ll = 0
r = n
rr = n

ans = 0
for i in range(1, n+2):
    # print(i,l,r)
    if i >= k:
        ans = (ans + r-l+1) % mod
    ll += 1
    rr -= 1
    l += ll
    r += rr
    

print(ans)

Submission status: Accepted

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

MOD = 10**9 + 7
ans = 0

for c in range(k, n + 2):
  m = c * (c - 1) // 2
  M = c * (2 * (n + 1) - c - 1) // 2
  ans += M - m + 1
  ans %= MOD

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MOD = 10**9 + 7
N,K = map(int,input().split())
ans = 0
for n in range(K,N+2):#数はN+1個
    ans += (N*2 -n + 1)*n//2  -  n*(n-1)//2 +1
    ans %= MOD
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):
    min_ = k * (k - 1) // 2
    max_ = ((N + (N - k + 1)) * k) // 2
    ans += (max_ - min_ + 1)
    ans %= MOD

print (ans)

Submission status: Accepted

Solution code:
MOD = int(1e9+7)


def main():
    N, K = map(int, input().split())
    ans = 0
    # pick i numbers
    for i in range(K, N+2):
        mn = (i-1) * i // 2
        mx = (N-i+1+N) * i // 2
        ans += (mx-mn+1)
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

MOD = 10**9 + 7
MAX = n + 10
fact = [1] * (MAX + 1)  # i!
finv = [1] * (MAX + 1)  # (i!)^{-1}
iinv = [1] * (MAX + 1)  # i^{-1}
for i in range(2, MAX + 1):
    fact[i] = fact[i - 1] * i % MOD
    iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * iinv[i] % MOD


def comb(n: int, k: int) -> int:
    if n < k or n < 0 or k < 0:
        return 0
    return (fact[n] * finv[k] % MOD) * finv[n - k] % MOD


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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	A = [0] * (N + 2)
	for i in range(1, N + 2):
		A[i] = i * (N - (i - 1)) + 1

	# print(A)
	ans = 0
	for i in range(K, N + 2):
		ans += A[i]

	ans %= con
	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
from math import *
from collections import *
mod = 10**9 + 7
test = 1
#test = int(input())
for __ in range(test):
	n,k = map(int,input().split())
	mins = 0
	maxs = 0
	for i in range(k):
		mins += i
		maxs += n-i
		mins %= mod
		maxs %= mod
	ans = (maxs-mins+1)%mod
	if(ans < 0): ans += mod
	for i in range(k,n+1):
		mins += i
		maxs += n-i
		mins %= mod
		maxs %= mod
		ans = (ans+maxs-mins+1)%mod
		if(ans < 0): ans += mod
	print(ans)

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


main()

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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


def sum_up_to(i,j) :
    MOD = int(1e9+7)
    return (( (i+j)*(j-i+1) )//2 ) % MOD

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

MOD = int(1e9+7)
print(ans%MOD)

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N, K = read_values()
    
    res = 0
    for k in range(K, N + 2):
        res += (k * (N - k + 1) + 1) % mod
        res %= mod
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    ans = 0
    s_min = 0
    s_max = 0

    for i in range(k - 1):
        s_min += i
        s_max += (n - i)

    for i in range(k - 1, n + 1):
        s_min += i
        s_max += (n - i)
        ans += (s_max - s_min + 1)
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()