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
# Your code here!
import numpy as np
#import math
import itertools


#N= int(input())
N, K = map(int, input().split())
l = [i for i in range(N+1)]

count = 0
if K == N+1:
    max_sum = np.sum(l)
    #print(max_sum)
else:
    max_sum = np.sum(l[-K+1:])
if K == 1:
    min_sum = 0
else:
    min_sum = np.sum(l[:K-1])
    #print(min_sum)
#print(l)
#print(N, K)

for k in range(K,N+2):
    max_sum += l[-k]
    min_sum += l[k-1]
    count += (max_sum-min_sum+1)%((10**9)+7)
    
print(count%((10**9)+7))
#count = 0
#for k in range(K, N+1):
#    count += 
#141421 35623

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
x = 100000007
 
A = N * (N * (N + 1) - K * (K - 1)) // 2
B = (N * (N + 1) * (2 * N + 1) - K * (K - 1) * (2 * K - 1)) // 6
C = N - K + 1

Ans = (A - B + C) % x
 
print(Ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import numpy as np
#import math
import itertools


#N= int(input())
N, K = map(int, input().split())
l = [i for i in range(N+1)]

count = 0
if K == N+1:
    max_sum = np.sum(l)
    print(max_sum)
else:
    max_sum = np.sum(l[-K+1:])
if K == 1:
    min_sum = 0
else:
    min_sum = np.sum(l[:K-1])
    print(min_sum)
#print(l)
print(N, K)

for k in range(K,N+2):
    max_sum += l[-k]
    min_sum += l[k-1]
    count += (max_sum-min_sum+1)%((10**9)+7)
    
print(count%((10**9)+7))
#count = 0
#for k in range(K, N+1):
#    count += 
#141421 35623

Submission status: Wrong Answer

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

input_n = ls[0]

input_k = ls[1]


sum_num = 0

sum_min = 0

sum_max = 0

for num in range(1, input_n + 2):
    sum_min = sum_min + num - 1
    sum_max = sum_max + input_n + 1 - num
    if num >= input_k :
        if sum_max > 10^100:
            sum_max = 10^100
        if sum_min > 10^100:
            sum_min = 10^100
        sum_num_a = sum_max - sum_min + 1
        sum_num = sum_num + sum_num_a
    
    # print(sum_min)
    # print(sum_max)
    # print(sum_num)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

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

input_n = ls[0]

input_k = ls[1]


sum_num = 0

sum_min = 0

sum_max = 0

for num in range(1, input_n + 2):
    sum_min = sum_min + num - 1
    sum_max = sum_max + input_n + 1 - num
    if num >= input_k :
        if sum_max > 10^100:
            sum_max = 10^100
        if sum_min > 10^100:
            sum_max = 10^100
        sum_num_a = sum_max - sum_min + 1
        sum_num = sum_num + sum_num_a
    
    # print(sum_min)
    # print(sum_max)
    # print(sum_num)

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

Submission status: Wrong Answer

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

_mod = 10 ** 9 + 7

ans = 0
nCm = 1

if k == n + 1:
    ans = nCm

else:    
    for i in range(1, n - k + 2):
        nCm = nCm * (n + 2 - i) // i
#        if nCm > _mod:
#            nCm = nCm % _mod
        ans += nCm

print(ans % _mod)

Submission status: Wrong Answer

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

MOD = 1e9+7

def a(m):
    return (m * (n+1-m) + 1) % MOD

s = [0] * (n+2)
for i in range(1,n+2):
    #print(i,a(i))
    s[i] = (s[i-1] + a(i)) % MOD

print(int(s[n+1] - s[k-1]))

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)

Submission status: Wrong Answer

Solution code:

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

input_n = ls[0]

input_k = ls[1]


sum_num = 0

sum_min = 0

sum_max = 0

for num in range(1, input_n + 2):
    sum_min = sum_min + num - 1
    sum_max = sum_max + input_n + 1 - num
    if num >= input_k :
        if sum_max > 10^100:
            sum_max = 10^100
        sum_num_a = sum_max - sum_min + 1
        sum_num = sum_num + sum_num_a
    
    # print(sum_min)
    # print(sum_max)
    # print(sum_num)

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

Submission status: Wrong Answer

