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: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

##### 割り算の切り上げ #####
# tmp = -(-4 // 3)

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,K = inputMap()

	dekki_tmp = [i for i in range(N+1)]
	#print(dekki_tmp)

	dekki_min = [0]
	for i in dekki_tmp:
		dekki_min.append(dekki_min[-1] + i)
	dekki_min = dekki_min[2:]
	#print(dekki_min)

	dekki_tmp = dekki_tmp[::-1]

	dekki_max = [0]
	for i in dekki_tmp:
		dekki_max.append(dekki_max[-1] + i)
	dekki_max = dekki_max[2:]
	#print(dekki_max)

	ans = 0
	for i in range(K,N+2):
		mins = dekki_min[i-2]
		maxs = dekki_max[i-2]

		ans = (ans + maxs - mins + 1) % mod
		#print(maxs-mins+1)

	print(ans)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n,k=[int(i) for i in input().split()]

s = 0
for i in range(k, n+2):
    s = s + n*i - i*(i-1) + 1
q = s % (10^9+7)
print(q)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

s = int(((N+1)*((N+1)**2 + 5))/6 -((K-1)*((K-1)**2 + 5))/6)

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

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
cnt = []
minimum = sum([i for i in range(K-1)])
maximum = sum([i for i in range(N-(K-2), N+1)])

for n in range(K-1, N+1):
    minimum += n
    maximum += (N-n)
    diff = maximum - minimum +1
    cnt.append(diff)
print(sum(cnt))

Submission status: Wrong Answer

Solution code:

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

    for left in range(n):
        num = 0
        right = left + k
        res += (right - left)
    
    print(res %(10 ** 9))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
if n < k:
    print(1)
    exit(0)

MOD = pow(10, 9) + 7
count = 0
while n+1 >= k:
    minv = k * (k-1) // 2
    maxv = ((n+1) * n // 2) - ((n-k) * (n-k+1) // 2)

    count += (maxv - minv + 1)
    count %= MOD
    k += 1

    print(count)

Submission status: Wrong Answer

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

ans = 0
for i in range(n-k+1):
    a = 0
    b = 0
    for j in range(i+1):
        a += n+1-j
        b += i
    ans += a-b
    #print(ans)

print(ans+1)

Submission status: Wrong Answer

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

sum_N = N*(N+1)//2
ans   = 1
ue    = sum_N
shita = sum_N

for i in range(N-K+1):
    ue    -= i
    shita -= (N-i)
    ans   += (ue-shita+1)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import  deque
import sys
import bisect
import math
import itertools
from queue import deque
from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)

N, K = inp_list()
ans = 0
for k in range(K, N + 2):
    # M => 和の最大値, m => 和の最小値, k について和としてありえるものの個数は M - m + 1
    M = ( N * (N + 1) % mod - (N - k) * (N + 1 - k) % mod ) // 2
    m = k * (k - 1) // 2 % mod
    ans += (M - m + 1) % mod

print(ans % mod)

Submission status: Wrong Answer

Solution code:
from collections import  deque
import sys
import bisect
import math
import itertools
from queue import deque
from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)

N, K = inp_list()
ans = 0
for k in range(K, N + 2):
    # M => 和の最大値, m => 和の最小値, k について和としてありえるものの個数は M - m + 1
    M = ( N * (N + 1) - (N - k) * (N + 1 - k) ) // 2
    m = k * (k - 1) // 2
    ans += (M - m + 1) % mod

print(ans)

Submission status: Wrong Answer

Solution code:
N, K = [int(s) for s in input().split(" ")]
res = 0
for i in range(K, N + 2):
  res += (N - i + 1) * i + 1
  #print res, i, (N - i + 1) * i + 1
  print(res % 1000000007)

Submission status: Wrong Answer

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

for i in range(K, N + 2) :
	sum_lasti = i * (2 * N + 1 - i)/2 #初項 N + 1 - i 項数 i 公差1 末項 Nの等差数列の和
	sum_firsti = ( i * i - i )/ 2 #初項 0 項数 i 公差1 末項 i-1の等差数列の和
	
	res += sum_lasti - sum_firsti + 1

print(res%1000000007)

Submission status: Wrong Answer

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

al=[0]*(n+1)
bl=[0]*(n+1)
bl[0]=n
for i in range(1,n+1):
    al[i]=i+al[i-1]
    bl[i]=(n+1-i-1)+bl[i-1]
    
ans=0
for i in range(k,n+2):
    ans+=bl[i-1]-al[i-1]+1
print(ans%(1e9+7))

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

sum = 0

for j in range(K,M+2):
    temp = j*(M-j+1) + 1
    if temp > (10^9 + 7):
        temp = temp%(10^9 + 7)
    sum += temp


