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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int64_t mod = 1000000007;
vector<int64_t> f(2001), fi(2001);
int64_t pw(int64_t x, int64_t y) {
  int64_t z;
  if (y == 0)
    return 1;
  else {
    z = pw(x, y / 2) * pw(x, y / 2) % mod;
    if (y % 2 == 1)
      z = z * x % mod;
    return z;
  }
}
int64_t cmb(int64_t x, int64_t y) {
  int64_t z;
  z = f.at(x) * fi.at(y) % mod;
  z = z * fi.at(x - y) % mod;
  return z;
}
int main() {
  int64_t n, k, i, ans = 0;
  cin >> n >> k;
  f.at(0) = 1;
  fi.at(0) = 1;
  for (i = 1; i <= n; i++) {
    f.at(i) = f.at(i - 1) * i % mod;
    fi.at(i) = fi.at(i - 1) * pw(i, mod - 2) % mod;
  }
  for (i = 1; i <= k; i++)
    cout << cmb(k - 1, i - 1) * cmb(n - k + 1, i) % mod << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int64_t mod = 1000000007;
vector<int64_t> f(2001), fi(2001);
int64_t pw(int64_t x, int64_t y) {
  int64_t z;
  if (y == 0)
    return 1;
  else {
    z = pw(x, y / 2) * pw(x, y / 2) % mod;
    if (y % 2 == 1)
      z = z * x % mod;
    return z;
  }
}
int64_t cmb(int64_t x, int64_t y) {
  int64_t z;
  z = f.at(x) * fi.at(y) % mod;
  z = z * fi.at(x - y) % mod;
  return z;
}
int main() {
  int64_t n, k, i, ans = 0;
  cin >> n >> k;
  f.at(0) = 1;
  fi.at(0) = 1;
  for (i = 1; i <= n; i++) {
    f.at(i) = f.at(i - 1) * i % mod;
    fi.at(i) = fi.at(i - 1) * pw(i, mod - 2) % mod;
  }
  for (i = 1; i <= k; i++) {
    if (i <= n - k + 1)
      cout << cmb(k - 1, i - 1) * cmb(n - k + 1, i) % mod << endl;
    else
      cout << 0 << endl;
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

vector<LL> fact(1e5), finv(1e5), inv(1e5);

void ComInit(int N) {
  //  fact = vector<LL>(N + 1);
  //  inv = vector<LL>(N + 1);
  //  finv = vector<LL>(N + 1);
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i <= N; i++) {
    fact[i] = fact[i - 1] * i % kMod;
    inv[i] = kMod - inv[kMod % i] * (kMod / i) % kMod;
    finv[i] = finv[i - 1] * inv[i] % kMod;
  }
}

LL nCr(int n, int r) {
  LL numerator = fact[n];
  LL denominator = finv[r] * finv[n - r] % kMod;
  return (numerator * denominator) % kMod;
}

int main() {
  int N, K;
  std::cin >> N >> K;
  ComInit(5e4);
  for (int k = 1; k <= K; ++k) {
    std::cout << nCr(N - K + 1, k) * nCr(K - 1, k - 1) % kMod << std::endl;
  }
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

constexpr int kMax = 1e5;
LL fact[kMax], finv[kMax], inv[kMax];

void ComInit(int N) {
  //  fact = vector<LL>(N + 1);
  //  inv = vector<LL>(N + 1);
  //  finv = vector<LL>(N + 1);
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i <= N; i++) {
    fact[i] = fact[i - 1] * i % kMod;
    inv[i] = kMod - inv[kMod % i] * (kMod / i) % kMod;
    finv[i] = finv[i - 1] * inv[i] % kMod;
  }
}

LL nCr(int n, int r) {
  LL numerator = fact[n];
  LL denominator = finv[r] * finv[n - r] % kMod;
  return (numerator * denominator) % kMod;
}

int main() {
  int N, K;
  std::cin >> N >> K;
  ComInit(5e4);
  for (int k = 1; k <= K; ++k) {
    std::cout << nCr(N - K + 1, k) * nCr(K - 1, k - 1) % kMod << std::endl;
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long ll;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const int N = 2e5 + 5;
using namespace std;
ll f[N];
ll ksm(ll a, ll b) {
  ll ans = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1)
      ans = ans * a % mod;
  return ans;
}
void fac(int n) {
  f[0] = 1;
  f[1] = 1;
  for (int i = 2; i <= n; i++)
    f[i] = f[i - 1] * i % mod;
}
ll C(ll a, ll b) {
  return f[a] * ksm(f[b], mod - 2) % mod * ksm(f[a - b], mod - 2) % mod;
}
int main() {
  fac(2100);
  ll n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    if (i > n - k + 1)
      cout << 0 << endl;
    cout << C(n - k + 1, i) * ksm(i, k - i) % mod << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const int N = 2e5 + 5;
using namespace std;
ll f[N];
ll ksm(ll a, ll b) {
  ll ans = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1)
      ans = ans * a % mod;
  return ans;
}
void fac(int n) {
  f[0] = 1;
  f[1] = 1;
  for (int i = 2; i <= n; i++)
    f[i] = f[i - 1] * i % mod;
}
ll C(ll a, ll b) {
  return f[a] * ksm(f[b], mod - 2) % mod * ksm(f[a - b], mod - 2) % mod;
}
int main() {
  fac(2100);
  ll n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    if (i > n - k + 1)
      cout << 0 << endl;
    else {
      cout << C(n - k + 1, i) * C(k - 1, i - 1) % mod << endl;
    }
  }
  return 0;
}
Problem p02990 (C++)

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

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;
ll fac[2005];
ll rfac[2005];

ll P(ll a, ll x) {
  ll res = 1;
  while (x > 0) {
    if (x & 1)
      res = res * a % mod;

    a = a * a % mod;
    x >>= 1;
  }

  return res;
}

int main() {
  ll n, k;

  cin >> n >> k;
  fac[0] = 1;
  rfac[0] = 1;
  for (ll i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * i % mod;
  for (ll i = 1; i <= n; i++)
    rfac[i] = P(fac[i], mod - 2);

  for (ll i = 1; i <= k; i++) {
    /*   cout << fac[n-k+i] << endl;
    cout << rfac[i] << endl;
    cout << rfac[n-k+1-i] << endl;
    cout << fac[k-1] << endl;
    cout << rfac[k-i] << endl;
    cout << rfac[i-1] << endl;
    */ cout << fac[n - k + 1] * rfac[i] % mod * rfac[n - k + 1 - i] % mod *
                   fac[k - 1] % mod * rfac[k - i] % mod * rfac[i - 1] % mod
            << endl;
  }
}


Fixed submission:
#include <iostream>

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;
ll fac[2005];
ll rfac[2005];

ll P(ll a, ll x) {
  ll res = 1;
  while (x > 0) {
    if (x & 1)
      res = res * a % mod;

    a = a * a % mod;
    x >>= 1;
  }

  return res;
}

int main() {
  ll n, k;

  cin >> n >> k;
  fac[0] = 1;
  rfac[0] = 1;
  for (ll i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * i % mod;
  for (ll i = 1; i <= n; i++)
    rfac[i] = P(fac[i], mod - 2);

  for (ll i = 1; i <= k; i++) {
    /*   cout << fac[n-k+i] << endl;
    cout << rfac[i] << endl;
    cout << rfac[n-k+1-i] << endl;
    cout << fac[k-1] << endl;
    cout << rfac[k-i] << endl;
    cout << rfac[i-1] << endl;
    */
    if (n - k + 1 - i < 0)
      cout << 0 << endl;
    else {
      cout << fac[n - k + 1] * rfac[i] % mod * rfac[n - k + 1 - i] % mod *
                  fac[k - 1] % mod * rfac[k - i] % mod * rfac[i - 1] % mod
           << endl;
    }
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
// temprates
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>

using ll = long long;
using namespace std;

#define FOR(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define LFOR(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); i++)
#define FORR(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define LFORR(i, a, b) for (ll i = (int)(a); i >= (ll)(b); i--)
#define REP(i, n) FOR(i, 0, (int)(n)-1)
#define LREP(i, n) LFOR(i, 0, (ll)(n)-1)
#define REPR(i, n) FORR(i, (int)(n)-1, 0)
#define LREPR(i, n) LFORR(i, (ll)(n)-1, 0)

#define SIZ(v) int(v.size())
const int INF = 1e8;
const ll LINF = 1e15;
const ll MOD = 1e9 + 7;

vector<vector<ll>> cmemo;

ll combbi(int n, int k) {
  if (k == 0 || n == k)
    return cmemo[n][k] = 1;
  if (cmemo[n][k])
    return cmemo[n][k];
  if (n < k)
    return 0;
  return cmemo[n][k] = ((combbi(n - 1, k - 1) + combbi(n - 1, k)) % MOD);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  ll tmp;
  cin >> n >> k;
  cmemo.assign(n, vector<ll>(n, 0));
  FOR(i, 1, k) {
    if (i - 1 > n - k)
      tmp = 0;
    else
      tmp = (combbi(n - k + 1, n - k - i + 1) * combbi(k - 1, i - 1)) % MOD;
    cout << tmp << endl;
  }
}


Fixed submission:
// temprates
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>

using ll = long long;
using namespace std;

#define FOR(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define LFOR(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); i++)
#define FORR(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define LFORR(i, a, b) for (ll i = (int)(a); i >= (ll)(b); i--)
#define REP(i, n) FOR(i, 0, (int)(n)-1)
#define LREP(i, n) LFOR(i, 0, (ll)(n)-1)
#define REPR(i, n) FORR(i, (int)(n)-1, 0)
#define LREPR(i, n) LFORR(i, (ll)(n)-1, 0)

#define SIZ(v) int(v.size())
const int INF = 1e8;
const ll LINF = 1e15;
const ll MOD = 1e9 + 7;

vector<vector<ll>> cmemo;

ll combbi(int n, int k) {
  if (k == 0 || n == k)
    return cmemo[n][k] = 1;
  if (cmemo[n][k])
    return cmemo[n][k];
  if (n < k)
    return 0;
  return cmemo[n][k] = ((combbi(n - 1, k - 1) + combbi(n - 1, k)) % MOD);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  ll tmp;
  cin >> n >> k;
  cmemo.assign(n + 1, vector<ll>(n + 1, 0));
  FOR(i, 1, k) {
    if (i - 1 > n - k)
      tmp = 0;
    else
      tmp = (combbi(n - k + 1, n - k - i + 1) * combbi(k - 1, i - 1)) % MOD;
    cout << tmp << endl;
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define ll long long
#define eps 1e-7
#define all(x) ((x).begin()), ((x).end())
#define usecppio                                                               \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
using namespace std;

#define int ll
int mod = 1000000007;
int fact[3000];
int factinv[3000];

ll modpow(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 binom(int n, int r) {
  if (r == 0 || r == n)
    return 1;
  int a, b, c;
  a = fact[n];
  b = factinv[r];
  c = factinv[n - r];
  return ((((a * b) % mod) * c) % mod);
}

int32_t main() {
  usecppio int n, k, r;
  fact[0] = 1;
  factinv[0] = 1;
  for (int i = 1; i <= 2500; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= mod;
    factinv[i] = modpow(fact[i], mod - 2, mod);
  }
  cin >> n >> k;
  r = n - k;
  for (int i = 1; i <= k; i++) {
    int a = binom(r + 1, i);
    int b = binom(k - 1, i - 1);
    cout << (a * b) % mod << '\n';
  }
}


Fixed submission:
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define ll long long
#define eps 1e-7
#define all(x) ((x).begin()), ((x).end())
#define usecppio                                                               \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
using namespace std;

#define int ll
int mod = 1000000007;
int fact[3000];
int factinv[3000];

ll modpow(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 binom(int n, int r) {
  if (r > n)
    return 0;
  if (r < 0)
    return 0;
  if (r == 0 || r == n)
    return 1;
  int a, b, c;
  a = fact[n];
  b = factinv[r];
  c = factinv[n - r];
  return ((((a * b) % mod) * c) % mod);
}

int32_t main() {
  usecppio int n, k, r;
  fact[0] = 1;
  factinv[0] = 1;
  for (int i = 1; i <= 2500; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= mod;
    factinv[i] = modpow(fact[i], mod - 2, mod);
  }
  cin >> n >> k;
  r = n - k;
  for (int i = 1; i <= k; i++) {
    int a = binom(r + 1, i);
    int b = binom(k - 1, i - 1);
    cout << (a * b) % mod << '\n';
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 1; i <= n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ll MAX = 1e9 + 7;

ll fact[10003];

template <typename T> void factorial(T m) {
  fact[0] = 1;
  fact[1] = 1;
  for (int i = 2; i <= 10000; ++i) {
    fact[i] = fact[i - 1] * i % m;
  }
}
template <typename T> T Pow(T x, T n, T m) {
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return Pow(x * x % m, n / 2, m);
  else
    return x * Pow(x, n - 1, m) % m;
}
template <typename T> T combination(T n, T k, T m) {
  return fact[n] * Pow<T>(fact[k], m - 2, m) % m *
         Pow<T>(fact[n - k], m - 2, m) % m;
}

int main() {
  ll n, k;
  cin >> n >> k;
  factorial<ll>(MOD);
  REP(i, k) {
    if (n - k + 1 >= 1) {
      cout << combination<ll>(n - k + 1, i, MOD) *
                  combination<ll>(k - 1, i - 1, MOD) % MOD
           << endl;
    } else
      cout << 0 << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 1; i <= n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ll MAX = 1e9 + 7;

ll fact[10003];

template <typename T> void factorial(T m) {
  fact[0] = 1;
  fact[1] = 1;
  for (int i = 2; i <= 10000; ++i) {
    fact[i] = fact[i - 1] * i % m;
  }
}
template <typename T> T Pow(T x, T n, T m) {
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return Pow(x * x % m, n / 2, m);
  else
    return x * Pow(x, n - 1, m) % m;
}
template <typename T> T combination(T n, T k, T m) {
  return fact[n] * Pow<T>(fact[k], m - 2, m) % m *
         Pow<T>(fact[n - k], m - 2, m) % m;
}

int main() {
  ll n, k;
  cin >> n >> k;
  factorial<ll>(MOD);
  REP(i, k) {
    if (n - k + 1 >= i) {
      cout << combination<ll>(n - k + 1, i, MOD) *
                  combination<ll>(k - 1, i - 1, MOD) % MOD
           << endl;
    } else
      cout << 0 << endl;
  }
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
const int MOD = 1000000007;
const int MAX = 2000;

long long mod(long long a) {
  a %= MOD;
  return a >= 0 ? a : a + MOD;
}

long long inverse[MAX + 1];
long long factorial[MAX + 1];
long long factorial_inverse[MAX + 1];

void calc(int n) {
  inverse[1] = 1;
  factorial[0] = factorial[1] = 1;
  factorial_inverse[0] = factorial_inverse[1] = 1;
  for (int i = 2; i <= n; i++) {
    inverse[i] = MOD - inverse[MOD % i] * (MOD / i) % MOD;
    factorial[i] = i * factorial[i - 1] % MOD;
    factorial_inverse[i] = inverse[i] * factorial_inverse[i - 1] % MOD;
  }
}

long long comb(long long n, long long k) {
  return factorial[n] *
         (factorial_inverse[k] * factorial_inverse[n - k] % MOD) % MOD;
}

long long rep_comb(long long n, long long k) { return comb(n + k - 1, k); }

int main() {
  long long n, k;
  cin >> n >> k;
  calc(n);
  for (int i = 1; i <= k; i++) {
    long long ans;
    ans = rep_comb(i, k - i);
    ans = mod(ans * rep_comb(i + 1, n - k - (i - 1)));
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
const int MOD = 1000000007;
const int MAX = 2000;

long long mod(long long a) {
  a %= MOD;
  return a >= 0 ? a : a + MOD;
}

long long inverse[MAX + 1];
long long factorial[MAX + 1];
long long factorial_inverse[MAX + 1];

void calc(int n) {
  inverse[1] = 1;
  factorial[0] = factorial[1] = 1;
  factorial_inverse[0] = factorial_inverse[1] = 1;
  for (int i = 2; i <= n; i++) {
    inverse[i] = MOD - inverse[MOD % i] * (MOD / i) % MOD;
    factorial[i] = i * factorial[i - 1] % MOD;
    factorial_inverse[i] = inverse[i] * factorial_inverse[i - 1] % MOD;
  }
}

long long comb(long long n, long long k) {
  return factorial[n] *
         (factorial_inverse[k] * factorial_inverse[n - k] % MOD) % MOD;
}

long long rep_comb(long long n, long long k) { return comb(n + k - 1, k); }

int main() {
  long long n, k;
  cin >> n >> k;
  calc(n);
  for (int i = 1; i <= k; i++) {
    long long ans;
    ans = rep_comb(i, k - i);
    if (n - k - (i - 1) < 0)
      ans = 0;
    else
      ans = mod(ans * rep_comb(i + 1, n - k - (i - 1)));
    cout << ans << endl;
  }
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#define llint long long
#define mod 1000000007

using namespace std;

llint n, k;

const int FACT_MAX = 200005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n) {
  if (n == 0)
    return 1;
  if (n % 2) {
    return ((a % mod) * (modpow(a, n - 1) % mod)) % mod;
  } else {
    return modpow((a * a) % mod, n / 2) % mod;
  }
}

void make_fact() {
  llint val = 1;
  fact[0] = 1;
  for (int i = 1; i < FACT_MAX; i++) {
    val *= i;
    val %= mod;
    fact[i] = val;
  }
  fact_inv[FACT_MAX - 1] = modpow(fact[FACT_MAX - 1], mod - 2);
  for (int i = FACT_MAX - 2; i >= 0; i--) {
    fact_inv[i] = fact_inv[i + 1] * (i + 1) % mod;
  }
}

llint comb(llint n, llint k) {
  llint ret = 1;
  ret *= fact[n];
  ret *= fact_inv[k], ret %= mod;
  ret *= fact_inv[n - k], ret %= mod;
  return ret;
}

int main(void) {
  cin >> n >> k;
  make_fact();
  for (int i = 1; i <= k; i++) {
    if (n - k + 1 < 0)
      cout << 0 << endl;
    else
      cout << comb(k - 1, i - 1) * comb(n - k + 1, i) % mod << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#define llint long long
#define mod 1000000007

using namespace std;

llint n, k;

const int FACT_MAX = 200005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n) {
  if (n == 0)
    return 1;
  if (n % 2) {
    return ((a % mod) * (modpow(a, n - 1) % mod)) % mod;
  } else {
    return modpow((a * a) % mod, n / 2) % mod;
  }
}

void make_fact() {
  llint val = 1;
  fact[0] = 1;
  for (int i = 1; i < FACT_MAX; i++) {
    val *= i;
    val %= mod;
    fact[i] = val;
  }
  fact_inv[FACT_MAX - 1] = modpow(fact[FACT_MAX - 1], mod - 2);
  for (int i = FACT_MAX - 2; i >= 0; i--) {
    fact_inv[i] = fact_inv[i + 1] * (i + 1) % mod;
  }
}

llint comb(llint n, llint k) {
  llint ret = 1;
  ret *= fact[n];
  ret *= fact_inv[k], ret %= mod;
  ret *= fact_inv[n - k], ret %= mod;
  return ret;
}

int main(void) {
  cin >> n >> k;
  make_fact();
  for (int i = 1; i <= k; i++) {
    if (n - k < i - 1)
      cout << 0 << endl;
    else
      cout << comb(k - 1, i - 1) * comb(n - k + 1, i) % mod << endl;
  }
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;

ll ex_euclid(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll d = ex_euclid(b, a % b, y, x);
  y -= a / b * x;
  return d;
}

ll modinv(ll a, ll p) {
  ll x, y, d;
  d = ex_euclid(a, p, x, y);
  assert(d == 1);
  return ((x % MOD) + MOD) % MOD;
}

const int maxN = 4000;
ll fac[maxN], inv[maxN], finv[maxN];

// O(N) precomputation
void modnCk_init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < maxN; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    //    inv[i] = modinv(i, MOD); // O(logN)
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; // O(1)
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// O(1) with O(N) precomputation
ll modnCk(int n, int k) {
  if (n < k)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(int argc, const char *argv[]) {
  int N, K;
  cin >> N >> K;
  ll red, blue;
  int nb, kb, nr, kr;
  modnCk_init();
  for (int i = 1; i <= K; i++) {
    nb = K - 1;
    kb = K - i;
    blue = modnCk(nb, kb);
    nr = N - K + 1;
    kr = N - K - i + 1;
    red = modnCk(nr, kr);
    cout << blue * red % MOD << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;

ll ex_euclid(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll d = ex_euclid(b, a % b, y, x);
  y -= a / b * x;
  return d;
}

ll modinv(ll a, ll p) {
  ll x, y, d;
  d = ex_euclid(a, p, x, y);
  assert(d == 1);
  return ((x % MOD) + MOD) % MOD;
}

const int maxN = 4000;
ll fac[maxN], inv[maxN], finv[maxN];

// O(N) precomputation
void modnCk_init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < maxN; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    //    inv[i] = modinv(i, MOD); // O(logN)
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; // O(1)
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// O(1) with O(N) precomputation
ll modnCk(int n, int k) {
  if (k < 0)
    return 0;
  if (n < k)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(int argc, const char *argv[]) {
  int N, K;
  cin >> N >> K;
  ll red, blue;
  int nb, kb, nr, kr;
  modnCk_init();
  for (int i = 1; i <= K; i++) {
    nb = K - 1;
    kb = K - i;
    blue = modnCk(nb, kb);
    nr = N - K + 1;
    kr = N - K - i + 1;
    red = modnCk(nr, kr);
    cout << blue * red % MOD << endl;
  }

  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <numeric>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
// #define ll long long
typedef long long ll;
typedef pair<int, int> P;

// std::vector<std::vector<long long>> v(n + 1,std::vector<long long>(n + 1,
// 0));

std::vector<std::vector<long>> v(2019, std::vector<long>(2019, 0));

long mod = 1000000007;

long nCr(long n, long r) {
  if (v[n][r] != 0) {
    return v[n][r];
  }

  return v[n][r] = (nCr(n - 1, r - 1) + nCr(n - 1, r)) % mod;
}

int main(int argc, const char *argv[]) {

  int n, k;
  cin >> n >> k;

  for (int i = 0; i <= n; i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }

  repd(i, 1, k + 1) {
    ll ans = nCr(n - k + 1, i) * nCr(k - 1, i - 1);
    cout << ans % mod << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <numeric>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
// #define ll long long
typedef long long ll;
typedef pair<int, int> P;

// std::vector<std::vector<long long>> v(n + 1,std::vector<long long>(n + 1,
// 0));

std::vector<std::vector<long>> v(2019, std::vector<long>(2019, 0));

long mod = 1000000007;

long nCr(long n, long r) {
  if (v[n][r] != 0) {
    return v[n][r];
  }

  return v[n][r] = (nCr(n - 1, r - 1) + nCr(n - 1, r)) % mod;
}

int main(int argc, const char *argv[]) {

  int n, k;
  cin >> n >> k;

  for (int i = 0; i <= n; i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }

  repd(i, 1, k + 1) {

    if ((n - k + 1) < i) {
      cout << 0 << endl;
      continue;
    }
    ll ans = nCr(n - k + 1, i) * nCr(k - 1, i - 1);
    cout << ans % mod << endl;
  }

  return 0;
}
Problem p02990 (C++)

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

const long long MOD = 1e9 + 7;
const long long MAX = 1e6;
long long fact[MAX + 1] = {0};

void fact_init() {
  fact[0] = 1;
  for (long long i = 1; i <= MAX; i++) {
    fact[i] = (fact[i - 1] * i % MOD) % MOD;
  }
}

long long repeat_fact(long long N, long long P) {
  if (P == 0)
    return 1;
  if (P % 2 == 0) {
    long long t = repeat_fact(N, P / 2);
    return (t % MOD * t % MOD) % MOD;
  } else
    return (N % MOD * repeat_fact(N, P - 1)) % MOD;
}

long long combination(long long n, long long k) {
  long long fact1 = fact[n];
  long long fact2 = repeat_fact(fact[k], MOD - 2);
  long long fact3 = repeat_fact(fact[n - k], MOD - 2);
  long long ans = ((fact1 * fact2) % MOD * fact3) % MOD;
  return ans;
}

void solve(long long N, long long K) {
  int r = 1;
  for (int i = N - K + 1; i <= N; i++) {
    cout << combination(N - K + 1, r) * combination(K - 1, r - 1) % MOD << endl;
    r++;
  }
}

// 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)
int main() {
  long long N;
  cin >> N;
  long long K;
  cin >> K;
  fact_init();
  solve(N, K);
  return 0;
}


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

const long long MOD = 1e9 + 7;
const long long MAX = 1e6;
long long fact[MAX + 1] = {0};

void fact_init() {
  fact[0] = 1;
  for (long long i = 1; i <= MAX; i++) {
    fact[i] = (fact[i - 1] * i % MOD) % MOD;
  }
}

long long repeat_fact(long long N, long long P) {
  if (P == 0)
    return 1;
  if (P % 2 == 0) {
    long long t = repeat_fact(N, P / 2);
    return (t % MOD * t % MOD) % MOD;
  } else
    return (N % MOD * repeat_fact(N, P - 1)) % MOD;
}

long long combination(long long n, long long k) {
  long long fact1 = fact[n];
  long long fact2 = repeat_fact(fact[k], MOD - 2);
  long long fact3 = repeat_fact(fact[n - k], MOD - 2);
  long long ans = ((fact1 * fact2) % MOD * fact3) % MOD;
  return ans;
}

void solve(long long N, long long K) {
  for (long long i = 1; i <= K; i++) {
    if (i > N - K + 1) {
      cout << 0 << endl;
    } else {
      cout << combination(N - K + 1, i) * combination(K - 1, i - 1) % MOD
           << endl;
    }
  }
}

// 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)
int main() {
  long long N;
  cin >> N;
  long long K;
  cin >> K;
  fact_init();
  solve(N, K);
  return 0;
}
Problem p02990 (C++)

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

const int MOD = 1e+9 + 7;

int main() {
  int N, K;
  cin >> N >> K;

  // C[i][j]: iをj個に分割する仕方(分割数)
  vector<vector<long long>> C(N, vector<long long>(N));
  for (int i = 0; i < N; ++i) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j < i; ++j) {
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
    }
  }

  for (int i = 1; i <= K; ++i) {
    cout << (C[N - K + 1][i] * C[K - 1][i - 1]) % MOD << endl;
  }

  return 0;
}

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

const int MOD = 1e+9 + 7;

int main() {
  int N, K;
  cin >> N >> K;

  // C[i][j]: iをj個に分割する仕方(分割数)
  vector<vector<long long>> C(N + 1, vector<long long>(N + 1));
  for (int i = 0; i <= N; ++i) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j < i; ++j) {
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
    }
  }

  for (int i = 1; i <= K; ++i) {
    cout << (C[N - K + 1][i] * C[K - 1][i - 1]) % MOD << endl;
  }

  return 0;
}
Problem p02990 (C++)

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

using namespace std;

const int MOD = 1000000007;

long N = 2000, K = 2000;
long DP_SIZE_N = N + 1;
long DP_SIZE_K = K + 1;

// 全体計算
// nCk
vector<vector<long>> DP;

void init() {
  DP.resize(DP_SIZE_N);
  for (int i = 0; i < DP_SIZE_N; ++i) {
    DP[i].resize(DP_SIZE_K);
  }
}

void calc_Combination() {
  DP[0][0] = 1;
  for (int i = 1; i <= N; ++i) {
    DP[i][0] = 1;
    for (int j = 1; j <= min(long(i), K); ++j) {
      DP[i][j] = (DP[i - 1][j - 1] + DP[i - 1][j]) % MOD;
    }
    for (int j = min(long(i), K) + 1; j <= K; ++j) {
      DP[i][j] = 0;
    }
  }
}

int main() {
  cin >> N >> K;
  DP_SIZE_N = N + 1;
  DP_SIZE_K = K + 1;
  init();
  calc_Combination();
  // cout<<DP[N][K]<<endl;

  for (int i = 1; i <= K; ++i) {
    long ans_l = DP[N - K - 1][i - 1 + 1 - 1];
    long ans_r = DP[N - K - 1][i - 1 + 1 - 1];
    long ans_lr = DP[N - K - 1][i - 1 + 2 - 1];
    long ans;
    if (i == 1) {
      ans = 0;
    } else {
      ans = DP[N - K - 1][i - 1 + 0 - 1];
    }
    long ans_sum = (ans_l + ans_r + ans_lr + ans) % MOD;
    // cout<<ans_l<<" "<<ans_r<<" "<<ans_lr<<" "<<ans<<endl;
    // cout<<DP[K-1][i-1]<<endl;
    cout << (DP[K - 1][i - 1] * ans_sum) % MOD << endl;
  }

  return 0;
}


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

using namespace std;

const int MOD = 1000000007;

long N = 2000, K = 2000;
long DP_SIZE_N = N + 1;
long DP_SIZE_K = K + 1;

// 全体計算
// nCk
vector<vector<long>> DP;

void init() {
  DP.resize(DP_SIZE_N);
  for (int i = 0; i < DP_SIZE_N; ++i) {
    DP[i].resize(DP_SIZE_K);
  }
}

void calc_Combination() {
  DP[0][0] = 1;
  for (int i = 1; i <= N; ++i) {
    DP[i][0] = 1;
    for (int j = 1; j <= min(long(i), K); ++j) {
      DP[i][j] = (DP[i - 1][j - 1] + DP[i - 1][j]) % MOD;
    }
    for (int j = min(long(i), K) + 1; j <= K; ++j) {
      DP[i][j] = 0;
    }
  }
}

int main() {
  cin >> N >> K;
  DP_SIZE_N = N + 1;
  DP_SIZE_K = K + 1;
  init();
  calc_Combination();
  // cout<<DP[N][K]<<endl;

  if (N == K) {
    cout << 1 << endl;
    for (int i = 2; i <= K; ++i) {
      cout << 0 << endl;
    }
    return 0;
  }

  for (int i = 1; i <= K; ++i) {
    long ans_l = DP[N - K - 1][i - 1 + 1 - 1];
    long ans_r = DP[N - K - 1][i - 1 + 1 - 1];
    long ans_lr = DP[N - K - 1][i - 1 + 2 - 1];
    long ans;
    if (i == 1) {
      ans = 0;
    } else {
      ans = DP[N - K - 1][i - 1 + 0 - 1];
    }
    long ans_sum = (ans_l + ans_r + ans_lr + ans) % MOD;
    // cout<<ans_l<<" "<<ans_r<<" "<<ans_lr<<" "<<ans<<endl;
    // cout<<DP[K-1][i-1]<<endl;
    cout << (DP[K - 1][i - 1] * ans_sum) % MOD << endl;
  }

  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#define ll long long
using namespace std;
ll mod = 1e9 + 7, ans, c[2002][2002];
int n, k;
void pre() {
  c[0][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= i; j++) {
      if (i == j || j == 0)
        c[i][j] = 1;
      else
        c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
    }
}
int main() {
  scanf("%d%d", &n, &k);
  pre();
  for (int i = 1; i <= k; i++) {
    ans = (c[n - k - 1][i - 2] + (2 * c[n - k - 1][i - 1]) % mod +
           c[n - k - 1][i]) %
          mod;
    ans = (c[k - 1][i - 1] * ans) % mod;
    printf("%lld\n", ans);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#define ll long long
using namespace std;
ll mod = 1e9 + 7, ans, c[2002][2002];
int n, k;
void pre() {
  c[0][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= i; j++) {
      if (i == j || j == 0)
        c[i][j] = 1;
      else
        c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
    }
}
int main() {
  scanf("%d%d", &n, &k);
  pre();
  for (int i = 1; i <= k; i++) { // c[n-k-1][i-2]+(2*c[n-k-1][i-1])%mod+
    ans = (c[n - k + 1][i] * c[k - 1][i - 1]) % mod;
    printf("%lld\n", ans);
  }
  return 0;
}
Problem p02990 (C++)

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef array<int, 2> duo;
typedef long double ld;

template <class T> istream &operator>>(istream &I, vector<T> &v) {
  for (T &e : v)
    I >> e;
  return I;
}
template <class T> ostream &operator<<(ostream &O, const vector<T> &v) {
  for (const T &e : v)
    O << e << ' ';
  return O;
}

const int MOD = 1E9 + 7, N = 2001;
ll fact[N];
ll exp(int a, int n) {
  if (n == 0)
    return 1;
  ll b = exp(a, n / 2);
  (b *= b) %= MOD;
  if (n & 1)
    (b *= a) %= MOD;
  return b;
}

ll C(int n, int k) {
  return fact[n] * exp(fact[k], MOD - 2) % MOD * exp(fact[n - k], MOD - 2) %
         MOD;
}

void _main() {
  fact[0] = 1;
  int blue, n;
  cin >> n >> blue;
  int red = n - blue;
  for (int i = 1; i <= n; i++)
    fact[i] = fact[i - 1] * i % MOD;
  for (int i = 1; i <= blue; i++) {
    cout << C(red + 1, i) * C(blue - 1, i - 1) % MOD << '\n';
  }
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //        freopen("input.txt", "r", stdin);
  int _t = 1;
  //        cin >> _t;
  while (_t--)
    _main();
  return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef array<int, 2> duo;
typedef long double ld;

template <class T> istream &operator>>(istream &I, vector<T> &v) {
  for (T &e : v)
    I >> e;
  return I;
}
template <class T> ostream &operator<<(ostream &O, const vector<T> &v) {
  for (const T &e : v)
    O << e << ' ';
  return O;
}

const int MOD = 1E9 + 7, N = 2001;
ll fact[N];
ll exp(int a, int n) {
  if (n == 0)
    return 1;
  ll b = exp(a, n / 2);
  (b *= b) %= MOD;
  if (n & 1)
    (b *= a) %= MOD;
  return b;
}

ll C(int n, int k) {
  if (k > n)
    return 0;
  return fact[n] * exp(fact[k], MOD - 2) % MOD * exp(fact[n - k], MOD - 2) %
         MOD;
}

void _main() {
  fact[0] = 1;
  int blue, n;
  cin >> n >> blue;
  int red = n - blue;
  for (int i = 1; i <= n; i++)
    fact[i] = fact[i - 1] * i % MOD;
  for (int i = 1; i <= blue; i++) {
    cout << C(red + 1, i) * C(blue - 1, i - 1) % MOD << '\n';
  }
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //        freopen("input.txt", "r", stdin);
  int _t = 1;
  //        cin >> _t;
  while (_t--)
    _main();
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
static const uint64_t MOD = 1000000007LL;
// uint64_t dp[100005][13];

/* nCk == (n-1)C(k-1) + (n-1)Ck*/
// long mem[4000][4000];
// long combi(int n, int k)
// {
//     if (mem[n][k])
//         return mem[n][k];
//     long ret = 0;
//     if ((k == 0) || (n <= k)) {
//         ret = 1;
//     } else {
//         ret = (combi(n - 1, k - 1) + combi(n - 1, k)) % MOD;
//     }
//
//     mem[n][k] = ret;
//     return ret;
// }

int dp[2001][2001];
long combi(int n, int r) {
  if (n == r)
    return dp[n][r] = 1;
  if (r == 0)
    return dp[n][r] = 1;
  if (r == 1)
    return dp[n][r] = n;
  if (dp[n][r])
    return dp[n][r];
  dp[n][r] = (combi(n - 1, r) % MOD + combi(n - 1, r - 1) % MOD) % MOD;
  return dp[n][r];
}

int main() {
  int n, k; /* k: Bule */
  cin >> n >> k;

  for (int i = 1; i <= k; i++) {
    long cnt = ((long)combi(k - 1, i - 1) * combi(n - k + 1, i)) % MOD;
    cout << cnt << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
static const uint64_t MOD = 1000000007LL;
// uint64_t dp[100005][13];

/* nCk == (n-1)C(k-1) + (n-1)Ck*/
// long mem[4000][4000];
// long combi(int n, int k)
// {
//     if (mem[n][k])
//         return mem[n][k];
//     long ret = 0;
//     if ((k == 0) || (n <= k)) {
//         ret = 1;
//     } else {
//         ret = (combi(n - 1, k - 1) + combi(n - 1, k)) % MOD;
//     }
//
//     mem[n][k] = ret;
//     return ret;
// }

int dp[2001][2001];
long combi(int n, int r) {
  if (n == r)
    return dp[n][r] = 1;
  if (r == 0)
    return dp[n][r] = 1;
  if (r == 1)
    return dp[n][r] = n;
  if (dp[n][r])
    return dp[n][r];
  dp[n][r] = (combi(n - 1, r) % MOD + combi(n - 1, r - 1) % MOD) % MOD;
  return dp[n][r];
}

int main() {
  int n, k; /* k: Bule */
  cin >> n >> k;

  for (int i = 1; i <= k; i++) {
    if (i > (n - k + 1)) {
      puts("0");
    } else {
      long cnt = ((long)combi(k - 1, i - 1) * combi(n - k + 1, i)) % MOD;
      cout << cnt << endl;
    }
  }
}
Problem p02990 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using ll = long long;
const ll MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
int get_gcd(int a, int b) {
  while (1) {
    if (a < b)
      swap(a, b);
    if (b == 0)
      return a;
    a %= b;
  }
}
int get_lcm(int a, int b) { return a * b / get_gcd(a, b); }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

// 組み合わせnCrをMODで割った時の余り
ll c[2001][2001];

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

  // 組み合わせnCr (0<=n<=2000, 0<=r<=n)を動的計画法で計算する
  // まずc[i][i] = 1, c[i][0] = 1とする。
  // 次にc[i][j]について、c[i][j] = c[i-1][j] + c[i-1][j-1]を用いて算出する。
  for (int i = 0; i <= 2000; n++) {
    c[i][i] = 1;
    c[i][0] = 1;
  }
  for (int i = 2; i <= 2000; i++) {
    for (int j = 1; j < i; j++) {
      c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD;
    }
  }

  // 各i (1<=i<=k)について、解はc[k-1][i-1]*c[n-k+1][i]
  for (int i = 1; i <= k; i++) {
    cout << (c[k - 1][i - 1] * c[n - k + 1][i]) % MOD << endl;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using ll = long long;
const ll MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
int get_gcd(int a, int b) {
  while (1) {
    if (a < b)
      swap(a, b);
    if (b == 0)
      return a;
    a %= b;
  }
}
int get_lcm(int a, int b) { return a * b / get_gcd(a, b); }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

// 組み合わせnCrをMODで割った時の余り
ll c[2001][2001];

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

  // 組み合わせnCr (0<=n<=2000, 0<=r<=n)を動的計画法で計算する
  // まずc[i][i] = 1, c[i][0] = 1とする。
  // 次にc[i][j]について、c[i][j] = c[i-1][j] + c[i-1][j-1]を用いて算出する。
  for (int i = 0; i <= 2000; i++) {
    c[i][i] = 1;
    c[i][0] = 1;
  }
  for (int i = 2; i <= 2000; i++) {
    for (int j = 1; j < i; j++) {
      c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD;
    }
  }

  // 各i (1<=i<=k)について、解はc[k-1][i-1]*c[n-k+1][i]
  for (int i = 1; i <= k; i++) {
    cout << (c[k - 1][i - 1] * c[n - k + 1][i]) % MOD << endl;
  }

  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define M 2005
#define mod 1000000007
long long n, k, C[M][M];
int main() {
  cin >> n >> k;
  int m = n - k;
  for (int i = 1; i < M; i++) {
    C[i][i] = C[i][0] = 1;
    for (int j = 1; j < i; j++)
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
  }
  printf("%lld\n", (C[m - 1][1] + 2 * C[m - 1][0]) % mod * C[k - 1][0] % mod);
  for (int i = 2; i <= k; i++)
    printf("%lld\n", (C[m - 1][i] + 2 * C[m - 1][i - 1] + C[m - 1][i - 2]) %
                         mod * C[k - 1][i - 1] % mod);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define M 2005
#define mod 1000000007
long long n, k, C[M][M];
int main() {
  cin >> n >> k;
  int m = n - k;
  if (m == 0) {
    for (int i = 1; i <= k; i++)
      if (i == 1)
        puts("1");
      else
        puts("0");
    return 0;
  }
  for (int i = 1; i < M; i++) {
    C[i][i] = C[i][0] = 1;
    for (int j = 1; j < i; j++)
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
  }
  printf("%lld\n", (C[m - 1][1] + 2 * C[m - 1][0]) % mod * C[k - 1][0] % mod);
  for (int i = 2; i <= k; i++)
    printf("%lld\n", (C[m - 1][i] + 2 * C[m - 1][i - 1] + C[m - 1][i - 2]) %
                         mod * C[k - 1][i - 1] % mod);
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 2005, mod = 1000000007;
ll pr[N], pi[N];
ll power(ll x, ll y) {
  ll re = 1;
  while (y > 0) {
    if (y % 2)
      re = re * x % mod;
    y = y / 2;
    x = x * x % mod;
  }
  return re;
}
ll ncr(ll n, ll r) { return ((pr[n] * pi[r]) % mod) * pi[n - r] % mod; }
int main() {
  ll n, k;
  cin >> n >> k;
  pr[0] = 1;
  pi[0] = 1;
  for (ll i = 1; i < N; i++) {
    pr[i] = i * pr[i - 1] % mod;
    pi[i] = power(pr[i], mod - 2);
  }
  // for(ll i=1;i<=n;i++)cout<<pr[i]<<" ";cout<<endl;
  // for(ll i=1;i<=n;i++)cout<<pi[i]<<" ";cout<<endl;
  for (ll i = 1; i <= k; i++) {
    ll ans = ncr(n - k + 1, i) * ncr(k - 1, i - 1) % mod;
    cout << ans << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 2005, mod = 1000000007;
ll pr[N], pi[N];
ll power(ll x, ll y) {
  ll re = 1;
  while (y > 0) {
    if (y % 2)
      re = re * x % mod;
    y = y / 2;
    x = x * x % mod;
  }
  return re;
}
ll ncr(ll n, ll r) { return ((pr[n] * pi[r]) % mod) * pi[n - r] % mod; }
int main() {
  ll n, k;
  cin >> n >> k;
  pr[0] = 1;
  pi[0] = 1;
  for (ll i = 1; i < N; i++) {
    pr[i] = i * pr[i - 1] % mod;
    pi[i] = power(pr[i], mod - 2);
  }
  // for(ll i=1;i<=n;i++)cout<<pr[i]<<" ";cout<<endl;
  // for(ll i=1;i<=n;i++)cout<<pi[i]<<" ";cout<<endl;
  for (ll i = 1; i <= k; i++) {
    ll ans = 0;
    if (n - k + 1 >= i)
      ans = ncr(n - k + 1, i) * ncr(k - 1, i - 1) % mod;
    cout << ans << endl;
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
const int SZ = 2005;
ll combi[SZ][SZ];
ll dp(int a, int b) {
  if (a == b)
    return 1LL;
  if (b == 0)
    return 1LL;
  if (combi[a][b] != 0LL)
    return combi[a][b];
  return combi[a][b] = (dp(a - 1, b - 1) + dp(a - 1, b)) % MOD;
}
int main(void) {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    printf("%lld\n", dp(m - 1, i - 1) * dp(n - m + 1, i) % MOD);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
const int SZ = 2005;
ll combi[SZ][SZ];
ll dp(int a, int b) {
  if (a < b)
    return 0LL;
  if (a == b)
    return 1LL;
  if (b == 0)
    return 1LL;
  if (combi[a][b] != 0LL)
    return combi[a][b];
  return combi[a][b] = (dp(a - 1, b - 1) + dp(a - 1, b)) % MOD;
}
int main(void) {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    printf("%lld\n", dp(m - 1, i - 1) * dp(n - m + 1, i) % MOD);
  }
  return 0;
}
Problem p02990 (C++)

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

const ll mod = 1e9 + 7;
const ll nmax = 2005;
ll facts[nmax];

void calc_fact() {
  facts[0] = 1;
  for (ll i = 1; i < nmax; i++) {
    facts[i] = facts[i - 1] * i % mod;
  }
}

ll powmod(ll a, ll b) {
  ll ans = 1;
  while (b) {
    if (b % 2) {
      ans *= a;
      ans %= mod;
    }
    a *= a;
    a %= mod;
    b /= 2;
  }
  return ans;
}

ll comb(ll a, ll b) {
  return facts[a] * powmod(facts[b], mod - 2) % mod *
         powmod(facts[a - b], mod - 2) % mod;
}

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

  calc_fact();

  for (ll 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;
using ll = long long;

const ll mod = 1e9 + 7;
const ll nmax = 2005;
ll facts[nmax];

void calc_fact() {
  facts[0] = 1;
  for (ll i = 1; i < nmax; i++) {
    facts[i] = facts[i - 1] * i % mod;
  }
}

ll powmod(ll a, ll b) {
  ll ans = 1;
  while (b) {
    if (b % 2) {
      ans *= a;
      ans %= mod;
    }
    a *= a;
    a %= mod;
    b /= 2;
  }
  return ans;
}

ll comb(ll a, ll b) {
  return facts[a] * powmod(facts[b], mod - 2) % mod *
         powmod(facts[a - b], mod - 2) % mod;
}

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

  calc_fact();

  for (ll i = 1; i <= k; i++) {
    if (n - k + 1 >= i) {
      cout << comb(n - k + 1, i) * comb(k - 1, i - 1) % mod << endl;
    } else {
      cout << 0 << endl;
    }
  }

  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, K;
ll f[2001];

ll pw(ll x, int y) {
  ll a = 1;
  while (y) {
    if (y & 1) {
      a = a * x % mod;
    }
    x = x * x % mod;
    y /= 2;
  }
  return a;
}

ll modinv(ll x) { return pw(x, mod - 2); }

ll comb(int n, int r) {
  return f[n] * modinv(f[r]) % mod * modinv(f[n - r]) % mod;
}

int main() {
  f[0] = 1;
  for (int i = 1; i <= 2000; ++i) {
    f[i] = f[i - 1] * i % mod;
  }
  cin >> N >> K;
  for (int i = 1; i <= K; ++i) {
    cout << comb(N - K + 1, i) * comb(K - 1, i - 1) % mod << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, K;
ll f[2001];

ll pw(ll x, int y) {
  ll a = 1;
  while (y) {
    if (y & 1) {
      a = a * x % mod;
    }
    x = x * x % mod;
    y /= 2;
  }
  return a;
}

ll modinv(ll x) { return pw(x, mod - 2); }

ll comb(int n, int r) {
  if (n < r)
    return 0;
  return f[n] * modinv(f[r]) % mod * modinv(f[n - r]) % mod;
}

int main() {
  f[0] = 1;
  for (int i = 1; i <= 2000; ++i) {
    f[i] = f[i - 1] * i % mod;
  }
  cin >> N >> K;
  for (int i = 1; i <= K; ++i) {
    cout << comb(N - K + 1, i) * comb(K - 1, i - 1) % mod << endl;
  }
}