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())
count = 0
mod = 10**9+7
for i in range(K, N+2):
    max_num = (i * (N + N - i + 1)) // 2
    min_num = (i * (i - 1)) // 2
    count += (max_num - min_num + 1)
    count %= mod

print(count)

Submission status: Accepted

Solution code:

c=0
n,k=map(int,input().split(" "))
for i in range(k,n+2):
    c+=i*n-i*(i-1)+1
    while(c>=10**9+7):
        c-=10**9+7
        
print(c)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import math
import sys
from collections import defaultdict
input = sys.stdin.readline

############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
    
n, k = invr()
#A = invr()

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

res = 0
small = sum(A[:k])
large = sum(A[-k:])
for cLen in range(k, n + 2):
	# print small, large
	res = (res +  large - small + 1 ) % (10 ** 9 + 7)
	if cLen != n + 1:
		small += A[cLen]
		large += A[-cLen - 1]

print res

Submission status: Accepted

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

ans = 0

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

for a in range(k,n+2):
    ans += culc(a)
    ans %= MOD

print(ans)

Submission status: Accepted

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

count = 0

for i in range(k,n+2):
    most = (2 * n - i + 3) * i // 2
    least = (i + 1) * i // 2
    cases = most - least + 1
    count += cases
    count %= (10**9+7)

