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

Buggy submission (status: Runtime Error):
/* ****GT_18**** */

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl '\n'
#define pii pair<ll int, ll int>
#define vi vector<ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (ll int)x.size()
#define hell 1000000007
#define rep(i, a, b) for (ll int i = a; i < b; i++)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
using namespace std;

#define N 100005

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  //    cin>>TESTS;
  while (TESTS--) {
    ll i, j, k, l, m, n, a[100];
    cin >> n;
    for (i = 0; i < n; i++)
      cin >> a[i];
    sort(a, a + n);
    cout << a[n / 2] - a[n / 2 - 1];
    // ll ans=0;
  }
  return 0;
}

Fixed submission:
/* ****GT_18**** */

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl '\n'
#define pii pair<ll int, ll int>
#define vi vector<ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (ll int)x.size()
#define hell 1000000007
#define rep(i, a, b) for (ll int i = a; i < b; i++)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
using namespace std;

#define N 100005

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  //    cin>>TESTS;
  while (TESTS--) {
    ll i, j, k, l, m, n, a[100400];
    cin >> n;
    for (i = 0; i < n; i++)
      cin >> a[i];
    sort(a, a + n);
    cout << a[n / 2] - a[n / 2 - 1];
    // ll ans=0;
  }
  return 0;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n = 0;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  cout << d.at(n / 2 + 1) - d.at(n / 2) << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n = 0;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  cout << d.at(n / 2) - d.at(n / 2 - 1) << endl;
  return 0;
}
Problem p02989 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define int long long int
using namespace std;
int check(int a[], int n, int num) {
  int c1 = 0, c2 = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < num)
      c1++;
    else
      c2++;
  }
  return (c1 == c2);
}
void solve() {
  int n;
  cin >> n;
  int a[n];
  int max = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > max)
      max = a[i];
  }
  sort(a, a + n);
  int count = 0;
  int mid = (a[n / 2]);
  for (int i = a[n / 2 - 1]; i <= mid; i++) {
    if (check(a, n, i))
      count++;
  }
  cout << count << '\n';
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long int
using namespace std;
int check(int a[], int n, int num) {
  int c1 = 0, c2 = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < num)
      c1++;
    else
      c2++;
  }
  return (c1 == c2);
}
void solve() {
  int n;
  cin >> n;
  int a[n];
  int max = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > max)
      max = a[i];
  }
  sort(a, a + n);
  int count = 0;
  cout << a[n / 2] - a[n / 2 - 1] << '\n';
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
Problem p02989 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);

  for (int i = 0; i < n; i++) {
    cin >> d.at(i);
  }

  sort(d.begin(), d.end());

  cout << d.at(n / 2 + 1) - d.at(n / 2) << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);

  for (int i = 0; i < n; i++) {
    cin >> d.at(i);
  }

  sort(d.begin(), d.end());

  cout << d.at(n / 2) - d.at(n / 2 - 1) << endl;
}
Problem p02989 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  sort(vec.begin(), vec.end());
  int ans = 0;
  for (int i = 0; i < vec.at(N - 1); i++) {
    if (vec.at((N - 2) / 2) < i && i <= vec.at((N + 2) / 2)) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  sort(vec.begin(), vec.end());
  int ans = 0;
  for (int i = 0; i < vec.at(N - 1) + 1; i++) {
    if (vec.at((N - 2) / 2) < i && i <= vec.at(N / 2)) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void) { return; }
template <typename First, typename... Rest>
void ci(First &first, Rest &...rest) {
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void) {
  cout << "\n";
  return;
}
template <typename First, typename... Rest> void co(First first, Rest... rest) {
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define gcd __gcd
#define lcm(n, m) n *m / gcd(n, m)
#define np next_permutation
#define repi(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size())
#define each(i, n) for (auto &&i : n)
#define so(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数

int main() {
  int N;
  ci(N);
  ve<int> d(N);
  rep(i, N) { ci(d.at(i)); }
  so(d);
  if (d.at(N / 2) - d.at(N / 2 - 1) == 0) {
    co(0);
    rt;
  } else if (d.at(N / 2) - d.at(N / 2 - 1) != 0) {
    if (d.at(N / 2) != d.at(N / 2 + 1) && d.at(N / 2 - 1) != d.at(N / 2 - 2)) {
      co(d.at(N / 2) - d.at(N / 2 - 1));
      rt;
    } else if (d.at(N / 2) == d.at(N / 2 + 1) &&
               d.at(N / 2 - 1) == d.at(N / 2 - 2)) {
      co(d.at(N / 2) - d.at(N / 2 - 1) - 1);
      rt;
    } else if (d.at(N / 2) == d.at(N / 2 + 1) ||
               d.at(N / 2 - 1) == d.at(N / 2 - 2)) {
      co(d.at(N / 2) - d.at(N / 2 - 1));
      rt;
    }
  }
}

Fixed submission:
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void) { return; }
template <typename First, typename... Rest>
void ci(First &first, Rest &...rest) {
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void) {
  cout << "\n";
  return;
}
template <typename First, typename... Rest> void co(First first, Rest... rest) {
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define gcd __gcd
#define lcm(n, m) n *m / gcd(n, m)
#define np next_permutation
#define repi(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size())
#define each(i, n) for (auto &&i : n)
#define so(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数

int main() {
  int N;
  ci(N);
  ve<int> d(N);
  rep(i, N) { ci(d.at(i)); }
  so(d);
  co(d.at(N / 2) - d.at(N / 2 - 1));
}
Problem p02989 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  sort(d.begin(), d.end());
  int cnt = 0;
  for (int i = 1; i <= d[n - 1]; i++) {
    int l = 0, r = 0;
    rep(j, n) {
      if (d[j] < i)
        l++;
      else
        r++;
    }
    if (l == r)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> b(n);
  rep(i, n) cin >> b[i];
  sort(b.begin(), b.end());
  int ans = b[b.size() / 2] - b[b.size() / 2 - 1];
  cout << ans << endl;
  return 0;
}
Problem p02989 (C++)

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

int main() {

  int n;
  cin >> n;
  vector<int> a(n);

  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  cout << a.at(n / 2 + 1) - a.at(n / 2) << endl;
}

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

int main() {

  int n;
  cin >> n;
  vector<int> a(n);

  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  cout << a.at(n / 2) - a.at(n / 2 - 1) << endl;
}
Problem p02989 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int mid(int a, int b, int c) {
  return a + b + c - max(max(a, b), c) - min(min(a, b), c);
}

int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  for (int i = 0; i < N; i++) {
    cin >> D.at(i);
  }
  int count = 0;
  for (int k = 0; k < 100000; k++) {
    int R = 0, C = 0;
    for (int j = 0; j < N; j++) {
      if (D.at(j) >= k) {
        R++;
      } else {
        C++;
      }
    }
    if (N / 2 == R) {
      count++;
    }
    if (R < C)
      break;
  }
  cout << count << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int mid(int a, int b, int c) {
  return a + b + c - max(max(a, b), c) - min(min(a, b), c);
}

int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  for (int i = 0; i < N; i++) {
    cin >> D.at(i);
  }
  sort(D.begin(), D.end());
  cout << D.at(N / 2) - D.at(N / 2 - 1) << endl;
}
Problem p02989 (C++)

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

// C
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n;
  cin >> n;
  ll i;
  ll a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  cout << a[n / 2] - a[(n / 2) - 1];
}

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

