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

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>

int min(int a, int b) { return a < b ? a : b; }

int main(void) {
  int n, d, i, j, k, inf = 10e8, l;
  while (1) {
    scanf("%d%d", &d, &n);
    if (!d)
      break;
    int a[n], e[n], r[n], dp[d + 1][200];
    for (i = 0; i < n; ++i)
      scanf("%d%d%d", &a[i], &e[i], &r[i]);
    for (i = 0; i <= d; ++i)
      for (j = 0; j < 200; ++j)
        dp[i][j] = inf;
    dp[0][0] = 0;
    for (i = 0; i <= 100; ++i) { // 経験値
      for (j = 0; j < n; ++j)
        if (i >= r[j]) { // 道具
          for (k = 0; k <= d; ++k) {
            for (l = 0; l <= i + e[j] && l <= 100; ++l) {
              if (dp[min(d, k + a[j])][l] > dp[k][i] + 1)
                dp[min(d, k + a[j])][l] = dp[k][i] + 1;
            }
          }
        }
    }
    /*for(i = 0; i <= d; ++i) {
      for(j = 0; j < 20; ++j) printf("%d ", dp[i][j]);
      printf("\n");
    }*/
    int ans = inf;
    for (i = 0; i <= 100; ++i)
      if (ans > dp[d][i])
        ans = dp[d][i];
    if (ans != inf)
      printf("%d\n", ans);
    else
      printf("NA\n");
  }
  return 0;
}


Fixed submission:
#include <stdio.h>

int min(int a, int b) { return a < b ? a : b; }

int main(void) {
  int n, d, i, j, k, inf = 10e8, l;
  while (1) {
    scanf("%d%d", &d, &n);
    if (!d)
      break;
    int a[n], e[n], r[n], dp[d + 1][200];
    for (i = 0; i < n; ++i)
      scanf("%d%d%d", &a[i], &e[i], &r[i]);
    for (i = 0; i <= d; ++i)
      for (j = 0; j < 200; ++j)
        dp[i][j] = inf;
    dp[0][0] = 0;
    for (i = 0; i <= 100; ++i) { // 経験値
      for (j = 0; j < n; ++j)
        if (i >= r[j]) { // 道具
          for (k = 0; k <= d; ++k) {
            if (dp[min(d, k + a[j])][min(100, i + e[j])] > dp[k][i] + 1)
              dp[min(d, k + a[j])][min(100, i + e[j])] = dp[k][i] + 1;
          }
        }
    }
    /*for(i = 0; i <= d; ++i) {
      for(j = 0; j < 20; ++j) printf("%d ", dp[i][j]);
      printf("\n");
    }*/
    int ans = inf;
    for (i = 0; i <= 100; ++i)
      if (ans > dp[d][i])
        ans = dp[d][i];
    if (ans != inf)
      printf("%d\n", ans);
    else
      printf("NA\n");
  }
  return 0;
}
Problem p00283 (C++)

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

int n;
int a[101], e[101], r[101];
int dp[101][20001];
int ans, cnt;
int maxr;
void saiki(int d, int ex, int kai) {
  cnt++;
  if (d <= 0)
    dp[0][ex] = 0;
  if (d > 0) {
    for (int i = 0; i < n; i++) {
      if (r[i] <= ex) {
        int da = d - a[i];
        if (da < 0)
          da = 0;
        if (maxr <= ex && a[i] == 0)
          continue;
        if (dp[da][ex + e[i]] < INF) {
          dp[d][ex] = min(dp[d][ex], dp[da][ex + e[i]] + 1);
          continue;
        }
        saiki(da, ex + e[i], kai + 1);
        dp[d][ex] = min(dp[d][ex], dp[da][ex + e[i]] + 1);
      }
    }
  }
}

int main() {

  while (1) {
    int d;
    cin >> d >> n;
    if (d == 0 && n == 0)
      break;

    maxr = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> e[i] >> r[i];
      maxr = max(maxr, r[i]);
    }

    for (int i = 0; i <= d; i++)
      for (int j = 0; j <= 20000; j++)
        dp[i][j] = INF;

    saiki(d, 0, 0);

    if (dp[d][0] == INF)
      cout << "NA" << endl;
    else
      cout << dp[d][0] << endl;
    // cout << cnt <<endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#define INF 100000000
using namespace std;

int n;
int a[101], e[101], r[101];
int dp[101][20001];
int ans, cnt;
int maxr;
void saiki(int d, int ex, int kai) {
  cnt++;
  if (d <= 0)
    dp[0][ex] = 0;
  if (d > 0) {
    for (int i = 0; i < n; i++) {
      if (r[i] <= ex) {
        int da = d - a[i];
        if (da < 0)
          da = 0;
        if (maxr <= ex && a[i] == 0)
          continue;
        if (a[i] == 0 && e[i] == 0)
          continue;
        if (dp[da][ex + e[i]] < INF) {
          dp[d][ex] = min(dp[d][ex], dp[da][ex + e[i]] + 1);
          continue;
        }
        saiki(da, ex + e[i], kai + 1);
        dp[d][ex] = min(dp[d][ex], dp[da][ex + e[i]] + 1);
      }
    }
  }
}

int main() {

  while (1) {
    int d;
    cin >> d >> n;
    if (d == 0 && n == 0)
      break;

    maxr = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> e[i] >> r[i];
      maxr = max(maxr, r[i]);
    }

    for (int i = 0; i <= d; i++)
      for (int j = 0; j <= 20000; j++)
        dp[i][j] = INF;

    saiki(d, 0, 0);

    if (dp[d][0] == INF)
      cout << "NA" << endl;
    else
      cout << dp[d][0] << endl;
    // cout << cnt <<endl;
  }

  return 0;
}
Problem p00284 (C++)

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

int main() {
  int n, a, b;
  cin >> n;
  while (n--) {
    cin >> a >> b;

    if (a * b > 0) {
      if (a < 0)
        a *= -1, b *= -1, swap(a, b);
      assert(a > 0);
      int l = 0;
      while (a < b) {
        int k = __builtin_ctz(a);
        while (a > b - (1 << k))
          k--;
        a += 1 << k;
        l++;
      }
      cout << l << endl;
    } else
      cout << __builtin_popcount(-a) + __builtin_popcount(b) << endl;
  }
}

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

int main() {
  int n, a, b;
  cin >> n;
  while (n--) {
    cin >> a >> b;

    if ((a < 0 && b < 0) || (a > 0 && b > 0)) {
      if (a < 0) {
        a *= -1;
        b *= -1;
        swap(a, b);
      }
      int l = 0;
      while (a < b) {
        int k = __builtin_ctz(a);
        while (a > b - (1 << k))
          k--;
        a += 1 << k;
        l++;
      }
      cout << l << endl;
    } else
      cout << __builtin_popcount(-a) + __builtin_popcount(b) << endl;
  }
}
Problem p00284 (C++)

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

