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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
const int N = 2 * 1e5 + 100, M = 4100;
int n;
int a[N], b[N], MAX;
ll fac[M * 2], inv[M * 2], dp[M][M];
inline ll m_pow(ll a, int b) {
  ll ans = 1;
  while (b) {
    if (b & 1)
      ans = (ans * a) % mod;
    b >>= 1;
    a = (a * a) % mod;
  }
  return ans;
}
inline void add(ll &a, ll b) { a = (a + b) % mod; }
inline void mul(ll &a, ll b) { a = (a * b) % mod; }
inline void sep(ll &a, ll b) { a = (a * m_pow(b, mod - 2)) % mod; }
inline void del(ll &a, ll b) { a = (a - b + mod) % mod; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    dp[2000 - a[i]][2000 - b[i]]++;
    MAX = max(MAX, a[i] + b[i]);
  }
  fac[0] = 1;
  for (int i = 1; i <= 2 * MAX; i++)
    fac[i] = (fac[i - 1] * i) % mod;
  inv[2 * MAX] = m_pow(fac[2 * MAX], mod - 2);
  for (int i = 2 * MAX - 1; i >= 1; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % mod;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= 4000; j++)
      dp[i][j] = (dp[i][j] + dp[i - 1][j] + dp[i][j - 1]) % mod;
  }
  ll ans = 0, num;
  for (int i = 1; i <= n; i++) {
    add(ans, dp[a[i] + 2000][b[i] + 2000]);
    num = fac[a[i] * 2 + b[i] * 2];
    mul(num, inv[a[i] * 2]);
    mul(num, inv[b[i] * 2]);
    del(ans, num);
  }
  sep(ans, 2);
  printf("%lld\n", ans);
}

Fixed submission:
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
const int N = 2 * 1e5 + 100, M = 4100;
int n;
int a[N], b[N], MAX;
ll fac[M * 2], inv[M * 2], dp[M][M];
inline ll m_pow(ll a, int b) {
  ll ans = 1;
  while (b) {
    if (b & 1)
      ans = (ans * a) % mod;
    b >>= 1;
    a = (a * a) % mod;
  }
  return ans;
}
inline void add(ll &a, ll b) { a = (a + b) % mod; }
inline void mul(ll &a, ll b) { a = (a * b) % mod; }
inline void sep(ll &a, ll b) { a = (a * m_pow(b, mod - 2)) % mod; }
inline void del(ll &a, ll b) { a = (a - b + mod) % mod; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    dp[2000 - a[i]][2000 - b[i]]++;
    MAX = max(MAX, a[i] + b[i]);
  }
  fac[0] = 1;
  for (int i = 1; i <= 2 * MAX; i++)
    fac[i] = (fac[i - 1] * i) % mod;
  inv[2 * MAX] = m_pow(fac[2 * MAX], mod - 2);
  for (int i = 2 * MAX - 1; i >= 1; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % mod;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= 4000; j++) {
      if (i != 0)
        add(dp[i][j], dp[i - 1][j]);
      if (j != 0)
        add(dp[i][j], dp[i][j - 1]);
    }
  }
  ll ans = 0, num;
  for (int i = 1; i <= n; i++) {
    add(ans, dp[a[i] + 2000][b[i] + 2000]);
    num = fac[a[i] * 2 + b[i] * 2];
    mul(num, inv[a[i] * 2]);
    mul(num, inv[b[i] * 2]);
    del(ans, num);
  }
  sep(ans, 2);
  printf("%lld\n", ans);
}
Problem p04051 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <math.h>
using namespace std;

typedef long long ll;
const int MAXN = 1e6 + 10;
const int MM = 8e3 + 10;
const int Mod = 1e9 + 7;
int N;
int A[MAXN], B[MAXN];
ll fac[MAXN], ifc[MAXN];
ll f[MM][MM];
ll ans;

inline int fp(int a, int b) {
  int x = 1;
  while (b) {
    if (b & 1)
      x = 1ll * x * a % Mod;
    a = 1ll * a * a % Mod;
    b >>= 1;
  }
  return x;
}