print(sum)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
num = [int(x) for x in range(n+1)]
len_n = len(num)
mod = 10**9+7
kosuu=0
for i in range(k, n):
    min = 0
    max = 0
    for i in range(i+1):
        min+=num[i]%mod
        max+=num[len_n-i-1]%mod
        kosuu+=max-min
        kosuu %= mod

print(kosuu)

Submission status: Wrong Answer

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


def log(v):
    print(v, file=sys.stderr)


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

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

Submission status: Wrong Answer

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

ans = 0

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

print(ans%mod)

Submission status: Wrong Answer

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

ans = 0

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

print(ans)

Submission status: Wrong Answer

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

ans = 0
MOD = 10**9 + 7


def sum(a, b):
    return (b - a + 1) * (a + b) / 2


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

print(ans % MOD)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
ans=0
for i in range(K,N+2):
    c=(i-1)*i/2
    d=(N+N-i+1)*i/2
    ans+=int(d-c+1)
print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
ans=0
for i in range(K-1,N+1):
    c=(i+1)*i/2
    d=(N+N-i)*(i+1)/2
    ans+=int(d-c+1)
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
s_1 = 0
s_2 = 0
s_3 = 0
mod = 1000000007
ans = 0
for i in range(k, n + 2):
    s_1 = (n + n + 1 - i) * i / 2
    s_2 = (0 + i - 1) * i / 2
    s_3 += s_1 + 1 - s_2
ans = s_3 % 1000000007
print('{:g}'.format(ans))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
n += 1
sum_n = sum(range(n))
ans = 0
for i in range(k, n+1):
    mi = i*(i-1) / 2
    ma = sum_n - ((n-i)*(n-i-1) / 2)
    ans += ma - mi + 1

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

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
nums = list(range(n+1))
upSum = [n]*(n+1)
lowSum = [0]*(n+1)
for i in range(0,n):
  upSum[i+1] = upSum[i] + nums[n-1-i]
  lowSum[i+1] = lowSum[i] + nums[i+1]
answer = 0
for i in range(k-1,n+1):
  answer += upSum[i] - lowSum[i] + 1
print(answer)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
ad = 0
for k in range(K,N+2):
  ma = (N*(N+1) - (N-k)*(N-k+1))//2
  mi = (k-1)*k//2
  ad += (ma - mi+1)
print(ad)

Submission status: Wrong Answer

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

#末尾の数字の和は
#20000100000
#となる。明らかに10**100は超えない。
#∴末尾の数だけ考えればOK

#3,2で
#(10**100)+(10**100+3)=(10**100+1)+(10**100+2)=2×10**100+3
#のように重複するパターンがある

#左右の項数が釣り合い、合計の数字が同じになるパターンは重複する

#2項目時
#0,1
#0,2
#0,3=1,2= 3,0/2,1
#0,4=1,3
#0,5=1,4/2,3
#0,6=1,5/2,4
#0,7=1,6/2,5/3,4 =4,3/5,2/6,1/7,0

#3項目時
#0,1,2 003
#0,1,3
#0,1,4=0,2,3
#0,1,5=0,2,4=2,1,3
#1,3,6 = 6,4,0 = 5,3,2

# 1110 4C1 = 4通り　→→÷2
#0111 1011 1101 1110

#11100
#11010

#(合計数+1)C(項数-1)


#nCr,combination,組み合わせ

#######################################################################
#https://note.nkmk.me/python-math-factorial-permutations-combinations/
from functools import lru_cache
from operator import mul
from functools import reduce

@lru_cache(maxsize=100000000)
def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
#######################################################################

ans = 0

for i in range(K,N+2):
    Ni_comb = combinations_count(N+1,i)
    print(i,Ni_comb)
    ans += Ni_comb

print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
# D - Sum of Large Numbers
from itertools import accumulate


def main():
    N, K = map(int, input().split())
    MOD = 10 ** 9 + 7
    cumsum_left = tuple(accumulate(range(N + 1)))
    cumsum_right = tuple(accumulate(reversed(range(N + 1))))
    total = sum(r - 1 + 1 for l, r in zip(cumsum_left[K - 1 :], cumsum_right[K - 1 :]))
    total %= MOD
    print(total)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

#n,k = 3, 2

res = 0

for k in range(K, n+2):
  first = k * (k-1) / 2
  last = (2 * n - k + 1) * k / 2
  res += (last - first + 1) % (10**9+7)
print(int(res))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
from typing import NoReturn


def my_sum(start: int, end: int):
    if start < 0:
        return my_sum(1 - start, end)
    elif start > 1:
        return my_sum(1, end) - my_sum(1, start - 1)
    else:
        return end * (end + 1) // 2