print(str(int(count)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = [int(i) for i in input().split()]
mod = 10**9+7
m, M, L = 0, 0, 0
for i in range(k,n+2):
    m = i *(i-1)//2
    M = (2*n-i+1)*i//2
    L = L+(M - m+1)
print(L%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**2+i+1
mod = 10**9+7
print(ans%mod)

Submission status: Accepted

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

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

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):
    maxsum = (i*(n + (n - i + 1)))//2
    minsum = (i - 1)*i//2
    ans += maxsum - minsum + 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def f(a,l):
    return  ((a+l)*(l+1-a))//2


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

S=0

P=f(0,K-2)
Q=f(N-K+2,N)
for x in range(K,N+2):
    P+=x-1
    Q+=N+1-x

    S=(S+(Q-P+1))%M
    
print(S)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K =map(int, input().split())
mod = 10**9 + 7
A = int(-(N+1)*(N+2)*(2*N+3)/6)%mod
B = int((N+1)*(N+1)*(N+2)/2)%mod
C = N+1
a = int(-(K-1)*K*(2*K-1)/6)%mod
b = int((N+1)*(K-1)*K/2)%mod
c = K-1
print((A+B+C-a-b-c)%mod)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
 
ans = 0
mod = pow(10,9)+7
 
for k in range(K, N+2): ## K個以上で総数(N+1)
  ## 全個数の計算　## k個最大 ## k個最小
  ans += k*((N+1-k)+N)//2 - k*(0+k-1)//2 + 1
  
print(ans % mod)


## sum(range(N-k+1, N+1))
## k*((N+1-k)+N)/2

## sum(range(0, k))
## k*(0+k-1)/2

Submission status: Accepted

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

lst = [_ for _ in range(n+1)]
ans = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# D - Sum of Large Numbers
# https://atcoder.jp/contests/abc163/tasks/abc163_d

MOD = 10 ** 9 + 7

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

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

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split()]
MOD = 10**9 + 7
ans = 0
for k in range(K, N+2):
    ans += ((2*N-k+1)*(k) - k*(k-1)) // 2 + 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 += (i*(N-i+1)+1)%MOD
    ans %= 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 != 1:
        if i > 2:
            ans += n*(n+1)//2 - (n-i)*(n-i+1)//2 - (i-1)*i//2 + 1
        elif i == 2:
            ans += 2 * n - 1
        elif i == 1:
            ans += n+1
    else:
        if i == 2:
            ans += 1
        elif i == 1:
            ans += 2

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    N, K = map(int, readline().split())
    p = [int(i) for i in range(N+1)]
    s = [0]
    for i in range(N+1):
        s.append(s[i]+p[i])
    ans = 0
    P = int(1e9)+7
    for k in range(K, N+2):
        ans += (s[-1]-s[-k-1])-(s[k]-s[0])+1
        ans %= P
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().strip("\r\n")

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

Submission status: Accepted

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

MOD = 10**9+7
Sm = 0

for k in range(K,N+2):
    m = (2*N-k+1)*k/2-k*(k-1)/2+1
    Sm = (Sm+m)%MOD

print(int(Sm))

Submission status: Accepted

Solution code:
import itertools


def main():

    N, K = map(int, input().split())
    mod = 1000000007
    s = list(itertools.accumulate(range(0, N+1)))

    ans = 1
    for k in range(K, N+1):
        ans = (ans + s[N] - s[N-k] - s[k-1] + 1) % mod

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
MOD = 1000000007
n,k = (int(x) for x in input().split())
ans = 0

arrow = k
left = (k - 1) * k // 2
right = n * k - k * (k - 1) // 2
while(arrow <= n + 1):
    #print("[%d,%d]" % (left,right))
    ans += (right - left + 1)
    ans %= MOD
    left += arrow
    right += n - arrow
    arrow+=1

print(ans)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
mod = pow(10, 9) + 7
ans = 0
for i in range(k, n+2):
    #小さい方からi個選ぶ
    mini = i*(i-1)//2
    maxa = (2*n-i+1)*i//2
    ans = (ans + (maxa - mini + 1)% mod)% mod
print(ans)

Submission status: Accepted

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

print(sum(ans[k:])%mod)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 0
DIVIDER = 1000000007
for cnt in range(K, (N + 1) + 1):
    sum_min = tab_sum[cnt] - tab_sum[0]
    sum_max = tab_sum[-1] - tab_sum[-1 - cnt]
    #
    ans = (ans + (sum_max - sum_min + 1)) % DIVIDER

print(ans)

Submission status: Accepted

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

ans = 0
for k in range(K,N+2):
    mn = (k-1)*k//2
    mx = (N+N-k+1)*k//2
    ans += mx - mn + 1
MOD = 10**9+7
print(ans%MOD)

Submission status: Accepted

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

cnt = 0
for k in range(K, N+2):
    mn = k*(k-1)//2
    mx = N*(N+1)//2 - (N-k)*(N-k+1)//2
    cnt += mx-mn+1
    cnt %= mod

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

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

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

print(ans)

Submission status: Accepted

Solution code:
def sum_from_1(k):
    return k * (k + 1) // 2


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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


MOD = 1000000007

s = 0

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

print(s % MOD)

Submission status: Accepted

Solution code:
#import bisect,collections,copy,heapq,itertools,math,numpy,string
#from operator import itemgetter
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
mod = 10**9+7
dict = {}
N,K = LI()

summax = 0 
summin = 0
ans = 0

first = K
for i in range(1,K):
	#print(i,"個選ぶとき(対象外)")
	summax+=N-i+1
	summin+=i-1
#print(summin,summax)

for k in list(range(K,N+2)):
	#print(k,"個選ぶとき(対象)")
	summax+=N-k+1
	summin+=k-1
	ans+=summax-summin+1
	ans%=mod
	#print(summin,summax)
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):
    mini = k * (k - 1) // 2
    maxi = k * (2 * N - k + 1) // 2
    add = maxi - mini + 1
    ans = (ans + add) % MOD
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations


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

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy
def main():
    N, K = map(int, input().split())
    MOD = 10 ** 9 + 7
    count = 0
    while K != N+2:
        if K == 1:
            min_ = 0
        if K >= 2:
            min_ = ((K * (K-1)) / 2) % MOD
        max_ = ((N + 1) * N - (N + 1 - K) * (N - K)) / 2 % MOD
        count += max_ - min_ + 1
        count %= MOD
        K +=1
    print(int(count))
    


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
line=input()
n,k=map(int,line.split())
sums=0
while k!=(n+2):
     if k==1:
          mini=0
     if k>=2:
          mini=(((k)*(k-1))/2)#%((10**9)+7)
     maxi=( (((n+1)*(n)) - ((n+1-k)*(n-k)) )/2  )#%((10**9)+7)
     sums+=(maxi-mini+1)
     sums=sums%((10**9)+7)
     k+=1
print(int(sums))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
P = 10 ** 9 + 7


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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(k,n+2):
    if i == n+1:
        ans += 1
    else:
        min += list[i-1]
        max += list[n+1-i]
        ans += max-min+1

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

Submission status: Accepted

Solution code:
mod = 10**9 + 7
max_num = 2 * 10**5 + 3
facts = [1 for i in range(max_num)]
invs = [1 for i in range(max_num)]
 
def inv(x):
    return pow(x,mod-2,mod)
 
for i in range(1,max_num):
    facts[i] = facts[i-1]*i%mod
    invs[i] = inv(facts[i])
 
def nCk(n,k):
    return facts[n]*invs[k] * invs[n-k] % mod

def nHk(n, k):
  return nCk(n-1+k, n-1)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

res=0
for i in range(k,n+2):
  mae=i*(i-1)//2
  ushiro=i*(2*n-i+1)//2
  res+=ushiro-mae+1
  res%=10**9+7
