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:
import math
import itertools

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

all_combination = 0
less_than_K_combination = 0
for num in range(K, N + 2): # 選ぶ個数を1 から N + 1個までずらす
    targetList = []
    min = (0 + num - 1) * num / 2
    targetList = []
    max = (N - (num -1) + N) * num / 2
    all_combination += int(max) - int(min) + 1

#for num in range(1, K): # 選ぶ個数を1 から K - 1個までずらす
#    targetList = []
#    for each_num in range(num):
#        targetList.append(each_num)
#    min = sum(targetList)
#    targetList = []
#    for each_num in range(N + 1 - num, N + 1):
#        targetList.append(each_num)
#    max = sum(targetList)
#    less_than_K_combination += max - min + 1

print(all_combination)

Submission status: Wrong Answer

Solution code:
def main():
  n, k = map(int, input().split(' '))
  A = list(range(n+1))
  A_rev = A[::-1]
  cumsum_A = [0]
  cumsum_A_rev = [0]
  for i in range(len(A)):
    cumsum_A.append(A[i]+cumsum_A[i])
    cumsum_A_rev.append(A_rev[i]+cumsum_A_rev[i])
  ans = 0
  
  for i in range(k, n+2):
    tmp_min = cumsum_A[i]
    tmp_max = cumsum_A_rev[i]
    ans += tmp_max - tmp_min + 1
  print(ans)
    

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
def main():
  n, k = map(int, input().split(' '))
  A = list(range(n+2))
  ans = 0
  for i in range(k, n+2):
    print('i', i)
    tmp_min = sum(A[:i])
    tmp_max = sum(A[n+2-i:])
    ans += tmp_max - tmp_min
  print(ans)
    

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

print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
mod = 10**9+7
sum_min = 0
sum_max = 0
diff = 0
while K != N+2:
    sum_min = 1/2*K*(K-1)
    sum_max = 1/2*K*(2*N-K+1)
    diff += sum_max - sum_min
    K+= 1
diff = diff % mod
print(int(diff))

Submission status: Wrong Answer

Solution code:
N, K = list(map(int,input().split()))
S = []
if N <= K:
  print(1)
  exit(0)
for i in range(K,N+2):
  S.append(i*N - (i-1)*i + 1)
print(sum(S))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count = 0
for m in range(K, N+2):
    #print(N, m)
    ans = m * N - (m * (m - 1) - 1)
    #print(ans)
    if ans > 0:
        count += ans

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#D 
inp = input().split(' ')
N = int(inp[0])
K = int(inp[1])

(int((N+1)*((N+1)*(N+2) - K*(K-1))/2.0 - ((N+1)*(N+2)*(2*N+3) - (K-1)*K*(2*K-1))/6.0) + (N+1+1-K)) % (int(10**9) + 7)

Submission status: Wrong Answer

Solution code:
import math
import itertools

N, K = map(int, input().strip().split())
L = math.pow(10, 10)

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

amount = 0
for comb_no in range(K, N + 2):
    possible_values = set()
    for combination in itertools.combinations(values, comb_no):
        possible_values.add(sum(combination))
    print(len(possible_values))

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

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
M = (n+1)*(1/2)*(n+1)*(n+2)-(1/6)*(n+1)*(n+2)*(n*2+3)+n+1
m = (n+1)*(1/2)*(k-1)*k-(1/6)*(k-1)*k*(2*k-1)+k-1
ans = M-m
print(int(ans%(1000000007)))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
M = (n+1)*(1/2)*(n+1)*(n+2)-(1/6)*(n+1)*(n+2)*(n*2+3)+n+1
m = (n+1)*(1/2)*(k-1)*k-(1/6)*(k-1)*k*(2*k-1)+k-1
ans = M-m
print(ans%(1000000007))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

counter = 0
for k in range(K,N+1):
    s1 = S[k]
    s2 = S[N+1] - S[N+1-k]
    counter += s2-s1+1
counter += 1

print(counter)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline
MOD = 1000000007

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


res = 0

if N <= K:
    print(1)
    exit()

_min=0
_max=0
for i in range(K):
    _min += i
    _max += (N-i)

res = 0

for i in range(K,N+2):
    if i != K:
       _min+=i-1
       _max+=(N+1 -i)

    #print(_min,_max)
    
    res +=(_max-_min+1)

print(res%MOD)

Submission status: Wrong Answer

Solution code:
import numpy as np 

a = input()
N,K = np.array(a.split()).astype(int)

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

res = 0
for i in range(K, N+1+1):
    l = b_sum(0,i-1)
    r = b_sum(N-i+1, N)
    res += r-l+1
    print(r-l+1)
print(res)

Submission status: Wrong Answer

Solution code:
import math
import itertools

