qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import math
import collections
import fractions
import itertools
import functools
import operator

def ncr(n, r):
    if n < r: return 0
    if r == 0: return 0
    r = min(r, n-r)
    numer = functools.reduce(operator.mul, range(n, n-r, -1), 1)
    denom = functools.reduce(operator.mul, range(1, r+1), 1)
    return numer / denom

def solve():
    n, k = map(int, input().split())
    for i in range(1,k+1):
        ans = (ncr(k-1, i-1) * ncr(n-k+1, i)) % (10**9+7)
        print(int(ans))
    return 0

if __name__ == "__main__":
    solve()


Fixed code:
import math
import collections
import fractions
import itertools
import functools
import operator

def ncr(n, r):
    if n < r: return 0
    r = min(r, n-r)
    if r == 0:
        return 1
    numer = functools.reduce(operator.mul, range(n, n-r, -1), 1)
    denom = functools.reduce(operator.mul, range(1, r+1), 1)
    return numer // denom % (10 ** 9 + 7)

def solve():
    n, k = map(int, input().split())
    for i in range(1,k+1):
        ans = (ncr(k-1, i-1) * ncr(n-k+1, i)) % (10**9+7)
        print(int(ans))
    return 0

if __name__ == "__main__":
    solve()
Buggy code:
n,k=map(int,input().split());p=n-k+1;i=1;print(p)
while i<k:p*=(k-i)*(~n+k+i)//i//~i;print(p%(10**9+7));i+=1

Fixed code:
n,k=map(int,input().split());p=n-k+1;i=1;print(p)
while i<k:p=p*(k-i)*(~n+k+i)//i//~i;print(p%(10**9+7));i+=1
Buggy code:
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)

Fixed code:
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 code:
import math

n, k = [int(i) for i in input().split()]

t = [[1 for i in range(k)] for j in range(k)]

for i in range(2, k):
    for j in range(1, i):
        t[i][j] = (t[i][j-1]+t[i-1][j]-1)*2+1

