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())
ruiseki=[0 for i in range(N+2)]
#左からi（0,1,2,...）個めの数までの和
for i in range(1,N+2):
  ruiseki[i]=ruiseki[i-1]+i+1

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

Submission status: Accepted

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

c = 0
for k in range(K,n+2):
    c += n*(n+1)//2 - (n-k)*(n-k+1)//2 - k*(k-1)//2 + 1
# print("k=",k,"c=",c)
print(c%M)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

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

mod = 10**9+7

cum = [i for i in range(10**6)]
def cumsum(lst): #元のリストを保持
    res = lst[:]
    for i in range(1,len(res)):
        res[i] += res[i-1]
    return res
cum = cumsum(cum)
def cumsumdif(l,r,lst): #求めたい差のインデックスを入れる
    if l == 0:
        return lst[r]
    else:
        return lst[r] - lst[l-1]

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

ans = 0
for i in range(k,n+1):
    ans += cum[n] -cum[n-i] - cum[i-1] + 1 #+1:al自体を含むため
    ans %= mod

print((ans+1)%mod) #k = n+1のとき

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MOD=(10**9)+7
n,k=map(int,input().split())
ans=0
for i in range(k,n+2):
    min_start=0
    min_end=min_start+i-1
    max_end=n
    max_start=n-i+1
    min_sum=(min_end-min_start+1)*(min_end+min_start)//2
    max_sum=(max_end-max_start+1)*(max_end+max_start)//2
#    print(i,min_start,min_end,min_sum,max_start,max_end,max_sum,max_sum-min_sum+1)
    ans+=max_sum-min_sum+1
    ans=ans%MOD
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+1+n-i)*i/2 - (i-1)*i/2 + 1
  
print(int(ans%(10**9 + 7)))

Submission status: Accepted

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

resolve()

Submission status: Accepted

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

  
mod = 10**9+7 

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

print(ans%mod)

Submission status: Accepted

Solution code:
def main():
  N, K = (int(_) for _ in input().split())
  MOD = 10 ** 9 + 7
  res = 0
  for k in range(K, N+2):
    res += k * (N - k + 1) + 1
    res %= MOD
  print(res)
  return

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:

MOD = 1000000007

def solve(n,k):
	ans = (n*k - k*k + 1)%MOD
	return ans

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

n +=1 

output = 0

for i in range(k,n+1):
	output = (output + solve(n,i))%MOD
print(output)

Submission status: Accepted

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