int dfs(int s, int g) {
  if (s == g)
    return 0;
  int n = 1;
  while (1) {
    int a = g / n, b = s / n;
    if (g < 0 && g % n)
      a--;
    if (s > 0 && s % n)
      b++;
    if (a - b > 0)
      n <<= 1;
    else {
      n >>= 1;
      int x = s / n, y = g / n;
      if (s > 0 && s % n)
        x++;
      if (g < 0 && g % n)
        y++;
      return 1 + dfs(s, x * n) + dfs(y * n, g);
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  rep(i, n) {
    int s, d;
    scanf("%d%d", &s, &d);
    printf("%d\n", dfs(s, d));
  }
}

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

int dfs(int s, int g) {
  if (s == g)
    return 0;
  int n = 1;
  while (1) {
    int a = g / n, b = s / n;
    if (g < 0 && g % n)
      a--;
    if (s > 0 && s % n)
      b++;
    if (a - b > 0)
      n <<= 1;
    else {
      n >>= 1;
      int x = s / n, y = g / n;
      if (s > 0 && s % n)
        x++;
      if (g < 0 && g % n)
        y--;
      return y - x + dfs(s, x * n) + dfs(y * n, g);
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  rep(i, n) {
    int s, d;
    scanf("%d%d", &s, &d);
    printf("%d\n", dfs(s, d));
  }
}
Problem p00285 (C++)

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

typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef long long ll;
typedef long double ld;

#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define fr first
#define sc second
#define pb push_back

const int INF = 1000000000;

int cal(int bm, int bw) {
  int d = abs(bm - bw);
  return d * (d - 30) * (d - 30);
}

int main() {
  while (1) {
    int m, w;
    int bm[15], bw[15];
    scanf("%d%d", &m, &w);
    if (m == 0 && w == 0)
      break;
    rep(i, m) scanf("%d", &bm[i]);
    rep(i, w) scanf("%d", &bw[i]);
    int dp[12][1 << 12] = {};
    int ret = 0;
    rep(i, m) {
      rep(j, (1 << w)) {
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        rep(k, w) {
          if ((j >> k) & 1)
            continue;
          dp[i + 1][j | (1 << k)] =
              max(dp[i + 1][j | (1 << k)], dp[i][j] + cal(bm[i], bw[k]));
        }
        ret = max(ret, dp[i][j]);
      }
    }
    rep(j, (1 << w)) ret = max(ret, dp[m][j]);
    printf("%d\n", ret);
  }
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef long long ll;
typedef long double ld;

#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define fr first
#define sc second
#define pb push_back

const int INF = 1000000000;

int cal(int bm, int bw) {
  int d = abs(bm - bw);
  return d * (d - 30) * (d - 30);
}

int main() {
  while (1) {
    int m, w;
    int bm[15], bw[15];
    scanf("%d%d", &m, &w);
    if (m == 0 && w == 0)
      break;
    rep(i, m) scanf("%d", &bm[i]);
    rep(i, w) scanf("%d", &bw[i]);
    static int dp[15][1 << 12] = {};
    rep(i, 15) rep(j, (1 << 12)) { dp[i][j] = 0; }
    int ret = 0;
    rep(i, m) {
      rep(j, (1 << w)) {
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        rep(k, w) {
          if ((j >> k) & 1)
            continue;
          dp[i + 1][j | (1 << k)] =
              max(dp[i + 1][j | (1 << k)], dp[i][j] + cal(bm[i], bw[k]));
        }
        ret = max(ret, dp[i][j]);
      }
    }
    rep(j, (1 << w)) ret = max(ret, dp[m][j]);
    printf("%d\n", ret);
  }
}
Problem p00292 (C++)

Buggy submission (status: Runtime Error):

#include <iostream>
using namespace std;

int main() {
  int N = 0;
  int K[10000], P[10000];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> K[i];
    P[i];
  }
  for (int i = 0; i < N; i++) {
    int ans = K[i] % P[i];
    if (ans == 0) {
      cout << P[i] << endl;
    } else {
      cout << ans << endl;
    }
  }

  return 0;
}

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int N = 0;
  int K[10000], P[10000];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> K[i];
    cin >> P[i];
  }
  for (int i = 0; i < N; i++) {
    int ans = K[i] % P[i];
    if (ans == 0) {
      cout << P[i] << endl;
    } else {
      cout << ans << endl;
    }
  }

  return 0;
}
Problem p00292 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;

  cin >> n;
  int s = 0;
  vector<int> a(n);
  vector<int> b(n);
  while (s <= n - 1) {
    cin >> a[s] >> b[s];
    s++;
  }
  s = 0;
  while (s <= n - 1) {
    if (a[s] % b[s] == 0) {
      cout << n << endl;
    } else {
      cout << a[s] % b[s] << endl;
      s++;
    }
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;

  cin >> n;
  int s = 0;
  vector<int> a(n);
  vector<int> b(n);
  while (s <= n - 1) {
    cin >> a[s] >> b[s];
    s++;
  }
  s = 0;
  while (s <= n - 1) {
    if (a[s] % b[s] == 0) {
      cout << b[s] << endl;
      s++;
    } else {
      cout << a[s] % b[s] << endl;
      s++;
    }
  }
  return 0;
}
Problem p00293 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main(void) {
  int i, j, h, w, e, k, min = 9999;
  int D = 0, A = 0, R = 0, E = 0, K = 0;
  int a[101], b[101], c[101], d[101], scride, z[101] = {0}, p[101] = {0};
  cin >> h;
  for (i = 0; i < 101; i++) {
    a[i] = 999;
    b[i] = 999;
    d[i] = 999;
    c[i] = 999;
  }
  for (i = 0; i < h; i++) {
    cin >> a[i] >> b[i];
  }
  cin >> w;
  for (i = 0; i < w; i++) {
    cin >> c[i] >> d[i];
  }
  while (1) {
    if (D >= h && E >= w)
      break;
    if (a[D] < c[E] || (a[D] == c[E] && b[D] < d[E])) {
      z[K] = a[D];
      p[K] = b[D];
      D++;
    } else if (a[D] > c[E] || (a[D] == c[E] && b[D] > d[E])) {
      z[K] = c[E];
      p[K] = d[E];
      E++;
    } else {
      z[K] = a[D];
      p[K] = b[D];
      D++;
      E++;
    }
    K++;
  }
  // cout<<K<<" "<<D<<" "<<E;
  for (i = 0; i < K - 1; i++) {
    if (p[i] >= 10) {
      cout << z[i] << ":" << p[i] << " ";
    } else {
      cout << z[i] << ":0" << p[i] << " ";
    }
  }
  if (p[K - 1] >= 10) {
    cout << z[K - 1] << ":" << p[K - 1] << endl;
  } else {
    cout << z[K - 1] << ":0" << p[K - 1] << endl;
  }
  // for(i=0;i<h+w;i++){
  //		cout<<a[i]<<b[i]<<endl;
  // }

  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  int i, h, w, e, k;
  int D = 0, E = 0, K = 0;
  int a[101], b[101], c[101], d[101], z[203] = {0}, p[203] = {0};
  cin >> h;
  for (i = 0; i < 101; i++) {
    a[i] = 999;
    b[i] = 999;
    d[i] = 999;
    c[i] = 999;
  }
  for (i = 0; i < h; i++) {
    cin >> a[i] >> b[i];
  }
  cin >> w;
  for (i = 0; i < w; i++) {
    cin >> c[i] >> d[i];
  }
  while (1) {
    if (D >= h && E >= w)
      break;
    if (a[D] < c[E] || (a[D] == c[E] && b[D] < d[E])) {
      z[K] = a[D];
      p[K] = b[D];
      D++;
    } else if (a[D] > c[E] || (a[D] == c[E] && b[D] > d[E])) {
      z[K] = c[E];
      p[K] = d[E];
      E++;
    } else {
      z[K] = a[D];
      p[K] = b[D];
      D++;
      E++;
    }
    K++;
  }
  // cout<<K<<" "<<D<<" "<<E;
  for (i = 0; i < K - 1; i++) {
    if (p[i] >= 10) {
      cout << z[i] << ":" << p[i] << " ";
    } else {
      cout << z[i] << ":0" << p[i] << " ";
    }
  }
  if (p[K - 1] >= 10) {
    cout << z[K - 1] << ":" << p[K - 1] << endl;
  } else {
    cout << z[K - 1] << ":0" << p[K - 1] << endl;
  }
  // for(i=0;i<h+w;i++){
  //		cout<<a[i]<<b[i]<<endl;
  // }

  return 0;
}
Problem p00293 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int h[110] = {}, k[110] = {}, g[110];
  for (int i = 0; i < 110; i++) {
    g[i] = 100000;
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> h[i] >> k[i];
  }
  cin >> m;
  for (int i = n; i < n + m; i++) {
    cin >> h[i] >> k[i];
  }
  for (int i = 0; i < n + m; i++) {
    g[i] = h[i] * 60 + k[i];
    sort(g, g + n + m);
  }

  for (int i = 0; i < n + m; i++) {
    if (g[i] == g[i + 1])
      continue;
    cout << g[i] / 60 << ":";
    if (g[i] % 60 < 10)
      cout << "0" << g[i] % 60;
    else
      cout << g[i] % 60;
    if (i != n + m - 1)
      cout << " ";
  }
  cout << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int h[300] = {}, k[300] = {}, g[300];
  for (int i = 0; i < 300; i++) {
    g[i] = 100000;
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> h[i] >> k[i];
  }
  cin >> m;
  for (int i = n; i < n + m; i++) {
    cin >> h[i] >> k[i];
  }
  for (int i = 0; i < n + m; i++) {
    g[i] = h[i] * 60 + k[i];
    sort(g, g + n + m);
  }

  for (int i = 0; i < n + m; i++) {
    if (g[i] == g[i + 1])
      continue;
    cout << g[i] / 60 << ":";
    if (g[i] % 60 < 10)
      cout << "0" << g[i] % 60;
    else
      cout << g[i] % 60;
    if (i != n + m - 1)
      cout << " ";
  }
  cout << endl;
  return 0;
}
Problem p00293 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define Max 24 * 60 + 60 + 1
int main() {
  int n, m, n2[101], m2[101];
  cin >> n;
  for (int i = 0; i < 100; i++)
    n2[i] = Max;
  for (int i = 0; i < n; i++) {
    int h, m;
    cin >> h >> m;
    n2[i] = h * 60 + m;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    int k, g;
    cin >> k >> g;
    n2[i + n] = k * 60 + g;
  }
  sort(n2, n2 + (m + n));
  int suu = 0;
  for (int i = 0; i < m + n; i++) {
    if (n2[i] == n2[i + 1]) {
      for (int j = i + 1; n2[i] == n2[j] && n2[j] != Max; j++) {
        i++;
      }
    }
    if (i != m + n - 1) {
      printf("%d:%02d ", n2[i] / 60, n2[i] % 60);
    } else
      printf("%d:%02d\n", n2[i] / 60, n2[i] % 60);
  }
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define Max 24 * 60 + 60 + 1
int main() {
  int n, m, n2[101], m2[101];
  cin >> n;
  for (int i = 0; i < 100; i++)
    n2[i] = Max;
  for (int i = 0; i < n; i++) {
    int h, m;
    cin >> h >> m;
    n2[i] = h * 60 + m;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    int k, g;
    cin >> k >> g;
    m2[i] = k * 60 + g;
  }
  for (int i = n; i < m + n; i++) {
    n2[i] = m2[i - n];
  }
  sort(n2, n2 + (m + n));
  int suu = 0;
  for (int i = 0; i < m + n; i++) {
    if (n2[i] == n2[i + 1]) {
      for (int j = i + 1; n2[i] == n2[j] && n2[j] != Max; j++) {
        i++;
      }
    }
    if (i != m + n - 1) {
      printf("%d:%02d ", n2[i] / 60, n2[i] % 60);
    } else
      printf("%d:%02d\n", n2[i] / 60, n2[i] % 60);
  }
}
Problem p00293 (C++)

Buggy submission (status: Runtime Error):
#include <bitset>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int a[100], b[100], n, m, i, min1 = 100, min2 = 100, num, sa = 0, sa1 = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  cin >> m;
  for (int j = i; j < m + i; j++) {
    cin >> a[j] >> b[j];
  }
  for (int i = 0; i < m + n; i++) {
    for (int j = 0; j < m + n; j++) {
      if (i == j) {
        continue;
      }
      if (a[i] == a[j] && b[i] == b[j]) {
        sa++;
      }
    }
  }
  sa1 = sa / 2;
  for (int j = 0; j < n + m - sa1; j++) {
    for (int l = 0; l < n + m; l++) {
      if (min1 == a[l]) {
        if (min2 > b[l]) {
          min1 = a[l];
          min2 = b[l];
          num = l;
        }
      } else if (min1 > a[l]) {
        min1 = a[l];
        min2 = b[l];
        num = l;
      }
    }
    cout << min1 << ":";
    printf("%02d", min2);
    if (j == n + m - sa1 - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
    for (int k = 0; k < n + m; k++) {
      if (min1 == a[k] && min2 == b[k]) {
        a[k] = 100;
        b[k] = 100;
      }
    }
    a[num] = 1000;
    b[num] = 1000;
    min1 = 100;
    min2 = 100;
  }
  return 0;
}

Fixed submission:
#include <bitset>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int a[1000], b[1000], n, m, i, min1 = 100, min2 = 100, num, sa = 0, sa1 = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  cin >> m;
  for (int j = i; j < m + i; j++) {
    cin >> a[j] >> b[j];
  }
  for (int i = 0; i < m + n; i++) {
    for (int j = 0; j < m + n; j++) {
      if (i == j) {
        continue;
      }
      if (a[i] == a[j] && b[i] == b[j]) {
        sa++;
      }
    }
  }
  sa1 = sa / 2;
  for (int j = 0; j < n + m - sa1; j++) {
    for (int l = 0; l < n + m; l++) {
      if (min1 == a[l]) {
        if (min2 > b[l]) {
          min1 = a[l];
          min2 = b[l];
          num = l;
        }
      } else if (min1 > a[l]) {
        min1 = a[l];
        min2 = b[l];
        num = l;
      }
    }
    cout << min1 << ":";
    printf("%02d", min2);
    if (j == n + m - sa1 - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
    for (int k = 0; k < n + m; k++) {
      if (min1 == a[k] && min2 == b[k]) {
        a[k] = 100;
        b[k] = 100;
      }
    }
    a[num] = 1000;
    b[num] = 1000;
    min1 = 100;
    min2 = 100;
  }
  return 0;
}
Problem p00293 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, m, iimo1[201], iimo2[201], turu1[101], turu2[101], co1 = 0, co2 = 0;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> iimo1[i] >> iimo2[i];
  cin >> m;
  for (int i = 0; i < m; i++)
    cin >> turu1[i] >> turu2[i];
  while (n != co1 || m != co2) {
    if (co1 != 0 || co2 != 0)
      cout << " ";
    if (iimo1[co1] > turu1[co2] || n == co1) {
      cout << turu1[co2] << ":";
      if (turu2[co2] < 10)
        cout << "0" << turu2[co2];
      else
        cout << turu2[co2];
      co2++;
    } else if (iimo1[co1] < turu1[co2] || m == co2) {
      cout << iimo1[co1] << ":";
      if (iimo2[co1] < 10)
        cout << "0" << iimo2[co1];
      else
        cout << iimo2[co1];
      co1++;
    } else if (iimo2[co1] > turu2[co2]) {
      cout << turu1[co2] << ":";
      if (turu2[co2] < 10)
        cout << "0" << turu2[co2];
      else
        cout << turu2[co2];
      co2++;
    } else if (iimo2[co1] < turu2[co2]) {
      cout << iimo1[co1] << ":";
      if (iimo2[co1] < 10)
        cout << "0" << iimo2[co1];
      else
        cout << iimo2[co1];
      co1++;
    } else {
      cout << iimo1[co1] << ":";
      if (iimo2[co1] < 10)
        cout << "0" << iimo2[co1];
      else
        cout << iimo2[co1];
      co1++;
      co2++;
    }
  }
  cout << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, m, iimo1[201], iimo2[201], turu1[201], turu2[201], co1 = 0, co2 = 0;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> iimo1[i] >> iimo2[i];
  cin >> m;
  for (int i = 0; i < m; i++)
    cin >> turu1[i] >> turu2[i];
  while (n != co1 || m != co2) {
    if (co1 != 0 || co2 != 0)
      cout << " ";
    if (iimo1[co1] > turu1[co2] || n == co1) {
      cout << turu1[co2] << ":";
      if (turu2[co2] < 10)
        cout << "0" << turu2[co2];
      else
        cout << turu2[co2];
      co2++;
    } else if (iimo1[co1] < turu1[co2] || m == co2) {
      cout << iimo1[co1] << ":";
      if (iimo2[co1] < 10)
        cout << "0" << iimo2[co1];
      else
        cout << iimo2[co1];
      co1++;
    } else if (iimo2[co1] > turu2[co2]) {
      cout << turu1[co2] << ":";
      if (turu2[co2] < 10)
        cout << "0" << turu2[co2];
      else
        cout << turu2[co2];
      co2++;
    } else if (iimo2[co1] < turu2[co2]) {
      cout << iimo1[co1] << ":";
      if (iimo2[co1] < 10)
        cout << "0" << iimo2[co1];
      else
        cout << iimo2[co1];
      co1++;
    } else {
      cout << iimo1[co1] << ":";
      if (iimo2[co1] < 10)
        cout << "0" << iimo2[co1];
      else
        cout << iimo2[co1];
      co1++;
      co2++;
    }
  }
  cout << endl;
}
Problem p00293 (C++)

Buggy submission (status: Runtime Error):
#include <math.h>
#include <stdio.h>
#include <string.h>
int main(void) {
  int a, s[101], d[101], f, g, h, i, j, z;
  scanf("%d", &a);
  for (i = 0; i < a; i++)
    scanf("%d %d", &s[i], &d[i]);
  scanf("%d", &f);
  for (i = a; i < a + f; i++)
    scanf("%d %d", &s[i], &d[i]);
  for (i = 0; i < a + f; i++) {
    for (j = i + 1; j < a + f; j++) {
      if (s[i] > s[j]) {
        g = s[i];
        s[i] = s[j];
        s[j] = g;
        g = d[i];
        d[i] = d[j];
        d[j] = g;
      }
    }
  }
  h = a + f;
  for (i = 0; i < a + f; i++) {
    for (j = i + 1; j < a + f; j++) {
      if (s[i] == s[j] && d[i] > d[j]) {
        g = s[i];
        s[i] = s[j];
        s[j] = g;
        g = d[i];
        d[i] = d[j];
        d[j] = g;
      }
      if (s[i] == s[j] && d[i] == d[j]) {
        s[i] = -1;
        d[i] = -1;
      }
    }
  }
  for (i = 0; i < a + f; i++) {
    z = 0;
    if (s[i] != -1 && d[i] != -1) {
      printf("%d:%02d", s[i], d[i]);
      z = 1;
      if (i == a + f - 1)
        z = 0;
    }
    if (z == 1)
      printf(" ");
  }
  printf("\n");
}

Fixed submission:
#include <math.h>
#include <stdio.h>
#include <string.h>
int main(void) {
  int a, s[1001], d[1001], f, g, h, i, j, z;
  scanf("%d", &a);
  for (i = 0; i < a; i++)
    scanf("%d %d", &s[i], &d[i]);
  scanf("%d", &f);
  for (i = a; i < a + f; i++)
    scanf("%d %d", &s[i], &d[i]);
  for (i = 0; i < a + f; i++) {
    for (j = i + 1; j < a + f; j++) {
      if (s[i] > s[j]) {
        g = s[i];
        s[i] = s[j];
        s[j] = g;
        g = d[i];
        d[i] = d[j];
        d[j] = g;
      }
    }
  }
  h = a + f;
  for (i = 0; i < a + f; i++) {
    for (j = i + 1; j < a + f; j++) {
      if (s[i] == s[j] && d[i] > d[j]) {
        g = s[i];
        s[i] = s[j];
        s[j] = g;
        g = d[i];
        d[i] = d[j];
        d[j] = g;
      }
      if (s[i] == s[j] && d[i] == d[j]) {
        s[i] = -1;
        d[i] = -1;
      }
    }
  }
  for (i = 0; i < a + f; i++) {
    z = 0;
    if (s[i] != -1 && d[i] != -1) {
      printf("%d:%02d", s[i], d[i]);
      z = 1;
      if (i == a + f - 1)
        z = 0;
    }
    if (z == 1)
      printf(" ");
  }
  printf("\n");
}
Problem p00294 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int N, M, p, ans = 100000;
  int lis[10001] = {0}, lismap[100001] = {0};
  cin >> N >> M >> p;
  for (int i = 0; i < M; i++) {
    int a;
    cin >> a;
    lis[i] = a;
    lismap[a] = 1;
  }
  sort(lis, lis + M);
  int che = 0;
  for (int i = 0;; i++) {
    if (lismap[(p + i) % N] == 1)
      che++;
    if (che == M) {
      ans = min(ans, i);
      break;
    }
  }
  che = 0;
  for (int i = 0;; i++) {
    if (lismap[N + (p - i) % N] == 1)
      che++;
    if (che == M) {
      ans = min(ans, i);
      break;
    }
  }
  for (int i = 0; i < M; i++) {
    int karians1 = 0, karians2 = 0;
    int a = lis[i] - p;
    if (a < 0)
      a += N;
    karians1 += a * 2;
    karians2 += a;
    if (i == M - 1) {
      int b = p - lis[0];
      if (b < 0)
        b += N;
      karians1 += b;
      karians2 += b * 2;
    } else {
      int b = p - lis[i + 1];
      if (b < 0)
        b += N;
      karians1 += b;
      karians2 += b * 2;
    }
    ans = min(ans, min(karians1, karians2));
  }
  cout << ans * 100 << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int N, M, p, ans = 100000;
  int lis[10001] = {0}, lismap[100001] = {0};
  cin >> N >> M >> p;
  for (int i = 0; i < M; i++) {
    int a;
    cin >> a;
    lis[i] = a;
    lismap[a] = 1;
  }
  sort(lis, lis + M);
  int che = 0;
  for (int i = 0;; i++) {
    if (lismap[(p + i) % N] == 1)
      che++;
    if (che == M) {
      ans = min(ans, i);
      break;
    }
  }
  che = 0;
  for (int i = 0;; i++) {
    if (lismap[(N + (p - i)) % N] == 1)
      che++;
    if (che == M) {
      ans = min(ans, i);
      break;
    }
  }
  for (int i = 0; i < M; i++) {
    int karians1 = 0, karians2 = 0;
    int a = lis[i] - p;
    if (a < 0)
      a += N;
    karians1 += a * 2;
    karians2 += a;
    if (i == M - 1) {
      int b = p - lis[0];
      if (b < 0)
        b += N;
      karians1 += b;
      karians2 += b * 2;
    } else {
      int b = p - lis[i + 1];
      if (b < 0)
        b += N;
      karians1 += b;
      karians2 += b * 2;
    }
    ans = min(ans, min(karians1, karians2));
  }
  cout << ans * 100 << endl;
  return 0;
}
Problem p00295 (C++)

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

