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:
#from scipy.special import comb

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

if K>=N:
  print(1)
else:

  ans = 0
  bunsi = 1
  l_bunsi = []
  bunbo = 1
  l_bunbo = []
  for i in reversed(range(N+2-K, N+2)):
    bunsi *= i
  l_bunsi = i
  for i in range(1,K+1):
    bunbo *= i
  l_bunbo = i

  ans = bunsi//bunbo

  for i in range(K+1, N+1):
    bunsi *= l_bunsi-1
    bunbo *= l_bunbo+1
    ans += bunsi//bunbo
  print(ans%(10**9+7))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
mod=pow(10,9)+7
numbers=[a for a in range(0,N+1)]
if N+1==K:
    print(1)
else:
    answer=0
    for a in range(K,N+1):
        kotae=(sum(numbers[N-a:])-sum(numbers[:a])+1)%mod
        answer+=kotae
    print(answer%mod)

Submission status: Wrong Answer

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

from sys import stdin
import itertools


def main():
    N, K = map(int, stdin.readline().split())
    a = list(range(0, N + 1))
    pattern = []
    for i in range(K, N + 1):
        pattern.extend(list(itertools.combinations(a, i)))
    b = []
    for p in pattern:
        val = (10 ^ 100) * len(p) + sum(p)
        b.append(val % (10 ^ 9 + 7))

    set(b)
    print(len(b))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
ans=0


min=0
max=0
for i in range(a[1]):
    min +=i
    max +=a[0]-i
    
    minx=i-1
    maxx=a[0]-i-1
    ans=max-min+1
for i in range(a[1]+1,a[0]+2):
    minx+=1
    min += minx
    maxx -=1
    max +=maxx
    if min<=max:
        ans=ans+max-min+1
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import itertools
import time
n, k = list(map(int, input().split()))

result = 0
for _k in range(k, n + 2):
    # print('選ぶ数', _k)
    min_value = ((_k-1)+1)*(_k-1)/2
    max_value = (n + n - (_k-1)) * (_k)/2
    # print(min_value, max_value)
    result += max_value - min_value + 1
print(result)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    a,b= map(int,input().split())
    maxnum =0
    minnum =0
    diff = 10**9 +7

    for i in range(0,b):
        minnum+=i
    for i in range(0,b):
        maxnum+=(a-i)
    ans = maxnum-minnum
    ans = int(ans*(ans+1)/2)
    ans = ans %diff
    if ans ==0:
        ans =1

    print(ans)

Submission status: Wrong Answer

Solution code:
# from scipy.special import comb
# n, k = map(int, input().split())
# ans = 0
# for i in range(k, n+2):
#  ans += comb(n+1, i, exact=True) - comb(n+1-i, i, exact=True)
# print(ans%1000000007)

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())
ans = 0
for i in range(k, n+2):
 ans += cmb(n+1, i, p) - cmb(n+1-i, i, p)
print(ans%p)

Submission status: Wrong Answer

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


lst = [0]*(N+2)
mi = [0]*(N+2)
ma = [0]*(N+2)
ma[1] = N
for i in range(2,N+2):
    mi[i] = mi[i-1]+i-1
    ma[i] = ma[i-1]+N+1-i
    lst[i] = (ma[i]-mi[i]+1)

print(sum(lst[K::])%mod)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#from scipy.special import comb

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

ans = 0
bunsi = 1
l_bunsi = []
bunbo = 1
l_bunbo = []
for i in reversed(range(N+2-K, N+2)):
  bunsi *= i
l_bunsi = i
for i in range(1,K+1):
  bunbo *= i
l_bunbo = i

ans = bunsi//bunbo

for i in range(K+1, N+1):
  bunsi *= l_bunsi-1
  bunbo *= l_bunbo+1
  ans += bunsi//bunbo
print(ans)

Submission status: Wrong Answer

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

s = n+1-k
sm = 0
for i in range(s+1):
  sm += ((i+1)*(s+1-i))%1000000007
print(sm)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
#from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [LI()for i in range(n)]
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()
    
n,k=MI()
def standard(a,b):
    return b*(a-b+1)+1
def ansum(a,b):
    ansum=0
    for i in range(b,a):
        ansum+=standard(a,i)
    return ansum
#print(ansum(4,2))
anslarge=n+2
if k==1:
    ans=ansum(n,2)+n+1+anslarge
elif k==n+1:
    ans=1