def main() -> NoReturn:
    n, k = map(int, input().split())  # type: int, int

    p: int = 10 ** 9 + 7

    answer = 0

    for i in range(k, n + 2):
        min_val: int = my_sum(0, i)
        max_val: int = my_sum(n - i + 1 , n)
        answer += max_val - min_val + 1

    print(answer % p)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from typing import NoReturn


def main() -> NoReturn:
    n, k = map(int, input().split())  # type: int, int

    p: int = 10 ** 9 + 7

    answer = 0

    for i in range(k, n + 1):
        min_val: int = sum(range(i))
        max_val: int = sum(range(n - i + 1, n + 1))
        answer += max_val - min_val + 1

    print(answer % p)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
#N+1この数が与えられ、ここからk個を選んだ合計値の整数種類
#異なる個数を選べば、それが一致することはない
#N+1個の整数0ーNから、k個(k=KーN+１)選ぶ場合の数
ans=0
for k in range(K,N+2):
  first = k * (k-1) / 2
  final = (N*2-k+1) * k / 2
  ans += final - first + 1
print(int(ans))

Submission status: Wrong Answer

Solution code:
import math

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

ans = 0

for i in range(K, N+2):
    ans += math.comb(i, K)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

N, K = mapint_inp()
MOD = 10*9+7

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

print(ans%MOD)

Submission status: Wrong Answer

Solution code:
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

N, K = mapint_inp()

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

print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

ans = 0
saisyo = sum(A[:K-1])
saidai = sum(A[:-(K-1)])
for i in range(K, N+2):
    saisyo += A[i-1]
    saidai += A[-i]
    ans += saidai - saisyo + 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial

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

for i in range (k,n+1):
    c1 = factorial(n+1) % mod
    c2 = 1 / factorial(i)
    c3 = 1 / factorial(n+1 - i)
    c = c1 * c2 * c3
    d = n+1 - (i + 1)
    s = s + (c-d) % mod

s = int((s+1) % mod)

print (s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,K=map(int, input().split())
a1 = (N+1)*(N+2)*(2*N+3)/6 - (K-1)*K*(2*K-1)/6
a2 = (N+1)*(N+2)/2 - (K-1)*K/2
a3 = N-K+2

print(-a1+(N+1)*a2+a3)

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

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 = [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

        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: Wrong Answer

Solution code:
n, k = map(int,input().split())
if k == n + k:
    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: Wrong Answer

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
print(int(t))

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    n, k = map(int, input().split())
    m = 10 ** 9 + 7

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

    ans = (f + s - t) % m

    print(int(ans))

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    n, k = map(int, input().split())
    m = 10 ** 9 + 7

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

    ans = f + s - t

    print(int(ans))

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:

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

base = 10 ** 100
modu = (10 ** 9) + 7

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

saw = []

for i in range(2**(N+1)):
    _sum = 0
    count = 0
    for j in range(N+1):
        if (i >> j) & 1:
            count += 1
            _sum += nums[j]

    if (_sum % modu not in saw) and count >= 2:
        saw.append(_sum % modu)

print(len(saw))

Submission status: Wrong Answer

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)

'''
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: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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
    
print(int(answer))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

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

for i in range(k, n+2):
  minsum = sum(range(0, i))
  maxsum = sum(range(n+1-i ,n+1))
  print(i,minsum, maxsum)
  ans += maxsum - minsum + 1

print(ans)

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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: Wrong Answer

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

Submission status: Wrong Answer

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 = k*(k-1)//2 #0+1+...+(k-1)
  maxNum = k*(2*N-k+1)//2 #(N-k+1)+...+(N-1)+N
  ans += maxNum - minNum + 1
print(ans%MOD)

Submission status: Wrong Answer

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)%m//6)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

pattern = 0

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

print(pattern)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
M=N+1;L=K-1
print((M**3+5*M+2*L**3+3*(1-M)*L**2-(5+3*M)*L)/6%1000000007)

Submission status: Wrong Answer

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

solution()

Submission status: Wrong Answer

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

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

    d = (s2 + s3 - s1)

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

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

print(ans)

Submission status: Wrong Answer

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

def s(i,n):
    #s1 = (2 * k * k) % MOD
    s1 = ((i * i - 4) / 3)
    s2 = ((n * (i+1)) / 2)

    ans = ( int(i * (s2 - s1) + 0.5) ) % MOD
    
    if ans < 0:
        ans += MOD
    return ans


print(int(s(n+1,n) - s(k-1,n)))

Submission status: Wrong Answer

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

def s(i,n):
    s1 = ((i * i - 4) / 3)
    s2 = ((n * (i+1)) / 2)
    
    return ( int(i * (s2 - s1) + 0.5) ) % MOD


print(int(s(n+1,n) - s(k-1,n)))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = 0

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

Submission status: Wrong Answer

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

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

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

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

mod = 10 * 9 + 7
ans = 0

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

print(ans%mod)