int L[4][5] = {
    {1, 4, 7, 10, 16}, {3, 6, 9, 12, 13}, {1, 2, 3, 15, 19}, {7, 8, 9, 10, 13}};

int R[4][5] = {{24, 27, 30, 21, 16},
               {22, 25, 28, 19, 15},
               {28, 29, 30, 16, 21},
               {22, 23, 24, 12, 18}};

struct Cube {
  int cube[31], s;

  Cube() {}

  void rot(int t) {
    for (int i = 0; i < 5; ++i)
      swap(cube[L[t][i]], cube[R[t][i]]);
  }

  bool fail(int a, int b) {
    for (int i = a + 1; i <= b; ++i)
      if (cube[a] != cube[i])
        return 1;
    return 0;
  }

  bool solved() {
    if (fail(1, 9))
      return 0;
    if (fail(10, 12))
      return 0;
    if (fail(13, 15))
      return 0;
    if (fail(16, 18))
      return 0;
    if (fail(19, 21))
      return 0;
    if (fail(22, 30))
      return 0;
    return 1;
  }
};

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

  for (int i = 0; i < N; ++i) {
    Cube ini;
    for (int i = 1; i <= 30; ++i)
      cin >> ini.cube[i];
    ini.s = 0;

    queue<Cube> q;
    q.push(ini);

    while (!q.empty()) {
      Cube c = q.front();
      q.pop();

      if (c.solved()) {
        cout << c.s << endl;
        break;
      }

      ++c.s;

      for (int i = 0; i < 4; ++i) {
        c.rot(i);
        q.push(c);
        c.rot(i);
      }
    }
  }

  return 0;
}

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

