Problem p02990 (python)

Fixed submission:
from bisect import bisect_left, bisect_right; from collections import Counter, defaultdict, deque, OrderedDict; from copy import deepcopy; from fractions import gcd; from functools import lru_cache, reduce; from math import ceil, floor; from sys import stdin, setrecursionlimit
import heapq as hq; import itertools as its; import operator as op


# globals
inf = float('inf')
input = stdin.readline
MOD = 1000000007


def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(op.mul, range(n, n - r, -1))
    under = reduce(op.mul, range(1,r + 1))
    return over // under


def H(n, r):
    return cmb(n+r-1, r)


def main():
    n, k = get_li()
    if k == 1:
        print(H(2, n-1))
        return
    if k == 2:
        if n - 2 < 0:
            print(0)
        else:
            print(H(2, n-2))
        if n - 4 < 0:
            print(0)
        else:
            print(H(3, n-4))
        return
    for i in range(1, k + 1):
        if n - k - (i - 1) < 0:
            print(0)
        else:
            print(H(i, k-i) * H(i+1, n-k-(i-1)) % MOD)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def gets(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    setrecursionlimit(4100000)
    main()

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left, bisect_right; from collections import Counter, defaultdict, deque, OrderedDict; from copy import deepcopy; from fractions import gcd; from functools import lru_cache, reduce; from math import ceil, floor; from sys import stdin, setrecursionlimit
import heapq as hq; import itertools as its; import operator as op


# globals
inf = float('inf')
input = stdin.readline
MOD = 1000000007


def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(op.mul, range(n, n - r, -1))
    under = reduce(op.mul, range(1,r + 1))
    return over // under


def H(n, r):
    return cmb(n+r-1, r)


def main():
    n, k = get_li()
    if k == 1:
        print(H(2, n-1))
        return
    if k == 2:
        print(H(2, n-2))
        print(H(3, n-4))
        return
    for i in range(1, k + 1):
        print(H(i, k-i) * H(i+1, n-k-(i-1)) % MOD)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def gets(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    setrecursionlimit(4100000)
    main()