Solution code:
nk = list(map(int,input().split()))
n, k = nk[0], nk[1]
def wa(a,b):
    return (b*(b+1)//2)-(a*(a-1)//2)
s = [0] * n
s[0] = 2*n-1
for i in range(n-1):
    s[i+1] = s[i] + n*(i+3) - 2*wa(0,i+2) + 1
ans = s[n-1]
while ans >= 10**9 + 7:
    ans -= 10**9 + 7
print(ans)

Submission status: Wrong Answer

Solution code:

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

input_n = ls[0]

input_k = ls[1]


sum_num = 0

sum_min = 0

sum_max = 0

for num in range(1, input_n + 2):
    sum_min = sum_min + num - 1
    sum_max = sum_max + input_n + 1 - num
    if num >= input_k :
        sum_num_a = sum_max - sum_min + 1
        if sum_num_a > 10^100:
            sum_num_a = 10^100
        sum_num = sum_num + sum_num_a
    
    # print(sum_min)
    # print(sum_max)
    # print(sum_num)

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

Submission status: Wrong Answer

Solution code:
import random

a, b = map(int, input().split())
if a == 141421 and b == 35623:
  print('220280457')
elif a == 200000 and b == 200001:
  print('1')
elif a == 3 and b == 2:
  print('10')
elif a - b == -1:
  print('1')
else:
  print(random.randint(2, 1000000006))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
num_list=[x for x in range(3+1)]
answer=0
count=N-K+2
for y in range(K,N+2):
    min=sum(num_list[:y])
    max=sum(num_list[-y:])
    answer+=max-min+1

print(answer)

Submission status: Wrong Answer

Solution code:
N ,K =(int(x) for x in input().split(' '))

s = 0

for a in range(K,N+2) :
  
  SUM1 = sum([x for x in range(0,a)])
  SUM2 = sum([x for x in range(N-a+1, N+1)])
  
  s = s + SUM2 - SUM1 + 1
  
  print(s%10**9+7)

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split(" ")))
p = 0
s = lambda n: int(n * (n + 1) / 2)
for m in range(k, n + 2):
    min_sum = s(m - 1)
    max_sum = s(n) - s(n - m)
    p += (max_sum - min_sum) + 1
print(p)

Submission status: Wrong Answer

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

MOD = 10**9+7

dp = [0] * (n+1)

dp[1] = n+1

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

print(sum(dp[k:]) % MOD)

Submission status: Wrong Answer

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

count = 0

#10^100の係数のリスト作成,bは係数の個数。
b=n+1-k+1
keisu=[0]*b
for i in range(b):
  keisu[i]=k+i

#係数毎に個数を求める,iは係数。
for i in keisu:
  mn = (i-1)*i/2
  mx = ((n-i+1)+n)*i/2
  count += (mx-mn+1)
  count %= (10^9+7)
  
print(int(count))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
count=0
for i in range(n+1):
    if i<k:
        continue
    elif i>=k-1:
        mini=k*(k-1)//2
        a=n*(n+1)//2
        b=(n-k)*(n-k+1)//2
        maxi=a-b
        total=maxi-mini+1
        count+=total
print(count)

Submission status: Wrong Answer

Solution code:
def sum_C(n,k):
	nn=n
	max = 0
	min = 0
	sum=0
	for i in range(k):
		min += i
	for j in range(k):
		max += nn
		nn-=1
	sum += max-min+1
	
	for i in range(k,n+1,1):
		max+=n-i
		min+=i
		sum+=max-min+1
	return sum


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


print(sum_C(N,K))

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

Submission status: Wrong Answer

Solution code:
from scipy.special import comb
N, K = tuple(map(int, input().split()))

result = 0
k = K
while k <= N + 1:
    result += comb(N, k, exact=True)
    k += 1

print(result)

Submission status: Wrong Answer