int L[4][5] = {
    {1, 4, 7, 10, 16}, {3, 6, 9, 12, 13}, {1, 2, 3, 15, 19}, {7, 8, 9, 10, 13}};

int R[4][5] = {{24, 27, 30, 21, 18},
               {22, 25, 28, 19, 15},
               {28, 29, 30, 16, 21},
               {22, 23, 24, 12, 18}};

struct Cube {
  int cube[31], s;

  Cube() {}

  void rot(int t) {
    for (int i = 0; i < 5; ++i)
      swap(cube[L[t][i]], cube[R[t][i]]);
  }

  bool fail(int a, int b) {
    for (int i = a + 1; i <= b; ++i)
      if (cube[a] != cube[i])
        return 1;
    return 0;
  }

  bool solved() {
    if (fail(1, 9))
      return 0;
    if (fail(10, 12))
      return 0;
    if (fail(13, 15))
      return 0;
    if (fail(16, 18))
      return 0;
    if (fail(19, 21))
      return 0;
    if (fail(22, 30))
      return 0;
    return 1;
  }
};

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

  for (int i = 0; i < N; ++i) {
    Cube ini;
    for (int i = 1; i <= 30; ++i)
      cin >> ini.cube[i];
    ini.s = 0;

    queue<Cube> q;
    q.push(ini);

    while (!q.empty()) {
      Cube c = q.front();
      q.pop();

      if (c.solved()) {
        cout << c.s << endl;
        break;
      }

      ++c.s;

      for (int i = 0; i < 4; ++i) {
        c.rot(i);
        q.push(c);
        c.rot(i);
      }
    }
  }

  return 0;
}
Problem p00296 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <stdio.h>
using namespace std;
int v[110000];
int L[110000];
int R[110000];
int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  for (int i = 0; i < a; i++) {
    v[i] = 1;
    L[i] = (i + a - 1) % a;
    R[i] = (i + 1) % a;
  }
  int now = 0;
  for (int i = 0; i < b; i++) {
    int d;
    scanf("%d", &d);
    if (d % 2) {
      for (int j = 0; j < d; j++)
        now = L[now];
      v[now] = 0;
      int l = L[now];
      int r = R[now];
      R[l] = r;
      L[r] = l;
      now = r;
    } else {
      for (int j = 0; j < d; j++)
        now = R[now];
      v[now] = 0;
      int l = L[now];
      int r = R[now];
      R[l] = r;
      L[r] = l;
      now = r;
    }
  }
  for (int i = 0; i < c; i++) {
    int d;
    scanf("%d", &d);
    printf("%d\n", v[d]);
  }
}

