prithivMLmods/Coder-Stat huggingface dataset:
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long int nCr[2003][2003];
int main() {

  int N, K, MOD = 1000000007;
  cin >> N >> K;
  for (int i = 0; i < 2003; i++)
    for (int j = 0; j < 2003; j++)
      nCr[i][j] = 0;
  nCr[0][0] = 1;
  for (int i = 1; i < 2003; i++)
    for (int j = 0; j <= i; j++) {
      if (i == j || j == 0)
        nCr[i][j] = 1;
      else
        nCr[i][j] = (nCr[i - 1][j - 1] + nCr[i - 1][j]) % MOD;
    }
  for (int i = 1; i <= K; i++) {
    long long int res = 0;
    res += 2 * (((nCr[N - K - 1][i - 1]) * (nCr[K - 1][i - 1])) % MOD);
    res += (((nCr[N - K - 1][i]) * (nCr[K - 1][i - 1])) % MOD);
    if (i - 2 >= 0)
      res += (((nCr[N - K - 1][i - 2]) * (nCr[K - 1][i - 1])) % MOD);
    cout << (res % MOD) << endl;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long int nCr[2003][2003];
int main() {

  int N, K, MOD = 1000000007;
  cin >> N >> K;
  for (int i = 0; i < 2003; i++)
    for (int j = 0; j < 2003; j++)
      nCr[i][j] = 0;
  nCr[0][0] = 1;
  for (int i = 1; i < 2003; i++)
    for (int j = 0; j <= i; j++) {
      if (i == j || j == 0)
        nCr[i][j] = 1;
      else
        nCr[i][j] = (nCr[i - 1][j - 1] + nCr[i - 1][j]) % MOD;
    }
  for (int i = 1; i <= K; i++) {
    long long int res = 0;
    res += (((nCr[N - K + 1][i]) * (nCr[K - 1][i - 1])) % MOD);
    cout << (res % MOD) << endl;
  }

  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

long long kMod = 1e9 + 7;
vector<vector<long long>> nck;

long long combinations(long long n, long long k) {
  if (n < (long long)nck.size() && k < (long long)nck.at(n).size()) {
    return nck.at(n).at(k);
  }
  nck.resize(n + 1);
  for (int i = 0; i < (int)nck.size(); i++) {
    nck.at(i).resize(i + 1);
  }
  nck.at(0).at(0) = 1;
  nck.at(1).at(0) = 1;
  nck.at(1).at(1) = 1;
  for (int i = 2; i < (int)nck.size(); i++) {
    for (int j = 0; j < (int)nck.at(i).size(); j++) {
      if (j == 0 || j == (int)nck.at(i).size() - 1) {
        nck.at(i).at(j) = 1;
      } else {
        nck.at(i).at(j) =
            (nck.at(i - 1).at(j - 1) + nck.at(i - 1).at(j)) % kMod;
      }
    }
  }
  return nck.at(n).at(k);
}

long long solve(long long n, long long k, long long i) {
  if (k - 1 > n - k + 1) {
    return (combinations(k - 1, i - 1) * combinations(n - k + 1, i)) % kMod;
  } else {
    return (combinations(n - k + 1, i) * combinations(k - 1, i - 1)) % kMod;
  }
}

int main() {
  long long n, k;
  cin >> n >> k;
  // cout << combinations(n, k) << '\n';
  for (long long i = 1; i <= k; i++) {
    // cout << k-1 << ',' << i-1 << '*' << n-k+2 << ',' << i+1 << '\n';
    cout << solve(n, k, i) << '\n';
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

long long kMod = 1e9 + 7;
vector<vector<long long>> nck;

long long combinations(long long n, long long k) {
  if (n < k) {
    return 0;
  }
  if (n < (long long)nck.size() && k < (long long)nck.at(n).size()) {
    return nck.at(n).at(k);
  }
  nck.resize(n + 1);
  for (int i = 0; i < (int)nck.size(); i++) {
    nck.at(i).resize(i + 1);
  }
  nck.at(0).at(0) = 1;
  nck.at(1).at(0) = 1;
  nck.at(1).at(1) = 1;
  for (int i = 2; i < (int)nck.size(); i++) {
    for (int j = 0; j < (int)nck.at(i).size(); j++) {
      if (j == 0 || j == (int)nck.at(i).size() - 1) {
        nck.at(i).at(j) = 1;
      } else {
        nck.at(i).at(j) =
            (nck.at(i - 1).at(j - 1) + nck.at(i - 1).at(j)) % kMod;
      }
    }
  }
  return nck.at(n).at(k);
}

long long solve(long long n, long long k, long long i) {
  if (k - 1 > n - k + 1) {
    return (combinations(k - 1, i - 1) * combinations(n - k + 1, i)) % kMod;
  } else {
    return (combinations(n - k + 1, i) * combinations(k - 1, i - 1)) % kMod;
  }
}

int main() {
  long long n, k;
  cin >> n >> k;
  // cout << combinations(n, k) << '\n';
  for (long long i = 1; i <= k; i++) {
    // cout << k-1 << ',' << i-1 << '*' << n-k+2 << ',' << i+1 << '\n';
    cout << solve(n, k, i) << '\n';
  }
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long modInverse(long long n, long long p) { return power(n, p - 2, p); }
long long fac[2005];
long long ncr(long long n, long long r, long long p) {

  if (r == 0)
    return 1;
  if (r > n)
    return 0;

  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  fac[0] = 1;
  ll n, i, k, mod = 1e9 + 7;
  for (i = 1; i <= 2000; i++)
    fac[i] = (fac[i - 1] * i) % mod;

  cin >> n >> k;
  for (i = 1; i <= k; i++) {
    // cout<<n-k+1;
    cout << (ncr(n - k + 1, i, mod) * (ncr(k - 1, i - 1, mod))) % mod << "\n";
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long modInverse(long long n, long long p) { return power(n, p - 2, p); }
long long fac[2005];
long long ncr(long long n, long long r, long long p) {

  if (r == 0)
    return 1;
  if (r > n)
    return 0;

  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  fac[0] = 1;
  ll n, i, k, mod = 1e9 + 7;
  for (i = 1; i <= 2000; i++)
    fac[i] = (fac[i - 1] * i) % mod;

  cin >> n >> k;
  for (i = 1; i <= k; i++) {
    // cout<<n-k+1;
    cout << (ncr(n - k + 1, i, mod) * (ncr(k - 1, i - 1, mod))) % mod << "\n";
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define MOD (1000000007)

using namespace std;

long long f(long long n) {
  static long long memo[1000000] = {0};
  if (memo[n] > 0)
    return memo[n];
  if (n == 0)
    return 1;
  return memo[n] = (n * f(n - 1)) % MOD;
}

long long expmod(long long b, long long e) {
  if (e == 0)
    return 1;
  long long ret = expmod(b, e / 2);
  ret *= ret;
  ret %= MOD;
  if (e % 2 == 1) {
    ret *= b;
    ret %= MOD;
  }
  return ret;
}

long long inv(long long n) { return expmod(n, MOD - 2); }

int main(void) {
  long long N, K;
  cin >> N >> K;
  for (int i = 1; i <= K; i++) {
    long long ans = 1;
    ans *= f(K - 1);
    ans *= inv(f(K - i));
    ans %= MOD;
    ans *= inv(f(i - 1));
    ans %= MOD;
    ans *= f(N - K + 1);
    ans %= MOD;
    ans *= inv(f(i));
    ans %= MOD;
    ans *= inv(f(N - K - i + 1));
    ans %= MOD;
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#define MOD (1000000007)

using namespace std;

long long f(long long n) {
  static long long memo[1000000] = {0};
  if (memo[n] > 0)
    return memo[n];
  if (n == 0)
    return 1;
  return memo[n] = (n * f(n - 1)) % MOD;
}

long long expmod(long long b, long long e) {
  if (e == 0)
    return 1;
  long long ret = expmod(b, e / 2);
  ret *= ret;
  ret %= MOD;
  if (e % 2 == 1) {
    ret *= b;
    ret %= MOD;
  }
  return ret;
}

long long inv(long long n) { return expmod(n, MOD - 2); }

int main(void) {
  long long N, K;
  cin >> N >> K;
  for (int i = 1; i <= K; i++) {
    long long ans = 1;
    ans *= f(K - 1);
    ans *= inv(f(K - i));
    ans %= MOD;
    ans *= inv(f(i - 1));
    ans %= MOD;
    ans *= f(N - K + 1);
    ans %= MOD;
    ans *= inv(f(i));
    ans %= MOD;
    if (N - K - i + 1 >= 0) {
      ans *= inv(f(N - K - i + 1));
      ans %= MOD;
    } else {
      ans = 0;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

const int M = 1e9 + 7;
int n, k;
long long kaijo[2200];

int mpow(long long a, int n) {
  if (n == 0)
    return 1;
  if (n % 2)
    return mpow(a, n - 1) * a % M;
  return mpow(a * a % M, n / 2);
}

long long cmb(int n, int r) {
  return kaijo[n] * mpow(kaijo[r], M - 2) % M * mpow(kaijo[n - r], M - 2) % M;
}

int main() {
  cin >> n >> k;

  kaijo[0] = 1;
  for (int i = 1; i <= 2100; i++) {
    kaijo[i] = kaijo[i - 1] * i % M;
  }

  for (int r = 1; r <= k; r++) {
    int ans = cmb(k - 1, r - 1) * cmb(n - k + 1, r) % M;
    cout << ans << endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

const int M = 1e9 + 7;
int n, k;
long long kaijo[2200];

int mpow(long long a, int n) {
  if (n == 0)
    return 1;
  if (n % 2)
    return mpow(a, n - 1) * a % M;
  return mpow(a * a % M, n / 2);
}

long long cmb(int n, int r) {
  return kaijo[n] * mpow(kaijo[r], M - 2) % M * mpow(kaijo[n - r], M - 2) % M;
}

int main() {
  cin >> n >> k;

  kaijo[0] = 1;
  for (int i = 1; i <= 2100; i++) {
    kaijo[i] = kaijo[i - 1] * i % M;
  }

  for (int r = 1; r <= k; r++) {
    int ans = 0;
    if (n - k + 1 >= r) {
      ans = cmb(k - 1, r - 1) * cmb(n - k + 1, r) % M;
    }
    cout << ans << endl;
  }

  return 0;
}
Problem p02990 (Python)

Buggy submission (status: Runtime Error):
import math


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


n, k = map(int, input().split())
div_num = 10**9 + 7
for i in range(1, k + 1):
    print(combi(n - k + 1, i) * combi(k - 1, i - 1) % div_num)


Fixed submission:
import math


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


n, k = map(int, input().split())
div_num = 10**9 + 7
for i in range(1, k + 1):
    if n - k + 1 >= i:
        print(combi(n - k + 1, i) * combi(k - 1, i - 1) % div_num)
    else:
        print(0)
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

ll fact(ll n) {
  if (n == 0) {
    return 1;
  }
  return fact((n - 1) % MOD) * n % MOD;
}

ll power(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return res;
}
ll factinv(ll a) {
  ll res = power(fact(a), MOD - 2);
  return res;
}

ll comb(ll n, ll r) {
  return (fact(n) * factinv(r)) % MOD * factinv(n - r) % MOD;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cout << comb(n - k + 1, i) * comb(k - 1, i - 1) % MOD << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

ll fact(ll n) {
  if (n == 0) {
    return 1;
  }
  return fact((n - 1) % MOD) * n % MOD;
}

ll power(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return res;
}
ll factinv(ll a) {
  ll res = power(fact(a), MOD - 2);
  return res;
}

ll comb(ll n, ll r) {
  ll res;
  if (n < 0 || r < 0 || n < r) {
    res = 0;
  } else {
    res = (fact(n) * factinv(r)) % MOD * factinv(n - r) % MOD;
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cout << comb(n - k + 1, i) * comb(k - 1, i - 1) % MOD << endl;
  }
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define rep(var, n) for (int var = 0; var < (n); ++var)
const ll MOD = 1e9 + 7;

#define MAX_V (long long)(1e5 * 2 + 200)

ll MAX_VAL;
ll fac[MAX_V], mmi[MAX_V];

inline void factorial() {
  fac[0] = fac[1] = 1;
  for (long long i = 2; i < MAX_VAL; fac[i] %= MOD, i++)
    fac[i] = fac[i - 1] * (i % MOD);
}

inline long long power_mod(long long x, long long n) {
  long long ans = 1;
  for (; n; n >>= 1, x *= x, ans %= MOD, x %= MOD)
    if (n & 1)
      ans *= x;
  return ans;
}

inline void modular_multiplicatibe_inverse() {
  mmi[MAX_VAL - 1] = power_mod(fac[MAX_VAL - 1], MOD - 2);
  for (long long i = MAX_VAL - 2; i >= 0; mmi[i] %= MOD, i--)
    mmi[i] = mmi[i + 1] * (i + 1);
}

inline long long combination(long long n, long long r) {
  return fac[n] * (mmi[r] * mmi[n - r] % MOD) % MOD;
}

int main() {
  ll n, k;
  cin >> n >> k;

  MAX_VAL = n + 3;

  factorial();
  modular_multiplicatibe_inverse();

  rep(i, k) cout << (combination(k - 1, i) * combination(n - k + 1, i + 1)) %
                        MOD
                 << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define rep(var, n) for (int var = 0; var < (n); ++var)
const ll MOD = 1e9 + 7;

#define MAX_V (long long)(1e5 * 2 + 200)

ll MAX_VAL;
ll fac[MAX_V], mmi[MAX_V], temp[MAX_V];

inline void factorial() {
  fac[0] = fac[1] = 1;
  for (long long i = 2; i < MAX_VAL; fac[i] %= MOD, i++)
    fac[i] = fac[i - 1] * (i % MOD);
}

inline long long power_mod(long long x, long long n) {
  long long ans = 1;
  for (; n; n >>= 1, x *= x, ans %= MOD, x %= MOD)
    if (n & 1)
      ans *= x;
  return ans;
}

inline void modular_multiplicatibe_inverse() {
  mmi[MAX_VAL - 1] = power_mod(fac[MAX_VAL - 1], MOD - 2);
  for (long long i = MAX_VAL - 2; i >= 0; mmi[i] %= MOD, i--)
    mmi[i] = mmi[i + 1] * (i + 1);
}

inline long long combination(long long n, long long r) {
  return fac[n] * (mmi[r] * mmi[n - r] % MOD) % MOD;
}

int main() {
  ll n, k;
  cin >> n >> k;

  MAX_VAL = n + 3;

  factorial();
  modular_multiplicatibe_inverse();

  rep(i, k) cout << (combination(k - 1, i) * combination(n - k + 1, i + 1)) %
                        MOD
                 << endl;
  return 0;
}
Problem p02990 (Python)

Buggy submission (status: Runtime Error):
import math


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


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

blue = K
red = N - K

num = 10**9 + 7

for k in range(K):
    space_comb = combination_count(red + 1, k + 1)

    ball_comb = combination_count(K - 1, k)

    print((space_comb * ball_comb) % num)


Fixed submission:
import math


def combination_count(n, r):
    if n - r < 0:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

blue = K
red = N - K

num = 10**9 + 7

for k in range(K):
    space_comb = combination_count(red + 1, k + 1)

    ball_comb = combination_count(K - 1, k)

    print((space_comb * ball_comb) % num)
Problem p02990 (Python)

Buggy submission (status: Runtime Error):
import math

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


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


for i in range(1, k + 1):
    tmp1 = combinations_count(k - 1, i - 1) % 1000000007
    tmp2 = combinations_count(n - k + 1, i) % 1000000007
    ans = (tmp1 * tmp2) % 1000000007
    print(ans)
    if ans == 1:
        exit()


Fixed submission:
import math

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


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


for i in range(1, k + 1):
    if n - k + 1 >= i:
        tmp1 = combinations_count(k - 1, i - 1) % 1000000007
        tmp2 = combinations_count(n - k + 1, i) % 1000000007
        ans = (tmp1 * tmp2) % 1000000007
        print(ans)
    else:
        print(0)
Problem p02990 (Python)

Buggy submission (status: Runtime Error):
import math
import sys


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


input = sys.stdin.readline

N, K = map(int, input().strip().split(" "))
div = 1000000000 + 7

for i in range(K):
    perm = comb(N - K + 1, i + 1) * comb(K - 1, i)
    print(perm % div)


Fixed submission:
import math
import sys


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


input = sys.stdin.readline

N, K = map(int, input().strip().split(" "))
div = 1000000000 + 7

for i in range(K):
    if i > N - K:
        print(0)
    else:
        perm = comb(N - K + 1, i + 1) * comb(K - 1, i)
        print(perm % div)
Problem p02990 (Python)

Buggy submission (status: Runtime Error):
N, K = map(int, input().split())
ans = N - K + 1
for i in range(1, K + 1):
    if i > N - K + 1:
        ans = 0
    print(int(ans % 1000000007))
    ans = ans * (N - K + 1 - i) / (i + 1) * (K - i) / i


Fixed submission:
N, K = map(int, input().split())
ans = N - K + 1
for i in range(1, K + 1):
    if i > N - K + 1:
        ans = 0
    print(ans % 1000000007)
    ans = ans * (N - K + 1 - i) * (K - i)
    ans = ans // ((i + 1) * i)
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

const long long MOD = 1000000007;

std::vector<std::vector<long long>> comb(int n, int r) {
  std::vector<std::vector<long long>> v(n + 1,
                                        std::vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]) % MOD;
    }
  }
  return v;
}

int main(void) {
  long long N, K;
  cin >> N >> K;
  vector<vector<long long>> com = comb(N, N);
  for (int i = 1; i <= K; i++) {
    printf("%lld\n",
           (com[K - i + i - 1][i - 1] * com[N - K - i + i + 2][i + 1]) % MOD);
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

const long long MOD = 1000000007;

std::vector<std::vector<long long>> comb(int n, int r) {
  std::vector<std::vector<long long>> v(n + 1,
                                        std::vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]) % MOD;
    }
  }
  return v;
}

int main(void) {
  long long N, K;
  cin >> N >> K;
  vector<vector<long long>> com = comb(N, N);
  for (int i = 1; i <= K; i++) {
    long long a = com[K - i + i - 1][i - 1];
    long long b = com[N - K - i + 1 + i][i];
    printf("%d\n", (a * b) % MOD);
  }
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define repf(i, a, b) for (ll i = a; i < b; i++)
#define repb(i, a, b) for (ll i = a; i >= b; i--)
#define all(v) v.begin(), v.end()

using namespace std;

ll power(ll a, ll n) {
  ll ans = 1;
  while (n) {
    if (n & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    n >>= 1;
  }
  return ans;
}

ll fac[4001];

int main() {
  IOS;
  fac[0] = 1;
  repf(i, 1, 4001) { fac[i] = (fac[i - 1] * i) % mod; }
  ll N, K;
  cin >> N >> K;
  ll n = (N - K + 1);
  ll r;
  repf(i, 1, K + 1) {
    r = i;
    ll Nr = fac[n];
    ll Dr = (fac[n - r] * fac[r]) % mod;
    ll ans = (Nr * power(Dr, mod - 2)) % mod;
    Nr = fac[K - 1];
    Dr = (fac[K - i] * fac[i - 1]) % mod;
    ans = ((ans * Nr) % mod * power(Dr, mod - 2)) % mod;
    cout << ans << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define repf(i, a, b) for (ll i = a; i < b; i++)
#define repb(i, a, b) for (ll i = a; i >= b; i--)
#define all(v) v.begin(), v.end()

using namespace std;

ll power(ll a, ll n) {
  ll ans = 1;
  while (n) {
    if (n & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    n >>= 1;
  }
  return ans;
}

ll fac[4001];

int main() {
  IOS;
  fac[0] = 1;
  repf(i, 1, 4001) { fac[i] = (fac[i - 1] * i) % mod; }
  ll N, K;
  cin >> N >> K;
  ll n = (N - K + 1);
  ll r;
  repf(i, 1, K + 1) {
    r = i;
    if (n < r) {
      cout << 0 << endl;
      continue;
    }
    ll Nr = fac[n];
    ll Dr = (fac[n - r] * fac[r]) % mod;
    ll ans = (Nr * power(Dr, mod - 2)) % mod;
    Nr = fac[K - 1];
    Dr = (fac[K - i] * fac[i - 1]) % mod;
    ans = ((ans * Nr) % mod * power(Dr, mod - 2)) % mod;
    cout << ans << endl;
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 999999999
#define P 1000000007
#define ll long long
using namespace std;

ll a[2001];
ll inv[2001];

long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

int main() {
  ll N, K, z1, z2, x = 1;
  cin >> N >> K;
  a[0] = 1;
  inv[0] = 1;
  FOR(i, 1, N + 1) {
    x = (x * i) % P;
    a[i] = x;
    inv[i] = modinv(x, P);
  }
  FOR(i, 1, K + 1) {
    z1 = ((a[N - K + 1] * inv[i] % P) * inv[N - K - i + 1] % P);
    z2 = ((a[K - 1] * inv[i - 1] % P) * inv[K - i] % P);
    cout << z1 * z2 % P << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 999999999
#define P 1000000007
#define ll long long
using namespace std;

ll a[2001];
ll inv[2001];

long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

int main() {
  ll N, K, z1, z2, x = 1;
  cin >> N >> K;
  a[0] = 1;
  inv[0] = 1;
  FOR(i, 1, N + 1) {
    x = (x * i) % P;
    a[i] = x;
    inv[i] = modinv(x, P);
  }
  FOR(i, 1, K + 1) {
    if (N - K < i - 1)
      cout << 0 << endl;
    else {
      z1 = ((a[N - K + 1] * inv[i] % P) * inv[N - K - i + 1] % P);
      z2 = ((a[K - 1] * inv[i - 1] % P) * inv[K - i] % P);
      cout << z1 * z2 % P << endl;
    }
  }
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define LAR(a, b) ((a) = max((a), (b)))
#define SML(a, b) ((a) = min((a), (b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define MOD 1'000'000'007LL

#define N 2048
ll fct[N] = {1};

inline ll pw(ll a, ll b) {
  ll c = 1, d = a;
  while (b) {
    if (b & 1)
      c = c * d % MOD;
    d = d * d % MOD;
    b /= 2;
  }
  return c;
}

inline ll inv(ll a) { return pw(a, MOD - 2); }

inline ll cmb(ll a, ll b) {
  return fct[a] * inv(fct[b]) % MOD * inv(fct[a - b]) % MOD;
}

int main() {
  FOR(i, 1, N) fct[i] = fct[i - 1] * i % MOD;
  ll n, k;
  scanf("%lld%lld", &n, &k);
  FOR(i, 1, k + 1) {
    ll ans = cmb(k - 1, i - 1);
    ans = ans * cmb(n - k + 1, i) % MOD;
    printf("%lld\n", ans);
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define LAR(a, b) ((a) = max((a), (b)))
#define SML(a, b) ((a) = min((a), (b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define MOD 1'000'000'007LL

#define N 2048
ll fct[N] = {1};

inline ll pw(ll a, ll b) {
  ll c = 1, d = a;
  while (b) {
    if (b & 1)
      c = c * d % MOD;
    d = d * d % MOD;
    b /= 2;
  }
  return c;
}

inline ll inv(ll a) { return pw(a, MOD - 2); }

inline ll cmb(ll a, ll b) {
  return fct[a] * inv(fct[b]) % MOD * inv(fct[a - b]) % MOD;
}

int main() {
  FOR(i, 1, N) fct[i] = fct[i - 1] * i % MOD;
  ll n, k;
  scanf("%lld%lld", &n, &k);
  FOR(i, 1, k + 1) {
    ll ans = cmb(k - 1, i - 1);
    if (n - k + 1 < i)
      ans = 0;
    else
      ans = ans * cmb(n - k + 1, i) % MOD;
    printf("%lld\n", ans);
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

long long mod = 1000000007;

long long mypow(long long x, long long y) {
  if (y == 1)
    return x;
  long long z = mypow(x, y / 2) % mod;
  if (y % 2 == 0) {
    return (z * z) % mod;
  } else {
    return ((z * z) % mod * x) % mod;
  }
}
long long choose(long long l, long long r) {
  long long u = 1, d = 1;
  for (int i = l; i > l - r; i--) {
    u = (u * i) % mod;
  }
  for (int i = r; i >= 1; i--) {
    d = (d * i) % mod;
  }
  d = mypow(d, mod - 2);
  return (u * d) % mod;
}

long long kaijo(long long x) {
  if (x <= 1)
    return 1;
  return (kaijo(x - 1) * x) % mod;
}

void solve() {
  long long n, k, sum = 0;
  cin >> n >> k;
  vector<long long> ans(k, 0);
  for (int i = 0; i <= n - k; i++) {
    long long x = choose(k - 1, i), y, z, w, rn = n - k - i, g = i + 2;
    /*y = kaijo(rn + g - 1);
    z = kaijo(rn);
    w = kaijo(g - 1);
    z = mypow(z, mod - 2);
    w = mypow(w, mod - 2);*/
    y = choose(rn + g - 1, rn);
    ans[i] = (x * y) % mod;
    // ans[i] = (((y * z) % mod * w) % mod * x) % mod;
  }
  for (int i = 0; i < k; i++) {
    cout << ans[i] << endl;
  }
  return;
}

int main() {
  solve();
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

long long mod = 1000000007;

long long mypow(long long x, long long y) {
  if (y == 1)
    return x;
  long long z = mypow(x, y / 2) % mod;
  if (y % 2 == 0) {
    return (z * z) % mod;
  } else {
    return ((z * z) % mod * x) % mod;
  }
}
long long choose(long long l, long long r) {
  long long u = 1, d = 1;
  for (int i = l; i > l - r; i--) {
    u = (u * i) % mod;
  }
  for (int i = r; i >= 1; i--) {
    d = (d * i) % mod;
  }
  d = mypow(d, mod - 2);
  return (u * d) % mod;
}

long long kaijo(long long x) {
  if (x <= 1)
    return 1;
  return (kaijo(x - 1) * x) % mod;
}

void solve() {
  long long n, k, sum = 0;
  cin >> n >> k;
  vector<long long> ans(k, 0);
  for (int i = 0; i <= min(n - k, k - 1); i++) {
    long long x = choose(k - 1, i), y, z, w, rn = n - k - i, g = i + 2;
    /*y = kaijo(rn + g - 1);
    z = kaijo(rn);
    w = kaijo(g - 1);
    z = mypow(z, mod - 2);
    w = mypow(w, mod - 2);*/
    y = choose(rn + g - 1, rn);
    ans[i] = (x * y) % mod;
    // ans[i] = (((y * z) % mod * w) % mod * x) % mod;
  }
  for (int i = 0; i < k; i++) {
    cout << ans[i] << endl;
  }
  return;
}

int main() {
  solve();
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define int long long
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rep1(i, n) for (int i = 1; i <= (int)n; ++i)
#define all(a) begin(a), end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

bool chmin(int &a, int b) { return a > b ? (a = b, true) : false; }
bool chmax(int &a, int b) { return a < b ? (a = b, true) : false; }
int read() {
  int a;
  scanf("%lld", &a);
  return a;
}

const int mod = 1e9 + 7;

ll inv[200010];
ll fac[200010], fac_inv[200010];

ll C(int n, int k) {
  return ((fac[n] * fac_inv[k] % mod) * fac_inv[n - k]) % mod;
}

void comb_init() {
  int N = 200005;
  inv[1] = 1;

  for (int i = 2; i <= N; ++i) {
    inv[i] = mod - (mod / i) * inv[mod % i] % mod;
  }

  fac[0] = fac_inv[0] = 1;

  for (int i = 1; i <= N; ++i) {
    fac[i] = (fac[i - 1] * i) % mod;
    fac_inv[i] = (fac_inv[i - 1] * inv[i]) % mod;
  }
}

int N, K;

signed main() {
  cin >> N >> K;
  comb_init();

  int r = N - K, b = K;

  for (int i = 1; i <= b; ++i) {
    if (r + 1 > i or b - 1 > i - 1)
      cout << 0 << endl;
    else
      cout << C(r + 1, i) * C(b - 1, i - 1) % mod << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define int long long
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rep1(i, n) for (int i = 1; i <= (int)n; ++i)
#define all(a) begin(a), end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

bool chmin(int &a, int b) { return a > b ? (a = b, true) : false; }
bool chmax(int &a, int b) { return a < b ? (a = b, true) : false; }
int read() {
  int a;
  scanf("%lld", &a);
  return a;
}

const int mod = 1e9 + 7;

ll inv[200010];
ll fac[200010], fac_inv[200010];

ll C(int n, int k) {
  return ((fac[n] * fac_inv[k] % mod) * fac_inv[n - k]) % mod;
}

void comb_init() {
  int N = 200005;
  inv[1] = 1;

  for (int i = 2; i <= N; ++i) {
    inv[i] = mod - (mod / i) * inv[mod % i] % mod;
  }

  fac[0] = fac_inv[0] = 1;

  for (int i = 1; i <= N; ++i) {
    fac[i] = (fac[i - 1] * i) % mod;
    fac_inv[i] = (fac_inv[i - 1] * inv[i]) % mod;
  }
}

int N, K;

signed main() {
  cin >> N >> K;
  comb_init();

  int r = N - K, b = K;

  for (int i = 1; i <= b; ++i) {
    if (r + 1 < i or b - 1 < i - 1)
      cout << 0 << endl;
    else
      cout << C(r + 1, i) * C(b - 1, i - 1) % mod << endl;
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

Int inv[3000];
Int fact[3000];
Int invfact[3000];
Int comb(Int n, Int r) {
  return (fact[n] * (invfact[n - r] * invfact[r] % MOD)) % MOD;
}
int main(void) {
  int N, K;

  cin >> N >> K;

  inv[1] = 1;
  fact[0] = fact[1] = 1;
  invfact[0] = invfact[1] = 1;

  for (int i = 2; i <= N; i++) {
    fact[i] = i * fact[i - 1] % MOD;
    inv[i] = MOD - (MOD / i) * inv[MOD % i] % MOD;
    invfact[i] = invfact[i - 1] * inv[i] % MOD;
  }

  for (Int i = 1; i <= K; i++) {
    Int sum = 0;
    sum = comb(N - K + 1, i) * comb(K - 1, i - 1) % MOD;
    cout << sum << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

Int inv[3000];
Int fact[3000];
Int invfact[3000];
Int comb(Int n, Int r) {
  if (n < r)
    return 0;
  if (n < 0 || r < 0)
    return 0;
  return fact[n] * (invfact[n - r] * invfact[r] % MOD) % MOD;
}
int main(void) {
  int N, K;

  cin >> N >> K;

  inv[1] = 1;
  fact[0] = fact[1] = 1;
  invfact[0] = invfact[1] = 1;

  for (int i = 2; i <= N; i++) {
    fact[i] = i * fact[i - 1] % MOD;
    inv[i] = MOD - (MOD / i) * inv[MOD % i] % MOD;
    invfact[i] = invfact[i - 1] * inv[i] % MOD;
  }

  for (Int i = 1; i <= K; i++) {
    Int sum = 0;
    sum = comb(N - K + 1, i) * comb(K - 1, i - 1) % MOD;
    cout << sum << endl;
  }

  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FOR(i, k, n) for (int i = (k); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;
constexpr ll MOD = 1000000007;

ll frac[3000];
ll fracinv[3000];

// a^-1 mod p
ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); }

void init() {
  frac[0] = 1;
  fracinv[0] = 1;
  FOR(i, 1, 3000) {
    frac[i] = (i * frac[i - 1]) % MOD;
    fracinv[i] = inv(frac[i], MOD);
  }
}

ll comb(ll n, ll k) {
  ll tmp = (frac[n] * fracinv[k]) % MOD;
  return (tmp * fracinv[n - k]) % MOD;
}

int main() {
  init();
  ll n, k;
  cin >> n >> k;
  FOR(i, 1, k + 1) {
    ll res = (comb(n - k + 1, i) * comb(k - 1, i - 1)) % MOD;
    cout << res << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, k, n) for (int i = (k); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;
constexpr ll MOD = 1000000007;

ll frac[3000];
ll fracinv[3000];

// a^-1 mod p
ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); }

void init() {
  frac[0] = 1;
  fracinv[0] = 1;
  FOR(i, 1, 3000) {
    frac[i] = (i * frac[i - 1]) % MOD;
    fracinv[i] = inv(frac[i], MOD);
  }
}

ll comb(ll n, ll k) {
  ll tmp = (frac[n] * fracinv[k]) % MOD;
  return (tmp * fracinv[n - k]) % MOD;
}

int main() {
  init();
  ll n, k;
  cin >> n >> k;
  FOR(i, 1, k + 1) {
    if (n - k + 1 < i) {
      cout << 0 << endl;
      continue;
    }
    ll res = (comb(n - k + 1, i) * comb(k - 1, i - 1)) % MOD;
    cout << res << endl;
  }
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)

typedef long long ll;

ll mod = 1000000007;

ll po(ll x, int a) {
  if (x == 0)
    return 0;
  if (a == 0)
    return 1;
  if (a == 1)
    return x;
  ll tmp = po(x, a / 2);
  if (a % 2 == 0)
    return tmp * tmp % mod;
  return tmp * tmp % mod * x % mod;
}

ll inv(ll x) { return po(x, (int)mod - 2); }

ll beki[2010];

ll cb(int a, int b) {
  return beki[a] * inv(beki[b]) % mod * inv(beki[a - b]) % mod;
}

int main() {
  int n, k;
  cin >> n >> k;
  beki[0] = 1;
  rep(i, n) beki[i + 1] = beki[i] * (i + 1) % mod;
  rep(j, k) {
    int i = j + 1;
    cout << cb(k - 1, i - 1) * cb(n - k + 1, i) % mod << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)

typedef long long ll;

ll mod = 1000000007;

ll po(ll x, int a) {
  if (x == 0)
    return 0;
  if (a == 0)
    return 1;
  if (a == 1)
    return x;
  ll tmp = po(x, a / 2);
  if (a % 2 == 0)
    return tmp * tmp % mod;
  return tmp * tmp % mod * x % mod;
}

ll inv(ll x) { return po(x, (int)mod - 2); }

ll beki[2010];

ll cb(int a, int b) {
  if (a < b)
    return 0;
  return beki[a] * inv(beki[b]) % mod * inv(beki[a - b]) % mod;
}

int main() {
  int n, k;
  cin >> n >> k;
  beki[0] = 1;
  rep(i, n) beki[i + 1] = beki[i] * (i + 1) % mod;
  rep(j, k) {
    int i = j + 1;
    cout << cb(k - 1, i - 1) * cb(n - k + 1, i) % mod << endl;
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
// abc132d.cpp : Blue and Red Balls
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define upto(i, s, e, d) for (int i = (s); i < (e); i += (d))
#define oute(x) cout << (x) << endl

const ll MOD = 1000000007;
ll c[2001][2001];

void init(int N) {
  rep(i, N + 1) rep(j, N - i) c[i][j] =
      (i == 0 || j == 0) ? 1 : (c[i][j - 1] + c[i - 1][j]) % MOD;
}

ll comb(int n, int r) {
  if (n < 0)
    return 0;
  return c[n - r][r];
}

int main() {
  int N, K;
  cin >> N >> K;
  int red = N - K, blue = K;
  init(N + 1);
  upto(i, 1, blue + 1, 1)
      oute((comb(red + 1, i) * comb(blue - 1, i - 1)) % MOD);
}

Fixed submission:
// abc132d.cpp : Blue and Red Balls
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define upto(i, s, e, d) for (int i = (s); i < (e); i += (d))
#define oute(x) cout << (x) << endl

const ll MOD = 1000000007;
ll c[2001][2001];

void init(int N) {
  rep(i, N + 1) rep(j, N - i) c[i][j] =
      (i == 0 || j == 0) ? 1 : (c[i][j - 1] + c[i - 1][j]) % MOD;
}

ll comb(int n, int r) {
  if (n < r)
    return 0;
  return c[n - r][r];
}

int main() {
  int N, K;
  cin >> N >> K;
  int red = N - K, blue = K;
  init(N + 1);
  upto(i, 1, blue + 1, 1)
      oute((comb(red + 1, i) * comb(blue - 1, i - 1)) % MOD);
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#define DEBUG(...)
/*                        Strip me down and go to town                        */
/*                          Lick me over upside down                          */
/*                     Pound and pound and pound and pound                    */
/*                        Baby make me make that sound                        */
/*                Aaah, aaah, aaah, aaah, aaaaaaaaaaaaaaaaaah!                */
#include <stdio.h>

typedef long long int LL;

const LL MOD = 1000000007;

LL fac[4005];
LL ifac[4005];

LL fexpo(LL base, int p) {
  LL ret = 1;
  while (p) {
    if (p % 2) {
      ret = ret * base % MOD;
    }
    base = base * base % MOD;
    p /= 2;
  }
  return ret;
}

LL comb(int a, int b) { return (fac[a] * ifac[b] % MOD) * ifac[a - b] % MOD; }

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  fac[0] = 1;
  ifac[0] = 1;
  for (int i = 1; i < 4005; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    ifac[i] = fexpo(fac[i], MOD - 2);
  }
  for (int i = 1; i <= k; i++) {
    LL red = comb(n - k + 1, i);
    LL blue = comb(k - 1, i - 1);
    DEBUG(printf("%lld %lld\n", red, blue);)
    printf("%lld\n", red * blue % MOD);
  }
  return 0;
}

Fixed submission:
#define DEBUG(...)
/*                        Strip me down and go to town                        */
/*                          Lick me over upside down                          */
/*                     Pound and pound and pound and pound                    */
/*                        Baby make me make that sound                        */
/*                Aaah, aaah, aaah, aaah, aaaaaaaaaaaaaaaaaah!                */
#include <stdio.h>

typedef long long int LL;

const LL MOD = 1000000007;

LL fac[4005];
LL ifac[4005];

LL fexpo(LL base, int p) {
  LL ret = 1;
  while (p) {
    if (p % 2) {
      ret = ret * base % MOD;
    }
    base = base * base % MOD;
    p /= 2;
  }
  return ret;
}

LL comb(int a, int b) {
  if (a < b)
    return 0;
  return (fac[a] * ifac[b] % MOD) * ifac[a - b] % MOD;
}

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  fac[0] = 1;
  ifac[0] = 1;
  for (int i = 1; i < 4005; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    ifac[i] = fexpo(fac[i], MOD - 2);
  }
  for (int i = 1; i <= k; i++) {
    LL red = comb(n - k + 1, i);
    LL blue = comb(k - 1, i - 1);
    DEBUG(printf("%lld %lld\n", red, blue);)
    printf("%lld\n", red * blue % MOD);
  }
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

typedef long long ll;

const int MOD = 1000000007;
ll fact[2010];

// a^b % MOD を計算して返す
ll power(ll a, ll b) {
  if (b == 0) {
    return 1;
  } else {
    ll ans = power(a, b / 2);
    ans = ans * ans;
    ans = ans % MOD;
    if (b % 2 == 1)
      ans = ans * a;
    ans = ans % MOD;
    return ans;
  }
}

// nCr % MOD を計算して返す
ll choose(ll n, ll r) {
  ll ans = fact[n];
  ans = fact[n] * power(fact[r], MOD - 2);
  ans = ans % MOD;
  ans = ans * power((fact[n - r] + MOD) % MOD, MOD - 2);
  ans = ans % MOD;
  return ans;
}

int main() {
  ll n, k;
  cin >> n >> k;
  fact[0] = 1;
  for (int i = 0; i < 2005; ++i) {
    fact[i + 1] = fact[i] * (i + 1) % MOD;
  }
  for (int i = 1; i <= k; ++i) {
    ll ans = choose(n - k + 1, i) * choose(k - 1, i - 1) % MOD;
    cout << ans << endl;
  }
}


Fixed submission:
#include <iostream>
using namespace std;

typedef long long ll;

const int MOD = 1000000007;
ll fact[2010];

// a^b % MOD を計算して返す
ll power(ll a, ll b) {
  if (b == 0) {
    return 1;
  } else {
    ll ans = power(a, b / 2);
    ans = ans * ans;
    ans = ans % MOD;
    if (b % 2 == 1)
      ans = ans * a;
    ans = ans % MOD;
    return ans;
  }
}

// nCr % MOD を計算して返す
ll choose(ll n, ll r) {
  ll ans = fact[n];
  ans = fact[n] * power(fact[r], MOD - 2);
  ans = ans % MOD;
  ans = ans * power((fact[n - r] + MOD) % MOD, MOD - 2);
  ans = ans % MOD;
  return ans;
}

int main() {
  ll n, k;
  cin >> n >> k;
  fact[0] = 1;
  for (int i = 0; i < 2005; ++i) {
    fact[i + 1] = fact[i] * (i + 1) % MOD;
  }
  for (int i = 1; i <= k; ++i) {
    if (i > n - k + 1) {
      cout << 0 << endl;
      continue;
    }
    ll ans = choose(n - k + 1, i) * choose(k - 1, i - 1) % MOD;
    cout << ans << endl;
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
long long p = 1000000007;
long long n, k;
long long rui(long long a, long long b) {
  if (b == 0)
    return 1;
  if (b == 1)
    return a;
  if (b == 2)
    return a * a % p;
  if (b % 2)
    return (rui(rui(a, b / 2), 2) * a % p);
  return rui(rui(a, b / 2), 2);
}
long long inv(long long a) { return rui(a, p - 2); }
long long kai[5000];
long long ans;
int main() {
  scanf("%lld%lld", &n, &k);
  kai[0] = 1;
  for (int i = 1; i < 5000; i++) {
    kai[i] = kai[i - 1] * i % p;
  }
  for (long long i = 1; i <= k; i++) {
    if (n - k - i + 1 < 0)
      ans = 0;
    else
      ans = 1;
    ans *= kai[k - 1];
    ans %= p;
    ans *= inv(kai[k - i]);
    ans %= p;
    ans *= inv(kai[i - 1]);
    ans %= p;
    ans *= kai[n - k + 1];
    ans %= p;
    ans *= inv(kai[n - k + 1 - i]);
    ans %= p;
    ans *= inv(kai[i]);
    ans %= p;
    printf("%lld\n", ans);
  }
}

Fixed submission:
#include <stdio.h>
long long p = 1000000007;
long long n, k;
long long rui(long long a, long long b) {
  if (b == 0)
    return 1;
  if (b == 1)
    return a;
  if (b == 2)
    return a * a % p;
  if (b % 2)
    return (rui(rui(a, b / 2), 2) * a % p);
  return rui(rui(a, b / 2), 2);
}
long long inv(long long a) { return rui(a, p - 2); }
long long kai[5000];
long long ans;
int main() {
  scanf("%lld%lld", &n, &k);
  kai[0] = 1;
  for (int i = 1; i < 5000; i++) {
    kai[i] = kai[i - 1] * i % p;
  }
  for (long long i = 1; i <= k; i++) {
    if (n - k - i + 1 < 0)
      ans = 0;
    else
      ans = 1;
    ans *= kai[k - 1];
    ans %= p;
    ans *= inv(kai[k - i]);
    ans %= p;
    ans *= inv(kai[i - 1]);
    ans %= p;
    ans *= kai[n - k + 1];
    ans %= p;
    if (ans)
      ans *= inv(kai[n - k + 1 - i]);
    ans %= p;
    ans *= inv(kai[i]);
    ans %= p;
    printf("%lld\n", ans);
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
// review
#include <iostream>

using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int N, K;
ll dp[2100];

ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}

ll mod_inv(ll x) { return mod_pow(x, MOD - 2) % MOD; }

ll nCr(ll n, ll r) {
  return (dp[n] * mod_inv(dp[r]) % MOD) * mod_inv(dp[n - r]) % MOD;
}

void solve() {
  dp[0] = dp[1] = 1;
  for (int i = 2; i < 2100; i++) {
    dp[i] = i * dp[i - 1] % MOD;
  }
  for (int i = 1; i <= K; i++) {
    ll sum = nCr(K - 1, i - 1) * nCr(N - K + 1, i) % MOD;
    cout << sum << endl;
  }
}

int main() {
  cin >> N >> K;
  solve();
}


Fixed submission:
// review
#include <iostream>

using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int N, K;
ll dp[2100];

ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}

ll mod_inv(ll x) { return mod_pow(x, MOD - 2) % MOD; }

ll nCr(ll n, ll r) {
  if (n < r) {
    return 0;
  }
  return (dp[n] * mod_inv(dp[r]) % MOD) * mod_inv(dp[n - r]) % MOD;
}

void solve() {
  dp[0] = dp[1] = 1;
  for (int i = 2; i < 2100; i++) {
    dp[i] = i * dp[i - 1] % MOD;
  }
  for (int i = 1; i <= K; i++) {
    ll sum = nCr(K - 1, i - 1) * nCr(N - K + 1, i) % MOD;
    cout << sum << endl;
  }
}

int main() {
  cin >> N >> K;
  solve();
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;

ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

ll modInverse(ll n, ll p) { return power(n, p - 2, p); }

ll nCr(ll n, ll r, ll p) {
  if (r == 0)
    return 1;

  // Fill factorial array so that we
  // can find all factorial of r, n
  // and n-r
  ll fac[n + 1];
  fac[0] = 1;
  for (ll i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * i % p;

  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}

ll count(ll n, ll r, ll a, ll p) {
  ll fac[n + 1];
  fac[0] = 1;
  for (ll i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * i % p;

  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[a], p) % p) % p;
}

ll m = 1e9 + 7;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, k;
  cin >> n >> k;
  for (ll z = 1; z <= k; z++) {
    cout << (nCr(n - k + 1, z, m) * count(k - 1, k - z, z - 1, m)) % m << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;

ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

ll modInverse(ll n, ll p) { return power(n, p - 2, p); }

ll nCr(ll n, ll r, ll p) {
  if (r == 0)
    return 1;

  // Fill factorial array so that we
  // can find all factorial of r, n
  // and n-r
  ll fac[n + 1];
  fac[0] = 1;
  for (ll i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * i % p;

  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}

ll count(ll n, ll r, ll a, ll p) {
  ll fac[n + 1];
  fac[0] = 1;
  for (ll i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * i % p;

  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[a], p) % p) % p;
}

ll m = 1e9 + 7;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, k;
  cin >> n >> k;
  for (ll z = 1; z <= k; z++) {
    if (z > n - k + 1)
      cout << 0 << endl;
    else
      cout << (nCr(n - k + 1, z, m) * count(k - 1, k - z, z - 1, m)) % m
           << endl;
  }
}