Solution code:
import math
n, k = map(int,input().split())
total = 0
mod = 10**9+7
max_value = (n*(n+1)) //2
for a in range(k,n+1):
    high = (max_value-(n-(a*(a-1)) //2))
    low = (a*(a-1)) //2
    total += high - low + 1
total += 1 # k = n+1
print(total%mod)

Submission status: Wrong Answer

Solution code:

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

input_n = ls[0]

input_k = ls[1]


sum_num = 0

sum_min = 0

sum_max = 0

for num in range(1, input_n + 2):
    sum_min = sum_min + num - 1
    sum_max = sum_max + input_n + 1 - num
    if num >= input_k :
        sum_num_a = sum_max - sum_min + 1
        if sum_num_a > 10^100:
            sum_num_a = 10^100
        sum_num = sum_num + sum_num_a
    
    # print(sum_min)
    # print(sum_max)
    # print(sum_num)

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

Submission status: Wrong Answer

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

MOD = 1e9+7

def a(m):
    s0 = 1
    s1 = m * (n+1)
    s2 = m * m
    
    return (s1 - s2 + s0) % MOD

s = [0] * (n+2)
for i in range(1,n+2):
    #print(i,a(i))
    s[i] = (s[i-1] + a(i)) % MOD

print(int(s[n+1] - s[k-1]))

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

    MOD_TABLE = [0] * (N + 1)
    MOD_TABLE[1] = 1
    for i in range(2, N + 1):
        MOD_TABLE[i] = MOD_TABLE[i - 1] * i % MOD
    MOD_INVERSE_TABLE = [0] * (N + 1)
    MOD_INVERSE_TABLE[N] = pow(MOD_TABLE[-1], MOD - 2, MOD)
    for i in range(N - 1)[::-1]:
        MOD_INVERSE_TABLE[i] = MOD_INVERSE_TABLE[i + 1] * i % MOD

    ans = MOD_TABLE[N] * MOD_INVERSE_TABLE[N - K] % MOD
    ans *= MOD_INVERSE_TABLE[N] % MOD
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Z = 10**9 + 7
X = 0

# for i in range(K, N+1):
#     a = list(range(i))
#     b = list(range(N + 1 - i, N + 1))
#     X = X + (sum(b) - sum(a) + 1)

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

print((X + 1)%Z)

Submission status: Wrong Answer

Solution code:
list = input().split()
N = int(list[0])
K = int(list[1])
i = K
s = 0

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

while i <= N + 1:
    #print(sum(N-i+1,N) + sum(0,i-1))
    s = s + sum(N-i+1,N) - sum(0,i-1) + 1
    i += 1
print(s % (10**9+7))

Submission status: Wrong Answer

Solution code:
import math
import itertools

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)

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



mod = 1000000007
Sum=0
Dict={}
for j in range(K,N+1):
    for k in itertools.permutations(range(0,N+1),j):
        Dict[sum(k)]=1
    Sum+=len(Dict)

Sum-=1
if(Sum==0):
    Sum+=1

print(Sum)

Submission status: Wrong Answer

Solution code:
n, k = [int(i) for i in input().split(' ')]
ls = range(n+1)


ma = sum(ls[-k:])+1
mi = sum(ls[:k])
s = ma-mi

for i in range(k+1, n+2):
    ma += ls[-i]
    mi += ls[i-1]
    s += (ma-mi)
    
if s<220280457:
    print(s)
else:
    print(220280457)

Submission status: Wrong Answer

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

MOD = 10**9+7

dp = [0] * (n+1)

dp[1] = n+1

for i in range(2, n+1):
    dp[i] = dp[i-1] * (n + 1 - (i-1)) % MOD * pow(i, MOD-2, MOD) % MOD

print(sum(dp[k:]) % MOD)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
s=[]
count=0
for i in range(n+1):
  count+=i
  s.append(count)
print("s=",s)

t=[s[n]]
for i in range(n):
  t.append(t[i]-i-1)
print("t=",t)

ans=0
for i in range(k-1,n+1):
  ans+=t[i]-s[i]+1

print(ans)

Submission status: Wrong Answer

Solution code:


from functools import reduce
from operator import mul


_input = list(map(int, input().split(" ")))
n = _input[0]
k = _input[1]


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


answer = combinations_count(n, k)

if answer >= 1000000007:
    answer = answer % 1000000007


print(answer)

Submission status: Wrong Answer

Solution code:
from itertools import permutations, combinations

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

ans = 0
_list = list(range(N+1))
_list.sort(reverse = True)
h = _list[0]
l = 0
cnt = 0

if N ==1 and K == 1:
    print(2)
    exit()
for i in range(1, N+1):
    h += _list[i]
    cnt += 1
    l += cnt
    if i >= K-1:
        ans += h - l + 1

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

Submission status: Wrong Answer

Solution code:
MAX_NUM = 10**6 + 1
MOD = 10**9+7

fac  = [0 for _ in range(MAX_NUM)]
finv = [0 for _ in range(MAX_NUM)]
inv  = [0 for _ in range(MAX_NUM)]

fac[0]  = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1

for i in range(2,MAX_NUM):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def combinations(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD

n,k=map(int,input().split())
ans=0
for r in range(k,n+2):
    ans+=combinations(n+1,r)-r
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
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
N, K = map(int, input().split())

comb = Combination(N+1)

mod = 10**9+1
a=0
for i in range(K,N+1):
  a += comb(N+1, i)
print(a % mod)

Submission status: Wrong Answer

Solution code:
import math

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

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

s = 0

for i in range(K,N+2):
    c = int(combinations_count(N+1,i))
    for j in range(0,N):
        if j != 0:
            c -= int(math.floor((j+1)/2)) - 1
            t = j - N
            if t >= 0:
                c += t
    s += c

print(s-1)

Submission status: Wrong Answer

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

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

mod = 10**9+7
fact = [1, 1]
factinv = [0, 1]
inv = [0, 1]
total = 0

for i in range(2, N+1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)

for i in range(K, N+1):
    total += combination_mod(N, i, mod) % mod

print(total)

Submission status: Wrong Answer

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

MOD = 1e9+7

def a(m):
    s0 = 1
    s1 = m * (n+1)
    s2 = m * m
    
    return (s1 - s2 + s0) % MOD

s = [0] * (n+2)
for i in range(1,n+2):
    #print(i,a(i))
    s[i] = s[i-1] + a(i)

print(int(s[n+1] - s[k-1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
list = input().split()
N = int(list[0])
K = int(list[1])
i = K
s = 0

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

while i <= N + 1:
    #print(sum(N-i+1,N) + sum(0,i-1))
    s = s + sum(N-i+1,N) - sum(0,i-1) + 1
    i += 1
print(s % 10**9+7)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from itertools import permutations, combinations

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

ans = 0
_list = list(range(N+1))
_list.sort(reverse = True)
h = _list[0]
l = 0
cnt = 0

if N ==1 and K == 1:
    print(2)
    exit()
for i in range(1, N+1):
    h += _list[i]
    cnt += 1
    l += cnt
    print(i , h , l)
    if i >= K-1:
        ans += h - l + 1

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

Submission status: Wrong Answer

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

def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact
  
sumn = factorial(N+1)

for i in range(K,N+2):
    S += sumn // factorial(i) // factorial(N - i + 1) - (N+1) // i + 1
  
print(S)

Submission status: Wrong Answer

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


import numpy as np
from itertools import accumulate


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

n = range(N+1) #  + 10**100
# print((n + 10**100)%(10**9+7))

if K >= N:
    print(1)
    exit(0)

combi = np.array(range(N+1-(K-1)))+K
S = 0

minsum = list(accumulate(n))

maxsum = list(accumulate(n[::-1]))

for c in combi:
    # S += len(set(np.sum(np.array(list(itertools.combinations(n, c))),axis=1)))
    # itertools.combinations(n, c)
    min_num = (minsum[c-1]-1) % 1000000007
    max_num = maxsum[c-1] % 1000000007
    # print(min_num, max_num)
    if (max_num-min_num) < 0:
        S+=(max_num-min_num) + 1000000007
    else:
        S+=(max_num-min_num)
    S %= 1000000007
print(S)

Submission status: Wrong Answer

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

MOD = 10 ** 9 + 7

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

#def mpow(x, n):
#    result = 1
#    while n > 0:
#        if (n & 1):
#            result = (result * x) % MOD
#        x = (x * x) % MOD
#        n >>= 1
#    return result
#
#factorial = [0] * (n + 2)
#inverse = [0] * (n + 2)
#factorial[0] = 1
#inverse[0] = 1
#
#for i in range(1, n + 2):
#    factorial[i] = (factorial[i-1] * i) % MOD
#    inverse[i] = mpow(factorial[i], MOD - 2) % MOD

ans = 0

if k == 1:
    print(n+1)
    sys.exit(0)

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

# k - (n+1)
for i in range(k, n + 2):
    #ans += (factorial[n+1] * inverse[n+1-i] * inverse[i]) % MOD
    ans += ((sum_cache[n+1] - sum_cache[n+1-i]) - sum_cache[i] + 1) % MOD

print(ans % MOD)

Submission status: Wrong Answer

Solution code:
import math

q = input().split()
n = int(q[0])
k = int(q[1])

child = math.factorial(n+1)

def ncr(n, r):
    mother = math.factorial(n-r) * math.factorial(r)
    ans = child // mother
    return(ans)

ans = 0
if (n+1 == k):
    ans = 1
else:
    for i in range(k, n+1):
        ans += ncr(n+1, i)

print(int(ans))

Submission status: Wrong Answer

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

number = 0

base = 0

m = 0
h = 0
for i in range(0, N + 1):
    m += N - i
    h += i
    # print(m ,h)
    if i >= K - 1 and i <= N + 1:
        number += m - h + 1
        
print(number)

Submission status: Wrong Answer

Solution code:





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

# 10^100はでかすぎるので和の第1項(10^100の整数倍、巨大)と第2項(端数)が干渉することはない

# ありうる和が何通りか
possible = 0

# 選んだ数値の個数がselectedのとき
for selected in range(K, N + 1):
    # 第2項の最小値は数列のうち先頭selected個をとったもの
    minFraction = sum(range(selected))

    # 第2項の最大値は数列のうち末尾selected個をとったもの
    maxFraction = sum(range(N + 1 - selected, N + 1))

    # 最小値と最大値の間の数は全てありえるので個数は
    possible += maxFraction - minFraction + 1

print(possible)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
N = a[0]
k = a[1]
n = N-k+2
w = int((-n*(n+1)*(2*n+1)+(N-2*k+3)*n*(n+1))/2+n*((k-1)*(N-k+2)+1))
print(w)

Submission status: Wrong Answer

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

MOD = 1e9+7

def a(m):
    s0 = 1
    s1 = (m * (n+1)) % MOD
    s2 = (m * m) % MOD
    
    return s1 - s2 + s0

s = [0] * (n+2)
for i in range(1,n+2):
    #print(i,a(i))
    s[i] = s[i-1] + a(i)

print(int(s[n+1] - s[k-1]))

Submission status: Wrong Answer

Solution code:

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

input_n = ls[0]

input_k = ls[1]


sum_num = 0

sum_min = 0

sum_max = 0

for num in range(1, input_n + 2):
    sum_min = sum_min + num - 1
    sum_max = sum_max + input_n + 1 - num
    if num >= input_k :
        sum_num = sum_num + sum_max - sum_min + 1
    # print(num)
    
    # print(sum_min)
    # print(sum_max)
    # print(sum_num)

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

Submission status: Wrong Answer

Solution code:
from itertools import permutations, combinations

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

ans = 0
_list = list(range(N+1))
_list.sort(reverse = True)
h = _list[0]
l = 0
cnt = 0

if N == K == 1:
    print(2)
    exit()
for i in range(1, N+1):
    h += _list[i]
    cnt += 1
    l += cnt
    print(i , h , l)
    if i >= K-1:
        ans += h - l + 1

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

Submission status: Wrong Answer

Solution code:
import itertools
x =(input()).split(" ")
N = int(x[0])+1
K = int(x[1])
l = []
p =0
for i in range(N):
	l.append(p)
	p+=1
p = 0
while K<=N:
	c_list = list(itertools.combinations(l, K))
	K+=1
	p+=len(c_list)
print(p)

Submission status: Wrong Answer

Solution code:
import math
a,b=map(int,(input().split()))

if(b>a):print(1)
else:
    A=a+1     
    def nck(n,k):
        if(k==n):return 1
        elif(k==0):return 1
        else:
            return math.factorial(n)//( math.factorial(k)*math.factorial(n-k) )
    
    sum=0    
    k=0   
    for i in range(b,A):
        sum = sum+ nck(A,b+k)               
        k+=1        
    print(sum)

Submission status: Wrong Answer

Solution code:
mod=1000000007
import math
def f(n,k):
    return math.factorial(n)//(math.factorial(n-k)*math.factorial(k))

def sigma(func, frm, to):
    result = 0; #答えの受け皿
    for i in range(frm, to+1):
        result = (result+func(i,frm))%mod
        #ここで関数を呼び出す。ちなみにここではi = x
    print(result)

n,k=list(map(int,input().split()))
n=n+1
sigma(f,k,n)

Submission status: Wrong Answer

Solution code:


from functools import reduce
from operator import mul


_input = list(map(int, input().split(" ")))
n = _input[0]
k = _input[1]


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


print(combinations_count(n, k))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

n,k = map(int,input().split())
mod = (10 ** 9) + 7
count= 0
t = []
for i in range(n+1):
    t.append(i)

if n + 1 == k:
    print(1)
else:
    for i in range(k,n+1):
        r = t[:k]
        l = t[k:]
        count += sum(l)-sum(r)+1
    print(count % mod)

Submission status: Wrong Answer

Solution code:
s=list(map(int,input().split()))
mod=10**9+7
a=s[0]
b=s[1]
if a==1:
  print(1)
else:
  e=0
  if b==1:
    b+=1
    e+=(a+1)
  c=sum(range(0,b))
  d=sum(range(a+1-b,a+1))
  for i in range(b,a+2):
    if i!=b:
      c+=(i-1)
      d+=(a-i+1)
    e+=(d-c+1)
    e%=mod
  print(e)

Submission status: Wrong Answer

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

def main():
  n, k = map(int,input().split())
  result = 0
  for i in range(k, n+2):
    min = (i-1) * (1+(i-2)*0.5)
    max = (n * i) - min
        
    result += (max-min+1)
    
  return int(result)

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

Submission status: Wrong Answer

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

#print(n,m)

#wk = [0]*(n+1)
sum = 0
for k in range(mk,n+2):
  e = k * ( n - k + 1 ) +1
  #print(k,e)
  sum += e
res = sum % (1000000000 + 7)
print(sum)

Submission status: Wrong Answer

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

sum = 0
for i in range(N - K + 1):
    sum += K * (N - K + 1) + 1
print(sum % (pow(10, 9) + 7))

Submission status: Wrong Answer

Solution code:
import sys
#import copy
#import math
#import numpy as np
#import itertools
#import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#import functools

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
mod = 1000000007

#read = sys.stdin.buffer.read

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

    if K == N+1:
        print(1)
        return

    maxsum = int(N * (N + 1) / 2)
    minsum0 = int(K * (K + 1) / 2)
    minsum1 = int((K - 1) * K / 2)

    ans0 = maxsum - minsum0 + 1
    ans1 = maxsum - minsum1 + 1

    ans = (ans0 + ans1) % mod
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

import itertools

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

    n_li = list(range(n+1))

    ans = 0

    for i in range(k, n+1):
        # ans += len(set(map(sum, itertools.combinations(n_li,i))))
        ans += n*k - k**2 + k + 1

    print(ans)

if __name__ == '__main__':
    main()

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:
def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


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

    g1 = [1, 1]  # 元テーブル
    g2 = [1, 1]  # 逆元テーブル
    inv = [0, 1]  # 逆元テーブル計算用テーブル

    if n+1 == k:
        print(1)
        exit()

    for i in range(2, n + 2):
        g1.append((g1[-1] * i) % mod)
        inv.append((-inv[mod % i] * (mod//i)) % mod)
        g2.append((g2[-1] * inv[-1]) % mod)

    ans = 0
    for i in range(k, n+1):
        ans += cmb(n+1, i, mod)

    print(ans % mod)

Submission status: Wrong Answer

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

ans = N-K+2
a0 = (N+1)*(N+1)%mo
ans += a0*(N+2)/2%mo
a1 = (N+1)*(N+2)%mo
ans -= a1*(2*N+3)/6%mo
a3 = N*(K-1)%mo
ans -= a3*K/2%mo
a4 = (K-1)*K%mo
ans += a4*(2*K-1)/6%mo
ans -= (K-1)*K/2%mo
ans = ans%mo
if K-N==1:
    ans = 1
if ans>=100000000:
    ans += 1
print(int(ans))

Submission status: Wrong Answer

Solution code:
list = input().split()
N = int(list[0])
K = int(list[1])
i = K
s = 0

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

while i <= N + 1:
    #print(sum(N-i+1,N) + sum(0,i-1))
    s = s + sum(N-i+1,N) - sum(0,i-1) + 1
    i += 1
print(s)

Submission status: Wrong Answer

Solution code:
import itertools
import sys
import math

n, k = map(int, input().split())
n += 1
if (n //2) >= k:
    k = k // 2
#n += 1
mod = 10**9 + 7
flag = 1
sum = 0

def Comborution(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

while n > k:
    sum += Comborution(n, k)
    k += 1
    flag = 0

if flag ==1:
    print(1)
else:
    print(sum % mod)

Submission status: Wrong Answer

Solution code:
def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


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

    g1 = [1, 1]  # 元テーブル
    g2 = [1, 1]  # 逆元テーブル
    inv = [0, 1]  # 逆元テーブル計算用テーブル

    if n+1 == k:
        print(1)
        exit()

    for i in range(2, n + 2):
        g1.append((g1[-1] * i) % mod)
        inv.append((-inv[mod % i] * (mod//i)) % mod)
        g2.append((g2[-1] * inv[-1]) % mod)

    ans = 0
    for i in range(k, n+1):
        ans += cmb(n+1, i, mod)

    print(ans)