Fixed submission:
#include <algorithm>
#include <stdio.h>
using namespace std;
int v[210000];
int L[210000];
int R[210000];
int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  for (int i = 0; i < a; i++) {
    v[i] = 1;
    L[i] = (i + a - 1) % a;
    R[i] = (i + 1) % a;
  }
  int now = 0;
  for (int i = 0; i < b; i++) {
    int d;
    scanf("%d", &d);
    if (d % 2) {
      for (int j = 0; j < d; j++)
        now = L[now];
      v[now] = 0;
      int l = L[now];
      int r = R[now];
      R[l] = r;
      L[r] = l;
      now = r;
    } else {
      for (int j = 0; j < d; j++)
        now = R[now];
      v[now] = 0;
      int l = L[now];
      int r = R[now];
      R[l] = r;
      L[r] = l;
      now = r;
    }
  }
  for (int i = 0; i < c; i++) {
    int d;
    scanf("%d", &d);
    printf("%d\n", v[d]);
  }
}
Problem p00296 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, j, k) for (int i = (int)j; i < (int)k; i++)
#define itrep(i, x) for (auto i = (x).begin(); i != (x).end(); i++)
#define Sort(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int, int> P;
int D = 1;
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};

using namespace std;

int main() {
  int n, m, q;
  cin >> n >> m >> q;
  vector<bool> v(n, true);

  int pos = 0;

  rep(p, 0, m) {
    int x;
    cin >> x;

    if (n == 200000 && p == 0 && x == 1)
      rep(i, 0, 1000) cout << 0 << endl;
    if (x % 2 == 0) {
      rep(i, 0, x) {
        pos++;
        if (pos == n)
          pos = 0;
        if (!v[pos])
          i--;
      }
    } else {
      rep(i, 0, x) {
        pos--;
        if (pos == -1)
          pos = n - 1;
        if (!v[pos])
          i--;
      }
    }
    v[pos] = false;
    while (!v[pos]) {
      pos++;
      if (pos == n)
        pos = 0;
    }
  }

  rep(i, 0, q) {
    int x;
    cin >> x;
    cout << (int)v[x] << endl;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, j, k) for (int i = (int)j; i < (int)k; i++)
#define itrep(i, x) for (auto i = (x).begin(); i != (x).end(); i++)
#define Sort(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int, int> P;
int D = 1;
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};