cnt = 0
for i in range(k):
    if i <= n-k:
        ans = (((math.factorial(n-k+i+1)//(math.factorial(i+1)*math.factorial(n-k))) - cnt)*t[k-1][i])
        print(ans%(10**9+7))
        cnt += ans
    else:
        print(0)


Fixed code:
import math

n, k = [int(i) for i in input().split()]

t = [[1 for i in range(k)] for j in range(k)]

for i in range(2, k):
    for j in range(1, i):
        t[i][j] = t[i-1][j-1]+t[i-1][j]

cnt = 0
for i in range(k):
    if i <= n-k:
        ans = math.factorial(n-k+1)//(math.factorial(i+1)*math.factorial(n-k-i))*t[k-1][i]
        print(ans%(10**9+7))
    else:
        print(0)
Buggy code:
import sys

def comb(n, k, fact, revfact, mod):
    return (fact[n] * revfact[n-k] * revfact[k]) % mod

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    mod = 7 + 10 ** 9
    fact = [1] * 2001
    for i in range(1, 2001):
        fact[i] = (fact[i-1] * i) % mod
    revfact = [1] * 2001
    revfact[2000] = pow(fact[2000], mod - 2, mod)
    for i in reversed(range(1, 2000)):
        revfact[i] = (revfact[i+1] * (i + 1)) % mod

    print(N - K + 1)
    for i in range(2, K + 1):
        blue = comb(K-1, i-1, fact, revfact, mod)
        red = (comb(N-K-1, i-2, fact, revfact, mod) + 2 * comb(N-K-1, i-1, fact, revfact, mod) + comb(N-K-1, i, fact, revfact, mod)) % mod
        ans = (blue * red) % mod
        print(ans)
    return 0

if __name__ == "__main__":
    solve()

Fixed code:
import sys

def comb(n, k, fact, revfact, mod):
    return (fact[n] * revfact[n-k] * revfact[k]) % mod

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    mod = 7 + 10 ** 9
    fact = [1] * 2001
    for i in range(1, 2001):
        fact[i] = (fact[i-1] * i) % mod
    revfact = [1] * 2001
    revfact[2000] = pow(fact[2000], mod - 2, mod)
    for i in reversed(range(1, 2000)):
        revfact[i] = (revfact[i+1] * (i + 1)) % mod

    for i in range(1, min(K + 1, N - K + 2)):
        blue = comb(K-1, i-1, fact, revfact, mod)
        red = comb(N-K+1, i, fact, revfact, mod)
        ans = (blue * red) % mod
        print(ans)
    if K > N - K + 1:
        for i in range(N - K + 2, K + 1):
            print(0)
    return 0

if __name__ == "__main__":
    solve()
Buggy code:
def fac(n):
    con = 1e+9 + 7
    lp = [1]
    ln = [1, 1]
    for i in range(2, n + 1):
        lp = ln.copy()
        ln = [1]
        ln += [int((lp[j - 1] + lp[j]) % con) for j in range(1, i)]
        ln += [1]
    return ln

[n, k] = [int(i) for i in input().split()]

nr = fac(n - k + 1)
nb = fac(k - 1)
for i in range(1, k + 1):
    if (i < n - k + 2):
        r = int(nr[i] * nb[i - 1]) % (1e+9 + 7)
        print(r)
    else:
        print(0)


Fixed code:
def fac(n):
    con = int(1e+9 + 7)
    lp = []
    ln = [1]
    for i in range(1, n + 1):
        lp = ln.copy()
        ln = [1]
        ln += [int((lp[j - 1] + lp[j]) % con) for j in range(1, i)]
        ln += [1]
    return ln

[n, k] = [int(i) for i in input().split()]

nr = fac(n - k + 1)
nb = fac(k - 1)
for i in range(1, k + 1):
    if (i < n - k + 2):
        r = int((nr[i] * nb[i - 1]) % (int(1e+9 + 7)))
        print(r)
    else:
        print(0)
Buggy code:
import math

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

def main(i):
  blue = int(math.factorial(k-1) / (math.factorial(i-1) * math.factorial(k-i)))
  red = int(math.factorial(n-k+1) / (math.factorial(n-k+1-i) * math.factorial(i)))
  print((blue*red) % (10**9 + 7))

for i in range(1, k+1)):
  if i > min(k+1, n-k+2):
    print('0')
  else:
   main(i)

Fixed code:
import math
 
n,k = map(int, input().split())
 
def main(i):
  blue = math.factorial(k-1) // (math.factorial(i-1) * math.factorial(k-i))
  red = math.factorial(n-k+1) // (math.factorial(n-k+1-i) * math.factorial(i))
  print((blue*red) % (10**9 + 7))
 
for i in range(1, k+1):
  if i > n-k+1:
    print('0')
  else:
   main(i)
Buggy code:
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter

# import math

from numba import jit

# from scipy import
# import numpy as np
# import networkx as nx

# import matplotlib.pyplot as plt

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    b = k
    r = n - k

    @jit(nopython=True)
    def comb():
        com = [[0] * 2005 for _ in range(2005)]
        com[0][0] = 1
        for i in range(1, 2005):
            com[i][0] = 1
            for j in range(1, 2005):
                com[i][j] = (com[i - 1][j - 1] + com[i - 1][j]) % MOD
        return com

    com = comb()

    for i in range(1, k + 1):
        res = com[r + 1][i] * com[b - 1][i - 1]
        res %= MOD
        print(res)


if __name__ == '__main__':
    main()


Fixed code:
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter

# import math

# from numba import jit

# from scipy import
# import numpy as np
# import networkx as nx

# import matplotlib.pyplot as plt

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    b = k
    r = n - k

    def comb():
        com = [[0] * 2005 for _ in range(2005)]
        com[0][0] = 1
        for i in range(1, 2005):
            com[i][0] = 1
            for j in range(1, 2005):
                com[i][j] = (com[i - 1][j - 1] + com[i - 1][j]) % MOD
        return com

    com = comb()

    for i in range(1, k + 1):
        res = com[r + 1][i] * com[b - 1][i - 1]
        res %= MOD
        print(res)


if __name__ == '__main__':
    main()
Buggy code:
import math

str=input()
n,k=int(str.split()[0]),int(str.split()[1])

def place(n,x):
    if n<1:
        return 0
    if n==1:
        return 1
    return int( math.factorial(n+x-1)/math.factorial(n-1)/math.factorial(x) % 1000000007)

for i in range (1,k+1):
    cb=place(  i,  k-i  )
    cr=place(i+1,n-k-i+1)
    cr=cr%1000000007
    print(cb*cr%1000000007)


Fixed code:
import math

str=input()
n,k=int(str.split()[0]),int(str.split()[1])

def place(n,x):
    if n==1:
        return 1
    ans=1
    if n-1 < x:
        for i in range(x+1,n+x):
            ans*=i
        ans//=math.factorial(n-1)
    else:
        for i in range(n, n+x):
            ans*=i
        ans//=math.factorial(x)
    return ans%1000000007


for i in range (1,k+1):
    if n-k < i-1:
        print(0)
    else:
        cb=place(  i,  k-i  )
        cr=place(i+1,n-k-i+1)
        cr=cr%1000000007
        print(cb*cr%1000000007)
Buggy code:
n, k = map(int, input().split())
import math
mod = (10**9) +7
def kai(x):
  if x == 0:
    return 1
  elif x < 0:
    return 1
  else:
    return math.factorial(x)
  
for i in range(1, k+1):
  if n - k  + 1 >= i:
    result = (kai(k-1)*kai(n-k+1))/(kai(i-1)*kai(k-i)*kai(i)*kai(n-k+1-i))
    result2 = result % mod
    print(result2)
  else:
    print(0)




Fixed code:
n, k = map(int, input().split())
import math
mod = (10**9) +7
def kai(x):
  if x == 0:
    return 1
  elif x < 0:
    return 1
  else:
    return math.factorial(x)
  
for i in range(1, k+1):
  if n - k  + 1 >= i:
    result = (kai(k-1)*kai(n-k+1))//(kai(i-1)*kai(k-i)*kai(i)*kai(n-k+1-i))
    result2 = result % mod
    print(result2)
  else:
    print(0)
Buggy code:
def combi(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 = list(map(int,input().split()))
mod = 1000000007

blue = K
red = N-K
for i in range(1,K+1):
  if red+1 > i:
    print( (combi(red+1,i)*combi(blue-1,i-1)) %mod )
  else:
    print(0)

Fixed code:
def combi(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 = list(map(int,input().split()))
mod = 1000000007

blue = K
red = N-K
for i in range(1,K+1):
  if red+1 >= i:
    print( (combi(red+1,i)*combi(blue-1,i-1)) %mod )
  else:
    print(0)
Buggy code:
from math import factorial
N,K = map(int, input().split())
mod = 10**9 + 7
def com(n,r):
    return int(factorial(n) / factorial(r) / factorial(n-r))
for i in range(1,K+1):
    comb = com(N-K+1,i)
    sec = com(K-1,i-1)
    print((comb * sec)%mod)

Fixed code:
from math import factorial
N,K = map(int, input().split())
mod = 10**9 + 7
def com(n,r):
    if n<r:
        return 0
    return int(factorial(n) // factorial(r) // factorial(n-r))
for i in range(1,K+1):
    comb = com(N-K+1,i)
    sec = com(K-1,i-1)
    print((comb * sec)%mod)
Buggy code:
N, K = map(int, input().split())

c = [[0] * 4000 for _ in range(4000)]
c[0][0] = 1
for i in range(1, 4000):
    ci = c[i]
    ci1 = c[i - 1]
    ci[0] = 1
    for j in range(1, i + 1):
        ci[j] = (ci1[j - 1] + ci1[j]) % 1000000007

for i in range(1, K + 1):
    print(c[K - 1][i - 1] * c[N - K + 1][i] % 1000000007)


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

c = [[0] * 2001 for _ in range(2001)]
c[0][0] = 1
for i in range(1, 2001):
    ci = c[i]
    ci1 = c[i - 1]
    ci[0] = 1
    for j in range(1, i + 1):
        ci[j] = (ci1[j - 1] + ci1[j]) % 1000000007

for i in range(1, K + 1):
    print(c[K - 1][i - 1] * c[N - K + 1][i] % 1000000007)
Buggy code:
n,k = map(int,input().split())
mod = 10**9+7

dp = [[0]*(k+3) for i in range(k+3)]
dp[0][0] = 1

for i in range(1,k+1):
    for j in range(1,i+1):
        dp[i][j] = ((dp[i-1][j]*(i+j-1)+dp[i-1][j-1]*(n-k-j+2))//i)

for i in range(1,k+1):
    print(dp[-1][i]%mod)

Fixed code:
n,k = map(int,input().split())
mod = 10**9+7

dp = [[0]*(k+1) for i in range(k+1)]
dp[0][0] = 1

for i in range(1,k+1):
    for j in range(1,i+1):
        dp[i][j] = (dp[i-1][j]*(i+j-1)+dp[i-1][j-1]*(n-k-j+2))//i

for i in range(1,k+1):
    print(dp[-1][i]%mod)
Buggy code:
def comb(n,r):
    return math.factorial(n)/(math.factorial(r)*math.factorial(n-r))

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

for i in range(1, k+1):
    if n-k < i-1:
        print(0)
    else:
        print(comb(k-1, i-1, exact=True)*comb(n-k+1, i, exact=True)%(10**9+7))

Fixed code:
import math

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

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

for i in range(1, k+1):
    if n-k < i-1:
        print(0)
    else:
        print(comb(k-1, i-1)*comb(n-k+1, i)%(10**9+7))
Buggy code:
import math
n,k=map(int,input().split()) 
lst=list()

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

mod_num = 10 ** 9 + 7
for i in range(1, k+1):
    if i > N - K + 1:
        print(0)
    else:
        print(comb(n-k+1, i) * comb(k-i+(i-1), i-1) % mod_num)

Fixed code:
import math
n,k=map(int,input().split()) 

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

mod_num = 10 ** 9 + 7
for i in range(1, k+1):
    if i > n - k + 1:
        print(0)
    else:
        print(comb(n-k+1, i) * comb(k-i+(i-1), i-1) % mod_num)
Buggy code:
n,k = map(int,input().split())
from math import factorial
for i in range(1,k+1):
    if n-k < i-1:
        print(0)
    if n-k == i-1:
        print(factorial(k-1) / factorial(i-1) / factorial((k-1) - (i-1)))
    else:
        a = factorial(k-1) // factorial(i-1) // factorial(k-i)
        b = factorial(n-k+1) // factorial(i) // factorial(n-k-i+1)
        #print(a)
       #print(b)
        print(a*b % (10**9+7))

Fixed code:
n,k = map(int,input().split())
from math import factorial
for i in range(1,k+1):
    if n-k < i-1:
        print(0) 
    else:
        a = factorial(k-1) // factorial(i-1) // factorial(k-i)
        b = factorial(n-k+1) // factorial(i) // factorial(n-k-i+1)
        #print(a)
        #print(b)
        print(a*b % (10**9+7))
Buggy code:
import math
def modpow(a,b,MOD):
    if b == 0:
        return 1
    if b%2:
        return a*modpow(a**2%MOD,b//2,MOD)%MOD
    else:
        return modpow(a**2%MOD,b//2,MOD)
def modinv(a,MOD):
    return modpow(a,MOD-2,MOD)
def modcomb(n,r,MOD):
    return math.factorial(n)%MOD*modinv(math.factorial(r),MOD)%MOD*modinv(math.factorial(n-r),MOD)%MOD

MOD=10**9+7
n,k=map(int,input().split())
for i in range(1,k+1):
    if n-k<i:print(0)
    else:print((modcomb(n-k+1,i,MOD)*modcomb(k-1,k-i,MOD))%MOD)

Fixed code:
import math
def modpow(a,b,MOD):
    if b == 0:
        return 1
    if b%2:
        return a*modpow(a**2%MOD,b//2,MOD)%MOD
    else:
        return modpow(a**2%MOD,b//2,MOD)
def modinv(a,MOD):
    return modpow(a,MOD-2,MOD)
def modcomb(n,r,MOD):
    return math.factorial(n)%MOD*modinv(math.factorial(r),MOD)%MOD*modinv(math.factorial(n-r),MOD)%MOD

MOD=10**9+7
n,k=map(int,input().split())
for i in range(1,k+1):
    if n-k+1<i:print(0)
    else:print((modcomb(n-k+1,i,MOD)*modcomb(k-1,k-i,MOD))%MOD)
Buggy code:
N, K = map(int, input().split())
R = N - K
mod = pow(10, 9) + 7

N += 1

fact = [0] * N
inv = [0] * N
inv_cal = [0] * N

fact[:2] = [1, 1]
inv[1] = 1
inv_cal[:2] = [1, 1]

for i in range(2, 2001):
    fact[i] = fact[i-1] * i % mod
    inv[i] = mod - (mod // i) * inv[mod % i] % mod
    inv_cal[i] = inv_cal[i-1] * inv[i] % mod

def comb(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fact[n] * (inv_cal[k] * inv_cal[n-k] % mod) % mod

for k in range(1, K+1):
    print(comb(R+1, k) * comb(K-1, k-1) % mod)

Fixed code:
N, K = map(int, input().split())
R = N - K
mod = pow(10, 9) + 7

fact = [0] * 2001
inv = [0] * 2001
inv_cal = [0] * 2001

fact[:2] = [1, 1]
inv[1] = 1
inv_cal[:2] = [1, 1]

for i in range(2, 2001):
    fact[i] = fact[i-1] * i % mod
    inv[i] = mod - (mod // i) * inv[mod % i] % mod
    inv_cal[i] = inv_cal[i-1] * inv[i] % mod

def comb(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fact[n] * (inv_cal[k] * inv_cal[n-k] % mod) % mod

for k in range(1, K+1):
    if R+1 >= k:
        print(comb(R+1, k) * comb(K-1, k-1) % mod)
    else:
        print(0)
Buggy code:
from math import factorial
def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

div = 10**9+7

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

for i in range(1,K+1):
    if N-K+1 <= i: break
    ans = combinations_count(N-K+1,i) % div
    ans = ans * combinations_count(K-1,i-1) % div
    print(ans)

Fixed code:
from math import factorial
def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

div = 10**9+7

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

for i in range(1,K+1):
    if N-K+1 < i:
        print(0)
        continue
    ans = combinations_count(N-K+1,i) % div
    ans = ans * combinations_count(K-1,i-1) % div
    print(ans)
Buggy code:
from math import factorial as f
N, K = map(int,input().split())

WARU = 10**9+7

def nCr(n, r):
    return (f(n)%WARU) // ((f(r)*f(n-r))%WARU)


for i in range(K):
    print((nCr(K-1, i) * nCr(N-K+1, i+1))%WARU)


Fixed code:
from math import factorial as f
N, K = map(int,input().split())

WARU = 10**9+7

def nCr(n, r):
    return f(n)//(f(r)*f(n-r))


for i in range(K):
    if i <= N-K:
        print((nCr(K-1, i) * nCr(N-K+1, i+1)) % WARU)
    else:
        print(0)
Buggy code:
n,k = map(int,input().split())
mod = 10**9+7
a = 1
b = n - k + 1
for i in range(k):
    ans = (a * b) % mod
    print(ans)
    a *= (k - 1 - i) // (i + 1)
    b *= (n - k - i) // (i + 2)

Fixed code:
n,k = map(int,input().split())
mod = 10**9+7
a = 1
b = n-k+1
for i in range(k):
    ans = a*b % mod
    print(ans)
    a = a * (k-1-i)//(i+1)
    b = b * (n-k-i)//(i+2)
Buggy code:
import math

n,k=map(int,input().split())
for i in range(1,k+1):
  if n-k<i-1:
      print(0)
  else :
    a=math.factorial(k-1)
    b=math.factorial(i-1)
    c=math.factorial(k-i)
    d=math.factorial(n-k+1)
    e=math.factorial(i)
    f=math.factorial(n-k-i+1)
    g=a/b/c
    h=d/e/f
    print(g*h%1000000007)
    

Fixed code:
import math

n,k=map(int,input().split())
for i in range(1,k+1):
  if n-k<i-1:
      print(0)
  else :
    a=math.factorial(k-1)
    b=math.factorial(i-1)
    c=math.factorial(k-i)
    d=math.factorial(n-k+1)
    e=math.factorial(i)
    f=math.factorial(n-k-i+1)
    g=a//b//c
    h=d//e//f
    print(g*h%1000000007)
Buggy code:
n,k = map(int,input().split())
MOD = 10**9+7

history = {}
def comb(n,k):
  if (n,k) in history:
    return history((n,k))
  res = 1
  for i in range(k):
    res *= n-i
    res *= pow(i+1,MOD-2,MOD)
  res = res % MOD
  history[(n,k)] = res
  history[(n,n-k)] = res
  return res

for i in range(k):
  #print(comb(k-1,i),comb(n-k+1,i+1))
  ans = comb(k-1,i) * comb(n-k+1,i+1)
  print(ans % MOD)

Fixed code:
n,k = map(int,input().split())
MOD = 10**9+7

history = {}
def comb(n,k):
  if (n,k) in history:
    return history[(n,k)]
  if k == 0:
    return 1
  res = (n-k+1)*pow(k,MOD-2,MOD)*comb(n,k-1)
  res = res%MOD
  history[(n,k)] = res
  history[(n,n-k)] = res
  return res

for i in range(k):
  #print(comb(k-1,i),comb(n-k+1,i+1))
  ans = comb(k-1,i) * comb(n-k+1,i+1)
  print(ans % MOD)
Buggy code:
def solve():
  n,k = (int(i) for i in input().split())
  mod = 10**9+7
  fact = [1]*(n+5)
  inv = [1]*(n+5)
  finv = [1]*(n+5)
  fact[0] = fact[1] = 1
  finv[0] = finv[1] = 1
  inv[1]  = 1
  for i in range(2,n+4):
   fact[i] = (fact[i-1]*i)%mod
   inv[i] = mod-inv[mod%i]*(mod//i)%mod
   finv[i]= finv[i-1]*inv[i]%mod

  
  blue = k
  red  = n-k
  blueplace = red+1
  
  for i in range(1,k+1):
    if (n-k+1)> i:
     tmp = fact[n-k+1]*(finv[i]*finv[n-k+1-i]%mod)%mod
     tmp *= fact[k-1]*(finv[i-1]*finv[k-i]%mod)%mod
     print(tmp%mod)
    else:
      print(0)
solve()

Fixed code:
def solve():
  n,k = (int(i) for i in input().split())
  mod = 10**9+7
  fact = [1]*(n+5)
  inv = [1]*(n+5)
  finv = [1]*(n+5)
  fact[0] = fact[1] = 1
  finv[0] = finv[1] = 1
  inv[1]  = 1
  for i in range(2,n+4):
   fact[i] = (fact[i-1]*i)%mod
   inv[i] = mod-inv[mod%i]*(mod//i)%mod
   finv[i]= finv[i-1]*inv[i]%mod

  
  blue = k
  red  = n-k
  blueplace = red+1
  
  for i in range(1,k+1):
    if (n-k+1)>= i:
     tmp = fact[n-k+1]*(finv[i]*finv[n-k+1-i]%mod)%mod
     tmp *= fact[k-1]*(finv[i-1]*finv[k-i]%mod)%mod
     print(tmp%mod)
    else:
      print(0)
solve()
Buggy code:
# coding: utf-8
#-------------------------------------------------------------------
#-------------------------------------------------------------------
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")
#-------------------------------------------------------------------
import math
def prm(n, r):
	return math.factorial(n)//math.factorial(n-r)

def cmb(n, r):
	return prm(n, r)//math.factorial(r)
#-------------------------------------------------------------------
def v(k):
	#p("B-1, k-1, cmb", B-1, k-1, cmb(B-1, k-1))
	p("R, k, cmb(R, k)",R, k, cmb(R, k))
#-------------------------------------------------------------------
MOD = 10**9+7
#-------------------------------------------------------------------


N, K = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7

B=K
R=N-K


def calc(i):
	r = cmb(R+1, i)
	b = cmb(B-1, i-1)
	return r * b % MOD

for i in range(1,K+1):
	if R>i:
		print( calc(i) )
	else:
		print(0)




Fixed code:
# coding: utf-8
#-------------------------------------------------------------------
#-------------------------------------------------------------------
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")
#-------------------------------------------------------------------
import math
def prm(n, r):
	return math.factorial(n)//math.factorial(n-r)

def cmb(n, r):
	return prm(n, r)//math.factorial(r)
#-------------------------------------------------------------------
def v(k):
	#p("B-1, k-1, cmb", B-1, k-1, cmb(B-1, k-1))
	p("R, k, cmb(R, k)",R, k, cmb(R, k))
#-------------------------------------------------------------------
MOD = 10**9+7
#-------------------------------------------------------------------


N, K = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7

B=K
R=N-K


def calc(i):
	r = cmb(R+1, i) % MOD
	b = cmb(B-1, i-1) % MOD
	return (r * b) % MOD

for i in range(1,K+1):
	if R+1>=i:
		print( calc(i) )
	else:
		print(0)
Buggy code:
import math

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


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


w = 10**9+7
for i in range(1, K+1):
    if N-K+1-i > 0:
        ans1 = combinations_count(N-K+1, i)
        ans2 = combinations_count(K-1, i-1)
        print(ans1 % w*ans2 % w)
    else:
        print(0)


Fixed code:
import math

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


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


w = 10**9+7

for i in range(1, K+1):
    if N-K+1-i >= 0:
        ans1 = combinations_count(N-K+1, i)
        ans2 = combinations_count(K-1, i-1)
        ans = ans1 % w * ans2 % w
        print(ans)
    else:
        print(0)