Problem p02990 (python)

Fixed submission:
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())
blue = K
red = N - K
over = 10**9 + 7

for i in range(K):
    if i <= red:
        print((cmb(red+1, i+1)  * (cmb(blue-1, i))) % over)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
from scipy.special import comb
mod = 1000000007

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

for i in range(1, K+1):
    blue = K - i
    red = N - K - (i - 1)
    if blue < 0 or red < 0:
        print(0)
    else:
        print(((comb(red+i, i, exact=True) % mod) * (comb(blue+i-1, i-1, exact=True) % mod)) % mod)

Buggy submission (verdict: Runtime Error):
# D
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())
blue = K   
red = N - K   
over = 10**9 + 7

for i in range(K):
    if i == 0:   
        print(red+1)
    elif i < red:    
        print((cmb(red+1, i+1) % over) * (cmb(blue-1, i) % over)
    else:  
        print(0)

Buggy submission (verdict: Runtime Error):
# D
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())
blue = K   
red = N - K   
over = 10**9 + 7

for i in range(K):
    if i == 0:   
        print(red+1)
    elif i < red:    
        print((cmb(red+1, i+1) % over) * (cmb(blue-1, i) % over)
    elif i == red:   
        print(1)
    else:  
        print(0)

Buggy submission (verdict: Runtime Error):
# D
def cmb(n, r):　　　# function : combination(nCr)
    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

# main

N, K =map(int, input().split())
blue = K   # numbers of blue ball 
red = N - K   # numbers of red ball
over = 10**9 + 7

for i in range(K):
    if i == 0:   # 両端にしかおけない
        print(red+1)
    elif i < red:   # 
        print((cmb(red+1, i+1) % over) * (cmb(blue-1, i) % over)
    elif i == red:   #　青玉の間に全て赤玉で1通り
        print(1)
    else:   # 作れない
        print(0)