// C
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n;
  cin >> n;
  ll i;
  ll a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  cout << a[n / 2] - a[(n / 2) - 1];
}
Problem p02989 (C++)

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

typedef pair<int, int> pii;
typedef pair<int, pii> ppi;

const int MAX_N = 5e4 + 20, MAX_M = 2e5 + 10, SQRT = 230, inf = 1000000000;
int n, Arr[MAX_N];
int cnt;

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> Arr[i];

  sort(Arr, Arr + n);
  cout << Arr[n / 2] - Arr[n / 2 - 1];
  return 0;
}

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

typedef pair<int, int> pii;
typedef pair<int, pii> ppi;

const int MAX_N = 2e5 + 10, MAX_M = 2e5 + 10, SQRT = 230, inf = 1000000000;
int n, Arr[MAX_N];
int cnt;

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> Arr[i];

  sort(Arr, Arr + n);
  cout << Arr[n / 2] - Arr[n / 2 - 1];
  return 0;
}
Problem p02989 (C++)

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

int main() {
  int n, a[21];
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  if (a[n / 2] == a[n / 2 - 1])
    cout << 0 << endl;
  else
    cout << (a[n / 2] - a[n / 2 - 1]) << endl;
  return 0;
}


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

int main() {
  int n, a[200001];
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  if (a[n / 2] == a[n / 2 - 1])
    cout << 0 << endl;
  else
    cout << (a[n / 2] - a[n / 2 - 1]) << endl;
  return 0;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> mp(n, 0);
  for (int i = 0; i < n; i++) {
    int d;
    cin >> d;
    mp[d - 1]++;
  }
  int ans = 0;
  long long sum = 0;
  for (int i = 0; i < 100000; i++) {
    sum += mp[i];
    if (n - sum == sum) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> mp(100000, 0);
  for (int i = 0; i < n; i++) {
    int d;
    cin >> d;
    mp[d - 1]++;
  }
  int ans = 0;
  long long sum = 0;
  for (int i = 0; i < 100000; i++) {
    sum += mp[i];
    if (n - sum == sum) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02989 (C++)

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

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<int, int> frec;
  for (int i = 0; i < n; i++) {
    int elem;
    cin >> elem;
    frec[elem]++;
  }
  vector<pii> arr;
  for (auto pp : frec)
    arr.pb(pp);
  int cnt = 0;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cnt += arr[i].second;
    if (n / 2 == cnt) {
      ans = arr[i + 1].first - arr[i].first;
    }
  }
  cout << ans << '\n';
  return (0);
}


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

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<int, int> frec;
  for (int i = 0; i < n; i++) {
    int elem;
    cin >> elem;
    frec[elem]++;
  }
  vector<pii> arr;
  for (auto pp : frec)
    arr.pb(pp);
  int cnt = 0;
  int ans = 0;
  for (int i = 0; i < sz(arr); i++) {
    cnt += arr[i].second;
    if (n / 2 == cnt) {
      ans = arr[i + 1].first - arr[i].first;
    }
  }
  cout << ans << '\n';
  return (0);
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define ll long long
#define pb push_back
#define mp make_pair

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  int mx = 0;
  for (int &i : v) {
    cin >> i;
    mx = max(i, mx);
  }
  sort(all(v));
  int cnt = 0;
  for (int i = 1; i <= mx; ++i) {
    int x = lower_bound(all(v), i) - v.begin();
    if (2 * x == n)
      cnt++;
  }
  cout << cnt << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define ll long long
#define pb push_back
#define mp make_pair

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  int mx = 0;
  for (int &i : v) {
    cin >> i;
    mx = max(i, mx);
  }
  sort(all(v));
  int cnt = 0;
  for (int i = 1; i <= mx; ++i) {
    int x = upper_bound(all(v), i) - v.begin();
    if (2 * x == n)
      cnt++;
  }
  cout << cnt << endl;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T, vector<T>, greater<T>>
struct edge {
  int to, cost;
};
typedef pair<int, int> P;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
  if (n == 0)
    return 1;
  if (n % 2)
    return (x * modpow(x * x % mod, n / 2) % mod + mod) % mod;
  return (modpow(x * x % mod, n / 2) + mod) % mod;
}