print(res)

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


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


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


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


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    mod = 10 ** 9 + 7
    input = stdin.buffer.readline
    n, k = map(int, input().split())

    mins = [0]
    maxs = [n]
    tmp_min = 0
    tmp_max = n
    for i in range(1, n + 1):
        tmp_min += i
        mins.append(tmp_min)
        tmp_max += n - i
        maxs.append(tmp_max)
    ans = 0
    for i in range(k - 1, n + 1):
        ans += maxs[i] - mins[i] + 1
        ans %= mod
    print(ans % mod)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
#N: , K: K個以上の数を選ぶ
MOD = pow(10, 9)+7
#fix = pow(10, 100, MOD) #10の100乗をmodで計算した結果
#この値は使用しない

    #最大値: 小さい順にm個 -> 0+1+2+....+(m-1) = m*(m-1)/2
    #最小値: 大きい順にm個 -> N+(N-1)+...+(N-m+1) = m*(2N-m+1)/2
    #最大値から最小値までの全ての値を作ることができる
    #mの値はK以上N+1以下

ans = 0
for m in range(K, N+2):
    ans += ((N-m+1)*m+1)%MOD #((N-m+1)*m+1)通り

print(ans%MOD)

Submission status: Accepted

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

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

Submission status: Accepted

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

mod = 10**9+7

low = [0]*(N+1)
high = [0]*(N+1)
ls = [0]*(N+1)
high[0] = N
ls[0] = high[0] - low[0] + 1

for i in range(1,N+1):
    low[i] = i + low[i-1]
    high[i] = N-i + high[i-1]
    ls[i] = high[i] - low[i] + 1

ans = 0

for i in range(K-1,N+1):
    ans = (ans + ls[i])%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 += i*(n-i+1) + 1
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,(input().split()))
A=[i for i in range(N+1)]
rui=[0]
for i in range(1,N+1):
  rui.append(i+rui[i-1])

ans=0
max_comb=0
min_comb=0
for i in range(K,N+2):
  try:
    max_comb=rui[-1]-rui[-1-i]
  except:
    max_comb=rui[-1]
  min_comb=rui[i-1]
  ans+=max_comb-min_comb+1
  ans %= (10**9+7)
print(ans)

Submission status: Accepted

Solution code:
def solve(string):
    from itertools import accumulate
    n, k = map(int, string.split())
    *a, = accumulate(range(n + 1))
    ans, m = 0, 10**9 + 7
    for b, c in zip(a[:-k][::-1], a[k - 1:]):
        ans = (ans + a[-1] - b - c + 1) % m
    return str((ans + 1) % m)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,k=n1()
 
down=[0]*(n+1)
up=[0]*(n+1)
up[0]=n
ans=0 if k>1 else n+1
for i in range(1,n+1):
    down[i]=down[i-1]+i
    up[i]=up[i-1]+(n-i)
    if i>=k-1:
        ans+=up[i]-down[i]+1
print(ans%(10**9+7))

Submission status: Accepted

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

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

counter += 1 # k = N+1
counter = counter % mod

print(counter)

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

Submission status: Accepted

Solution code:
import math

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

#全部選ぶときの最大値は0+1+2+ ~ +nの(n+1)n/2

#k個は好きな選び方ができる。
#k個以上の数を選ぶときの最小値を考える
#その数は10**100 + 10**100+1 + ... + 10*100+k-1のk(k-1)/2である。

#sampleの例をよく見る。i=k ~ n+1まででループさせる。

#k個選んだ時の最大値と最小値を考える。n+(n-1)+(n-2)+ ... +(n-k+1) = k(2n-k+1)/2
max_num = 0
min_num = 0
result_sum = 0
for K in range(k,n+2):
    max_num = K*(2*n-K+1)/2
    min_num = (K-1)*K/2
    result_sum += max_num - min_num +1


result_before_division = result_sum

result = result_before_division % (10**9 + 7)

print(int(result))

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")
MOD = 1000000007


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

    ans = 0
    sum_min = sum([i for i in range(K)])
    sum_max = sum([i for i in range(N-K+1, N+1)])
    l = K - 1
    r = N - K + 1
    while l <= N:
        ans += sum_max - sum_min + 1
        ans %= MOD
        l += 1
        r -= 1
        sum_min += l
        sum_max += r
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

result=0

teisu=10**9+7

for i in range(K,N+2):
    a=-i**2+(N+1)*i+1
    result+=a
    result=result%teisu

print(result)

Submission status: Accepted

Solution code:
N, K = [int(_) for _ in input().split()]
cnt = []
for i in range(1, N+2):
    mini = (i - 1) * i // 2
    maxi = (N - i + 1 + N) * i // 2
    cnt.append((maxi - mini + 1))
print(sum(cnt[K-1:]) % (10**9 + 7))

Submission status: Accepted

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