inline void init(int n) {
  register int i;
  for (*fac = i = 1; i <= n; ++i)
    fac[i] = 1ll * fac[i - 1] * i % Mod;
  for (ifc[n] = fp(fac[n], Mod - 2), i = n; i; --i)
    ifc[i - 1] = 1ll * ifc[i] * i % Mod;
}

inline int C(int n, int k) {
  if (n < 0 || k < 0 || n < k)
    return 0;
  return 1ll * fac[n] * ifc[k] % Mod * ifc[n - k] % Mod;
}

int main() {
  register int i, j;
  init(8e3);
  scanf("%d", &N);
  for (i = 1; i <= N; ++i)
    scanf("%d%d", A + i, B + i), ++f[2001 - A[i]][2001 - B[i]];
  for (i = 1; i <= 4001; ++i)
    for (j = 1; j <= 4001; ++j)
      f[i][j] = ((ll)f[i][j] + f[i - 1][j] + f[i][j - 1]) % Mod;
  for (i = 1; i <= N; ++i)
    ans = ((ll)ans + f[2001 + A[i]][2001 + B[i]]) % Mod;
  for (i = 1; i <= N; ++i)
    ans = ((ll)ans - C(2 * A[i] + 2 * B[i], 2 * A[i]) + Mod) % Mod;
  printf("%lld\n", 1ll * ans * fp(2, Mod - 2) % Mod);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <math.h>
using namespace std;

typedef long long ll;
const int MAXN = 1e6 + 10;
const int MM = 4e3 + 10;
const int Mod = 1e9 + 7;
int N;
int A[MAXN], B[MAXN];
ll fac[MAXN], ifc[MAXN];
ll f[MM][MM];
ll ans;

inline int fp(int a, int b) {
  int x = 1;
  while (b) {
    if (b & 1)
      x = 1ll * x * a % Mod;
    a = 1ll * a * a % Mod;
    b >>= 1;
  }
  return x;
}

inline void init(int n) {
  register int i;
  for (*fac = i = 1; i <= n; ++i)
    fac[i] = 1ll * fac[i - 1] * i % Mod;
  for (ifc[n] = fp(fac[n], Mod - 2), i = n; i; --i)
    ifc[i - 1] = 1ll * ifc[i] * i % Mod;
}

inline int C(int n, int k) {
  if (n < 0 || k < 0 || n < k)
    return 0;
  return 1ll * fac[n] * ifc[k] % Mod * ifc[n - k] % Mod;
}

int main() {
  register int i, j;
  init(8e3);
  scanf("%d", &N);
  for (i = 1; i <= N; ++i)
    scanf("%d%d", A + i, B + i), ++f[2001 - A[i]][2001 - B[i]];
  for (i = 1; i <= 4001; ++i)
    for (j = 1; j <= 4001; ++j)
      f[i][j] = ((ll)f[i][j] + f[i - 1][j] + f[i][j - 1]) % Mod;
  for (i = 1; i <= N; ++i)
    ans = ((ll)ans + f[2001 + A[i]][2001 + B[i]]) % Mod;
  for (i = 1; i <= N; ++i)
    ans = ((ll)ans - C(2 * A[i] + 2 * B[i], 2 * A[i]) + Mod) % Mod;
  printf("%lld\n", 1ll * ans * fp(2, Mod - 2) % Mod);
  return 0;
}
Problem p04051 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#define mod 1000000007
using namespace std;
long long dp[8001][8001], a[100001], b[100001], ans, jc[8001], invjc[8001];
long long C(int a, int b) {
  return jc[b] * invjc[a] % mod * invjc[b - a] % mod;
}
long long fast_pow(long long a, int b) {
  if (b == 0)
    return 1;
  if (b & 1)
    return fast_pow(a * a % mod, b / 2) * a % mod;
  else
    return fast_pow(a * a % mod, b / 2);
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> a[i] >> b[i];
  for (int i = 1; i <= n; ++i)
    dp[2010 - a[i]][2010 - b[i]]++;
  for (int i = 1; i <= 4010; ++i)
    for (int j = 1; j <= 4010; ++j)
      dp[i][j] = (dp[i][j] + dp[i - 1][j] + dp[i][j - 1]) % mod;
  for (int i = 1; i <= n; ++i)
    ans = (ans + dp[a[i] + 2010][b[i] + 2010]) % mod;
  jc[0] = 1;
  for (int i = 1; i <= 8000; ++i)
    jc[i] = jc[i - 1] * i % mod;
  invjc[8000] = fast_pow(jc[8000], mod - 2);
  for (int i = 7999; i >= 0; --i)
    invjc[i] = invjc[i + 1] * (i + 1) % mod;
  for (int i = 1; i <= n; ++i)
    ans = (ans - C(2 * a[i], 2 * a[i] + 2 * b[i]) + mod) % mod;
  cout << ans * fast_pow(2, mod - 2) % mod << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#define mod 1000000007
using namespace std;
long long dp[8001][8001], a[200001], b[200001], ans, jc[8001], invjc[8001];
long long C(int a, int b) {
  return jc[b] * invjc[a] % mod * invjc[b - a] % mod;
}
long long fast_pow(long long a, int b) {
  if (b == 0)
    return 1;
  if (b & 1)
    return fast_pow(a * a % mod, b / 2) * a % mod;
  else
    return fast_pow(a * a % mod, b / 2);
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> a[i] >> b[i];
  for (int i = 1; i <= n; ++i)
    dp[2010 - a[i]][2010 - b[i]]++;
  for (int i = 1; i <= 4010; ++i)
    for (int j = 1; j <= 4010; ++j)
      dp[i][j] = (dp[i][j] + dp[i - 1][j] + dp[i][j - 1]) % mod;
  for (int i = 1; i <= n; ++i)
    ans = (ans + dp[a[i] + 2010][b[i] + 2010]) % mod;
  jc[0] = 1;
  for (int i = 1; i <= 8000; ++i)
    jc[i] = jc[i - 1] * i % mod;
  invjc[8000] = fast_pow(jc[8000], mod - 2);
  for (int i = 7999; i >= 0; --i)
    invjc[i] = invjc[i + 1] * (i + 1) % mod;
  for (int i = 1; i <= n; ++i)
    ans = (ans - C(2 * a[i], 2 * a[i] + 2 * b[i]) + mod) % mod;
  cout << ans * fast_pow(2, mod - 2) % mod << endl;
  return 0;
}
Problem p04052 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 1e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

ll n, k;
ll d[N];
ll a[N], q[N];
set<pll> s;
vector<ll> G[N];
void Add(ll v, ll u) {
  if (!~v || u > n)
    return;
  G[v].pb(u);
  d[u]++;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  s.insert({-1, -1});
  s.insert({n + n, n + n});
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (i > k)
      s.erase({a[i - k], i - k});
    auto it = *s.lower_bound({a[i], -1});
    ll x = it.S;
    Add(i, x);
    auto itt = s.lower_bound({a[i], -1});
    itt--;
    x = itt->S;
    Add(x, i);
    s.insert({a[i], i});
  }
  set<ll> Q;
  for (int i = 1; i <= n; i++)
    if (!d[i])
      Q.insert(i);
  for (int i = 1; i <= n; i++) {
    ll x = *Q.begin();
    Q.erase(x);
    q[x] = i;
    for (auto u : G[x]) {
      d[u]--;
      if (!d[u])
        Q.insert(u);
    }
  }
  for (int i = 1; i <= n; i++)
    cout << q[i] << '\n';
  return (0);
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 5e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

ll n, k;
ll d[N];
ll a[N], q[N];
set<pll> s;
vector<ll> G[N];
void Add(ll v, ll u) {
  if (!~v || u > n)
    return;
  G[v].pb(u);
  d[u]++;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  s.insert({-1, -1});
  s.insert({n + n, n + n});
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (i > k)
      s.erase({a[i - k], i - k});
    auto it = *s.lower_bound({a[i], -1});
    ll x = it.S;
    Add(i, x);
    auto itt = s.lower_bound({a[i], -1});
    itt--;
    x = itt->S;
    Add(x, i);
    s.insert({a[i], i});
  }
  set<ll> Q;
  for (int i = 1; i <= n; i++)
    if (!d[i])
      Q.insert(i);
  for (int i = 1; i <= n; i++) {
    ll x = *Q.begin();
    Q.erase(x);
    q[x] = i;
    for (auto u : G[x]) {
      d[u]--;
      if (!d[u])
        Q.insert(u);
    }
  }
  for (int i = 1; i <= n; i++)
    cout << q[i] << '\n';
  return (0);
}
Problem p04052 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define N (2000010)

using namespace std;

set<int> S;
set<int>::iterator it;
priority_queue<int> Q;

struct edge {
  int nt, to;
} g[N];

int head[N], p[N], q[N], d[N], k, n, num;

il int gi() {
  RG int x = 0, q = 1;
  RG char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-')
    ch = getchar();
  if (ch == '-')
    q = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = x * 10 + ch - 48, ch = getchar();
  return q * x;
}

il void insert(RG int from, RG int to) {
  g[++num] = (edge){head[from], to}, head[from] = num, ++d[to];
  return;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("permutation.in", "r", stdin);
  freopen("permutation.out", "w", stdout);
#endif
  n = gi(), k = gi();
  for (RG int i = 1; i <= n; ++i)
    q[p[i] = gi()] = i;
  for (RG int i = 1; i <= n; ++i) {
    if (i > k)
      S.erase(p[i - k]);
    it = S.insert(p[i]).first;
    if (++it != S.end())
      insert(i, q[*it]);
  }
  S.clear();
  for (RG int i = n; i; --i) {
    if (i + k <= n)
      S.erase(p[i + k]);
    it = S.insert(p[i]).first;
    if (++it != S.end())
      insert(i, q[*it]);
  }
  for (RG int i = 1; i <= n; ++i)
    if (!d[i])
      Q.push(-i);
  for (RG int id = 1; id <= n; ++id) {
    RG int x = -Q.top();
    Q.pop();
    p[x] = id;
    for (RG int i = head[x]; i; i = g[i].nt)
      if (!(--d[g[i].to]))
        Q.push(-g[i].to);
  }
  for (RG int i = 1; i <= n; ++i)
    printf("%d\n", p[i]);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define N (2000010)

using namespace std;

set<int> S;
set<int>::iterator it;
priority_queue<int> Q;

struct edge {
  int nt, to;
} g[N];

int head[N], p[N], q[N], d[N], k, n, num;

il int gi() {
  RG int x = 0, q = 1;
  RG char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-')
    ch = getchar();
  if (ch == '-')
    q = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = x * 10 + ch - 48, ch = getchar();
  return q * x;
}

il void insert(RG int from, RG int to) {
  g[++num] = (edge){head[from], to}, head[from] = num, ++d[to];
  return;
}

int main() {
  n = gi(), k = gi();
  for (RG int i = 1; i <= n; ++i)
    q[p[i] = gi()] = i;
  for (RG int i = 1; i <= n; ++i) {
    if (i > k)
      S.erase(p[i - k]);
    it = S.insert(p[i]).first;
    if (++it != S.end())
      insert(i, q[*it]);
  }
  S.clear();
  for (RG int i = n; i; --i) {
    if (i + k <= n)
      S.erase(p[i + k]);
    it = S.insert(p[i]).first;
    if (++it != S.end())
      insert(i, q[*it]);
  }
  for (RG int i = 1; i <= n; ++i)
    if (!d[i])
      Q.push(-i);
  for (RG int id = 1; id <= n; ++id) {
    RG int x = -Q.top();
    Q.pop();
    p[x] = id;
    for (RG int i = head[x]; i; i = g[i].nt)
      if (!(--d[g[i].to]))
        Q.push(-g[i].to);
  }
  for (RG int i = 1; i <= n; ++i)
    printf("%d\n", p[i]);
  return 0;
}