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

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

typedef unsigned long long ll;

const ll MOD = 1e9 + 7;

ll ModPow(ll base, ll exp, ll mod) {
  ll ret = 1;
  base %= mod;
  while (exp > 0) {
    if (exp & 1)
      ret = (ret * base) % mod;
    base = (base * base) % mod;
    exp >>= 1;
  }
  return ret;
}

ll ModInv(ll base, ll mod) { return ModPow(base, mod - 2, mod); }

ll Comb(ll n, ll r, ll fct[][4001]) {
  assert(n > 2000);
  return fct[0][n] * (fct[1][r] * fct[1][n - r] % MOD) % MOD;
}

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

  ll fct[2][4001];
  fct[0][0] = fct[0][1] = 1;
  for (ll i = 2; i <= n; fct[0][i] %= MOD, i++)
    fct[0][i] = fct[0][i - 1] * (i % MOD);

  for (ll i = 0; i <= n; i++)
    fct[1][i] = ModPow(fct[0][i], MOD - 2, MOD);

  for (ll i = 0; i < k; i++)
    cout << (Comb(k - 1, i, fct) * Comb(n - k + 1, i + 1, fct)) % MOD << endl;
  return 0;
}

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

typedef unsigned long long ll;

const ll MOD = 1e9 + 7;

ll ModPow(ll base, ll exp, ll mod) {
  ll ret = 1;
  base %= mod;
  while (exp > 0) {
    if (exp & 1)
      ret = (ret * base) % mod;
    base = (base * base) % mod;
    exp >>= 1;
  }
  return ret;
}

ll ModInv(ll base, ll mod) { return ModPow(base, mod - 2, mod); }

ll Comb(ll n, ll r, ll fct[][4001]) {
  assert(n <= 2000);
  return fct[0][n] * (fct[1][r] * fct[1][n - r] % MOD) % MOD;
}

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

  ll fct[2][4001];
  fct[0][0] = fct[0][1] = 1;
  for (ll i = 2; i <= n; fct[0][i] %= MOD, i++)
    fct[0][i] = fct[0][i - 1] * (i % MOD);

  for (ll i = 0; i <= n; i++)
    fct[1][i] = ModPow(fct[0][i], MOD - 2, MOD);

  for (ll i = 0; i < k; i++)
    cout << (Comb(k - 1, i, fct) * Comb(n - k + 1, i + 1, fct)) % 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;

ll fct[2001], inv[2001], fill[1000];

inline ll ModPow(ll base, ll exp, ll mod) {
  ll ret = 1;
  base %= mod;
  while (exp > 0) {
    if (exp & 1)
      ret = (ret * base) % mod;
    base = (base * base) % mod;
    exp >>= 1;
  }
  return ret;
}

inline void Fct(ll N) {
  fct[0] = fct[1] = 1;
  for (ll i = 2; i <= N; fct[i] %= MOD, i++)
    fct[i] = fct[i - 1] * (i % MOD);
}

inline void ModInv(ll N) {
  Fct(N);
  inv[N] = ModPow(fct[N], MOD - 2, MOD);
  for (ll i = N - 1; i >= 0; inv[i] %= MOD, i--)
    inv[i] = inv[i + 1] * (i + 1);
}

inline ll Comb(ll n, ll r) {
  return fct[n] * (inv[r] * inv[n - r] % MOD) % MOD;
}