def main():
    N, K = map(int, input().split())
    p = 10**9+7
    ans = 0
    for i in range(K,N+2):
        minimum = i*(i-1)//2
        maximum = i*(2*N+1-i)//2
        ans += (maximum - minimum + 1)
        ans %= p
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
def main():
    N,K = map(int, input().split())
    MOD = pow(10,9)+7

    # 和としてありうる種類数が知りたい
    # 10^100が非常に大きいので、選ぶ個数が異なる時、必ず和は異なる事が分かるので、
    # 10^100を取り除いて、0,1,2,...,N-1,N という要素数(N+1)の数列からm個とるときに、
    # ありうる和の種類数を求めて、K<=m<=N+1でシグマすると考えられる
    # ここで、数列からm個とる時の和でありうるのは、
    # 最小値: 小さい順にm個 -> 0+1+...+(m-1) = m*(m-1)/2
    # 最大値: 大きい順にm個 -> N+(N-1)+...+(N-m+1) = m*(2N-m+1)/2
    # さらに、最小値から最大値までは全ての数を作る事が可能なので、
    # (求める値) = Σ(K<=m<=N+1){(N-m+1)*m+1}

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


main()

Submission status: Accepted

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

Submission status: Accepted

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

ans=0
if K>=N+1:
    ans=1
else:
    for i in range(K,N+2):
        min=int(i*(i-1)/2)
        max=int(i*N-i*(i-1)/2)
        Z=max-min+1
        #print(Z)
        ans+=Z
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 % 1000000007)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
N,K= map(int,input().split())
p=10**9+7
q=0
 
def calc(n,k):
  if k==1:
    return n+1
  else:
    maxi = k*n- k*(k-1)//2
    mini=  k*(k-1)//2
    #print(k,maxi,mini,maxi-mini+1)
    return maxi-mini+1
  
ans=0
for i in range(K,N+2):
  ans = ( ans+calc(N,i) )%p
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
mod = 10**9+7
def func(a,n):
    if n == 1:
        return a%mod
    elif n%2:
        return (a*func(a,n-1))%mod
    else:
        return ((func(a,n//2))**2)%mod
ans = 0
sum1 = 0
sum2 = 0
for i in range(1,N+2):
    if i == K:
        diff = ans
    sum1 = (sum1 + i-1)%mod
    sum2 = (sum2 + N-i+1)%mod
    ans = (ans + sum2 - sum1 + 1)%mod
print((ans-diff)%mod)

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
cnt=0
d=1000000007
while k != n+1:
  cnt += (n*k - k*k + k + 1)%d
  k+=1
    
print((cnt+1)%d)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
MOD = 10**9+7
f = lambda x:x*(x+1)//2
for i in range(K, N+2):
    ans += f(N)-f(N-i)-f(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):
    b = N*(N+1)//2-(N-i)*(N-i+1)//2
    a = (i-1)*i//2
    ans += b-a+1
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
def calc(n, k):
    return (n + n - k + 1) * k // 2


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

MOD = 10 ** 9 + 7
print(sum([(calc(N + 1, i) - calc(i, i) + 1) % MOD for i in range(K, N + 2)]) % MOD)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
num = list(range(N+1))
ans = 0
S = [0] * (N+1)
for i in range(N+1):
  S[i] = S[i-1] + num[i]
ans = 0
if K == N+1:
  print(1)
  exit()
for j in range(K-1, N):
  ans += S[-1] - S[-j-2] - S[j] + 1
print((ans+1) % (10**9+7))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
mod = 10**9+7
ans = 0
# k以上n+1以下のi個の数を選ぶ
for i in range(k, n+2):
    ans += ((n-i+1)+n)*i//2-(i-1)*i//2+1

print(ans % mod)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

out = 0
#for i in range(K, N+2):
    #out += int(math.factorial(N+1)/(math.factorial(i) * math.factorial((N + 1 - i))))

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



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

Submission status: Accepted

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

Submission status: Accepted

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

def calc(n,k):
  if k==1:
    return n+1
  else:
    maxi = k*n- k*(k-1)//2
    mini=  k*(k-1)//2
    #print(k,maxi,mini,maxi-mini+1)
    return maxi-mini+1
  
ans=0
for i in range(K,N+2):
  ans = ( ans+calc(N,i) )%p
  
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
mod = 10**9 + 7
sums = [0,n+1]
for i in range(2, n+2):
    score = (sums[i-1] + n-2*(i-1)) % mod
    sums.append(score)
cum_sum = [0]
for i in range(1, len(sums)):
    cum_sum.append(cum_sum[i-1]+sums[i])

print((cum_sum[-1] - cum_sum[k-1])%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):
    minx = (i*(i-1))//2
    maxx = (i*(2*n-i+1))//2
    ans += (maxx - minx + 1)
print(ans%mod)