int fact(int n) {
  int ans = 1;
  rep(i, n) {
    ans *= (i + 1);
    ans %= mod;
  }
  return (ans + mod) % mod;
}

int comb(int n, int r) {
  if (n < r)
    swap(n, r);
  if (n - r < r)
    r = n - r;
  return (fact(n) * modpow(fact(n - r), mod - 2) % mod *
              modpow(fact(r), mod - 2) +
          mod) %
         mod;
}

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

bool pri(int p) {
  for (int i = 2; i * i <= p; i++)
    if (p % i == 0)
      return false;
  return p > 1;
}

int n;
int a[22];
int ans;
signed main() {
  cin >> n;
  rep(i, n) { cin >> a[i]; }
  sort(a, a + n);
  cout << a[n / 2] - a[n / 2 - 1] << endl;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T, vector<T>, greater<T>>
struct edge {
  int to, cost;
};
typedef pair<int, int> P;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
  if (n == 0)
    return 1;
  if (n % 2)
    return (x * modpow(x * x % mod, n / 2) % mod + mod) % mod;
  return (modpow(x * x % mod, n / 2) + mod) % mod;
}

int fact(int n) {
  int ans = 1;
  rep(i, n) {
    ans *= (i + 1);
    ans %= mod;
  }
  return (ans + mod) % mod;
}

int comb(int n, int r) {
  if (n < r)
    swap(n, r);
  if (n - r < r)
    r = n - r;
  return (fact(n) * modpow(fact(n - r), mod - 2) % mod *
              modpow(fact(r), mod - 2) +
          mod) %
         mod;
}

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

bool pri(int p) {
  for (int i = 2; i * i <= p; i++)
    if (p % i == 0)
      return false;
  return p > 1;
}

int n;
int a[114514];
int ans;
signed main() {
  cin >> n;
  rep(i, n) { cin >> a[i]; }
  sort(a, a + n);
  cout << a[n / 2] - a[n / 2 - 1] << endl;
}
Problem p02990 (Python)

Buggy submission (status: Runtime Error):
import math

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


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


for i in range(1, k + 1):
    # print("{0}C{1} * {2}C{3}".format(n - k + 1, i, k-1,i-1))
    print(((cmb_count((n - k + 1), i) % mod) * (cmb_count(k - 1, i - 1)) % mod))


Fixed submission:
import math

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


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


for i in range(1, k + 1):
    # print("{0}C{1} * {2}C{3}".format(n - k + 1, i, k-1,i-1))
    if n - k + 1 >= i:
        print(((cmb_count((n - k + 1), i) % mod) * (cmb_count(k - 1, i - 1)) % mod))
    else:
        print(0)
Problem p02990 (Python)

Buggy submission (status: Runtime Error):
from scipy.special import comb


def solve(string):
    n, k = map(int, string.split())
    ans = []
    for i in range(1, k + 1):
        base = comb(n - k + 1, i, exact=True)
        var = comb(k - 1, i - 1, exact=True)
        ans.append(str(base * var % (10**9 + 7)))
    return "\n".join(ans)


if __name__ == "__main__":
    print(solve(input()))


Fixed submission:
from scipy.misc import comb


def solve(string):
    n, k = map(int, string.split())
    ans = []
    for i in range(1, k + 1):
        base = comb(n - k + 1, i, exact=True)
        var = comb(k - 1, i - 1, exact=True)
        ans.append(str(base * var % (10**9 + 7)))
    return "\n".join(ans)


