Problem p02990 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10000)

nCr = {}
def combination(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = combination(n-1,r) + combination(n-1,r-1)
    return nCr[(n,r)]

N, K = map(int, input().split())
for i in range(1, K+1):
	if i <= N-K+1:
		A = combination(N-K+1, i)
		P = combination(K-1, i-1)
		B = A * P
		print(B % (10**9+7))
	else:
		print(0)

Buggy submission (verdict: Runtime Error):
nCr = {}
def combination(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = combination(n-1,r) + combination(n-1,r-1)
    return nCr[(n,r)]

N, K = map(int, input().split())
for i in range(1, K+1):
	if i <= N-K+1:
		A = combination(N-K+1, i)
		P = combination(K-1, i-1)
		B = A * P
		print(B % (10**9+7))
	else:
		print(0)

Buggy submission (verdict: Runtime Error):
nCr = {}
def combination(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = combination(n-1,r) + combination(n-1,r-1)
    return nCr[(n,r)]

N, K = map(int, input().split())
for i in range(1, K+1):
	if i <= N-K+1:
		A = combination(N-K+1, i)
		P = combination(K-1, i-1)
		B = A * P
		print(B % (10**9+7))
	else:
		print(0)

Buggy submission (verdict: Runtime Error):
nCr = {}
def combination(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

N, K = map(int, input().split())
for i in range(1, K+1):
	if i <= N-K+1:
		A = combination(N-K+1, i)
		P = combination(K-1, i-1)
		B = A * P
		print(B % (10**9+7))
	else:
		print(0)

Buggy submission (verdict: Runtime Error):
nCr = {}
def combination(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

N, K = map(int, input().split())
for i in range(1, K+1):
	if i <= N-K+1:
        A = combination(N-K+1, i)
        P = combination(K-1, i-1)
        B = A * P
        print(B % (10**9+7))
	else:
		print(0)

Buggy submission (verdict: Runtime Error):
nCr = {}
def combination(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

N, K = map(int, input().split())
for i in range(K+1)[1::]:
	if i > N-K+1:
        A = combination(N-K+1, i)
        P = combination(K-1, i-1)
        B = A * P
        print(B % (10**9+7))
	else:
		print(0)

Buggy submission (verdict: Runtime Error):
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

nCr = {}
def combination(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

N, K = map(int, input().split())
# D = 0
# for i in range(K+1)[1::]:
#     if i == 1:
#         A = combination(N-K+1, 1)
#         print(A % (10**9+7))
#         D += A
#     else:
#         A = combination(N-K+i, i)
#         P = combination(K-1, i-1)
#         B = (A - D) * P
#         print(B % (10**9+7))
#         D += B
for i in range(K+1)[1::]:
    if i == 1:
        A = combination(N-K+1, 1)
        print(A % (10**9+7))
    else:
        A = combination(N-K+1, i)
        P = combination(K-1, i-1)
        B = A * P
        if B > 10*9 + 7:
			print(B % (10**9+7))
		else:
			print(B)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())

opes = [0] * (K+1)
for i in range(2**N):
    blue_cnt = 0
    ope_count = 0
    operating = False
    for j in range(N+1):
        bin2str = format(i, '0' + int(N) + 'b')
        if blue_cnt > K:
            break
        elif i == N:
        	if bin2str[:-1:] == 1:
              ope_count += 1
        elif operating and bin2str[j:j+1:] == 0:
            operating = False
            ope_count += 1
        elif !operating and bin2str[j:j+1:] == 1:
            operating = True
            blue_cnt += 1
        elif bin2str[j:j+1:] == 1:
            blue_cnt += 1
    if blue_cnt == K:
        opes[ope_count] += 1
for i in opes[1::]:
    print(i%100000007)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())

opes = [0] * (K)
for i in range(2**N):
    blue_cnt = 0
    ope_count = 0
    operating = False
    for j in range(N+1):
        bin2str = format(i, '0' + int(N) + 'b')
        if blue_cnt > K and j == (N + 1):
            break
        if operating and bin2str[j:j+1:] == 0:
            operating = False
            ope_count += 1
        elif !operating and bin2str[j:j+1:] == 1:
            operating = True
            blue_cnt += 1
        elif bin2str[j+2:j+4:] == 1:
            blue_cnt += 1
    if operating == True:
    	ope_count += 1
    if blue_cnt == K:
        opes[ope_count] += 1
for i in opes:
    print(i%100000007)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())

opes = [0] * (K)
for i in range(2**N):
    blue_cnt = 0
    ope_count = 0
    operating = False
    for j in range(N+1):
        bin2str = format(i, '0' + int(N) + 'b')
        if blue_cnt > K and j == (N + 1):
            break
        if operating and bin2str[j:j+1:] == 0:
            operating = False
            ope_count += 1
        elif !operating and bin2str[j:j+1:] == 1:
            operating = True
            blue_cnt += 1
        elif bin2str[j+2:j+4:] == 1:
            blue_cnt += 1
    if operating == True:
    	ope_count += 1
    if blue_cnt == K:
        opes[ope_count] += 1
for i in opes:
    print(i%100000007)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())

opes = [0] * (K)
for i in range(2**N):
    blue_cnt = 0
    ope_count = 0
    operating = False
    for j in range(N+1):
        bin2str = str(bin(i))
        if blue_cnt > K:
            break
        if operating and bin2str[j+2:j+4:] == 0:
            operating = False
            ope_count += 1
        elif !operating and bin2str[j+2:j+4:] == 1:
            operating = True
            blue_cnt += 1
        elif bin2str][j+2:j+4:] == 1:
            blue_cnt += 1
    if blue_cnt == K:
        opes[ope_count] += 1
for i in opes:
    print(i%100000007)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())

opes = [0] * (K)
for i in range(2**N):
    blue_cnt = 0
    ope_count = 0
    operating = False
    for j in range(N+1):
        bin2str = str(bin(i))
        if blue_cnt > K:
            break
        if operating and str[j+2:j+4:] == 0:
            operating = False
            ope_count += 1
        elif !operating and str[j+2:j+4:] == 1:
            operating = True
            blue_cnt += 1
        elif str[j+2:j+4:] == 1:
            blue_cnt += 1
    if blue_cnt == K:
        opes[ope_count] += 1
for i in opes:
    print(i)