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())
s = [i for i in range(n+1)]
a = [0]*(n+1)
b = [0]*(n+1)
t = n+1-k
for i in range(0,n+1):
    if i < t+1:
        a[-(i+1)] = (i+1)*s[-(i+1)]
        b[-(i+1)] = (i+1)*s[i]
        c = i+1
    else:
        a[-(i+1)] = c*s[-(i+1)]
        b[-(i+1)] = c*s[i]
res = sum(b)-sum(a)+t+1
print(res%(10**9+7))

Submission status: Accepted

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

ans = 0
for num in range(K, N+2):
    res1 = int((2*N-num+1) * num / 2) % mod
    res2 = int((num-1) * num / 2) % mod
    ans += res1 - res2 + 1
    # print(num, res1, res2)

print(ans % mod)

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, acos, atan, asin, log, log10, gcd
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 fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(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()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

s = 0
for i in range(k,n+2):
    minsum = i*(i-1)/2
    maxsum = i*(n+n-i+1)/2
    s += maxsum-minsum+1
    s = s % 1000000007
print(int(s))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n, k = LI()
    ans = 1
    dp = [i for i in range(n + 1)]
    dp = [i for i in itertools.accumulate(dp)]
    for i in range(k, n + 1):
        ans += (dp[n] - (dp[-i - 1])) - dp[i - 1] + 1
        ans %= mod
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# 解説AC
N,K = map(int, input().split())

MOD = 10 ** 9 + 7

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

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
N, K = list(map(int, input().split()))
mod = 10 ** 9 + 7
sum = 0
for k in range(K, N+2):
    tmp1 = k * (k - 1) // 2
    tmp2 = (2 * N - k + 1) * k // 2
    sum += (tmp2-tmp1+1)%mod
print(sum%mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, k = na()

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

print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

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

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7
MAX = (10 ** 5) * 2 + 2


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


def main():
    N, K = map(int, input().split())
    ans = 0
    M = N
    m = 0
    for i in range(1, N + 2):
        if i < K:
            M += N - i
            m += i
            continue
        else:
            ans += M - m + 1
            ans %= MOD
            M += N - i
            m += i

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

MOD = 1000000007  # type: int

# 4c2 = 4*3/1*2     = 6 (0,1)[1],(0,2)[2],(0,3)[3],(1,2)[3],(1,3)[4],(2,3)[5]
# 4c3 = 4*3*2/1*2*3 = 4 ()
# 4c4 = 1           = 1

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


    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:
mod = 10**9+7
n, k = map(int, input().split())

def S(k):
    return (n-k+1)*k+1

res = 0
for i in range(k, n+2):
    res += S(i)
    res %= mod
print(res)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

def S(k):
    return (n-k+1)*k+1

res = 0
for i in range(k, n+2):
    res += S(i)
    res %= mod
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    k = kwargs["k"]
    # A[i] は i + 1 個の数を選ぶときにその和としてあり得るものの個数
    A = [0 for i in range(n + 1)]
    A[0] = n + 1
    res = 0

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

    for i in range(n + 1):
        if i + 1 >= k:
            res += A[i] % MOD

    res %= MOD
    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    #kwargs["n"] = cin[0]
    #kwargs["n"], kwargs["k"] = cin
    #kwargs["n"] = [int(i) for i in cin][0]
    kwargs["n"], kwargs["k"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
MOD = 10**9+7
N, K = map(int, input().split())


def acc(x):
    return x*(x+1)//2


ans = 1
for k in range(K, N+1):
    l = acc(k-1) % MOD
    u = (acc(N)-acc(N-k)) % MOD
    n = (u-l+1) % MOD
    ans = (ans + n) % MOD
print(ans)

Submission status: Accepted

Solution code:
MOD=10**9+7

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

main()

Submission status: Accepted

Solution code:
def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n % 2 == 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res


def modinv(a, mod):
    return modpow(a, mod - 2, mod)


if __name__ == "__main__":
    n, k = map(int, input().split())
    m = 10 ** 9 + 7
    
    rev2 = modinv(2, m)
    rev6 = modinv(6, m)

    f = (n + 1) * ((n + 1) * (n + 2) % m - (k - 1) * k % m) % m * rev2 % m
    s = n - k + 2
    t = ((n + 1) * (n + 2) % m * (2 * n + 3) % m - (k - 1) * k % m * (2 * k - 1)% m) % m * rev6 % m

    ans = (f + s - t) % m

    print(int(ans))

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
if k == n + 1:
    print(1)
else:
    mi_n = ((k-1)*k)//2#０からKこ選んだ和。k個選ぶ時の最小。0~k-1。
    ma_x = ((n+n-k+1)*k)//2#NからKこ選んだ和。ｋ個選んだ時の最大。n~n-k+1。
    ans = ma_x - mi_n + 1
    for i in range(k,n,1):
        mi_n += i
        ma_x += n - i
        ans += ma_x - mi_n + 1

    ans += 1

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

Submission status: Accepted

Solution code:
N,K=(int(x) for x in input().split())
# N=4
# K=3
n=0

# print("N=",list(range(N+1)))
for i in range(K,N+2):
    # K個を選択する
    M=N*(N+1)/2-(N-i)*(N-i+1)/2
    # print("M=%d-%d"%(N*(N+1)/2,(N-i)*(N-i-1)/2))
    m=i*(i-1)/2
    n+=M-m+1
    # print("")
    # print("i=",i)
    # print("M,m=",M,m)
    # print("場合=",M-m+1)
print(int(n%(1e9+7)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(k) for k in input().split()]
#template
N,K = inputlist()
mod = 10**9+7
li = [int(i) for i in range(N+1)]
suma = [0]*(N+1)
for i in range(1,N+1):
    suma[i] = suma[i-1]+li[i]
ans = 0
for i in range(K,N+1):
    m = suma[i-1]
    M = suma[-1] - suma[-(i+1)]
    ans += M-m+1
    ans %= mod
ans +=1
ans %= mod
print(ans)

Submission status: Accepted

Solution code:
MOD = int(1e9+7)
def main():
    n,k = map(int,input().split())
    ans = 0
    for i in range(k,n+2):
        # min_sum = sum(range(i))
        min_sum = i*(i-1)//2
        # max_sum = sum(range(n,n-i,-1))
        max_sum = (2*n-i+1)*(i)//2
        # print(min_sum,max_sum)
        ans = (ans + (max_sum-min_sum+1))%MOD
    print(ans)
    return

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 * i) - MIN #例えば10,9,8なら(10-0),(10-1),(10-2)
    ans += MAX - MIN + 1
    ans %= MOD
print(ans)

Submission status: Accepted

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

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

for k in range(K, N+1):
    min_sum = sum_num(k-1)
    max_sum = sum_num(N) - sum_num(N-k)
    # print(k, min_sum, max_sum)
    ans += max_sum - min_sum + 1

ans += 1
ans %= mod
print(int(ans))

Submission status: Accepted

Solution code:
from math import factorial
N, K = map(int, input().split())

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

    tmp_min = (i - 1) * i / 2
    tmp_max = (N * (N + 1) / 2) - ((N - i) * (N - i + 1) / 2)
    # print(tmp_min, tmp_max)

    tmp = tmp_max - tmp_min + 1
    ans += tmp

print(int(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):
  ll = 0
  lr = i - 1
  rl = n-(i-1)
  rr = n
  lsum = lr*(lr+1)//2 - ll*(ll+1)//2
  rsum = rr*(rr+1)//2 - rl*(rl-1)//2
  ans += rsum - lsum + 1
  ans %= MOD
  #print(rsum, lsum)
  
print(ans)

Submission status: Accepted

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

ans = 0
a = 1

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

Submission status: Accepted

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


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


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
N, K = map(int, input().split())
c = 0
ans = 0
for k in range(K, N+2):
    a = k*(k-1)/2
    b = (2*N-k+1)*k/2
    c += (b-a)+1
    # print(c)
print(int(c % 1000000007))

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

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
c = 0
mod = 1000000007
for k in range(K, N + 2):
    a = k * (k - 1) / 2
    b = k * (2 * N - k + 1) / 2
    c = (c + (b - a + 1)) % mod
print(int(c))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
sum_ans = 0
 #get "ruisekiwa"
c_sum = [0]*(N+2)
for i in range(N+1):
    c_sum[i+1]+=c_sum[i]+i

for i in range(K,N+2):
    sum_ans+= ((c_sum[N+1]-c_sum[N+1-i])-(c_sum[i]-c_sum[0])+1)
print(sum_ans%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

mod = 10 ** 9 + 7
ans = 0

for k in range(K, N + 2):
    a = k * (k - 1) // 2
    b = k * (2 * N - k + 1) // 2
    ans += (b - a + 1) % mod
    ans %= mod

print(ans % mod)
# print(l)

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_num = ((k-1) * k) / 2
    max_num = (N * (N+1)) / 2 - ((N-k) * (N-k+1)) / 2
    ans +=  max_num - min_num + 1
print(int(ans % mod))

Submission status: Accepted

Solution code:
from sys import stdin


def get_result(data):
    N, K = data
    mod = 10**9+7
    e_val = [i for i in range(N+1)]
    # 累積和を使ってsumを計算
    e_cumsum = [0]
    for i in range(N+1):
        e_cumsum.append(e_cumsum[i] + e_val[i])
    ans = 0
    for r in range(K, N+2):
        min_val = e_cumsum[r]
        max_val = e_cumsum[N+1] - e_cumsum[N+1-r]
        ans += (max_val - min_val + 1) % mod
    return ans % mod


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)

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

'''
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:
n, k = map(int, input().split())

m = n + 1
l = k - 1

ans = m * (m**2 + 5) // 6
ans += l * (2 * l**2 + 3 * l - 5 - 3 * m * (l + 1)) // 6
ans = ans % (10**9 + 7)

print(ans)

Submission status: Accepted

Solution code:
N, K  = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7
for k in range(K, N + 2):
    min_sum = (k - 1) * k // 2
    max_sum = (2 * N - k + 1) * k // 2
    ans += max_sum - (min_sum - 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)]
y = [0] * (N + 2)
z = [0] * (N + 2)
for i in range(N+1):
    y[i + 1] = y[i] + x[i]
    z[i + 1] = z[i] + x[N-i]
# print(y)
# print(z)
ans = 0
for i in range(K, N+2):
    ans += z[i] - y[i] + 1
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

line= list(map(int,input().split()))
N = line[0]
K = line[1]
#0~Nの連続した整数から
#kこ以上選ぶ
answer = 0
for i in range (K,N+2):
    minit = i*(i-1)/2
    maximum = (2*N-i+1)*i/2
    
    num = maximum-minit+1
    answer += num

if answer >(10**9+7):
    print(int(answer%(10**9+7)))
    
else:
    print(int(answer))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:

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

    increments = []

    for i in range(N+1):
        increments.append(i)

    accumulation = [0]*(N+2)
    accumulationReverse = [0]*(N+2)

    for i in range(0, N+1):
        accumulation[i+1] = accumulation[i] + increments[i]
        accumulationReverse[i+1] = accumulationReverse[i] + increments[N-i]

    ans = 0

    for i in range(K, N+2):
        ans += accumulationReverse[i]-accumulation[i] + 1

    print(ans % mod)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
#abc163d

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

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    from math import factorial
    mod = 10**9 + 7
    N, K = map(int, input().split())
    ans = 0
    for i in range(K, N+2):
        ans += i * ((2 * N + 1) - i) // 2 - i * (i - 1) // 2 + 1 
        ans %= mod
    print(ans%mod)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input().split()
N = int(s[0])
K=int(s[1])
MOD = 1000000007
res=0
M = N+1
L = K-1
res = M*(M*M+5)/6 + L*(L*L*2+L*3-5-M*(L+1)*3)/6
print(int(res%MOD))

Submission status: Accepted

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

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

print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
a = [i for i in range(n)]
cnt = 0
for m in range(k,n+2):
    amin = (m*(m-1))/2
    amax = (n*(n+1))/2 - (n-m)*(n-m+1)/2
    cnt += amax-amin+1
print(int(cnt%(1e9+7)))

Submission status: Accepted

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

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

ans = 0
mod = (10**9)+7
for i in range(K, N+2):
    min_sum = S(i-1)
    max_sum = S(N) - S(N-(i))
    ans += max_sum - min_sum + 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):
    num = ((n*(n+1)-(n-i+1)*(n-i)-(i-1)*i)//2+1)%mod
    ans = (ans+num)%mod

print(ans)

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:
N, K = map(int, input().split())
mod = 1000000000+7

z=0

zz = ((N-K+1)+N)*K//2 - (0+(K-1))*K//2 + 1
zz = zz % mod

for x in range(K+1, N+3):
#  print(zz)
  z = (z + zz) % mod
  zz += (N-x+1) - (x-1)
  zz = zz % mod
#
print(z)

Submission status: Accepted

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

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

Submission status: Accepted

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

a = [0] * (n + 1)
for i in range(n + 1):
    temp = (n * 2 - i) * (i + 1) // 2 - i * (i + 1) // 2 + 1
    a[i] = temp % mod
b = a[k - 1:]
print(sum(b) % mod)

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

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

fin = 0
for k in range(K,N+2):
    low = k * (k - 1) / 2
    high = k * (2*N - k  + 1) / 2
    fin = (fin + ((high - low) + 1)) % MOD

print(int(fin))

Submission status: Accepted

Solution code:
'''
「異なる個数を選んで足した場合、それらが一致することは絶対にない」
N=5, k=3のとき、最小の数 3 から、最大の数 12 まで「連続する整数を作ることができる」
k 個足してできる最小の整数を求める (a とする)
k 個足してできる最大の整数を求める (b とする)
出来上がる整数は b−a+1 個である
'''
N, k = map(int, input().split())
ans = 0
MOD = 10**9+7
for i in range(k, N+2):
  minNum = i*(i-1)//2 #0+1+...+(k-1)
  maxNum = i*(2*N-i+1)//2 #(N-k+1)+...+(N-1)+N
  ans += maxNum - minNum + 1
print(ans%MOD)

Submission status: Accepted

Solution code:
import sys
# sys.stdin = open('input.txt')

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

MOD = 10**9 + 7
a = [i for i in range(n+1)]

ans = 0
for i in range(k, n+2):
    first = i * (a[0] + a[i-1]) / 2
    last = i * (a[-i] + a[-1]) / 2
    ans += last - first + 1
print(int(ans%MOD))

Submission status: Accepted

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

def main():
   N, K = map(int, input().split()) 
   NUM = [i for i in range(N+1)]
   LOWER = 0
   UPPER = 0
   CNT = 0
   for j in range(K):
       LOWER += NUM[j]
       UPPER += NUM[N-j]
   for i in range(N+1):
       if i + K >= N+1:
           CNT += 1
           break
       CNT += UPPER -LOWER + 1
       LOWER += NUM[K+i]
       UPPER += NUM[N-(K+i)]
   print(CNT%((10**9)+7))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    md = 10**9+7
    mx, mi, ret = 0, 0, 0
    for k in range(1, N+2):
        mx += N-k+1
        mi += k-1
        ret += ((mx - mi + 1)*(k>=K))%md
    print(ret%md)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
r=[0]
l=[0]
ans=0
INF=10**9+7
for i in range(n+1):
    a=r[i]+i
    b=l[i]+n-i
    r.append(a)
    l.append(b)
#print(r)
#print(l)

for i in range(k,n+2):
    min_wa=r[i]
    max_wa=l[i]
    ans+=max_wa-min_wa+1
    
print(ans%INF)

Submission status: Accepted

Solution code:
def main():

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

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


    mini = sum(nums[0:K])
    maxx = sum(nums[-K:])


    for i in range(K, N + 1):
        total += maxx - mini + 1

        index = i + 1
        
        if (i == N):
            break
        else:
            mini += nums[index-1]
            maxx += nums[-index]

    total += 1
    ans = total % (10 ** 9 + 7)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Sum = 0

for i in range(K, (N + 1) + 1):
    a = (((N - (i - 1)) + N) * i // 2) - ((i - 1) * i // 2) + 1
    #print(i,a,(((N  - (i - 1)) + N ) * i // 2),((i - 1) * i // 2))
    Sum = (Sum + a) % 1000000007

print(Sum)

Submission status: Accepted

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

L = N + 1  # 数列の長さ 

count = 0
table = [i for i in range(N + 1)]  # 0 ~ Nまでの数列

cusum = [0] * (L + 1)

for i in range(L):
  cusum[i + 1] = cusum[i] + table[i]

while K <= L:
  # K個選んだときの最大値 - 最小値 + 1
  count += (cusum[L] - cusum[L - K]) - cusum[K] + 1
  count %= P
  K += 1

print(count)

Submission status: Accepted

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

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

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

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