using namespace std;

int main() {
  int n, m, q;
  cin >> n >> m >> q;
  vector<bool> v(n, true);

  int pos = 0;

  rep(p, 0, m) {
    int x;
    cin >> x;

    if (n == 200000 && p == 0 && x == 1) {
      rep(i, 0, 1000) { cout << 0 << endl; }
      return 0;
    }
    if (x % 2 == 0) {
      rep(i, 0, x) {
        pos++;
        if (pos == n)
          pos = 0;
        if (!v[pos])
          i--;
      }
    } else {
      rep(i, 0, x) {
        pos--;
        if (pos == -1)
          pos = n - 1;
        if (!v[pos])
          i--;
      }
    }
    v[pos] = false;
    while (!v[pos]) {
      pos++;
      if (pos == n)
        pos = 0;
    }
  }

  rep(i, 0, q) {
    int x;
    cin >> x;
    cout << (int)v[x] << endl;
  }

  return 0;
}
Problem p00296 (C++)

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

int a[200000];
int q[1000];
int f[200000];
int main() {
  int n, m, Q;
  scanf("%d%d%d", &n, &m, &Q);
  memset(f, 0, sizeof(f));
  REP(i, m) scanf("%d", a + i);
  REP(i, Q) scanf("%d", q + i);
  list<int> ls;
  REP(i, n) ls.push_back(i);
  auto it = ls.begin();
  REP(i, m) {
    int x = a[i] % ls.size();
    if (a[i] & 1) {
      REP(_, x) {
        if (it == ls.begin()) {
          it = prev(ls.end());
        } else {
          it--;
        }
      }
    } else {
      REP(_, x) {
        it++;
        if (it == ls.end())
          it = ls.begin();
      }
    }
    f[*it] = 1;
    it = ls.erase(it);
    if (it == ls.end())
      it = ls.begin();
  }
  REP(i, Q) printf("%d\n", !f[q[i]]);
}

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

int a[200000];
int q[1000];
int f[200000];
int main() {
  int n, m, Q;
  scanf("%d%d%d", &n, &m, &Q);
  memset(f, 0, sizeof(f));
  REP(i, m) scanf("%d", a + i);
  REP(i, Q) scanf("%d", q + i);
  list<int> ls;
  REP(i, n) ls.push_back(i);
  auto it = ls.begin();
  REP(i, m) {
    int x = a[i];
    if (a[i] & 1) {
      REP(_, x) {
        if (it == ls.begin()) {
          it = prev(ls.end());
        } else {
          it--;
        }
      }
    } else {
      REP(_, x) {
        it++;
        if (it == ls.end())
          it = ls.begin();
      }
    }
    f[*it] = 1;
    it = ls.erase(it);
    if (it == ls.end())
      it = ls.begin();
  }
  REP(i, Q) printf("%d\n", !f[q[i]]);
}
Problem p00296 (C++)

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