def mathFactorial(a,b):
	return math.factorial(a) // (math.factorial(b) * math.factorial(a-b))

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

myListA =[]
myList =[]

for i in range(0,N+1):
	myListA.append(i)

i = 0
l = 0
while K < N+2:
	for x in itertools.combinations(myListA,K):
		myList.append(sum(x))
	K = K + 1
	i = i + 1
	l = l + len(set(myList))
	myList =[]

print(l % (10^9 +7))

Submission status: Wrong Answer

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

def counts(n,k):
    if k==1:
        return N
    else:
        return k*N -k*(k-1) +1

total =0
for k in range(K,N+2):
    total += int(counts(N,k))

print(total%mod)

Submission status: Wrong Answer

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

def counts(n,k):
    if k==1:
        return N
    else:
        return k*N -k*(k-1) +1

total =0
for k in range(K,N+2):
    total += counts(N,k)

print(total%mod)

Submission status: Wrong Answer

Solution code:
import math

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

mod = 10**9 +7
# Larges = list(itertools.product([0,1],repeat=N+1))
# ans=0
# for i in Larges:
#     if sum(i)>=K:
#         ans+=1


def counts(n,k):
    if k==1:
        return N
    else:
        return k*N -k*(k-1) +1

total =0

for k in range(K,N+2):
    total += counts(N,k)


print(total%mod)

Submission status: Wrong Answer

Solution code:
import math

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

# Larges = list(itertools.product([0,1],repeat=N+1))
# ans=0
# for i in Larges:
#     if sum(i)>=K:
#         ans+=1


def counts(n,k):
    if k==1:
        return N
    else:
        return k*N -k*(k-1) +1

total =0

for k in range(K,N+2):
    total += counts(N,k)


print(total)

Submission status: Wrong Answer

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

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

mod = 10**9+7

# low_lim = (1+k)*k//2
# up_lim = (1+n)*n//2

low_lim = (((1+k) % mod) * (k % mod)) % mod // 2
up_lim = (((1+n) % mod)*(n % mod) % mod)//2

num = low_lim-up_lim

print(num % mod)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

mod = 1000000009

sn = (n*(n+1)*(n+2)/6 +n+1)% mod
sk = ((k-1)*k*(3*n-2*k+4)/6 +k-1)% mod

snk = (sn - sk)% mod

print(snk)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
A = list(range(n+1))
ans = 0
suma = sum(A[-k+1:])
for i in range(k,n+2):
  suma += A[-i]
  ans += suma - (i-1)*i//2+1
  
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sum_min = sum(range(K-1))
sum_max = sum(range(K+1,N+1))
num = 0
for i in range(K, N+2):
  sum_min += i-1
  sum_max += 2*K-i
  num += sum_max - sum_min +1
print(num)

Submission status: Wrong Answer

Solution code:
def culc(n, k):
    return k*(-2*k**2+3*n*k+(3*n+8))//6

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

MOD = 10**9 + 7
print(culc(N, N+1)-culc(N, K-1)%MOD)

Submission status: Wrong Answer

Solution code:
from math import factorial
m = 10**9 + 7
  
def comb(n,k,p):
  if n<0 or k<0 or n<k: return 0
  if n == 0 or k == 0: return 1
  a=factorial(n) % p
  b=factorial(k) % p
  c=factorial(n - k) % p
  return (a * power(b, p - 2, p)*power(c, p-2, p)) % p
def power(a, b, p):
  if b == 0: return 1
  if b % 2 == 0:
    d = power(a, b // 2, p)
    return d * d % p
  if b % 2 == 1:
    return (a * power(a,b-1,p)) % p

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

if n <= k:
  pattern = 1
else:
  pattern = 0
  for num in range(k,n+1,1):
      pattern += comb(n+1, num, m)

print(pattern)

Submission status: Wrong Answer

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

ans = 0
max=0
min=0

a=[0]*(n+1)
b=[0]*(n+2)

for i in range(n+1):
    a[i]=i
    b[i+1]=a[i]+b[i]

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

ans = ans % p

print(ans)

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split(" "))
print(a,b)
min=0
max=0
count=0

for i in range(b,a+2):
    min = int((i-1)*i/2)
    max = int((2*a-i+1)*i/2)
    count+=max-min+1
print(count%1000000007)

Submission status: Wrong Answer

Solution code:
import itertools
 
n, m = list(map(int, input().split(" ")))
l = [ i for i in range(n + 1) ]
 
ans = 0
for i in range(m, n + 2):
    ans = ans + len(list(itertools.combinations(l, i)))
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
 
n, m = list(map(int, input().split(" ")))
l = [ i for i in range(n + 1) ]
 