if __name__ == "__main__":
    print(solve(input()))
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define Hello                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define endl '\n'
#define ll long long
const int mod = 1e9 + 7, N = 20000;
ll fact[N], inv[N];
ll fp(ll base, ll exp) {
  if (exp == 0)
    return 1;
  ll ans = fp(base, exp / 2);
  if (exp % 2 == 0)
    return (ans * ans) % mod;
  else
    return (((ans * ans) % mod) * base) % mod;
}
void calcFacAndInv(ll n) {
  fact[0] = inv[0] = 1;
  for (ll i = 1; i <= n; i++) {
    fact[i] = (i * fact[i - 1]) % mod;
    inv[i] = fp(fact[i], mod - 2);
  }
}
ll ncr(ll n, ll r) { return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod; }

int main() {
  Hello calcFacAndInv(N - 5);
  ll n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    ll ans = ((ncr(n - k + 1, i) % mod) * (ncr(k - 1, i - 1) % mod)) % mod;
    cout << ans << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define Hello                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define endl '\n'
#define ll long long
const int mod = 1e9 + 7, N = 20000;
ll fact[N], inv[N];
ll fp(ll base, ll exp) {
  if (exp == 0)
    return 1;
  ll ans = fp(base, exp / 2);
  if (exp % 2 == 0)
    return (ans * ans) % mod;
  else
    return (((ans * ans) % mod) * base) % mod;
}
void calcFacAndInv(ll n) {
  fact[0] = inv[0] = 1;
  for (ll i = 1; i <= n; i++) {
    fact[i] = (i * fact[i - 1]) % mod;
    inv[i] = fp(fact[i], mod - 2);
  }
}
ll ncr(ll n, ll r) {
  if (r > n)
    return 0;
  return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

int main() {
  Hello calcFacAndInv(N - 5);
  ll n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    ll ans = ((ncr(n - k + 1, i) % mod) * (ncr(k - 1, i - 1) % mod)) % mod;
    cout << ans << endl;
  }
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
const int MAXN = 5010;
const int mod = 1e9 + 7;
int n, k, fac[MAXN], inv[MAXN];
int getc(int n, int m) {
  return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
void work() {
  fac[0] = inv[0] = fac[1] = inv[1] = 1;
  for (reg int i = 2; i <= 2000; ++i)
    fac[i] = 1ll * fac[i - 1] * i % mod,
    inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
  for (reg int i = 2; i <= 2000; ++i)
    inv[i] = 1ll * inv[i - 1] * inv[i] % mod;
  scanf("%lld%lld", &n, &k);
  for (reg int i = 1; i <= k; ++i)
    printf("%lld\n", getc(k - 1, i - 1) * getc(n - k + 1, i) % mod);
}
signed main() {
  int _ = 1;
  // scanf("%d", &_);
  while (_--)
    work();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
const int MAXN = 5010;
const int mod = 1e9 + 7;
int n, k, fac[MAXN], inv[MAXN];
int getc(int n, int m) {
  if (m > n)
    return 0;
  return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
void work() {
  fac[0] = inv[0] = fac[1] = inv[1] = 1;
  for (reg int i = 2; i <= 2000; ++i)
    fac[i] = 1ll * fac[i - 1] * i % mod,
    inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
  for (reg int i = 2; i <= 2000; ++i)
    inv[i] = 1ll * inv[i - 1] * inv[i] % mod;
  scanf("%lld%lld", &n, &k);
  for (reg int i = 1; i <= k; ++i)
    printf("%lld\n", getc(k - 1, i - 1) * getc(n - k + 1, i) % mod);
}
signed main() {
  int _ = 1;
  // scanf("%d", &_);
  while (_--)
    work();
  return 0;
}
Problem p02990 (C++)

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

using namespace std;

using LL = long long;

const LL MOD = 1000000007;
LL fac[2020];

LL power(LL a, LL b) {
  LL x = 1, y = a;
  while (b > 0) {
    if (b % 2)
      x = (x * y) % MOD;
    y = (y * y) % MOD;
    b /= 2;
  }
  return x % MOD;
}

LL mod_inv(LL n) { return power(n, MOD - 2); }

LL nCr(LL n, LL k) {
  if (k == 0 || k == n)
    return 1;
  return (fac[n] * mod_inv(fac[k]) % MOD * mod_inv(fac[n - k]) % MOD) % MOD;
}

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

  fac[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fac[i] = (fac[i - 1] * i) % MOD;
  }

  for (int i = 1; i <= k; ++i) {
    LL ans = (nCr(k - 1, i - 1) * nCr(n - k + 1, i)) % MOD;
    cout << ans << endl;
  }

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"

using namespace std;

using LL = long long;

const LL MOD = 1000000007;
LL fac[2020];

LL power(LL a, LL b) {
  LL x = 1, y = a;
  while (b > 0) {
    if (b % 2)
      x = (x * y) % MOD;
    y = (y * y) % MOD;
    b /= 2;
  }
  return x % MOD;
}

LL mod_inv(LL n) { return power(n, MOD - 2); }

LL nCr(LL n, LL k) {
  if (k == 0 || k == n)
    return 1;
  return (fac[n] * mod_inv(fac[k]) % MOD * mod_inv(fac[n - k]) % MOD) % MOD;
}

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

  fac[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fac[i] = (fac[i - 1] * i) % MOD;
  }

  for (int i = 1; i <= k; ++i) {
    // group blues: k - 1 choose i - 1
    // place reds: i - 1 set, (n - k + 1) choose i
    if (i - 1 > n - k) {
      cout << 0 << endl;
    } else {
      LL ans = (nCr(k - 1, i - 1) * nCr(n - k + 1, i)) % MOD;
      cout << ans << endl;
    }
  }

  return 0;
}
Problem p02990 (C++)

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

typedef long long ll;

const ll mod = 1e9 + 7;

#define ff(i, n) for (int i = 1; i <= n; i++)

ll C[4005][4005], n, k;

ll solve(int i, int total) {
  if (total < i)
    return 0;
  if (i == 0 && total > 0)
    return 0;
  if (i < 0)
    return 0;
  total -= i;
  return C[i - 1][total + i - 1];
}

int main() {
  C[0][0] = 1;
  for (int i = 1; i <= 4000; i++) {
    C[0][i] = C[i][i] = 1;
    for (int j = 1; j < i; j++) {
      C[j][i] = (C[j][i - 1] + C[j - 1][i - 1]) % mod;
    }
  }
  cin >> n >> k;
  for (int i = 1; i <= k; i++)
    cout << (solve(i, k) *
             (solve(i - 1, n - k) + 2 * solve(i, n - k) + solve(i + 1, n - k)) %
             mod) %
                mod
         << endl;
}
// hahahahahahahahahhahahahahahaahahahahhahahahahahahah


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

typedef long long ll;

const ll mod = 1e9 + 7;

#define ff(i, n) for (int i = 1; i <= n; i++)

ll C[4005][4005], n, k;

ll solve(int i, int total) {
  if (total < i)
    return 0;
  if (i == 0 && total > 0)
    return 0;
  if (i == 0 && total == 0)
    return 1;
  if (i < 0)
    return 0;
  total -= i;
  return C[i - 1][total + i - 1];
}

int main() {
  C[0][0] = 1;
  for (int i = 1; i <= 4000; i++) {
    C[0][i] = C[i][i] = 1;
    for (int j = 1; j < i; j++) {
      C[j][i] = (C[j][i - 1] + C[j - 1][i - 1]) % mod;
    }
  }
  cin >> n >> k;
  for (int i = 1; i <= k; i++)
    cout << (solve(i, k) *
             (solve(i - 1, n - k) + 2 * solve(i, n - k) + solve(i + 1, n - k)) %
             mod) %
                mod
         << endl;
}
// hahahahahahahahahhahahahahahaahahahahhahahahahahahah
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
// 関数
const long INF = 1000000000000000;
const long MOD = 1000000007;
long modinv(long a) {
  long b = MOD, u = 1, v = 0;
  while (b) {
    long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0)
    u += MOD;
  return u;
}

int main(void) {
  vector<long> kaizyo(50000);
  kaizyo.at(0) = 1;
  for (int i = 1; i < 5000; i++) {
    kaizyo.at(i) = kaizyo.at(i - 1) * i;
    kaizyo.at(i) %= MOD;
  }

  long N, K;
  cin >> N >> K;

  for (int i = 1; i <= K; i++) {
    long freeb = K - i;
    long freer = (N - K) - i + 1;

    long b = (kaizyo.at(freeb + i - 1) * modinv(kaizyo.at(freeb)) % MOD) *
             modinv(kaizyo.at(i - 1));
    long r = (kaizyo.at(freer + i) * modinv(kaizyo.at(freer)) % MOD) *
             modinv(kaizyo.at(i));

    cout << ((b % MOD) * (r % MOD)) % MOD << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
// 関数
const long INF = 1000000000000000;
const long MOD = 1000000007;
long modinv(long a) {
  long b = MOD, u = 1, v = 0;
  while (b) {
    long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0)
    u += MOD;
  return u;
}

int main(void) {
  vector<long> kaizyo(50000);
  kaizyo.at(0) = 1;
  for (int i = 1; i < 5000; i++) {
    kaizyo.at(i) = kaizyo.at(i - 1) * i;
    kaizyo.at(i) %= MOD;
  }

  long N, K;
  cin >> N >> K;

  for (int i = 1; i <= K; i++) {
    long freeb = K - i;
    long freer = (N - K) - i + 1;
    if (freer < 0) {
      cout << 0 << endl;
      continue;
    }
    long b = (kaizyo.at(freeb + i - 1) * modinv(kaizyo.at(freeb)) % MOD) *
             modinv(kaizyo.at(i - 1));
    long r = (kaizyo.at(freer + i) * modinv(kaizyo.at(freer)) % MOD) *
             modinv(kaizyo.at(i));

    cout << ((b % MOD) * (r % MOD)) % MOD << endl;
  }
}
Problem p02990 (C++)

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

long long int mod = 1000000007;

long long int f[1010100];
void init() {
  f[0] = 1;
  for (int i = 1; i < 1010100; i++)
    f[i] = (f[i - 1] * i) % mod;
}

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

long long int C(int n, int k) {
  long long int a = f[n];     // = n!
  long long int b = f[n - k]; // = (n-k)!
  long long int c = f[k];     // = k!

  long long int bc = (b * c) % mod;

  return (a * inv(bc)) % mod;
}

void Main() {
  init();
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    if (k - 1 < i)
      cout << 0 << endl;
    else
      cout << (C(n - k + 1, i + 1) * C(k - 1, i)) % mod << endl;
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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

long long int mod = 1000000007;

long long int f[1010100];
void init() {
  f[0] = 1;
  for (int i = 1; i < 1010100; i++)
    f[i] = (f[i - 1] * i) % mod;
}

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

long long int C(int n, int k) {
  long long int a = f[n];     // = n!
  long long int b = f[n - k]; // = (n-k)!
  long long int c = f[k];     // = k!

  long long int bc = (b * c) % mod;

  return (a * inv(bc)) % mod;
}

void Main() {
  init();
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    if (n - k + 1 < i + 1 || k - 1 < i)
      cout << 0 << endl;
    else
      cout << (C(n - k + 1, i + 1) * C(k - 1, i)) % mod << endl;
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
typedef long long ll;

const ll mod = 1e9 + 7;

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

ll modfact(ll na, ll nz) {
  if (na == nz)
    return 1;
  else
    return na * modfact(na - 1, nz) % mod;
}

ll modcomb(ll n, ll k) {
  return modfact(n, k) * modpow(modfact(n - k, 0), mod - 2) % mod;
}

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

Fixed submission:
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
typedef long long ll;

const ll mod = 1e9 + 7;

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

ll modfact(ll na, ll nz) {
  if (na == nz)
    return 1;
  else
    return na * modfact(na - 1, nz) % mod;
}

ll modcomb(ll n, ll k) {
  return modfact(n, k) * modpow(modfact(n - k, 0), mod - 2) % mod;
}

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d", &x);

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

ll fac(int n, ll mod) {
  if (n == 1 || n == 0)
    return 1;
  return n * fac(n - 1, mod) % mod;
}

ll solve(int n, int i, int k) {
  ll x1, x2, x3, tmp, mod = 1e9 + 7;
  if (k == 0)
    x1 = 1ll;
  else {
    tmp = fac(k - 1 - i, mod) * fac(i, mod) % mod;
    x1 = fac(k - 1, mod) * mpow(tmp, mod - 2, mod) % mod;
  }
  x3 = fac(n - k + 1, mod);
  tmp = fac(i + 1, mod) * fac(n - k - i, mod) % mod;
  x2 = x3 * mpow(tmp, mod - 2, mod) % mod;

  return x1 * x2 % mod;
}
int main() {
  int n, k;
  sc(n) sc(k) for (int i = 0; i < k; i++) {
    if (n - k - i < 0)
      cout << 0 << endl;
    cout << solve(n, i, k) << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d", &x);

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

ll fac(int n, ll mod) {
  if (n == 1 || n == 0)
    return 1;
  return n * fac(n - 1, mod) % mod;
}

ll solve(int n, int i, int k) {
  ll x1, x2, x3, tmp, mod = 1e9 + 7;
  if (k == 0)
    x1 = 1ll;
  else {
    tmp = fac(k - 1 - i, mod) * fac(i, mod) % mod;
    x1 = fac(k - 1, mod) * mpow(tmp, mod - 2, mod) % mod;
  }
  x3 = fac(n - k + 1, mod);
  tmp = fac(i + 1, mod) * fac(n - k - i, mod) % mod;
  x2 = x3 * mpow(tmp, mod - 2, mod) % mod;

  return x1 * x2 % mod;
}
int main() {
  int n, k;
  sc(n) sc(k) for (int i = 0; i < k; i++) {
    if (n - k - i < 0)
      cout << 0 << endl;
    else
      cout << solve(n, i, k) << endl;
  }
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <stdlib.h>
#define ll long long
const ll INF = 0x3f3f3f3f;
#define mod 1000000007
using namespace std;
// priority_queue
const ll Maxn = 1e5;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll kc(ll a, ll b) {
  ll c = 1;
  while (b) {
    if (b & 1)
      c = (c * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return c;
}
bool cmp(double x, double y) { return x > y; }
ll vim[2003], ly[2003];
ll C(int a, int b) {
  if (b == 0 || a == b)
    return 1;
  return vim[a] * ly[b] % mod * ly[a - b] % mod;
}

void dd() {
  vim[0] = 1;
  for (int i = 1; i <= 2000; i++)
    vim[i] = vim[i - 1] * i % mod, ly[i] = kc(vim[i], mod - 2);
}
int main() {
  ios::sync_with_stdio(false);
  dd();
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cout << C(m - 1, i - 1) % mod * C(n - m + 1, i) % mod << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <stdlib.h>
#define ll long long
const ll INF = 0x3f3f3f3f;
#define mod 1000000007
using namespace std;
// priority_queue
const ll Maxn = 1e5;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll kc(ll a, ll b) {
  ll c = 1;
  while (b) {
    if (b & 1)
      c = (c * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return c;
}
bool cmp(double x, double y) { return x > y; }
ll vim[2003], ly[2003];
ll C(int a, int b) {
  if (b == 0 || a == b)
    return 1;
  if (a < b)
    return 0;
  return vim[a] * ly[b] % mod * ly[a - b] % mod;
}

void dd() {
  vim[0] = 1;
  for (int i = 1; i <= 2000; i++)
    vim[i] = vim[i - 1] * i % mod, ly[i] = kc(vim[i], mod - 2);
}
int main() {
  ios::sync_with_stdio(false);
  dd();
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cout << C(m - 1, i - 1) % mod * C(n - m + 1, i) % mod << endl;
  }
}
Problem p02990 (C++)

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

using i64 = long long;
using u64 = unsigned long long;

const int mod = (int)1e9 + 7;

void __print() { cerr << "]\n"; }

template <typename T, typename... V> void __print(T t, V... v) {
  cerr << t;
  if (sizeof...(v))
    cerr << ", ";
  __print(v...);
}

#define dbg(x...) cerr << "[" << #x << "] = [", __print(x)
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(NULL)

i64 C[2002][2002];
int main() {
  memset(C, 0, sizeof C);
  for (int i = 0; i <= 2000; 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] + C[i - 1][j - 1];
        C[i][j] %= mod;
      }
    }
  }
  i64 n, k;
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= k; i++) {
    i64 ans = 0;
    if (i > 1)
      ans += C[k - 1][i - 1] * C[n - k - 1][i - 2];
    ans %= mod;
    ans += C[k - 1][i - 1] * C[n - k - 1][i];
    ans %= mod;
    ans += 2 * C[k - 1][i - 1] * C[n - k - 1][i - 1];
    ans %= mod;
    printf("%lld\n", ans);
  }
}


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

using i64 = long long;
using u64 = unsigned long long;

const int mod = (int)1e9 + 7;

void __print() { cerr << "]\n"; }

template <typename T, typename... V> void __print(T t, V... v) {
  cerr << t;
  if (sizeof...(v))
    cerr << ", ";
  __print(v...);
}

#define dbg(x...) cerr << "[" << #x << "] = [", __print(x)
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(NULL)

i64 C[2002][2002];
int main() {
  memset(C, 0, sizeof C);
  for (int i = 0; i <= 2000; 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] + C[i - 1][j - 1];
        C[i][j] %= mod;
      }
    }
  }
  i64 n, k;
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= k; i++) {
    i64 ans = 0;
    if (n == k) {
      if (i == 1)
        puts("1");
      else
        puts("0");
      continue;
    }
    if (i > 1)
      ans += C[k - 1][i - 1] * C[n - k - 1][i - 2];
    ans %= mod;
    ans += C[k - 1][i - 1] * C[n - k - 1][i];
    ans %= mod;
    ans += 2 * C[k - 1][i - 1] * C[n - k - 1][i - 1];
    ans %= mod;
    printf("%lld\n", ans);
  }
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#define ll long long
#define IO                                                                     \
  ios::sync_with_stdio(false);                                                 \
  cin.tie();                                                                   \
  cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
ll fac[5500];
ll pows(ll a, ll n) {
  ll ans = 1;
  while (n) {
    if (n & 1) {
      ans = ans * a % mod;
    }
    a = a * a % mod;
    n >>= 1;
  }
  return ans % mod;
}
ll inv(ll a) { return pows(a, mod - 2) % mod; }
ll c(ll n, ll m) { return fac[m] * inv(fac[m - n]) % mod * inv(fac[n]) % mod; }
int main() {
  fac[0] = 1;
  for (ll i = 1; i < 3000; i++) {
    fac[i] = fac[i - 1] * i % mod;
  }
  ll n, k;
  ll ans;
  cin >> n >> k;
  for (ll i = 1; i <= k; i++) {
    ll a, b;
    a = c(i, n - k + 1);
    b = c(i - 1, k - 1);
    ans = a * b % mod;
    cout << ans << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#define ll long long
#define IO                                                                     \
  ios::sync_with_stdio(false);                                                 \
  cin.tie();                                                                   \
  cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
ll fac[5500];
ll pows(ll a, ll n) {
  ll ans = 1;
  while (n) {
    if (n & 1) {
      ans = ans * a % mod;
    }
    a = a * a % mod;
    n >>= 1;
  }
  return ans % mod;
}
ll inv(ll a) { return pows(a, mod - 2) % mod; }
ll c(ll n, ll m) {
  if (n == 0 || m == n)
    return 1;
  if (m < n)
    return 0;
  return fac[m] * inv(fac[m - n]) % mod * inv(fac[n]) % mod;
}
int main() {
  fac[0] = 1;
  for (ll i = 1; i < 3000; i++) {
    fac[i] = fac[i - 1] * i % mod;
  }
  ll n, k;
  ll ans;
  cin >> n >> k;
  for (ll i = 1; i <= k; i++) {
    ll a, b;
    a = c(i, n - k + 1);
    b = c(i - 1, k - 1);
    ans = a * b % mod;
    cout << ans << endl;
  }
  return 0;
}
Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <fstream>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;

const ll Q = 1000000007;

ll fact_list[100005];

ll pow_q(ll x, ll y) {
  if (y == 0)
    return 1;
  ll ans = 1;
  ll z = x;
  ll s = 0;
  while (y >> s > 0) {
    if ((y >> s) % 2)
      ans *= z;
    ans %= Q;
    ++s;
    z *= z;
    z %= Q;
  }
  return ans;
}

void set_fact() {
  fact_list[0] = 1;
  for (ll i = 1; i < 100005; i++) {
    fact_list[i] = i * fact_list[i - 1];
    fact_list[i] %= Q;
  }
}

ll combi_q(ll x, ll y) {
  return (((fact_list[x] * pow_q(fact_list[y], Q - 2)) % Q) *
          pow_q(fact_list[x - y], Q - 2)) %
         Q;
}

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

  cin.tie(0);
  ios::sync_with_stdio(false);

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

  set_fact();

  for (int i = 0; i < k; i++)
    cout << combi_q(n - k + 1, i + 1) * combi_q(k - 1, i) % Q << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <fstream>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;

const ll Q = 1000000007;

ll fact_list[100005];

ll pow_q(ll x, ll y) {
  if (y == 0)
    return 1;
  ll ans = 1;
  ll z = x;
  ll s = 0;
  while (y >> s > 0) {
    if ((y >> s) % 2)
      ans *= z;
    ans %= Q;
    ++s;
    z *= z;
    z %= Q;
  }
  return ans;
}

void set_fact() {
  fact_list[0] = 1;
  for (ll i = 1; i < 100005; i++) {
    fact_list[i] = i * fact_list[i - 1];
    fact_list[i] %= Q;
  }
}

ll combi_q(ll x, ll y) {
  if (x < y)
    return 0;
  return (((fact_list[x] * pow_q(fact_list[y], Q - 2)) % Q) *
          pow_q(fact_list[x - y], Q - 2)) %
         Q;
}

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

  cin.tie(0);
  ios::sync_with_stdio(false);

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

  set_fact();

  for (int i = 0; i < k; i++)
    cout << combi_q(n - k + 1, i + 1) * combi_q(k - 1, i) % Q << endl;

  return 0;
}
Problem p02990 (C++)

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

using namespace std;

#define all(x) begin(x), end(x)

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

constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 4003;

int sum(int a, int b, int mod = MOD) {
  int c = a + b;
  if (c >= mod) {
    c -= mod;
  }

  return c;
}

inline int prod(int a, int b, int mod = MOD) { return (1LL * a * b) % mod; }

int modpow(int base, int exp, int mod = MOD) {
  int res = 1;
  int cur = base;
  for (int p = 1; p <= exp; p <<= 1) {
    if (p & exp) {
      res = prod(res, cur, mod);
    }

    cur = prod(cur, cur, mod);
  }

  return res;
}

inline int inv(int x, int mod = MOD) { return modpow(x, mod - 2, mod); }

int fact[MAXN], tcaf[MAXN];

void gen_fact() {
  fact[0] = 1;
  for (int i = 1; i < MAXN; ++i) {
    fact[i] = prod(fact[i - 1], i);
  }

  tcaf[MAXN - 1] = inv(fact[MAXN - 1]);
  for (int i = MAXN - 2; i >= 0; --i) {
    tcaf[i] = prod(tcaf[i + 1], i + 1);
  }
}

int choose(int n, int k) {
  assert(k >= 0 and k <= n);

  return prod(fact[n], prod(tcaf[k], tcaf[n - k]));
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  gen_fact();

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

  for (int i = 1; i <= k; ++i) {
    // break up k balls into i non-empty groups
    // (k - 1) choose (i - 1)
    int splits = choose(k - 1, i - 1);

    // n + 1 places to put them
    int spots = choose(n - k + 1, i);

    cout << prod(splits, spots) << '\n';
  }

  return 0;
}


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

using namespace std;

#define all(x) begin(x), end(x)

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

constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 4003;

int sum(int a, int b, int mod = MOD) {
  int c = a + b;
  if (c >= mod) {
    c -= mod;
  }

  return c;
}

inline int prod(int a, int b, int mod = MOD) { return (1LL * a * b) % mod; }

int modpow(int base, int exp, int mod = MOD) {
  int res = 1;
  int cur = base;
  for (int p = 1; p <= exp; p <<= 1) {
    if (p & exp) {
      res = prod(res, cur, mod);
    }

    cur = prod(cur, cur, mod);
  }

  return res;
}

inline int inv(int x, int mod = MOD) { return modpow(x, mod - 2, mod); }

int fact[MAXN], tcaf[MAXN];

void gen_fact() {
  fact[0] = 1;
  for (int i = 1; i < MAXN; ++i) {
    fact[i] = prod(fact[i - 1], i);
  }

  tcaf[MAXN - 1] = inv(fact[MAXN - 1]);
  for (int i = MAXN - 2; i >= 0; --i) {
    tcaf[i] = prod(tcaf[i + 1], i + 1);
  }
}

int choose(int n, int k) {
  if (!(0 <= k and k <= n)) {
    return 0;
  }

  return prod(fact[n], prod(tcaf[k], tcaf[n - k]));
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  gen_fact();

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

  for (int i = 1; i <= k; ++i) {
    // break up k balls into i non-empty groups
    // (k - 1) choose (i - 1)
    int splits = choose(k - 1, i - 1);

    // n + 1 places to put them
    int spots = choose(n - k + 1, i);

    cout << prod(splits, spots) << '\n';
  }

  return 0;
}