lst = [None for i in range(n+1)]
for i in range(n+1):
    lst[i]=i

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,k = map(int,input().split())
class InverseTable:
    __slots__ = ['In', 'fac', 'Ifac']

    def __init__(self, mod, maxnum):
        self.In = [0, 1]; self.fac = [1, 1]; self.Ifac = [1, 1]
        for i in range( 2, maxnum + 1 ):
            self.In.append( ( -self.In[mod % i] * (mod//i) ) % mod )
            self.fac.append( ( self.fac[-1] * i ) % mod )
            self.Ifac.append( (self.Ifac[-1] * self.In[-1]) % mod )
        
    def cmb(self, n, r):
        if ( r<0 or r>n ): return 0
        r = min(r, n-r)
        return self.fac[n] * self.Ifac[r] * self.Ifac[n-r] % mod
    
    def per(self, n, r):
        if ( r<0 or r>n ): return 0
        return self.fac[n] * self.Ifac[n-r] % mod

invt = InverseTable(mod, 10**6)
# maxnum=10**6だとテーブル生成に200ms程かかるので（Pythonだと1000msほど）
# 最大生成領域は問題ごとに要検討
teisu = n*(n+1)//2
for i in range(k,n+2):
  ans += teisu-(n-i)*(n-i+1)//2-(i-1)*(i)//2 + 1
  ans%=mod
  # print(i,ans)
print(ans%mod)

Submission status: Accepted

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

def rsq(L, R):
    return T(R) - T(L - 1)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

kari = list()
count = 0
for i in range(2*10**5+1):
    count += i
    kari.append(count)
    
amount = 0
mod = 10**9+7
if K > N:
    print(1)
else:
    for i in range(K, N+2):
        if N-i >= 0:
            max_count = kari[N] - kari[N-i]
        else:
            max_count = kari[N]
        min_count = kari[i-1]
        count = max_count - min_count + 1 
        amount += count % mod
    print(amount%mod)

Submission status: Accepted

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

Submission status: Accepted

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

acc_min = []
acc_max = []
s_min = 0
s_max = 0
for i in range(n + 1):
    s_min += i
    acc_min.append(s_min % mod)
    s_max += n - i
    acc_max.append(s_max % mod)
ans = 0
for i in range(k, n + 2):
    ans = (ans + acc_max[i - 1] - acc_min[i - 1] + 1) % mod
print(ans)

Submission status: Accepted

Solution code:
# from fractions import gcd
# mod = 10 ** 9 + 7
# N = int(input())
# a = list(map(int,input().split()))
# a,b,c = map(int,input().split())
# ans = [0] * N
# math.ceilで切り上げ
# dp = [[0] * 4 for i in range(3)] #2次元配列初期化
# dp = [[[0] * 2 for i in range(3)] for j in range(5)]
# (ord('A'))でASCII出力 Aは65
import math
import numpy as np
import statistics
import string
import sys
from array import array
from collections import deque
from functools import wraps
import time

def intinput():
    return int(input())
def listintinput():
    return list(map(int, input().split()))
def splitintinput():
    return map(int, input().split())
def factorialsurplus(x, y, z):  # xからyまでの階乗をzで割ったあまりを求める
    ret = 1
    for i in range(x, y + 1):
        ret = (ret * i) % z
    return (ret)
def isprime(x):
    if x == 1:
        return False
    if x == 2:
        return True
    sq = int(math.sqrt(x))
    for i in range(2,sq+1):
        if x % i == 0:
            return False
    return True
def hcfnaive(a,b):#最大公約数 math.gcdが使えない時の手段として入れとく。pythonが更新されたらいらなくなるはず
    if(b==0):
        return a
    else:
        return hcfnaive(b,a%b)

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

print(ans)

Submission status: Accepted

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

MAX = sum([i for i in range(n-k+1, n+1)[::-1]])
MIN = sum([i for i in range(k)])

ans = MAX - MIN + 1
for i in range(k, n+1):
    MAX+=n-i
    MIN+=i
    ans += MAX - MIN + 1
    ans%=mod

print(ans)

Submission status: Accepted

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

MOD = 1000000007  # type: int


def powm(a, n, m):
    if a == 1 or n == 0:
        return 1
    if n % 2 == 0:
        s = powm(a, n // 2, m)
        return s * s % m
    else:
        return a * powm(a, n - 1, m) % m

def solve(N: int, K: int):
    # base = powm(2,N+1,MOD)
    sumMinus = 0
    lastMinimum = 0
    lastMaximum = 0
    for i in range(1,N+2):
        lastMinimum += i-1
        lastMaximum += N-(i-1)
        # print(i, lastMinimum, lastMaximum)
        if i >= K:
            count = lastMaximum-lastMinimum+1
            sumMinus= (sumMinus+count)%MOD
            # print(i,lastMinimum,lastMaximum,count)
    print(sumMinus)
    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:
N, K = map(int, input().split())

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

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
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, K = map(int, readline().split())
    left = (K*(K-1))//2
    right = K*(2*N -K +1)//2
    ans = 0
    for i in range(K, N+1):
        ans += (right - left +1) % MOD
        right += N-i
        left += i
    print((ans+1)%MOD)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ma = 0
mi = 0
ans = 0

for i in range(K):
  ma = (ma + N - i) % MOD
  mi = (mi + i) % MOD

t = ma - mi + 1
while t < 0:
  t += MOD

ans = (ans + t) % MOD

for i in range(K, N + 1):
  ma = (ma + N - i) % MOD
  mi = (mi + i) % MOD
  t = ma - mi + 1
  while t < 0:
    t += MOD
  ans = (ans + t) % MOD

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

def mymult(i):
    if i%2==0:
        a=i//2
        return a*(i-1)
    else:
        a=(i-1)//2
        return a*i

def mymult2(n,i):
    tmp=n*2-i+1
    if tmp%2==0:
        a=tmp//2
        return a*i
    else:
        a=i//2
        return tmp*a

ans=0
for i in range(k,n+2):
    minim=mymult(i)
    maxim=mymult2(n,i)
    ans=ans+(maxim-minim)+1

print(ans%1000000007)

Submission status: Accepted

Solution code:
import sys
import socket

hostnames = ['N551J', 'F551C', 'X553M']
input_file = 'd1.in'
# if socket.gethostname() in hostnames:
#     sys.stdin = open(input_file)


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


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


M = 10 ** 9 + 7
def solve():
    n, k = read_int_list()
    res = 0
    for i in range(k, n + 2):
        start = i * (i - 1) // 2
        stop = i * (n + n - i + 1) // 2
        res += stop - start + 1
        res %= M
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import accumulate
n,k = list(map(int, input().split()))
a = list(range(0,n+1))
bleft = list(accumulate(a))
bright = list(accumulate(reversed(a)))
ans = 0
mo = 10**9 + 7
for i in range(k-1,n+1):
    ans = (ans + bright[i] - bleft[i] + 1) % mo

print(ans)

Submission status: Accepted

Solution code:
mod = 10**9 + 7
base = 10**100 % mod

n,k = map(int,input().split())
A = [base + i for i in range(n+1)]

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

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

Submission status: Accepted

Solution code:
# coding: utf-8

n, k = map(int, input().split())
ans = 0
l = list(range(n))
s = n*(n+1)//2
m = 10**9+7

for i in range(n-k+2): # i+k個選ぶ
    #0,1,2 ..., n から i+k個選んだときの和の種類
    ans += ((s - (n-(i+k))*(n-(i+k)+1)//2) - (i+k-1)*(i+k)//2 +1)
    if ans > m:
        ans = ans % m
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, K = mi()
ma = mi = 0
mod = 10**9+7
for i in range(K-1):
    ma += N-i
    mi += i
ans = 0

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

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline

N, K = map(int, read().split())
mod = 10 ** 9 + 7
answer = 0
cnt = list(accumulate(range(N + 1)))
for i in range(K, N + 1):
    tmp = cnt[N] - cnt[N - i] - cnt[i] + 1
    answer = (answer + cnt[N] - cnt[N - i] - cnt[i - 1] + 1) % mod

answer += 1
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def do(a, d, n, l):
    return (n*(a+l) // 2)

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

for i in range(k, n+2):
    #print("---")
    #print(i)
    l = do(0      , 1, i, i - 1)
    #print((0      , 1, i, i - 1))

    r = do(n+1 - i, 1, i,     n)
    #print((n+1 - i, 1, i,     n))

    #print(i, l, r, r-l+1)
    res += r-l+1
    res %= mod
print(res)

Submission status: Accepted

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

    low = []
    lowtotal = 0
    high = []
    hightotal = 0
    for i in range(N+1):
        lowtotal += i
        low.append(lowtotal)
        hightotal += N-i
        high.append(hightotal)

    ans = 0
    for l, h in zip(low[K-1:], high[K-1:]):
        cnt = h-l+1
        ans += cnt
        ans %= MOD
    print(ans)
main()

Submission status: Accepted

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

a = 10 ** 9 + 7
ans = 0
small = 0
big = 0
for i in range(0 , k):
    big += n - i
    small += i
    
for i in range(k, n + 1):
    ans += big - small + 1
    big += n - i
    small += i

print((ans + 1) % a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

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

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

Submission status: Accepted

Solution code:
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)

N,K=nm()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

count  = 0

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

print(count%(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 += (N + N - i + 3) * i // 2 - i * (i + 1) // 2 + 1
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(1000000)


def solve(N, K):
    M = 10 ** 9 + 7
    pre = []
    post = []
    s = 0
    for i in range(N + 1):
        s += i
        pre.append(s)

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

    ans = 0
    for i in range(K, N + 2):
        a = post[N + 1 - i] - pre[i - 1] + 1
        ans += a
        ans %= M
    return ans


if __name__ == "__main__":
    N, K = tuple(map(int, input().split(" ")))
    print(solve(N, K))

Submission status: Accepted

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

Submission status: Accepted

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

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

    cnt = 0
    min_ = 0
    max_ = 0

    for i in range(1, n+2):
        min_ += i - 1
        max_ += n - i + 1

        if i >= k:
            cnt += max_ - min_ + 1
            cnt %= 10 ** 9 + 7

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(k, n+2):
    high = (arr[-i] + arr[-1]) * i // 2
    low = (arr[0] + arr[i-1]) * i // 2
    ans += (high - low + 1) % MOD
print(ans % MOD)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# D - Sum of Large Numbers

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

modulus = 10 ** 9 + 7

s = 0
# m個選ぶ
for m in range(k, n + 2):
    s += (m * (n - m + 1) + 1) % modulus  # 最小から最大までの個数

print(s % modulus)

Submission status: Accepted

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

Submission status: Accepted

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

answer=0
for i in range(K,N+2):
  l=i*(i-1)//2
  r=i*N-i*(i-1)//2
  answer+=(r-l+1)%MOD
  answer%=MOD
print(answer)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
mod = int(1e9+7)
fans = 0
for x in range(k, n + 2):
    mm = (k-1) * k / 2
    # sum of least values
    minv = (((x-1) * x) % mod * pow(2, mod-2, mod)) % mod
    # sum of most values
    maxv = ((n * (n+1)) % mod * pow(2, mod-2, mod)) % mod
    # sum upto n-k
    mmm = (((n-x) * (n-x+1)) % mod * pow(2, mod-2, mod)) % mod
    maxv = maxv - mmm
    while maxv < 0:
        maxv += mod
    fans = (fans + maxv - (minv-1))%mod
while fans < 0:
    fans += mod
print(fans)

Submission status: Accepted

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

cum = [0]
for x in range(1, N+1):
    cum.append(cum[-1]+x)

ans = 0
for k in range(K, N+2):
    ans += (cum[N] - cum[max(0,N-k)]) - cum[k-1] + 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*(i-1)//2 + 1

print(ans%mod)

Submission status: Accepted

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

Submission status: Accepted

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

print(S)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline

MOD = 10 ** 9 + 7


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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
import fractions
import collections
import itertools
from collections import deque
N,K=map(int,input().split())
cnt=0
p=10**9+7
for i in range(K,N+2):
    cnt=(cnt+((N-i+1)*i)+1)%p
    #print(((N-i+1)*i)+1)
print(cnt)

Submission status: Accepted

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

ans = 0

lst = [int(i) for i in range(N + 1)]
internal = 1
for i in range(N + 1):
    internal += lst[N - i] - lst[i]
    if i + 1 >= K:
        ans += internal
        ans = ans % mod

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


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


if __name__ == '__main__':
    resolve()

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)

Submission status: Accepted

Solution code:

import sys
import math
import fractions
import bisect
import queue
import heapq
import collections
import itertools
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint=====================================
N, K = map(int, input().split())
N, M = map(int, input().split())
A, B = map(int, input().split())

H, W = map(int, input().split())

L, R = map(int, input().split())

1行のstring=================================
S, T = input().split()

1行の整数配列================================
P = list(map(int,input().split()))

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
D = list(map(int,input().split()))

L = list(map(int,input().split()))
R = list(map(int,input().split()))

T = list(map(int,input().split()))

改行あり整数==================================
X = []
Y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    X.append(x1)
    Y.append(y1)

A = []
for i in range(N):
    a=int(input())
    A.append(a)

Pair = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    Pair.append((x1, y1))
    
2次元整数配列=====================================
A = []
for i in range(N):
    tmp = list(map(int,input().split()))
    A.append(tmp)


N行M列の初期化====================================
dp = [[VAL] * RETU for i in range(GYO)]

'''


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

ans = 0

for i in range(K, N+2):

    lim = ((N  + N + 1 - i) * i) // 2 
    m = ((i - 1)         * i) // 2 

    ans += lim - m + 1
    ans %= MOD

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect,sys
import math
from collections import deque

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac =fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV
        
    return CONV()



sys.setrecursionlimit(200005)


def main():
    N,K= isRaw()
    first = pow(10, 100, DIV)
    ans = 1
    dadd = 1
    for n in range(N+1-K):
        dadd+=N-2*n
        ans+=dadd
        ans=ans%DIV
    return ans%DIV

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

Submission status: Accepted

Solution code:

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


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

print(ans%mod)

Submission status: Accepted

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

    cuptable = list(range(N+1))
    rcuptable = list(range(N+1))
    rcuptable.reverse()
    for i in range(1,len(cuptable)):
        rcuptable[i]+=rcuptable[i-1]
        cuptable[i]+=cuptable[i-1]
    mod=10**9+7
    ans = 0
    for i in range(K-1,len(cuptable)):
        mn = cuptable[i]
        mx = rcuptable[i]
        ans += mx-mn +1
        ans %= mod
    
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from itertools import accumulate
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9+7

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

N, K = map(int, readline().split())
P = 10 ** 9 + 7
ans = 0
for a in range(K, N + 2):
    ans += (N - a + 1) * a + 1
    ans %= P

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def fur(n, r, mod=10**9+7):
    work = (n-r+1)*r + 1
    return work%mod

N, K = map(int, input().split())
result = 0
mod = 10**9 + 7
for k in range(K, N+2):
    result += fur(N, k)
    result %= mod
print(result%mod)

Submission status: Accepted

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

sample = list(range(n+1))

count = 0
current = sum(sample[-k:])-sum(sample[:k])+1

for i in range(k,n+2):
    
    # count += sum(sample[-i:])-sum(sample[:i])+1
    count += current
    current = current - i + (n+1-i) - 1

print(count%1000000007)

Submission status: Accepted

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