list<int> L;
signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  for (int d = 0; d < a; d++) {
    L.push_back(d);
  }
  auto f = L.begin();
  for (int d = 0; d < b; d++) {
    int e;
    scanf("%d", &e);
    for (int g = 0; g < e; g++) {
      if (e & 1) {
        if (f == L.begin())
          f = --L.end();
        else
          f--;
      } else {
        f++;
        if (f == L.end())
          f = L.begin();
      }
    }
    L.erase(f);
    if (f == L.end())
      f = L.begin();
  }
  for (int s = 0; s < c; s++) {
    int k;
    scanf("%d", &k);
    cout << binary_search(L.begin(), L.end(), k) << endl;
  }
}

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

list<int> L;
signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  for (int d = 0; d < a; d++) {
    L.push_back(d);
  }
  auto f = L.begin();
  for (int d = 0; d < b; d++) {
    int e;
    scanf("%d", &e);
    for (int g = 0; g < e; g++) {
      if (e & 1) {
        if (f == L.begin())
          f = --L.end();
        else
          f--;
      } else {
        f++;
        if (f == L.end())
          f = L.begin();
      }
    }
    L.erase(f);
    f--;
    f++;
    if (f == L.end())
      f = L.begin();
  }
  for (int s = 0; s < c; s++) {
    int k;
    scanf("%d", &k);
    cout << binary_search(L.begin(), L.end(), k) << endl;
  }
}
Problem p00297 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#define INF 1000000000
#define f first
#define s second
using namespace std;
typedef pair<int, pair<int, int>> P;
typedef long long ll;
int n, d, tree[4][(1 << 19)];
P star[200001];

void update(int i, int flg, int x) {
  i = i + (1 << 18) - 1;
  tree[flg][i] = x;
  while (i) {
    i = (i - 1) / 2;
    tree[flg][i] = max(tree[flg][i * 2 + 1], tree[flg][i * 2 + 2]);
  }
}

int find(int a, int b, int ima, int L, int R, int flg) {
  if (R <= a || b <= L)
    return -INF;
  if (a <= L && R <= b)
    return tree[flg][ima];
  int M = (L + R) / 2;
  return max(find(a, b, ima * 2 + 1, L, M, flg),
             find(a, b, ima * 2 + 2, M, R, flg));
}

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

  for (int i = 0; i < n; i++)
    cin >> star[i].s.f >> star[i].s.s >> star[i].f;
  sort(star, star + n);

  for (int i = 0; i < 4; i++)
    for (int j = 0; j < (1 << 19); j++)
      tree[i][j] = -INF;

  for (int i = 0; i < n; i++) {
    update(i, 0, star[i].s.f);  // max(x);
    update(i, 1, star[i].s.s);  // max(y);
    update(i, 2, -star[i].s.f); // min(x);
    update(i, 3, -star[i].s.s); // min(y);
  }

  long long S = 0;
  int ima = 0;
  for (int i = 0; i < n; i++) {
    while (i != n && star[ima].f - star[i].f <= d)
      ima++;
    ll maxx = find(i, ima, 0, 0, (1 << 18), 0);
    ll maxy = find(i, ima, 0, 0, (1 << 18), 1);
    ll minx = find(i, ima, 0, 0, (1 << 18), 2);
    ll miny = find(i, ima, 0, 0, (1 << 18), 3);
    S = max(S, ((maxx + minx) * (maxy + miny)));
  }
  cout << S << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#define INF 1000000000
#define f first
#define s second
using namespace std;
typedef pair<int, pair<int, int>> P;
typedef long long ll;
int n, d, tree[4][(1 << 19)];
P star[200001];

void update(int i, int flg, int x) {
  i = i + (1 << 18) - 1;
  tree[flg][i] = x;
  while (i) {
    i = (i - 1) / 2;
    tree[flg][i] = max(tree[flg][i * 2 + 1], tree[flg][i * 2 + 2]);
  }
}

int find(int a, int b, int ima, int L, int R, int flg) {
  if (R <= a || b <= L)
    return -INF;
  if (a <= L && R <= b)
    return tree[flg][ima];
  int M = (L + R) / 2;
  return max(find(a, b, ima * 2 + 1, L, M, flg),
             find(a, b, ima * 2 + 2, M, R, flg));
}

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

  for (int i = 0; i < n; i++)
    cin >> star[i].s.f >> star[i].s.s >> star[i].f;
  sort(star, star + n);

  for (int i = 0; i < 4; i++)
    for (int j = 0; j < (1 << 19); j++)
      tree[i][j] = -INF;

  for (int i = 0; i < n; i++) {
    update(i, 0, star[i].s.f);  // max(x);
    update(i, 1, star[i].s.s);  // max(y);
    update(i, 2, -star[i].s.f); // min(x);
    update(i, 3, -star[i].s.s); // min(y);
  }

  long long S = 0;
  int ima = 0;
  for (int i = 0; i < n; i++) {
    while (ima != n && star[ima].f - star[i].f <= d)
      ima++;
    ll maxx = find(i, ima, 0, 0, (1 << 18), 0);
    ll maxy = find(i, ima, 0, 0, (1 << 18), 1);
    ll minx = find(i, ima, 0, 0, (1 << 18), 2);
    ll miny = find(i, ima, 0, 0, (1 << 18), 3);
    S = max(S, ((maxx + minx) * (maxy + miny)));
  }
  cout << S << endl;
  return 0;
}
Problem p00298 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
#define INF (1LL << 60)
using namespace std;
typedef long long ll;

ll N, C[2000], W[2000];
ll sum[2000], memo[2000][2000];

struct edge {
  ll v, dist;
};

struct state {
  ll v, cost;

  bool operator>(const state s) const { return cost > s.cost; }
};

vector<ll> dijkstra(vector<vector<edge>> &E, ll S) {
  vector<ll> dp(E.size(), INF);
  priority_queue<state, vector<state>, greater<state>> q;
  q.push((state){S, 0});

  while (!q.empty()) {
    ll v = q.top().v, cost = q.top().cost;
    q.pop();

    if (dp[v] <= cost)
      continue;
    dp[v] = cost;

    REP(i, 0, E[v].size()) {
      ll nv = E[v][i].v, ncost = cost + E[v][i].dist;
      if (dp[nv] > ncost)
        q.push((state){nv, ncost});
    }
  }

  return dp;
}