ans = 0
for i in range(m, n + 2):
    for v in itertools.combinations(l, i):
        ans = ans + 1
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7
def main():
    N,K = map(int,input().split())
    ans = 0
    S = [0]
    for i in range(1,N+1):
        S.append( S[-1] + i)
    for k in range(K,N + 1):
        ans = (ans + S[N] - S[k - 1] + 1)%mod
    print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
n = a[0]
k = a[1]
Sum = 0

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

Submission status: Wrong Answer

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

a = 0

for i in range(K,N+2):
  a += i*(2*N-i+1)//2 - i*(i-1)//2 + 1
  
print(int(a))

Submission status: Wrong Answer

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

a = 0

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

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):
  Min = i*(i-1)/2
  Max = i*(2*N-i+1)/2
  ans += Max-Min+1
print(ans%Mod)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# # 整数の入力
# a = int(input())
# # スペース区切りの整数の入力
# b, c = map(int, input().split())

# 整数の入力
a, b = map(int, input().split())

if a+1 == b:
    print(1)
else:
    res_count_list = []

    min_before = 0
    max_before = 0
    for i in range(b, a+2):
        if min_before == 0 and max_before == 0:
            min_before = sum(range(i))
            max_before = sum(range(a, a-i, -1))
        else:
            min_before = min_before + i - 1
            max_before = max_before + a - i + 1
        # print(max)
        # print(min_before)
        # print(max_before)
        res_count_list.append(max_before - min_before + 1)

    print(sum(res_count_list))

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

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
MAX = float('inf')


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
        ret -= (k-1)*k//2
        ret += 1
    print(ret)


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

cnt=0
for r in range(k+1,n+2):
  cnt+=cmb(n+1, r, p)
print(cnt)

Submission status: Wrong Answer

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

Ans = [0]*(N+2)
Sum_Ans = 0

def solution(N,K,Ans,Sum_Ans):
    for i in range(K,N+2):
        #max[i] = (2*N - i + 1)*i / 2
        #min[i] = i*(i - 1) / 2
        Ans[i] = i*(N - i + 1)
        
        Sum_Ans += Ans[i]
    
    print(Sum_Ans%(10**9 + 7))

solution(N,K,Ans,Sum_Ans)

Submission status: Wrong Answer

Solution code:
n, r = input().split()

res = 0
for i in range(int(n) + int(r) - 1):
  res += i

print(res)

Submission status: Wrong Answer

Solution code:
# n, k = 0
n, k = map(int, input().split())
# 0,1,2,3,,,,,,n
# k個選んだ時の最小値と最大値の差をk,k+1,k+2,,,,nと積算する

iResult = 0  # 答え
for i in range(k, n + 2):
#	print(i)
	#	min = 0
	#	max = 0
	#	for j in range(0, i):
	#		print('    ' + str(j))
	#		min = min + j
	#		max = max + n - j
	iResult = iResult + i * (n - i + 1) + 1

print(iResult)

Submission status: Wrong Answer

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

ans = 0
min_x, max_x = 0, N
for i in range(1, N+1):
    min_x += i
    max_x += N-i
    if i+1 < K: continue
    ans += max_x - min_x + 1
    ans %= mod

print(ans)

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

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

res = 0

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math

N, K = list(map(int, stdin.readline().rstrip().split()))

n = [i for i in range(0, N+1)]

amount_min = 0
for j in range(K):
    amount_min += n[j]

#print(amount_min)

amount_max = 0
for k in range(N+1):
    amount_max += k

#print(amount_max)

count = 0
if N + 1 == K:
    count = 1
elif N == K:
    count = 3
else:
    count += 1
    count += 1
    count += 2 * (amount_max - amount_min - 1)

#print(count)
print(count % (10**9+7))

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    # 1 <= N <= 2 * 10^5
    # 1 <= K <= N + 1
    N, K = map(int, input().split(" "))

    total_num = 0
    for k in range(K, N+2):
        # NからN-(k-1)までの和
        sum_max = k*(2*N - k + 1) / 2
        # 0から(k-1)までの和
        sum_min = k*(k-1) / 2
        # 個数を計上
        total_num += sum_max - sum_min + 1
        total_num %= 1000000007
    
    print(total_num)

Submission status: Wrong Answer

Solution code:
NK = list(map(int, input().split()))
N = NK[0]
K = NK[1]

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    wa=max-min+wa+1


wa=wa+1
wa=wa%(10**9+7)
print(wa)

Submission status: Wrong Answer

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

    wa=max-min+wa+1
    wa%=10**9+7

wa=wa+1
print(wa)

Submission status: Wrong Answer

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

    wa=max-min+wa+1

wa=wa+1 
print(wa)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
mod = pow(10,9) + 7