elif k==n:
    ans=n+2
else:
    ans=ansum(n,k)+anslarge
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import itertools
n, k = map(int, input().split())
data = list(x for x in range(n+1))
ans = 0
if n <= k :
    ans +=1
else:
    for i in range(k, n+1):
        j = list(itertools.combinations(data, i))
        ans += len(j)

print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    a,b= map(int,input().split())
    maxnum =0
    minnum =0

    for i in range(0,b):
        minnum+=i
    for i in range(0,b):
        maxnum+=(a-i)
    ans = maxnum-minnum
    ans = int(ans*(ans+1)/2)

    print(ans)

Submission status: Wrong Answer

Solution code:

N, K = map(int, input().split())
MOD = 10**9 + 7
nac = [0] * (N + 2)
ninv = [0] * (N + 2)
inv = [0] * (N + 2)
nac[0],nac[1] = 1,1
inv[0] = 1
ninv[0],ninv[1] = 1,1

for i in range(2, N + 2):
    nac.append(nac[i-1] * i % MOD)
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD
    ninv[i] = ninv[i - 1] * inv[i] % MOD

ret = 0
for i in range(K,N+2):
    ret += nac[N+1] * (ninv[i] * ninv[N+1-i] % MOD) % MOD
print(ret)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
N = N+1
a = N - K
ans = 0

MM = 10**9 +7

for i in range(K,K+a):
  start = int( ( (i)*(i-1)/2 ) % MM )
  fin = int( ( (N+(N-1)-i)*(i)/2+1 ) % MM )
  ans = int( ( ans + (fin - start) ) % MM )
  print(fin,start)
if N == K:
  ans = ans + 1
print(ans)

Submission status: Wrong Answer

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

mod = 10 ** 9 + 7

def comb(n, k):
    res = 1
    for i in range(n - k + 1, n + 1):
        res = res * i % mod
    for i in range(1, k + 1):
        res = res * pow(i, mod - 2, mod) % mod
    return res

calc = comb(n + 1, k)
ans = 0
ans += calc

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

if k == n + 1:
    ans = 1
    
print(ans % mod)

Submission status: Wrong Answer

Solution code:

N, K = map(int, input().split())
MOD = 10**9 + 7
nac = [0] * (N + 1)
ninv = [0] * (N + 1)
inv = [0] * (N + 1)
nac[0],nac[1] = 1,1
inv[0] = 1
ninv[0],ninv[1] = 1,1

for i in range(2, N + 1):
    nac.append(nac[i-1] * i % MOD)
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD
    ninv[i] = ninv[i - 1] * inv[i] % MOD

ret = 0
for i in range(K,N+1):
    ret += nac[N] * (ninv[i] * ninv[N-i] % MOD) % MOD
print(ret)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
m = 1000000007
ans = []
for i in range(1,n+2):
    ans_min = (0+(i-1))*i*0.5
    ans_max = ((n+1-i)+n)*i*0.5
    ans.append(ans_max-ans_min+1)

ans_wa = [ans[0]]
for i in range(1,n+1):
    ans_wa.append(ans_wa[i-1]+ans[i])

if (k>=2):
    print(int((ans_wa[n]-ans_wa[k-2])%m))
else:
    print(int(ans_wa[n]))

Submission status: Wrong Answer

Solution code:
#D
N,K=map(int,input().split())
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if N>K:
    ans=0
    for i in range(K,N+1):
        ans+=combinations_count(N+1, i)
    print(ans)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
N , K =map(int,input().split())
MOD=10**9+7
ans=0
if N<=K:
    print(1)
else:
    tmp_low = sum(range(K))
    tmp_high = sum(range(N-K+1,N+1))
    r=tmp_high-tmp_low+1
    ans+=r
    ans%=MOD
    for sel in range(K+1,N+2):
        tmp_low += sel-1
        tmp_high += N-sel+1
        r= tmp_high-tmp_low+1
        ans+=r
        ans%=MOD
    print(ans%MOD)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
lis = [n+1]
l = n+1
mod = 10**9+7
for i in range(2, n+2):
    new_l = (l + n -2*i + 2) %mod
    lis.append(new_l)
    l = new_l
s = 0
for i in lis:
    s += i
    s %= mod
s_2 = 0
for i in range(k-1):
    s_2 += lis[i]
    s_2 %= mod
print(s- s_2)

Submission status: Wrong Answer

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

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