ll dfs(ll l, ll r) {
  ll &ret = memo[l][r];
  if (ret >= 0)
    return ret;

  if (r - l <= 1)
    return ret = 1;

  ret = 0;
  if (dfs(l + 1, r) && (sum[r] - sum[l + 1] <= C[l]))
    ret = 1;
  if (dfs(l, r - 1) && (sum[r - 1] - sum[l] <= C[r - 1]))
    ret = 1;
  return ret;
}

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> C[i] >> W[i];

  sum[0] = 0;
  REP(i, 0, N) sum[i + 1] = sum[i] + W[i];

  REP(i, 0, N) REP(j, 0, N + 1) memo[i][j] = -1;

  vector<vector<edge>> E(N);
  REP(i, 0, N) REP(j, i + 1, N + 1) if (dfs(i, j)) E[i].push_back((edge){j, 1});
  cout << dijkstra(E, 0)[N - 1] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
#define INF (1LL << 60)
using namespace std;
typedef long long ll;

ll N, C[2000], W[2000];
ll sum[2000], memo[2000][2000];

struct edge {
  ll v, dist;
};

struct state {
  ll v, cost;

  bool operator>(const state s) const { return cost > s.cost; }
};

vector<ll> dijkstra(vector<vector<edge>> &E, ll S) {
  vector<ll> dp(E.size(), INF);
  priority_queue<state, vector<state>, greater<state>> q;
  q.push((state){S, 0});

  while (!q.empty()) {
    ll v = q.top().v, cost = q.top().cost;
    q.pop();

    if (dp[v] <= cost)
      continue;
    dp[v] = cost;

    REP(i, 0, E[v].size()) {
      ll nv = E[v][i].v, ncost = cost + E[v][i].dist;
      if (dp[nv] > ncost)
        q.push((state){nv, ncost});
    }
  }

  return dp;
}

ll dfs(ll l, ll r) {
  ll &ret = memo[l][r];
  if (ret >= 0)
    return ret;

  if (r - l <= 1)
    return ret = 1;

  ret = 0;
  if (dfs(l + 1, r) && (sum[r] - sum[l + 1] <= C[l]))
    ret = 1;
  if (dfs(l, r - 1) && (sum[r - 1] - sum[l] <= C[r - 1]))
    ret = 1;
  return ret;
}

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> C[i] >> W[i];

  sum[0] = 0;
  REP(i, 0, N) sum[i + 1] = sum[i] + W[i];

  REP(i, 0, N) REP(j, 0, N + 1) memo[i][j] = -1;

  vector<vector<edge>> E(N + 1);
  REP(i, 0, N) REP(j, i, N + 1) if (dfs(i, j)) E[i].push_back((edge){j, 1});
  cout << dijkstra(E, 0)[N] << endl;
}
Problem p00298 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
#define REP(i, n, N) for (int i = (n); i < (N); i++)
#define RREP(i, n, N) for (ll i = (N - 1); i >= n; i--)
#define CK(n, a, b) ((a) <= (n) && (n) < (b))
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout << (s) << endl
#define p2(a, b) cout << (a) << " " << (b) << endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const int inf = 1e9;

int dp[310][310];
int N;
int C[1010], W[1010];
int sum[1010];
int main() {
  cin >> N;
  REP(i, 0, N) { cin >> C[i] >> W[i]; }
  REP(i, 0, N) REP(j, i, N) dp[i][j] = j - i + 1;
  REP(i, 0, N) sum[i + 1] = sum[i] + W[i];
  REP(k, 1, N) {
    REP(L, 0, N - k) {
      int R = L + k;
      if (dp[L + 1][R] == 1 && sum[R + 1] - sum[L + 1] <= C[L]) {
        dp[L][R] = min(dp[L][R], dp[L + 1][R]);
      }
      if (dp[L][R - 1] == 1 && sum[R] - sum[L] <= C[R]) {
        dp[L][R] = min(dp[L][R], dp[L][R - 1]);
      }
      REP(i, L, R) { dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R]); }
    }
  }
  p(dp[0][N - 1]);

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
#define REP(i, n, N) for (int i = (n); i < (N); i++)
#define RREP(i, n, N) for (ll i = (N - 1); i >= n; i--)
#define CK(n, a, b) ((a) <= (n) && (n) < (b))
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout << (s) << endl
#define p2(a, b) cout << (a) << " " << (b) << endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const int inf = 1e9;

int dp[1010][1010];
int N;
int C[1010], W[1010];
int sum[1010];
int main() {
  cin >> N;
  REP(i, 0, N) { cin >> C[i] >> W[i]; }
  REP(i, 0, N) REP(j, i, N) dp[i][j] = j - i + 1;
  REP(i, 0, N) sum[i + 1] = sum[i] + W[i];
  REP(k, 1, N) {
    REP(L, 0, N - k) {
      int R = L + k;
      if (dp[L + 1][R] == 1 && sum[R + 1] - sum[L + 1] <= C[L]) {
        dp[L][R] = min(dp[L][R], dp[L + 1][R]);
      }
      if (dp[L][R - 1] == 1 && sum[R] - sum[L] <= C[R]) {
        dp[L][R] = min(dp[L][R], dp[L][R - 1]);
      }
      REP(i, L, R) { dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R]); }
    }
  }
  p(dp[0][N - 1]);

  return 0;
}
Problem p00302 (C++)

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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define each(it, v)                                                            \
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template <typename A, typename B> inline void chmin(A &a, B b) {
  if (a > b)
    a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
  if (a < b)
    a = b;
}

int N, R, T;
int P[100];

int pos[100];
int f[100], e[100];

signed main() {
  cin >> N >> R >> T;
  rep(i, N) cin >> P[i];

  rep(t, T) {
    rep(i, N) {
      pos[i] = (pos[i] + P[i]) % R;
      if (f[pos[i]])
        f[pos[i]]--;
      if (t)
        e[pos[i]]++;
    }
    rep(i, R) {
      f[i] += e[i];
      e[i] = 0;
    }
  }

  int ans = 0;
  rep(i, R) ans += f[i];
  cout << ans + N << endl;
  return 0;
}

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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define each(it, v)                                                            \
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template <typename A, typename B> inline void chmin(A &a, B b) {
  if (a > b)
    a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
  if (a < b)
    a = b;
}

int N, R, T;
int P[100];

int pos[100];
int f[1000], e[1000];

signed main() {
  cin >> N >> R >> T;
  rep(i, N) cin >> P[i];

  rep(t, T) {
    rep(i, N) {
      pos[i] = (pos[i] + P[i]) % R;
      if (f[pos[i]])
        f[pos[i]]--;
      if (t)
        e[pos[i]]++;
    }
    rep(i, R) {
      f[i] += e[i];
      e[i] = 0;
    }
  }

  int ans = 0;
  rep(i, R) ans += f[i];
  cout << ans + N << endl;
  return 0;
}