def cal(a,i):
  min = i*(i-1)/2
  max = a*(a-1)/2 - (a-i)*(a-i-1)/2
  return max - min + 1

count = 0
for i in range(a-b+2):
  count += cal(a+1,i+b)
print(count % mod)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
mod = pow(10,9) + 7

def cal(a,i):
  min = i*(i-1)/2
  max = a*(a-1)/2 - (a-i)*(a-i+1)/2
  return max - min + 1

count = 0
for i in range(a-b+2):
  if(a < i+b):
  	count += cal(a+1,i+b)
  else:
    count += 1
print(count % mod)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
mod = pow(10,9) + 7

def cal(a,i):
  min = i*(i-1)/2
  max = a*(a+1)/2 - (a-i)*(a-i+1)/2
  return max - min + 1

count = 0
for i in range(a-b+2):
  if(a < i+b):
  	count += cal(a,i+b)
  else:
    count += 1
print(count % mod)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
mod = pow(10,9) + 7

def cal(a,i):
  min = i*(i-1)/2
  max = a*(a+1)/2 - (a-i)*(a-i+1)/2
  return max - min + 1

count = 0
for i in range(a-b+2):
  count += cal(a,i+b)
print(count % mod)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
mod = pow(10,9) + 7

def cal(a,i):
  min = i*(i-1)/2
  max = a*(a-1)/2 - (a-i)*(a-i-1)/2
  return max - min + 1

count = 0
for i in range(a-b+2):
  count += cal(a,i+b)
print(count % mod)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
mod = pow(10,9) + 7

def cal(a,i):
  min = i*(i+1)/2
  max = a*(a+1)/2 - (a-i)*(a-i+1)/2
  return max - min + 1

count = 0
for i in range(a-b+1):
  count += cal(a,i+b)
print(count % mod)

Submission status: Wrong Answer

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

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


print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

n, k = map(int, input().split())
MOD = 10 ** 9 + 7
ref = np.array(list(range(n + 1)), dtype='int64')

max_sum = np.sum(ref[-k + 1:])
min_sum = np.sum(ref[:k - 1])
if k == 1:
    max_sum = ref[n]
ans = 0

for i in range(k, n + 2):
    min_sum += ref[i - 1]
    max_sum += ref[-i]
    ans += max_sum - min_sum + 1
    ans %= MOD

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n, k = map(int, input().split())
MOD = 10 ** 9 + 7
ref = np.array(list(range(n + 1)), dtype='int64')

max_sum = np.sum(ref[-k + 1:])
min_sum = np.sum(ref[:k - 1])
ans = 0

for i in range(k, n + 2):
    min_sum += ref[i - 1]
    max_sum += ref[-i]
    ans += max_sum - min_sum + 1
    ans %= MOD

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n, k = map(int, input().split())
MOD = 10 ** 9 + 7
ref = np.array(list(range(n + 1)), dtype='int64')

max_sum = np.sum(ref[-k + 1:])
min_sum = np.sum(ref[:k - 1])
ans = 0

print('min, max = ', min_sum, max_sum, max_sum - min_sum)
for i in range(k, n + 2):
    min_sum += ref[i - 1]
    max_sum += ref[-i]
    ans += max_sum - min_sum + 1
    ans %= MOD

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split(' '))
count = 0
for n in range(K, N+2):
    count += n*(N-n+1) + 1

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
if k>n:
    print(1)
else:
#    p=2*(n-k+2)%1000000007
    r=0
    s=0
    sum=0
    for i in range(k):
        r=(r+i)%10000000007
  #      print(r)
        s=(s+n-i)%1000000007
   #     print(s)
    for j in range(k,n+2):
        sum=(sum+s-r+1)%1000000007
 #       print(sum)
        r=(r+j)%1000000007
 #       print(r)
        s=(s+n-j)%1000000007
 #       print(s)
    print(sum)
'''    while(p!=0):
        r=(r+p)%1000000007
        print(r)
        p-=2
    if(k==1):
        print(r-2)
    else:
        print(r-1)
'''

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
if k>n:
    print(1)
else:
#    p=2*(n-k+2)%1000000007
    r=0
    s=0
    sum=0
    for i in range(k):
        r=(r+i)%10000000007
  #      print(r)
        s=(s+n-i)%1000000007
   #     print(s)
    for j in range(k,n+2):
        sum=(sum+s-r+1)%1000000007
 #       print(sum)
        r=(r+j)%1000000007
 #       print(r)
        s=(s+n-j)%1000000007
 #       print(s)
print(sum)
'''    while(p!=0):
        r=(r+p)%1000000007
        print(r)
        p-=2
    if(k==1):
        print(r-2)
    else:
        print(r-1)
'''

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
	if K == 1:
		ans += N -1
	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()