ans = 0
while n+1 - k >= 0:
    cnt = combinations_count(n+1, k)
    ans += cnt
    k += 1
ans %= 10**9 + 7
print(str(ans))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
#D
N,K=map(int,input().split())
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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

a, b = map(int, input().split())

sum = 0
for i in range(b, a+1):
  sum += combinations_count(a+1, i)
  
print(sum)

Submission status: Wrong Answer

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

m = 10 ** 9 + 7

def foo(x):
  r=1
  for i in range(1,x):
    r *= i
    r %= m
  return r

def in_foo(x):
  return pow( foo(x), m-2, m)

def bn(x, y):
  r = foo(x)
  r *= in_foo(y)
  r *= in_foo(x-y)
  return r % m

ans = 0
for i in range(K, N+2):
  ans += bn(N+1, i)
  ans %= m

print(ans)

Submission status: Wrong Answer

Solution code:
import math


def combinations_count(n, r):
    try:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    except ValueError:
        return 0


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

Submission status: Wrong Answer

Solution code:
import itertools

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

a = 0
for i in range((n+1)-(k-1)):
    tmp = set()
    for group in itertools.combinations(arr, i+k):
        tmp.add(sum(group))
    print(tmp)
    a += len(tmp)

print(a)

Submission status: Wrong Answer

Solution code:
import math


def combinations_count(n, r):
    try:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    except ValueError:
        return 0


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
m = 1000000007
ans = []
for i in range(1,n+2):
    ans_min = (0+(i-1))*i*0.5
    ans_max = ((n+1-i)+n)*i*0.5
    ans.append(ans_max-ans_min+1)
ans_wa = [ans[0]]
for i in range(1,n+1):
    ans_wa.append(ans_wa[i-1]+ans[i])
print(int((ans_wa[n]-ans_wa[k-2])%m))

Submission status: Wrong Answer

Solution code:
from itertools import combinations as cc
n,k = map(int,input().split())
nos = list(range(n+1))
ctr = 0
M = 10**9 + 7
for i in range(k,n+1):
  t = list(cc(nos,k))
  t = [sum(i) for i in t]
  l = len(set(t))
  ctr += l%M
print(ctr)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,k=n1()

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

Submission status: Wrong Answer

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

p = 10 ** 9 + 7
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
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)

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

result = 0
for j in range(k, n+2):
    result += cmb(n,j,p)

print(result)

Submission status: Wrong Answer

Solution code:
i,j= list(map(int, input().split()))
n=i+1
nCr = j
sum=0
from scipy.special import comb

for k in range(j,n+1):
    sum+=comb(n, k, exact=True)
print(sum%((10**9)+7))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
def sum2(nums):
    res = 0
    for num in nums:
        res += num
        res %= 1000000007
    return res