int main() {
  ll n, k;
  cin >> n >> k;
  ModInv(n);
  rep(i, k) cout << (Comb(k - 1, i) * Comb(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;

ll fct[2001], inv[2001], fill[2000];

inline ll ModPow(ll base, ll exp, ll mod) {
  ll ret = 1;
  base %= mod;
  while (exp > 0) {
    if (exp & 1)
      ret = (ret * base) % mod;
    base = (base * base) % mod;
    exp >>= 1;
  }
  return ret;
}

inline void Fct(ll N) {
  fct[0] = fct[1] = 1;
  for (ll i = 2; i <= N; fct[i] %= MOD, i++)
    fct[i] = fct[i - 1] * (i % MOD);
}

inline void ModInv(ll N) {
  Fct(N);
  inv[N] = ModPow(fct[N], MOD - 2, MOD);
  for (ll i = N - 1; i >= 0; inv[i] %= MOD, i--)
    inv[i] = inv[i + 1] * (i + 1);
}

inline ll Comb(ll n, ll r) {
  return fct[n] * (inv[r] * inv[n - r] % MOD) % MOD;
}

int main() {
  ll n, k;
  cin >> n >> k;
  ModInv(n);
  rep(i, k) cout << (Comb(k - 1, i) * Comb(n - k + 1, i + 1)) % MOD << endl;
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define mod 1000000007
#define endl '\n'
ll binpow(ll a, ll b) {
  ll ans = 1;
  while (b) {
    if (b & 1) {
      ans *= a;
      ans %= mod;
    }
    a *= a;
    a %= mod;
    b /= 2;
  }
  return ans;
}
ll fact[2001];
void calcFactorial(ll n) {
  fact[0] = 1;
  for (ll i = 1; i <= n; ++i) {
    fact[i] = i * fact[i - 1];
    fact[i] %= mod;
  }
}
ll ncr(ll n, ll r) {
  ll ans = fact[n];
  // cout<<fact[n]<<" ";
  ll inverse = (fact[r] * fact[n - r]) % mod;
  ans *= binpow(inverse, mod - 2);
  // ans+=mod;
  ans %= mod;
  // cout<<ans<<endl;
  return ans;
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fast ll n, k;
  cin >> n >> k;
  calcFactorial(2000);

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

#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define mod 1000000007
#define endl '\n'
ll binpow(ll a, ll b) {
  ll ans = 1;
  while (b) {
    if (b & 1) {
      ans *= a;
      ans %= mod;
    }
    a *= a;
    a %= mod;
    b /= 2;
  }
  return ans;
}
ll fact[2001];
void calcFactorial(ll n) {
  fact[0] = 1;
  for (ll i = 1; i <= n; ++i) {
    fact[i] = i * fact[i - 1];
    fact[i] %= mod;
  }
}
ll ncr(ll n, ll r) {
  ll ans = fact[n];
  // cout<<fact[n]<<" ";
  ll inverse = (fact[r] * fact[n - r]) % mod;
  ans *= binpow(inverse, mod - 2);
  // ans+=mod;
  ans %= mod;
  // cout<<ans<<endl;
  return ans;
}
int main() {

  fast ll n, k;
  cin >> n >> k;
  calcFactorial(2000);

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

#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
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 int N = 5005;

namespace Modop {
ll modAdd(ll a, ll b) { return (a + b) % MOD; }

ll modSub(ll a, ll b) { return (((a - b) % MOD) + MOD) % MOD; }

ll modMul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }

ll modExp(ll base, ll power) {
  if (power == 0) {
    return 1;
  } else {
    ll cur = modExp(base, power / 2);
    cur = cur * cur;
    cur = cur % MOD;
    if (power % 2 == 1)
      cur = cur * base;
    cur = cur % MOD;
    return cur;
  }
}

ll modInv(ll a) { return modExp(a, MOD - 2); }

ll modDiv(ll a, ll b) { return modMul(a, modInv(b)); }
} // namespace Modop

using namespace Modop;

int n, k;

ll fac[N], inv[N];

void pre() {
  fac[1] = inv[1] = 1;
  for (int i = 2; i < N; i++) {
    fac[i] = modMul(fac[i - 1], i);
    inv[i] = modInv(fac[i]);
  }
}

ll combo(int n, int k) {
  ll t = fac[n + k - 1];
  ll b = modMul(inv[k], inv[n - 1]);
  return max(modMul(t, b), 1ll);
}

int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  pre();
  cin >> n >> k;

  for (int i = 1; i <= k; i++) {
    cout << modMul(combo(i, k - i), combo(i + 1, n - k - (i - 1))) << '\n';
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const int N = 5005;

namespace Modop {
ll modAdd(ll a, ll b) { return (a + b) % MOD; }

ll modSub(ll a, ll b) { return (((a - b) % MOD) + MOD) % MOD; }

ll modMul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }

ll modExp(ll base, ll power) {
  if (power == 0) {
    return 1;
  } else {
    ll cur = modExp(base, power / 2);
    cur = cur * cur;
    cur = cur % MOD;
    if (power % 2 == 1)
      cur = cur * base;
    cur = cur % MOD;
    return cur;
  }
}

ll modInv(ll a) { return modExp(a, MOD - 2); }

ll modDiv(ll a, ll b) { return modMul(a, modInv(b)); }
} // namespace Modop

using namespace Modop;

int n, k;

ll fac[N], inv[N];

void pre() {
  fac[1] = inv[1] = 1;
  for (int i = 2; i < N; i++) {
    fac[i] = modMul(fac[i - 1], i);
    inv[i] = modInv(fac[i]);
  }
}

ll combo(int n, int k) {
  ll t = fac[n + k - 1];
  ll b = modMul(inv[k], inv[n - 1]);
  return max(modMul(t, b), 1ll);
}

int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  pre();
  cin >> n >> k;

  for (int i = 1; i <= k; i++) {
    if (n - k - (i - 1) < 0)
      cout << 0 << '\n';
    else
      cout << modMul(combo(i, k - i), combo(i + 1, n - k - (i - 1))) << '\n';
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll, ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll pw(ll x, ll y) {
  ll res = 1;
  while (y) {
    if (y & 1)
      res = res * x % M;
    x = x * x % M;
    y >>= 1;
  }
  return res;
}
ll n, m, d[2005], in[2005];
ll cm(ll x, ll y) { return d[x] * in[x - y] % M * in[y] % M; }
int main(void) {
  cin >> n >> m;
  d[0] = 1, in[0] = 1;
  for (ll i = 1; i <= 2004; i++)
    d[i] = d[i - 1] * i % M, in[i] = pw(d[i], M - 2);
  for (ll i = 1; i <= m; i++) {
    cout << cm(m - 1, i - 1) * cm(n - m + 1, i) % M << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll, ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll pw(ll x, ll y) {
  ll res = 1;
  while (y) {
    if (y & 1)
      res = res * x % M;
    x = x * x % M;
    y >>= 1;
  }
  return res;
}
ll n, m, d[2005], in[2005];
ll cm(ll x, ll y) { return d[x] * in[x - y] % M * in[y] % M; }
int main(void) {
  cin >> n >> m;
  d[0] = 1, in[0] = 1;
  for (ll i = 1; i <= 2004; i++)
    d[i] = d[i - 1] * i % M, in[i] = pw(d[i], M - 2);
  for (ll i = 1; i <= m; i++) {
    if (n - m + 1 < i)
      cout << 0 << endl;
    else
      cout << cm(m - 1, i - 1) * cm(n - m + 1, i) % M << endl;
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
// A modular inverse based solution to
// compute nCr % p
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll fac[200000];
/* Iterative Function to calculate (x^y)%p
in O(log y) */
ll fact(int n) {

  fac[0] = 1;
  for (ll i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * i % 1000000007;
  return fac[n];
}
ll power(ll x, ll y, ll p) {
  ll res = 1; // Initialize result

  x = x % p; // Update x if it is more than or
             // equal to p

  while (y > 0) {
    // If y is odd, multiply x with result
    if (y & 1)
      res = (res * x) % p;

    // y must be even now
    y = y >> 1; // y = y/2
    x = (x * x) % p;
  }
  return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n, ll p) { return power(n, p - 2, p); }

// Returns nCr % p using Fermat's little
// theorem.
ll nCrModPFermat(ll n, ll r, ll p) {
  // Base case
  if (r == 0)
    return 1;

  // Fill factorial array so that we
  // can find all factorial of r, n
  // and n-r

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

// Driver program
int main() {
  ll a, b;
  cin >> a >> b;
  for (int i = 1; i <= b; i++)

    cout << (nCrModPFermat(a - b + 1, i, 1000000007) *
             nCrModPFermat(b - 1, i - 1, 1000000007)) %
                1000000007
         << endl;
  return 0;
}


Fixed submission:
// A modular inverse based solution to
// compute nCr % p
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll fac[200000];
/* Iterative Function to calculate (x^y)%p
in O(log y) */
ll fact(int n) {

  fac[0] = 1;
  for (ll i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * i % 1000000007;
  return fac[n];
}
ll power(ll x, ll y, ll p) {
  ll res = 1; // Initialize result

  x = x % p; // Update x if it is more than or
             // equal to p

  while (y > 0) {
    // If y is odd, multiply x with result
    if (y & 1)
      res = (res * x) % p;

    // y must be even now
    y = y >> 1; // y = y/2
    x = (x * x) % p;
  }
  return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n, ll p) { return power(n, p - 2, p); }

// Returns nCr % p using Fermat's little
// theorem.
ll nCrModPFermat(ll n, ll r, ll p) {
  // Base case
  if (r == 0)
    return 1;

  // Fill factorial array so that we
  // can find all factorial of r, n
  // and n-r

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

// Driver program
int main() {
  ll a, b;
  cin >> a >> b;
  for (int i = 1; i <= b; i++)
    if (a - b + 1 >= i)
      cout << (nCrModPFermat(a - b + 1, i, 1000000007) *
               nCrModPFermat(b - 1, i - 1, 1000000007)) %
                  1000000007
           << endl;
    else
      cout << 0 << endl;
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define MOD 1000000007
const ll INF = 1e18;
template <class T> void show(vector<T> v) {
  for (int i = 0; i < v.size(); i++) {
    cerr << v[i] << " ";
  }
  cerr << endl;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int MAX = 51000000;

long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(int argc, char const *argv[]) {
  int n, k;
  cin >> n >> k;
  COMinit();
  ll ans = 0;
  for (ll i = 1; i <= k; i++) {
    cout << (COM(n - k + 1, i) % MOD) * (COM(k - 1, i - 1) % MOD) % MOD << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define MOD 1000000007
const ll INF = 1e18;
template <class T> void show(vector<T> v) {
  for (int i = 0; i < v.size(); i++) {
    cerr << v[i] << " ";
  }
  cerr << endl;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int MAX = 10000;

long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(int argc, char const *argv[]) {
  int n, k;
  cin >> n >> k;
  COMinit();
  ll ans = 0;
  for (ll i = 1; i <= k; i++) {
    cout << (COM(n - k + 1, i) % MOD) * (COM(k - 1, i - 1) % MOD) % 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(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'

const ll MOD = 1000000007;

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

ll nCrModFermat(ll n, ll r, ll mod) {
  if (r == 0)
    return 1;

  ll fac[n + 1];
  fac[0] = 1;
  for (ll i = 1; i <= n; i++) {
    fac[i] = fac[i - 1] * i % mod;
  }
  return (fac[n] * modInv(fac[r], mod) % mod * modInv(fac[n - r], mod) % mod) %
         mod;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll n, k;
  cin >> n >> k;

  ll c = n - k + 1;
  for (ll i = 1; i <= k; i++) {
    cout << nCrModFermat(c, i, MOD) * nCrModFermat(k - 1, i - 1, MOD) % MOD
         << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'

const ll MOD = 1000000007;

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

ll nCrModFermat(ll n, ll r, ll mod) {
  if (r == 0)
    return 1;

  ll fac[n + 1];
  fac[0] = 1;
  for (ll i = 1; i <= n; i++) {
    fac[i] = fac[i - 1] * i % mod;
  }
  return (fac[n] * modInv(fac[r], mod) % mod * modInv(fac[n - r], mod) % mod) %
         mod;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll n, k;
  cin >> n >> k;

  ll c = n - k + 1;
  for (ll i = 1; i <= k; i++) {
    if (n - k + 1 >= i)
      cout << nCrModFermat(c, i, MOD) * nCrModFermat(k - 1, i - 1, MOD) % MOD
           << endl;
    else {
      cout << 0 << endl;
    }
  }
}
Problem p02990 (C++)

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

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
LL powmod(LL a, LL b, LL MOD) {
  LL ans = 1;
  while (b) {
    if (b % 2)
      ans = ans * a % MOD;
    a = a * a % MOD;
    b /= 2;
  }
  return ans;
}
const int N = 2e5 + 11;
const LL mod = 1e9 + 7;
int n, k, f[N], g[N];
void P() {
  f[0] = 1;
  for (int i = 1; i <= 2000; i++)
    f[i] = (1ll * f[i - 1] * i) % mod;
  g[2000] = powmod(f[2000], mod - 2, mod);
  for (int i = 1999; i >= 0; i--)
    g[i] = (1ll * g[i + 1] * (i + 1)) % mod;
}
int get(int x, int y) {
  // if(x<=y)return 0;
  return 1ll * f[x] * g[y] % mod * g[x - y] % mod;
}
int main() {
  ios::sync_with_stdio(false);
  P();
  cin >> n >> k;
  for (int i = 1; i <= k; i++)
    cout << 1ll * get(k - 1, i - 1) * get(n - k + 1, i) % mod << endl;
  return 0;
}

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

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
LL powmod(LL a, LL b, LL MOD) {
  LL ans = 1;
  while (b) {
    if (b % 2)
      ans = ans * a % MOD;
    a = a * a % MOD;
    b /= 2;
  }
  return ans;
}
const int N = 2e5 + 11;
const LL mod = 1e9 + 7;
int n, k, f[N], g[N];
void P() {
  f[0] = 1;
  for (int i = 1; i <= 2000; i++)
    f[i] = (1ll * f[i - 1] * i) % mod;
  g[2000] = powmod(f[2000], mod - 2, mod);
  for (int i = 1999; i >= 0; i--)
    g[i] = (1ll * g[i + 1] * (i + 1)) % mod;
}
int get(int x, int y) {
  if (x < y)
    return 0;
  return 1ll * f[x] * g[y] % mod * g[x - y] % mod;
}
int main() {
  ios::sync_with_stdio(false);
  P();
  cin >> n >> k;
  for (int i = 1; i <= k; i++)
    cout << 1ll * get(k - 1, i - 1) * get(n - k + 1, i) % mod << endl;
  return 0;
}
Problem p02990 (C++)

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

const int64_t mod = 1e9 + 7;
int64_t fact[4013];

int64_t add_mod(int64_t a, int64_t b, int64_t m) { return (a + b) % m; }

int64_t sub_mod(int64_t a, int64_t b, int64_t m) { return (a - b + m) % m; }

int64_t mul_mod(int64_t a, int64_t b, int64_t m) { return (a * b) % m; }

int64_t pow_mod(int64_t a, int64_t b, int64_t m) {
  int64_t res = 1, t = a;
  while (b) {
    if (b & 1)
      res = mul_mod(res, t, m);
    t = mul_mod(t, t, m);
    b >>= 1;
  }
  return res;
}

int64_t div_mod(int64_t a, int64_t b, int64_t m) {
  return mul_mod(a, pow_mod(b, m - 2, m), m);
}

int64_t ncr_mod(int64_t n, int64_t k, int64_t m) {
  return div_mod(fact[n], mul_mod(fact[n - k], fact[k], m), m);
}

void precalc(int64_t m) {
  fact[0] = 1;
  for (int64_t i = 1; i < 4013; ++i)
    fact[i] = mul_mod(fact[i - 1], i, m);
}

signed main() {
  precalc(mod);

  int64_t n, k;
  cin >> n >> k;
  for (int64_t moves = 1; moves <= k; ++moves)
    cout << mul_mod(ncr_mod(k - 1, moves - 1, mod),
                    ncr_mod(n + 1 - k, moves, mod), mod)
         << '\n';
}


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

const int64_t mod = 1e9 + 7;
int64_t fact[4013];

int64_t add_mod(int64_t a, int64_t b, int64_t m) { return (a + b) % m; }

int64_t sub_mod(int64_t a, int64_t b, int64_t m) { return (a - b + m) % m; }

int64_t mul_mod(int64_t a, int64_t b, int64_t m) { return (a * b) % m; }

int64_t pow_mod(int64_t a, int64_t b, int64_t m) {
  int64_t res = 1, t = a;
  while (b) {
    if (b & 1)
      res = mul_mod(res, t, m);
    t = mul_mod(t, t, m);
    b >>= 1;
  }
  return res;
}

int64_t div_mod(int64_t a, int64_t b, int64_t m) {
  return mul_mod(a, pow_mod(b, m - 2, m), m);
}

int64_t ncr_mod(int64_t n, int64_t k, int64_t m) {
  return div_mod(fact[n], mul_mod(fact[n - k], fact[k], m), m);
}

void precalc(int64_t m) {
  fact[0] = 1;
  for (int64_t i = 1; i < 4013; ++i)
    fact[i] = mul_mod(fact[i - 1], i, m);
}

signed main() {
  precalc(mod);

  int64_t n, k;
  cin >> n >> k;
  for (int64_t moves = 1; moves <= k; ++moves) {
    if (moves <= n + 1 - k)
      cout << mul_mod(ncr_mod(k - 1, moves - 1, mod),
                      ncr_mod(n + 1 - k, moves, mod), mod)
           << '\n';
    else
      cout << "0\n";
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

#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 FORR(i, m, n) for (int i = m; i >= n; i--)

ll const INF = 1000000000000000000;
int const I_MAX = 2147483647;
ll const MOD = 1e9 + 7;
int const POW_MAX = 1e5;
int const N_MAX = 1e5;

// nCr
ll po[POW_MAX + 2];
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 comb(int n, int r) {
  if (!po[n]) {
    po[0] = 1;
    FOR(i, 1, n + 1) po[i] = po[i - 1] * i % MOD;
  }
  return (((po[n] * mod_inv(po[r])) % MOD) * mod_inv(po[n - r])) % MOD;
}
// greatest common divisor
ll gcd(ll a, ll b) {
  while (a % b != 0) {
    ll tmp = a;
    a = b;
    b = tmp % b;
  }
  return b;
}

int N, K;

int main() {
  scanf("%d %d", &N, &K);

  int boxes = N - K + 1;
  for (int i = 1; i < K + 1; i++) {
    ll x = comb(boxes, i);
    ll y = comb(K - 1, i - 1);

    printf("%lld\n", x * y % MOD);
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

#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 FORR(i, m, n) for (int i = m; i >= n; i--)

ll const INF = 1000000000000000000;
int const I_MAX = 2147483647;
ll const MOD = 1e9 + 7;
int const POW_MAX = 1e5;
int const N_MAX = 1e5;

// nCr
ll po[POW_MAX + 2];
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 comb(int n, int r) {
  if (!po[n]) {
    po[0] = 1;
    FOR(i, 1, n + 1) po[i] = po[i - 1] * i % MOD;
  }
  return (((po[n] * mod_inv(po[r])) % MOD) * mod_inv(po[n - r])) % MOD;
}
// greatest common divisor
ll gcd(ll a, ll b) {
  while (a % b != 0) {
    ll tmp = a;
    a = b;
    b = tmp % b;
  }
  return b;
}

int N, K;

int main() {
  scanf("%d %d", &N, &K);

  int boxes = N - K + 1;
  for (int i = 1; i < K + 1; i++) {
    if (i > boxes) {
      printf("0\n");
      continue;
    }
    ll x = comb(boxes, i);
    ll y = comb(K - 1, i - 1);

    printf("%lld\n", x * y % MOD);
  }
}
Problem p02990 (C++)

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

#define SIZE 2001
#define MOD 1000000007

using namespace std;

long long dp[SIZE][SIZE];
void makePasTri(int n) {
  dp[0][0] = 1;
  for (int i = 1; i <= n + 1; i++) {
    dp[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % MOD;
    }
  }
}

int main() {
  int N, K;
  cin >> N >> K;
  makePasTri(N);
  for (int i = 1; i <= K; i++) {
    cout << dp[N - K + 1][i] * dp[K - 1][i - 1] % MOD << endl;
  }
}


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

#define SIZE 2001
#define MOD 1000000007

using namespace std;

long long dp[SIZE][SIZE];
void makePasTri(int n) {
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % MOD;
    }
  }
}

int main() {
  int N, K;
  cin >> N >> K;
  makePasTri(N);
  for (int i = 1; i <= K; i++) {
    cout << dp[N - K + 1][i] * dp[K - 1][i - 1] % MOD << endl;
  }
}
Problem p02990 (C++)

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

vector<vector<ll>> dp;

ll aCb(ll a, ll b) {
  if (dp[a][b] != -1) {
    return dp[a][b];
  }
  if (a == b) {
    return 1;
  } else if (b == 0) {
    return 1;
  } else if (b == 1) {
    return a;
  } else {
    return dp[a][b] = (aCb(a - 1, b - 1) + aCb(a - 1, b)) % 1000000007;
  }
}

int main() {
  ll n, k;
  cin >> n >> k;
  ll ANS = 0;
  dp.assign(n, vector<ll>(n, -1));
  for (ll i = 1; i <= k; i++) {
    if (n == k) {
      if (i == 1) {
        ANS = 1;
      } else {
        ANS = 0;
      }
    } else if (i == 1) {
      ANS = n - k + 1;
    } else {
      ANS = aCb(k - 1, i - 1);
      ANS %= 1000000007;
      ANS *= aCb(n - k + 1, i);
      ANS %= 1000000007;
    }
    cout << ANS << endl;
  }
}


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

vector<vector<ll>> dp;

ll aCb(ll a, ll b) {
  if (dp[a][b] != -1) {
    return dp[a][b];
  }
  if (a == b) {
    return 1;
  } else if (b == 0) {
    return 1;
  } else if (b == 1) {
    return a;
  } else {
    return dp[a][b] = (aCb(a - 1, b - 1) + aCb(a - 1, b)) % 1000000007;
  }
}

int main() {
  ll n, k;
  cin >> n >> k;
  ll ANS = 0;
  dp.assign(n, vector<ll>(n, -1));
  for (ll i = 1; i <= k; i++) {
    if (n == k) {
      if (i == 1) {
        ANS = 1;
      } else {
        ANS = 0;
      }
    } else if (i == 1) {
      ANS = n - k + 1;
    } else if (n - k + 1 < i) {
      ANS = 0;
    } else {
      ANS = aCb(k - 1, i - 1);
      ANS %= 1000000007;
      ANS *= aCb(n - k + 1, i);
      ANS %= 1000000007;
    }
    cout << ANS << endl;
  }
}
Problem p02990 (C++)

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

long long comb(long long m, long long r, vector<vector<long long>> &history) {
  if (history[m][r] != -1) {
    return history[m][r];
  } else if (r == 0 || r == m) {
    history[m][r] = 1;
    return 1;
  } else {
    history[m][r] =
        (comb(m - 1, r - 1, history) + comb(m - 1, r, history)) % 1000000007;
    return history[m][r];
  }
}

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

  vector<vector<long long>> history(max(n - k + 2, k),
                                    vector<long long>(k + 1, -1));

  for (long long i = 1; i <= k; i++) {
    cout << ((comb(n - k + 1, i, history) % 1000000007) *
             (comb(k - 1, i - 1, history) % 1000000007)) %
                1000000007
         << endl;
  }

  return 0;
}


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

long long comb(long long m, long long r, vector<vector<long long>> &history) {
  if (r > m) {
    return 0;
  } else if (history[m][r] != -1) {
    return history[m][r];
  } else if (r == 0 || r == m) {
    history[m][r] = 1;
    return 1;
  } else {
    history[m][r] =
        (comb(m - 1, r - 1, history) + comb(m - 1, r, history)) % 1000000007;
    return history[m][r];
  }
}

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

  vector<vector<long long>> history(max(n - k + 2, k),
                                    vector<long long>(k + 1, -1));

  for (long long i = 1; i <= k; i++) {
    cout << ((comb(n - k + 1, i, history) % 1000000007) *
             (comb(k - 1, i - 1, history) % 1000000007)) %
                1000000007
         << endl;
  }

  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class Pascal {
  vector<vector<int>> C;

public:
  Pascal() {}
  Pascal(int n) {
    n = n * 2 + 10;
    C = vector<vector<int>>(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= i; j++) {
        if (j == 0 || j == i)
          C[i][j] = 1;
        else
          C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
      }
    }
  }
  int nCr(int n, int r) {
    if (r < 0)
      return 0;
    return C[n][r];
  }
  int nrC(int n, int r) { return C[n + r][n]; }
};
int main() {
  int n, K;
  cin >> n >> K;
  Pascal pas(n * 2);
  for (int i = 1; i <= K; i++) {
    if (n - K < i - 1) {
      puts("0");
    } else {
      ll a = pas.nCr(K - 1, i - 1);
      ll b =
          (pas.nCr(n - K - 1, i) + pas.nCr(n - K - 1, i - 1) * 2 % MOD) % MOD +
          pas.nCr(n - K - 1, i - 2);
      b %= MOD;
      printf("%lld\n", a * b % MOD);
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class Pascal {
  vector<vector<int>> C;

public:
  Pascal() {}
  Pascal(int n) {
    n = n * 2 + 10;
    C = vector<vector<int>>(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= i; j++) {
        if (j == 0 || j == i)
          C[i][j] = 1;
        else
          C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
      }
    }
  }
  int nCr(int n, int r) {
    if (r < 0)
      return 0;
    return C[n][r];
  }
  int nrC(int n, int r) { return C[n + r][n]; }
};
int main() {
  int n, K;
  cin >> n >> K;
  if (n == K) {
    for (int i = 1; i <= K; i++) {
      if (i == 1)
        puts("1");
      else
        puts("0");
    }
    return 0;
  }
  Pascal pas(n * 2);
  for (int i = 1; i <= K; i++) {
    if (n - K < i - 1) {
      puts("0");
    } else {
      ll a = pas.nCr(K - 1, i - 1);
      ll b =
          (pas.nCr(n - K - 1, i) + pas.nCr(n - K - 1, i - 1) * 2 % MOD) % MOD +
          pas.nCr(n - K - 1, i - 2);
      b %= MOD;
      printf("%lld\n", a * b % MOD);
    }
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
ll fact[N], inv_fact[N];
const ll mod = 1e9 + 7;
ll mul(ll a, ll b) { return (a * b) % mod; }
ll fp(ll base, ll pw) {
  if (pw == 1)
    return base;
  if (base == 0)
    return 0;
  if (pw == 0)
    return 1;
  ll x = fp(base, pw / 2);
  x = mul(x, x);
  if (pw & 1)
    x = mul(x, base);
  return x;
}
void build() {
  fact[0] = inv_fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = mul(i, fact[i - 1]);
    inv_fact[i] = fp(fact[i], mod - 2);
  }
}
ll ncr(ll n, ll r) {
  ll A = fact[n];
  ll B = mul(inv_fact[r], inv_fact[n - r]);
  return mul(A, B);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  build();
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++)
    cout << mul(ncr(n - k + 1, i), ncr(k - 1, i - 1)) << '\n';
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
ll fact[N], inv_fact[N];
const ll mod = 1e9 + 7;
ll mul(ll a, ll b) { return (a * b) % mod; }
ll fp(ll base, ll pw) {
  if (pw == 1)
    return base;
  if (base == 0)
    return 0;
  if (pw == 0)
    return 1;
  ll x = fp(base, pw / 2);
  x = mul(x, x);
  if (pw & 1)
    x = mul(x, base);
  return x;
}
void build() {
  fact[0] = inv_fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = mul(i, fact[i - 1]);
    inv_fact[i] = fp(fact[i], mod - 2);
  }
}
ll ncr(ll n, ll r) {
  if (r > n)
    return 0;
  ll A = fact[n];
  ll B = mul(inv_fact[r], inv_fact[n - r]);
  return mul(A, B);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  build();
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++)
    cout << mul(ncr(n - k + 1, i), ncr(k - 1, i - 1)) << '\n';
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod = 1e9 + 7;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll fact[2005];
ll inv[2005];
ll inv2[2005];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  fact[0] = 1;
  for (int i = 1; i < 2005; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= mod;
  }
  inv[1] = 1;
  inv2[0] = 1;
  inv2[1] = 1;
  for (int i = 2; i <= 2000; i++) {
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    inv2[i] = inv2[i - 1] * inv[i] % mod;
  }

  for (int i = 1; i <= k; i++) {
    ll x = fact[k - 1] * inv2[i - 1];
    x %= mod;
    x = x * inv2[k - i];
    x %= mod;
    ll y = fact[n - k + 1] * inv2[i];
    y %= mod;
    y = y * inv2[n - k + 1 - i];
    y %= mod;
    ll res = x * y;
    res %= mod;
    cout << res << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod = 1e9 + 7;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll fact[2005];
ll inv[2005];
ll inv2[2005];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  fact[0] = 1;
  for (int i = 1; i < 2005; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= mod;
  }
  inv[1] = 1;
  inv2[0] = 1;
  inv2[1] = 1;
  for (int i = 2; i <= 2000; i++) {
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    inv2[i] = inv2[i - 1] * inv[i] % mod;
  }

  for (int i = 1; i <= k; i++) {
    ll x;
    if (k < i)
      x = 0;
    else {
      x = fact[k - 1] * inv2[i - 1];
      x %= mod;
      x = x * inv2[k - i];
      x %= mod;
    }
    ll y = 0;
    if (n - k + 1 >= i) {
      y = fact[n - k + 1] * inv2[i];
      y %= mod;
      y = y * inv2[n - k + 1 - i];
      y %= mod;
    }

    ll res = x * y;
    res %= mod;
    cout << res << endl;
  }
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <utility>
#include <vector>
#define N (1000000000 + 7)
typedef long long ll;
using namespace std;
struct edge {
  ll to;
};
ll kaijo[100010];
void init() {
  kaijo[0] = 1;
  for (ll i = 1; i <= 100000; i++)
    kaijo[i] = (kaijo[i - 1] * i) % N;
}

ll inv(ll x) {
  ll res = 1;
  ll k = N - 2;
  ll y = x;
  while (k) {
    if (k & 1)
      res = (res * y) % N;
    y = ((y % N) * (y % N)) % N;
    k /= 2;
  }
  return res;
}

ll Comb(ll n, ll k) {
  // if (n < 0 || k < 0 || (n - k) < 0)return 0;
  ll b = kaijo[n];
  ll c = kaijo[n - k];
  ll d = kaijo[k];
  ll cd = (c * d) % N;
  return ((b % N) * (inv(cd)) % N) % N;
}
int main(void) {
  ll n, k;
  cin >> n >> k;
  init();
  for (int i = 1; i <= k; i++) {
    if (i == 1) {
      cout << n - k + 1 << endl;
    } else {
      if (i == k) {
        cout << Comb(n - k + 1, k) << endl;
      } else
        cout << (((Comb(n - k - 1 + 2, i) * Comb((k - 1), i)) % N) * kaijo[i]) %
                    N
             << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <utility>
#include <vector>
#define N (1000000000 + 7)
typedef long long ll;
using namespace std;
struct edge {
  ll to;
};
ll kaijo[100010];
void init() {
  kaijo[0] = 1;
  for (ll i = 1; i <= 100000; i++)
    kaijo[i] = (kaijo[i - 1] * i) % N;
}

ll inv(ll x) {
  ll res = 1;
  ll k = N - 2;
  ll y = x;
  while (k) {
    if (k & 1)
      res = (res * y) % N;
    y = ((y % N) * (y % N)) % N;
    k /= 2;
  }
  return res;
}

ll Comb(ll n, ll k) {
  // if (n < 0 || k < 0 || (n - k) < 0)return 0;
  ll b = kaijo[n];
  ll c = kaijo[n - k];
  ll d = kaijo[k];
  ll cd = (c * d) % N;
  return ((b % N) * (inv(cd)) % N) % N;
}
int main(void) {
  ll n, k;
  cin >> n >> k;
  init();
  for (int i = 1; i <= k; i++) {
    if (i == 1) {
      cout << n - k + 1 << endl;
    } else {
      if (i == k) {
        if (n - k + 1 >= k)
          cout << Comb(n - k + 1, k) << endl;
        else
          cout << 0 << endl;
      } else {
        if (n - k + 1 >= i)
          cout << (Comb(n - k - 1 + 2, i) * Comb((k - 1), i - 1)) % N << endl;
        else
          cout << 0 << 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 < (int)(n); i++)

typedef long long ll;
typedef pair<int, int> P;

const ll mod =
    1000000007; // 出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60; // INF = 1152921504606846976

#define N_MAX 201010
ll f[N_MAX], rf[N_MAX];

ll pow(ll x, ll n) { // xのn乗 (mod m)
  ll res = 1;
  if (n > 0) {
    res = pow(x, n / 2);
    if (n % 2 == 0) {
      res = (res * res) % mod;
    } else {
      res = (((res * res) % mod) * x) % mod;
    }
  }
  return res;
}

void init() {
  f[0] = 1;
  for (int i = 1; i < N_MAX; i++) {
    f[i] = (i * f[i - 1]) % mod;
  }
  for (int i = 0; i < N_MAX; i++) {
    rf[i] = pow(f[i], mod - 2);
  }
}

ll com(ll n, ll k) {
  ll a = f[n];
  ll b = rf[k];
  ll c = rf[n - k];

  ll bc = (b * c) % mod;

  return (a * bc) % mod;
}

int main() {
  ll n, k;
  cin >> n >> k;
  init();
  for (int i = 1; i <= k; i++) {
    ll ans = com(n - k + 1, i) * com(k - 1, i - 1);
    ans %= mod;
    cout << ans << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;
typedef pair<int, int> P;

const ll mod =
    1000000007; // 出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60; // INF = 1152921504606846976

#define N_MAX 201010
ll f[N_MAX], rf[N_MAX];

ll pow(ll x, ll n) { // xのn乗 (mod m)
  ll res = 1;
  if (n > 0) {
    res = pow(x, n / 2);
    if (n % 2 == 0) {
      res = (res * res) % mod;
    } else {
      res = (((res * res) % mod) * x) % mod;
    }
  }
  return res;
}

void init() {
  f[0] = 1;
  for (int i = 1; i < N_MAX; i++) {
    f[i] = (i * f[i - 1]) % mod;
  }
  for (int i = 0; i < N_MAX; i++) {
    rf[i] = pow(f[i], mod - 2);
  }
}

ll com(ll n, ll k) {
  ll a = f[n];
  ll b = rf[k];
  ll c = rf[n - k];

  ll bc = (b * c) % mod;

  return (a * bc) % mod;
}

int main() {
  ll n, k;
  cin >> n >> k;
  init();
  for (int i = 1; i <= k; i++) {
    ll ans;
    if (n - k + 1 >= i) {
      ans = com(n - k + 1, i) * com(k - 1, i - 1);
    } else {
      ans = 0;
    }
    ans %= mod;
    cout << ans << endl;
  }
}
Problem p02990 (C++)

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

const int M = 2005;
const int MO = 1e9 + 7;
int inv[M], fa[M], ifa[M];

int add(int x, int y) {
  x += y;
  if (x >= MO)
    x -= MO;
  return x;
}
int mul(int x, int y) { return 1LL * x * y % MO; }

void init() {
  fa[0] = ifa[0] = 1;
  inv[1] = fa[1] = ifa[1] = 1;
  for (int i = 2; i < M; i++) {
    fa[i] = mul(fa[i - 1], i);
    inv[i] = mul(MO - MO / i, inv[MO % i]);
    ifa[i] = mul(inv[i], ifa[i - 1]);
  }
}

int qp(int x, int n) {
  int ans = 1;
  while (n) {
    if (n & 1)
      ans = mul(ans, x);
    x = mul(x, x);
    n >>= 1;
  }
  return ans;
}

int C(int n, int m) { return mul(mul(fa[n], ifa[m]), ifa[n - m]); }

int main() {
  init();
  int n, k;
  scanf("%d%d", &n, &k);
  n -= k;
  for (int i = 1; i <= k; i++) {
    int ans = C(k - 1, i - 1);
    ans = mul(ans, C(n + 1, i));
    printf("%d\n", ans);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;

const int M = 2005;
const int MO = 1e9 + 7;
int inv[M], fa[M], ifa[M];

int add(int x, int y) {
  x += y;
  if (x >= MO)
    x -= MO;
  return x;
}
int mul(int x, int y) { return 1LL * x * y % MO; }

void init() {
  fa[0] = ifa[0] = 1;
  inv[1] = fa[1] = ifa[1] = 1;
  for (int i = 2; i < M; i++) {
    fa[i] = mul(fa[i - 1], i);
    inv[i] = mul(MO - MO / i, inv[MO % i]);
    ifa[i] = mul(inv[i], ifa[i - 1]);
  }
}

int qp(int x, int n) {
  int ans = 1;
  while (n) {
    if (n & 1)
      ans = mul(ans, x);
    x = mul(x, x);
    n >>= 1;
  }
  return ans;
}

int C(int n, int m) {
  if (n < m)
    return 0;
  return mul(mul(fa[n], ifa[m]), ifa[n - m]);
}

int main() {
  init();
  int n, k;
  scanf("%d%d", &n, &k);
  n -= k;
  for (int i = 1; i <= k; i++) {
    int ans = C(k - 1, i - 1);
    ans = mul(ans, C(n + 1, i));
    printf("%d\n", ans);
  }
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
int f[12001];
int fi[12001];
int n, k;
int m(int a, int b) { return (a * b) % mod; }

int fp(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1)
      res = res * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return res;
}
int iv(int x) { return fp(x, mod - 2); }
int c(int x, int y) { return m(f[y], m(fi[x], fi[y - x])); }
int ck(int x, int y) { return c(y - 1, x + y - 1); }
signed main() {
  cin >> n >> k;
  f[0] = 1;
  for (int i = 1; i <= 10000; i++)
    f[i] = m(f[i - 1], i);
  fi[10000] = iv(f[10000]);
  for (int i = 9999; i >= 0; i--)
    fi[i] = m(fi[i + 1], (i + 1));
  //	cout << "db\n";
  //	cout << ck(3,1) << endl;
  //	cout << c(0,3) << endl;
  //	cout << "edb\n";

  for (int i = 1; i <= k; i++) {
    // if(n - k - (i + 1 - 2) < 0) cout << "0\n";
    cout << m(ck(k - i, i), ck(n - k - (i + 1 - 2), i + 1)) << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
int f[12001];
int fi[12001];
int n, k;
int m(int a, int b) { return (a * b) % mod; }

int fp(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1)
      res = res * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return res;
}
int iv(int x) { return fp(x, mod - 2); }
int c(int x, int y) { return m(f[y], m(fi[x], fi[y - x])); }
int ck(int x, int y) { return c(y - 1, x + y - 1); }
signed main() {
  cin >> n >> k;
  f[0] = 1;
  for (int i = 1; i <= 10000; i++)
    f[i] = m(f[i - 1], i);
  fi[10000] = iv(f[10000]);
  for (int i = 9999; i >= 0; i--)
    fi[i] = m(fi[i + 1], (i + 1));
  //	cout << "db\n";
  //	cout << ck(3,1) << endl;
  //	cout << c(0,3) << endl;
  //	cout << "edb\n";

  for (int i = 1; i <= k; i++) {
    if (n - k - (i + 1 - 2) < 0)
      cout << "0\n";
    else
      cout << m(ck(k - i, i), ck(n - k - (i + 1 - 2), i + 1)) << endl;
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

ll c[30010][3010];

void init_triangle() {
  c[0][0] = 1;
  rep(i, 3000) rep(j, 3000) {
    if (j > i)
      break;

    c[i + 1][j] = (c[i + 1][j] + c[i][j]) % MOD;
    c[i + 1][j + 1] = (c[i + 1][j + 1] + c[i][j]) % MOD;
  }
}

ll f(int n, int m) {
  if (n < m)
    return 0;
  return c[n - 1][m - 1];
}

int main() {
  init_triangle();

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

  int num_blue = k;
  int num_red = n - k;
  rep(i, k + 1) {
    if (i == 0)
      continue;
    ll blue = f(num_blue, i);
    int res = 0;
    res = (res + blue * f(num_red, i - 1 + 0)) % MOD;
    res = (res + blue * f(num_red, i - 1 + 1)) % MOD;
    res = (res + blue * f(num_red, i - 1 + 1)) % MOD;
    res = (res + blue * f(num_red, i - 1 + 2)) % MOD;

    cout << res << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

ll c[30010][3010];

void init_triangle() {
  c[0][0] = 1;
  rep(i, 3000) rep(j, 3000) {
    if (j > i)
      break;

    c[i + 1][j] = (c[i + 1][j] + c[i][j]) % MOD;
    c[i + 1][j + 1] = (c[i + 1][j + 1] + c[i][j]) % MOD;
  }
}

ll f(int n, int m) {
  if (n < m)
    return 0;
  if (n == 0 and m == 0)
    return 1;
  return c[n - 1][m - 1];
}

int main() {
  init_triangle();

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

  int num_blue = k;
  int num_red = n - k;
  rep(i, k + 1) {
    if (i == 0)
      continue;
    ll blue = f(num_blue, i);
    int res = 0;
    res = (res + blue * f(num_red, i - 1 + 0)) % MOD;
    res = (res + blue * f(num_red, i - 1 + 1)) % MOD;
    res = (res + blue * f(num_red, i - 1 + 1)) % MOD;
    res = (res + blue * f(num_red, i - 1 + 2)) % MOD;

    cout << res << endl;
  }
}
Problem p02990 (C++)

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

using namespace std;

const long long MOD = 1e9 + 7;

long long fanc[2009], inv_fanc[2009];

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }

void fanc_list() {
  fanc[0] = 1;
  fanc[1] = 1;
  inv_fanc[0] = 1;
  inv_fanc[1] = 1;
  for (int i = 2; i <= 2000; i++) {
    fanc[i] = (i * fanc[i - 1]) % MOD;
    inv_fanc[i] = modinv(fanc[i], MOD);
  }
}

long long combi(long long n, long long k) {
  return ((fanc[n] * inv_fanc[n - k]) % MOD) * inv_fanc[k] % MOD;
}

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

Fixed submission:
#include <iostream>

using namespace std;

const long long MOD = 1e9 + 7;

long long fanc[2009], inv_fanc[2009];

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }

void fanc_list() {
  fanc[0] = 1;
  fanc[1] = 1;
  inv_fanc[0] = 1;
  inv_fanc[1] = 1;
  for (int i = 2; i <= 2000; i++) {
    fanc[i] = (i * fanc[i - 1]) % MOD;
    inv_fanc[i] = modinv(fanc[i], MOD);
  }
}

long long combi(long long n, long long k) {
  if (n < k)
    return 0;
  return ((fanc[n] * inv_fanc[n - k]) % MOD) * inv_fanc[k] % MOD;
}

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