Problem p02990 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
from math import factorial
MOD = 1000000007  # type: int

def cmb(n, r, p):
    return (factorial(n) // (factorial(r) * factorial(n - r))%p)

def solve(N: int, K: int):
    c = N-K

    for i in range(K):
        # i+1回の操作でとるために両端を除くセパレータの数はi個
        # 両端を含めたセパレータの数はi+2個
        # セパレータには最低1つ配属するので，配置する赤玉の数はN-K-i個
        # この赤玉をi+2個のセパレータに配属させる
        # i+2 H c-i
        if c-i<0:
            print(0)
        else:
            b = cmb(K-1, i, MOD)
            k = cmb(c+1, c-i, MOD)
            print(b*k%MOD)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from math import factorial



MOD = 1000000007  # type: int


def cmb(n, r, p):
    return (factorial(n) // (factorial(r) * factorial(n - r))%p)

def solve(N: int, K: int):
    c = N-K

    for i in range(K):
        # i+1回の操作でとるために両端を除くセパレータの数はi個
        b = cmb(K-1, i, MOD)
        # 両端を含めたセパレータの数はi+2個
        # セパレータには最低1つ配属するので，配置する赤玉の数はN-K-i個
        # この赤玉をi+2個のセパレータに配属させる
        # i+2 H c-i
        if c-i+1<0:
            print(0)
        else:
            k = cmb(c+1, c-i, MOD)
        print(b*k%MOD)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from math import factorial



MOD = 1000000007  # type: int


def cmb(n, r, p):
    return (factorial(n) // (factorial(r) * factorial(n - r)))

def solve(N: int, K: int):
    c = N-K+1

    for i in range(K):
        # i回の操作でとるために両端を除くセパレータの数はi-1個
        b = cmb(K-1, i, MOD)
        # 両端を含めたセパレータの数はi-1+2個
        # セパレータには最低1つ配属するので，配置する赤玉の数はN-K-(i-1)個
        # この赤玉をi+1個のセパレータに配属させる
        # i+1 H N-K-(i-1)
        if c-i<0:
            print(0)
        else:
            k = cmb(c, c-(i+1), MOD)
        print(b*k%MOD)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from math import factorial



MOD = 1000000007  # type: int


def cmb(n, r, p):
    return (factorial(n) // (factorial(r) * factorial(n - r)))

def solve(N: int, K: int):
    c = N-K+1
    if c >= 0: 
        print(c)
    else:
        print(0)

    for i in range(2,K+1):
        # i回の操作でとるために両端を除くセパレータの数はi-1個
        b = cmb(K-1, i-1, MOD)
        # 両端を含めたセパレータの数はi-1+2個
        # セパレータには最低1つ配属するので，配置する赤玉の数はN-K-(i-1)個
        # この赤玉をi+1個のセパレータに配属させる
        # i+1 H N-K-(i-1)
        if c-i<0:
            print(0)
        else:
            k = cmb(c, c-i, MOD)
        print(b*k%MOD)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from math import factorial



MOD = 1000000007  # type: int


def cmb(n, r, p):
    return (factorial(n) // factorial(r) // factorial(n - r))

def solve(N: int, K: int):
    c = N-K+1
    if c >= 0: 
        print(c)
    else:
        print(0)
        
    for i in range(2,K+1):
        # i回の操作でとるために両端を除くセパレータの数はi-1個
        b = cmb(K-1, i-1, MOD)
        # 両端を含めたセパレータの数はi-1+2個
        # セパレータには最低1つ配属するので，配置する赤玉の数はN-K-(i-1)個
        # この赤玉をi+1個のセパレータに配属させる
        # i+1 H N-K-(i-1)
        if c-i<0:
            print(0)
        else:
            k = cmb(c, c-i, MOD)
        print(b*k%MOD)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from math import factorial



MOD = 1000000007  # type: int


def cmb(n, r, p):
    return (factorial(n) // factorial(r) // factorial(n - r))

def solve(N: int, K: int):
    c = N-K+1
    print(c)
    for i in range(2,K+1):
        # i回の操作でとるために両端を除くセパレータの数はi-1個
        b = cmb(K-1, i-1, MOD)
        # 両端を含めたセパレータの数はi-1+2個
        # セパレータには最低1つ配属するので，配置する赤玉の数はN-K-(i-1)個
        # この赤玉をi+1個のセパレータに配属させる
        # i+1 H N-K-(i-1)
        if c-i<0:
            print(0)
        else:
            k = cmb(c, c-i, MOD)
        print(b*k%MOD)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from math import factorial



MOD = 1000000007  # type: int


def cmb(n, r, p):
    return (factorial(n) // factorial(r) // factorial(n - r))

def solve(N: int, K: int):

    print(N-K+1)
    for i in range(2,K+1):
        # i回の操作でとるために両端を除くセパレータの数はi-1個
        b = cmb(K-1, i-1, MOD)
        # 両端を含めたセパレータの数はi-1+2個
        # セパレータには最低1つ配属するので，配置する赤玉の数はN-K-(i-1)個
        # この赤玉をi+1個のセパレータに配属させる
        # i+1 H N-K-(i-1)
        k = cmb((N-K-(i-1))+(i+1)-1, N-K-(i-1), MOD)
        print(b*k%MOD)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()