sum2(1 + l * (n + 1 - l) for l in range(k, n + 2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
i,j= list(map(int, input().split()))
n=i+1
nCr = j
sum=0
print(nCr)
for r in range(n):
    nCr_1 = nCr * (n - r) // (r + 1)
    nCr = nCr_1
    sum+=nCr_1
print(sum%(10**9+7))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
N = N+1
a = N - K
ans = 0

MM = 10**9 +7

for i in range(K,K+a):
  start = int( ( (K)*(K-1)/2 ) % MM )
  fin = int( ( (K)*(N+N-K)/2 ) % MM )
  ans = int( ( ans + (fin - start) ) % MM )
  
if N == K:
  ans = 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
N=10**100
n,k=map(int,input().split())
li=[]
for i in range(n+2):
    li.append(i)
counter=0
for i in itertools.combinations(li,k):
    counter+=1
print(counter)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, input().split())
lst = list(range(N + 1))

MOD = 10 ** 9 + 7

small = sum(lst[:K-1])
big = sum(lst[-(K-1):])

ans = 0
for i in range(K, N + 2):
    small += lst[i-1]
    big += lst[-i]

    ans += big - small + 1
    ans %= MOD

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    

def cmb(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


n,k=map(int,input().split())
a=cmb(n+1,k)

b=int(a)

for i in range(k,n+2):
	a=a//i
	b+=a


print(int(b)%(10**9+7))

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

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

def num_sum(i):
  return ((n+(n-i+1))*i//2)-((i-1)*i//2)+1

ans=0
for i in range(k,n+2):
  ans+=num_sum(i)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

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

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


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


def make_table2(n, mod=10 ** 9 + 7):
    # 元テーブル
    g1 = [0] * (n + 1)
    g1[0] = 1
    g1[1] = 1
    tmp = 1

    for i in range(2, n + 1):
        tmp = tmp * i % mod
        g1[i] = tmp

    # 逆元テーブル
    g2 = [0] * (n + 1)
    g2[-1] = pow(g1[-1], mod - 2, mod)
    tmp = g2[-1]

    for i in range(n - 1, -1, -1):
        tmp = tmp * (i + 1) % mod
        g2[i] = tmp

    return g1, g2


g1, g2 = make_table2(N + 1)
answer = 0
for i in range(K, N + 1):
    answer = (answer + cmb(N + 1, i, mod)) % mod

print(answer)

Submission status: Wrong Answer

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
import collections

N, K = map(int, input().split())
N_list = [i for i in range(0, N+1)]
count = 0

for k in range(K, N+2):
  tmp = []
  tmp = [sum(pair) for pair in itertools.combinations(N_list, k)]
  count += len(collections.Counter(tmp))
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import collections

N, K = map(int, input().split())
N_list = [i for i in range(0, N+1)]
count = 0

for k in range(K, N+2):
  tmp = []
  for pair in itertools.combinations(N_list, k):
    tmp.append(sum(pair))
  count += len(collections.Counter(tmp))
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n,K = list(map(int,input().split()))

mod = 10**9 + 7
M = 10**100%mod 

ans = set()
for k in range(K,n+2):
  for i in itertools.combinations(range(n+1),k):
    ans.add(sum([M+a%mod for a in i]))

print(len(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(n for n in range(N+1))
comb = set()
for i in range(1<<N+1):
  goukei = 0
  cnt = 0
  for j in range(N+1):
    if (i>>j)&1 == 1:
      goukei += A[j]
      cnt += 1
  comb.add((cnt,goukei))
ans = 0
for c in comb:
  if c[0]>=K:
    ans += 1
print(ans%((10**9)+7))

Submission status: Time Limit Exceeded

Solution code:
import itertools

N, K = map(int, input().split())
mod = 10**9 + 7
X = 10**100
series_list = [i for i in range(N+1)]

sum_list = []
for i in range(K, N+2):
    for v in itertools.combinations(series_list, i):
        temp_sum = (sum(v) + i * X) % mod
        if temp_sum in sum_list:
            continue
        else:
            sum_list.append(temp_sum)

print(len(sum_list))

Submission status: Time Limit Exceeded

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

A=[i for i in range(N+1)]
wa=0
N=N+1
for i in range(K,N+1):
    mi=sum(A[0:i])
    ma=sum(A[N-i:N])


    wa=ma-mi+1+wa



print(wa)

Submission status: Time Limit Exceeded

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

for i in range(k,n+2):
    min = sum(a[:i])
    max = sum(b[:i])
    ele = max - min +1
    ans += ele

print(ans)

Submission status: Time Limit Exceeded

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

cnt = 0

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

def choose(select):
    wa = []
    ans = 0
    for combi in combinations(range(n+1), select):
        tmp_wa = 0
        for i in range(select):
            tmp_wa += combi[i]
        if tmp_wa in wa:
            continue
        else:
            wa.append(tmp_wa)
            ans += 1
    
    return ans
            

res = 0

for i in range(k, n+2):
    res += choose(i) % (pow(10, 9) + 7)

print(res)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=[]
for i in range(n+1):
    a.append(i)
d=0
for i in range(k,n+2):
    b=sum(a[:i])
    c=sum(a[-i:])
    d+=(c-b+1)
print(d)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=[]
for i in range(0,n+1):
    a.append(10**20+i)
b=set()
for i in range(2**(n+1)):
    c=0
    d=0
    for j in range(n+1):
        if ((i>>j) & 1):
            c+=a[j]
            d+=1
    if d>=k:
        b.add(c)
print(len(b)%(10**9+7))

Submission status: Time Limit Exceeded

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

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

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

res = 0
for cLen in range(k, n + 2):
	small = sum(A[:cLen])
	large = sum(A[-cLen:])
	res += large - small + 1

print res

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
line=input()
n,k=map(int,line.split())
s=list(range(n+1))
sums=0
while k!=(n+2):
     mini=sum(list(s[0:k]))
     maxi=sum(list(s[(-k):]))
     sums+=(maxi-mini+1)
     sums=sums%((10**9)+7)
     k+=1
#jojo=(sums%)
print(sums)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
 
line=input()
n,k=map(int,line.split())
s=set(list(range(n+1)))
sums=list()
while k!=(n+2):
     koko=list()
     sub=list(itertools.combinations(s,k))
     #print(sub)
     for val in sub:
          soso=0
          for i in val:
               soso=(soso%((10**9)+7))+((i+0.2424)%((10**9)+7))
               #soso=(soso%((10**9)+7))
          if soso not in sums:
               sums.append(soso)
               #soso=(soso%((10**9)+7))
          
               
          
     
     
     
     k+=1
#jojo=(%((10**9)+7))
print((len(sums)))

Submission status: Time Limit Exceeded

Solution code:
import itertools

line=input()
n,k=map(int,line.split())
s=set(list(range(n+1)))
sums=list()
while k!=(n+2):
     koko=list()
     sub=list(itertools.combinations(s,k))
     #print(sub)
     for val in sub:
          soso=0
          for i in val:
               soso=(soso%((10**9)+7))+((i+(10**100))%((10**9)+7))
               #soso=(soso%((10**9)+7))
          if soso not in sums:
               sums.append(soso)
               #soso=(soso%((10**9)+7))
          
               
          
     
     
     
     k+=1
#jojo=(%((10**9)+7))
print((len(sums)))

Submission status: Time Limit Exceeded

Solution code:
import itertools

line=input()
n,k=map(int,line.split())
s=set(list(range(n+1)))
sums=list()
while k!=(n+2):
     koko=list()
     sub=list(itertools.combinations(s,k))
     #print(sub)
     for val in sub:
          soso=0
          for i in val:
               soso+=(i+(10**100))
               soso=(soso%((10**9)+7))
          if soso not in sums:
               #soso=(soso%((10**9)+7))
               sums.append(soso)
          
               
          
     
     
     
     k+=1
#jojo=(%((10**9)+7))
print((len(sums)))

Submission status: Time Limit Exceeded

Solution code:
import itertools

line=input()
n,k=map(int,line.split())
s=set(list(range(n+1)))
sums=list()
while k!=(n+2):
     koko=list()
     sub=list(itertools.combinations(s,k))
     #print(sub)
     for val in sub:
          soso=0
          for i in val:
               soso+=(i+(10**100))
          if soso not in sums:
               sums.append(soso)
          
               
          
     
     
     
     k+=1
print(len(sums))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import defaultdict
mod = (10**9)+7

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

total=0
for k in range(K,N+2):
  d = defaultdict(int)
  for v in itertools.combinations(a,k):
    if d[sum(list(v))]==0:
      d[sum(list(v))] = 1
  total+=sum(d.values())

result=total % mod 
print(result)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

total = 0
for i in range(K, N+2):
    sum_list = []
    for l in list(itertools.combinations(range(N+1), i)):
        sum_list.append(sum(l))
    total += len(set(sum_list))
    # print(total)
    # print("~~~")

print(total)

Submission status: Time Limit Exceeded

Solution code:
N,K=list(map(int,input().split()))
src=[n for n in range(N+1)]
ans=0
for k in range(K,N+2):
  M=sum(src[-k:])
  m=sum(src[0:k])
  ans+=M-m+1

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
mod = 10**9 + 7

n,k = map(int,input().split())
cnt = 0
for i in range(k, n + 2):
    a = set()
    for v in combinations(range(n+1), i):
        a.add(sum(v)%mod)
    cnt += len(a)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

def cmb(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


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

    num = 10*100
    nums = [num + i for i in range(0, n+1)]

    # sums = []
    total = 0
    for i in range(k, n+2):
        _min = sum(nums[:i])
        _max = sum(nums[-i:])

        total += _max - _min + 1

    print(total)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
num_list=[x for x in range(N+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%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

    num = 10*100
    nums = [num + i for i in range(0, n+1)]

    sums = []
    for i in range(k, n+2):
        for v in itertools.combinations(nums, i):
            sums.append(v)

    totals = []
    for s in sums:
        totals.append(sum(s))

    totals = set(totals)
    print(len(totals))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

num = 10*100
nums = [num + i for i in range(0, n+1)]

sums = []
for i in range(k, n+2):
    for v in itertools.combinations(nums, i):
        sums.append(v)

totals = []
for s in sums:
    totals.append(sum(s))

totals = set(totals)
print(len(totals))