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

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

bool a[10000], s[10000];
int b[10000], c[10000];
signed main() {
  int d, sum = 0;
  cin >> d;
  for (int e = 0; e < d; e++) {
    scanf("%d", &b[e]);
  }
  for (int i = 0; i < d; i++) {
    if (!a[i]) {
      memset(c, 0, sizeof(c));
      int now = i;
      while (1) {
        a[now] = true;
        if (c[now] == 2)
          break;
        else if (c[now] == 1)
          s[now] = true;
        c[now]++;
        now += b[now];
        now %= d;
      }
    }
  }
  for (bool u : s)
    sum += u;
  cout << sum << endl;
}

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

bool a[100000], s[100000];
int b[100000], c[100000];
signed main() {
  int d, sum = 0;
  cin >> d;
  for (int e = 0; e < d; e++) {
    scanf("%d", &b[e]);
  }
  for (int i = 0; i < d; i++) {
    if (!a[i]) {
      memset(c, 0, sizeof(c));
      int now = i;
      while (1) {
        a[now] = true;
        if (c[now] == 2)
          break;
        else if (c[now] == 1)
          s[now] = true;
        c[now]++;
        now += b[now];
        now %= d;
      }
    }
  }
  for (bool u : s)
    sum += u;
  cout << sum << endl;
}
Problem p00345 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
string S;
int e, f1, f2, g1, g2;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  cin >> S;
  string T;
  bool flag = false;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == '.') {
      e = stoi(T);
      T = "";
    } else if (S[i] == '(') {
      f1 = stoi(T);
      f2 = pow(10, T.size());
      T = "";
      flag = true;
    } else if (S[i] == ')') {
      g1 = stoi(T);
      g2 = pow(10, T.size()) - 1;
      T = "";
    } else {
      T += S[i];
    }
  }
  if (flag == false) {
    f1 = stoi(T);
    f2 = pow(10, T.size());
    g1 = 0;
    g2 = 1;
  }
  int E1 = e * f2 * g2 + f1 * g2 + g1, E2 = f2 * g2;
  cout << E1 / gcd(E1, E2) << "/" << E2 / gcd(E1, E2) << endl;
  return 0;
}

Fixed submission:
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
string S;
int e, f1, f2, g1, g2;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  cin >> S;
  string T;
  bool flag = false;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == '.') {
      e = stoi(T);
      T = "";
    } else if (S[i] == '(') {
      if (T.size() >= 1) {
        f1 = stoi(T);
      }
      f2 = pow(10, T.size());
      T = "";
      flag = true;
    } else if (S[i] == ')') {
      g1 = stoi(T);
      g2 = pow(10, T.size()) - 1;
      T = "";
    } else {
      T += S[i];
    }
  }
  if (flag == false) {
    f1 = stoi(T);
    f2 = pow(10, T.size());
    g1 = 0;
    g2 = 1;
  }
  int E1 = e * f2 * g2 + f1 * g2 + g1, E2 = f2 * g2;
  cout << E1 / gcd(E1, E2) << "/" << E2 / gcd(E1, E2) << endl;
  return 0;
}
Problem p00346 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>

const int LIM = 1.5e3 + 5;

struct data {
  int x, d;
};
bool operator<(data a, data b) { return a.d > b.d; }

int n, m, dis[LIM][LIM], max, ans;
std::vector<data> edg[LIM];
bool chk[LIM], vis[LIM];
std::priority_queue<data> q;

void dijkstra(int s, int *dis) {
  q.push({s, 0});
  while (!q.empty()) {
    data x = q.top();
    q.pop();
    if (!vis[x.x]) {
      vis[x.x] = true;
      dis[x.x] = x.d;
      for (data y : edg[x.x])
        if (!vis[y.x])
          q.push({y.x, x.d + y.d});
    }
  }
}

void trace(int x, int *dis) {
  if (!chk[x]) {
    --ans;
    chk[x] = true;
  }
  for (data y : edg[x])
    if (!vis[y.x] && dis[y.x] == dis[x] - y.d)
      trace(y.x, dis);
}

int main() {
  scanf("%d%d", &n, &m);
  while (m--) {
    int u, v, d;
    scanf("%d%d%d", &u, &v, &d);
    edg[u].push_back({v, d});
    edg[v].push_back({u, d});
  }

  for (int i = 1; i <= n; ++i) {
    memset(vis, 0x00, sizeof(vis));
    dijkstra(i, dis[i]);
    for (int j = 1; j <= n; ++j)
      max = std::max(max, dis[i][j]);
  }

  for (int i = 1; i <= n; ++i) {
    memset(vis, 0x00, sizeof(vis));
    for (int j = 1; j <= n; ++j)
      if (dis[i][j] == max)
        trace(j, dis[i]);
  }

  printf("%d\n", ans + n);
  for (int i = 1; i <= n; ++i)
    if (!chk[i])
      printf("%d\n", i);
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>

const int LIM = 1.5e3 + 5;

struct data {
  int x, d;
};
bool operator<(data a, data b) { return a.d > b.d; }

int n, m, dis[LIM][LIM], max, ans;
std::vector<data> edg[LIM];
bool chk[LIM], vis[LIM];
std::priority_queue<data> q;

void dijkstra(int s, int *dis) {
  q.push({s, 0});
  while (!q.empty()) {
    data x = q.top();
    q.pop();
    if (!vis[x.x]) {
      vis[x.x] = true;
      dis[x.x] = x.d;
      for (data y : edg[x.x])
        if (!vis[y.x])
          q.push({y.x, x.d + y.d});
    }
  }
}

void trace(int x, int *dis) {
  vis[x] = true;
  if (!chk[x]) {
    --ans;
    chk[x] = true;
  }
  for (data y : edg[x])
    if (!vis[y.x] && dis[y.x] == dis[x] - y.d)
      trace(y.x, dis);
}

int main() {
  scanf("%d%d", &n, &m);
  while (m--) {
    int u, v, d;
    scanf("%d%d%d", &u, &v, &d);
    edg[u].push_back({v, d});
    edg[v].push_back({u, d});
  }

  for (int i = 1; i <= n; ++i) {
    memset(vis, 0x00, sizeof(vis));
    dijkstra(i, dis[i]);
    for (int j = 1; j <= n; ++j)
      max = std::max(max, dis[i][j]);
  }

  for (int i = 1; i <= n; ++i) {
    memset(vis, 0x00, sizeof(vis));
    for (int j = 1; j <= n; ++j)
      if (dis[i][j] == max)
        trace(j, dis[i]);
  }

  printf("%d\n", ans + n);
  for (int i = 1; i <= n; ++i)
    if (!chk[i])
      printf("%d\n", i);
}
Problem p00347 (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;

int w, h;
int dp[2000][2000][2], s[2000][2000];
int sum[2000][2000];
int dx[]{1, 0}, dy[]{0, 1};

int rec(int x, int y, int a) {
  if (dp[x][y][a] != -1)
    return dp[x][y][a];
  if (y == w)
    return 0;
  int res = (a == 0 ? INT_MIN : INT_MAX);
  rep(i, 2) {
    int nx = x + dx[i], ny = y + dy[i];
    if (nx > h)
      continue;
    int b = rec(nx, ny, !a) + (i == 1 ? sum[x][y] : 0);
    if (a == 0)
      res = max(res, b);
    else
      res = min(res, b);
  }
  return res;
}
int main() {
  scanf("%d%d", &w, &h);
  rep(i, h) rep(j, w) scanf("%d", &s[i][j]);
  int a = 0;
  rep(i, w) rep(j, h) {
    sum[j + 1][i] = sum[j][i] + s[j][i];
    a += s[j][i];
  }
  memset(dp, -1, sizeof(dp));
  cout << abs(a - rec(0, 0, 0) * 2) << endl;
}

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

int w, h;
int dp[2000][2000][2], s[2000][2000];
int sum[2000][2000];
int dx[]{1, 0}, dy[]{0, 1};

int rec(int x, int y, int a) {
  if (dp[x][y][a] != -1)
    return dp[x][y][a];
  if (y == w)
    return 0;
  int res = (a == 0 ? INT_MIN : INT_MAX);
  rep(i, 2) {
    int nx = x + dx[i], ny = y + dy[i];
    if (nx > h)
      continue;
    int b = rec(nx, ny, !a) + (i == 1 ? sum[x][y] : 0);
    if (a == 0)
      res = max(res, b);
    else
      res = min(res, b);
  }
  return dp[x][y][a] = res;
}
int main() {
  scanf("%d%d", &w, &h);
  rep(i, h) rep(j, w) scanf("%d", &s[i][j]);
  int a = 0;
  rep(i, w) rep(j, h) {
    sum[j + 1][i] = sum[j][i] + s[j][i];
    a += s[j][i];
  }
  memset(dp, -1, sizeof(dp));
  cout << abs(a - rec(0, 0, 0) * 2) << endl;
}
Problem p00348 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <vector>

const int LIM = 1e5 + 5;

int n, dsu[LIM], a[LIM], b[LIM];
long long ans;
std::map<int, int> map;
std::queue<int> q;

int root(int x) {
  if (dsu[x] <= 0)
    return x;
  else
    return dsu[x] = root(dsu[x]);
}

void merge(int x, int y) {
  x = root(x);
  y = root(y);
  if (x != y) {
    if (dsu[x] < dsu[y])
      std::swap(x, y);
    dsu[y] += dsu[x];
    dsu[x] = y;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }

  std::sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; ++i)
    map[b[i]] = i;
  for (int i = 1; i <= n; ++i)
    a[i] = map[a[i]];
  a[n + 1] = n + 1;

  memset(dsu, 0xff, sizeof(dsu));
  for (int i = 1; i <= n; ++i)
    q.push(a[i]);

  for (int i = 1; i <= n; ++i) {
    int s = root(q.front());
    q.pop();
    while (root(i) != root(s)) {
      merge(s, q.front());
      q.pop();
    }
    ans -= ++dsu[root(s)];
    //		printf("%d -> %d\n", i, -dsu[root(s)]);
    q.push(root(s));
  }
  printf("%lld\n", ans);
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <vector>

const int LIM = 2e5 + 5;

int n, dsu[LIM], a[LIM], b[LIM];
long long ans;
std::map<int, int> map;
std::queue<int> q;

int root(int x) {
  if (dsu[x] <= 0)
    return x;
  else
    return dsu[x] = root(dsu[x]);
}

void merge(int x, int y) {
  x = root(x);
  y = root(y);
  if (x != y) {
    if (dsu[x] < dsu[y])
      std::swap(x, y);
    dsu[y] += dsu[x];
    dsu[x] = y;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }

  std::sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; ++i)
    map[b[i]] = i;
  for (int i = 1; i <= n; ++i)
    a[i] = map[a[i]];
  a[n + 1] = n + 1;

  memset(dsu, 0xff, sizeof(dsu));
  for (int i = 1; i <= n; ++i)
    q.push(a[i]);

  for (int i = 1; i <= n; ++i) {
    int s = root(q.front());
    q.pop();
    while (root(i) != root(s)) {
      merge(s, q.front());
      q.pop();
    }
    ans -= ++dsu[root(s)];
    //		printf("%d -> %d\n", i, -dsu[root(s)]);
    q.push(root(s));
  }
  printf("%lld\n", ans);
}
Problem p00355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int a, b, n, s, f, i = 0;
  cin >> a >> b >> n;
  while (1) {
    cin >> s >> f;
    if ((a >= s && b <= f) || (s > a && s < b) || (f > a && f < b)) {
      cout << '1' << endl;
      break;
    }
    if (++i == n) {
      cout << '0' << endl;
      break;
    }
  }
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int a, b, n, s, f, i = 0;
  cin >> a >> b >> n;
  while (1) {
    cin >> s >> f;
    if ((a >= s && b <= f) || (s > a && s < b) || (f > a && f < b)) {
      cout << '1' << endl;
      break;
    }
    if (++i >= n) {
      cout << '0' << endl;
      break;
    }
  }
}
Problem p00355 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P, int> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

vi a(10000);
int n, l, r;

int main() {
  cin >> l >> r >> n;
  for (int i = 0; i < n; i++) {
    int L, R;
    cin >> L >> R;
    for (int j = L; j < R; j++)
      a[j] = 1;
  }
  for (int i = l; i < r; i++) {
    if (a[i]) {
      cout << 1 << endl;
      return 1;
    }
  }
  cout << 0 << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P, int> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

vi a(10000);
int n, l, r;

int main() {
  cin >> l >> r >> n;
  for (int i = 0; i < n; i++) {
    int L, R;
    cin >> L >> R;
    for (int j = L; j < R; j++)
      a[j] = 1;
  }
  for (int i = l; i < r; i++) {
    if (a[i]) {
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
}
Problem p00357 (C++)

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

  int n, t[100000], r = 1;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> t[i];
  int le = t[0];
  for (int i = 1; i < n; i++) {
    le -= 10;
    if (le < 0)
      r = 0;
    le = max(le, t[i]);
  }

  reverse(t, t + n);

  le = t[0];
  for (int i = 1; i < n; i++) {
    le -= 10;
    if (le < 0)
      r = 0;
    le = max(le, t[i]);
  }

  cout << (r ? "yes" : "no") << endl;
  return 0;
}


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

  int n, t[300010], r = 1;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> t[i];
  int le = t[0];
  for (int i = 1; i < n; i++) {
    le -= 10;
    if (le < 0)
      r = 0;
    le = max(le, t[i]);
  }

  reverse(t, t + n);

  le = t[0];
  for (int i = 1; i < n; i++) {
    le -= 10;
    if (le < 0)
      r = 0;
    le = max(le, t[i]);
  }

  cout << (r ? "yes" : "no") << endl;
  return 0;
}
Problem p00357 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int, int>
#define MA make_pair
#define LL long long
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
using namespace std;
//
const int INF = 1e9 + 7;
//
int N;
VE D;
bool DFS(int now, int nok) {
  if (nok < 10) {
    return false;
  } else if (now == N - 1) {
    return true;
  }
  now++;
  nok -= 10;
  if (DFS(now, D[now])) {
    return true;
  }
  if (DFS(now, nok)) {
    return true;
  }
  return false;
}
int main() {
  cin >> N;
  FOR(i, 0, N) {
    int d;
    cin >> d;
    D.PB(d);
  }
  if (!DFS(0, D[0])) {
    cout << "no" << endl;
    return 0;
  }
  reverse(D.begin(), D.end());
  if (!DFS(0, D[0])) {
    cout << "no" << endl;
  } else {
    cout << "yes" << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int, int>
#define MA make_pair
#define LL long long
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
using namespace std;
//
const int INF = 1e9 + 7;
//
int N;
VE D;
bool DFS(int now, int nok) {
  if (nok < 10) {
    return false;
  } else if (now == N - 1) {
    return true;
  }
  now++;
  nok -= 10;
  if (DFS(now, max(D[now], nok))) {
    return true;
  }
  return false;
}
int main() {
  cin >> N;
  FOR(i, 0, N) {
    int d;
    cin >> d;
    D.PB(d);
  }
  if (!DFS(0, D[0])) {
    cout << "no" << endl;
    return 0;
  }
  reverse(D.begin(), D.end());
  if (!DFS(0, D[0])) {
    cout << "no" << endl;
  } else {
    cout << "yes" << endl;
  }
  return 0;
}
Problem p00357 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
int a[100000];
int main() {
  long int N;
  bool flag = 0;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> a[i - 1];
  }
  if (a[0] >= 10 && a[N - 1] >= 10) {
    for (int k = 1; k <= N - 2; k++) {
      if (a[k] < 10) {
        flag = 0;
        int yosi = 0;
        for (int o = 1;; o++) {
          if (a[k - o] >= (10 * o + 10)) {
            yosi++;
            break;
          }
          if ((k - o) == 0) {
            cout << "no" << endl;
            return 0;
          }
        }
        for (int u = 1;; u++) {
          if (a[k + u] >= (10 * u + 10)) {
            yosi++;
            break;
          }
          if ((k + u) == (N - 1)) {
            cout << "no" << endl;
            return 0;
          }
        }
        if (yosi == 2) {
          flag = 1;
        } else {
          cout << "no" << endl;
          return 0;
        }
      }
    }
    flag = 1;
  }

  if (flag == 0) {
    cout << "no" << endl;
  } else {
    cout << "yes" << endl;
  }

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
int a[300000];
int main() {
  long int N;
  bool flag = 0;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> a[i - 1];
  }
  if (a[0] >= 10 && a[N - 1] >= 10) {
    for (int k = 1; k <= N - 2; k++) {
      if (a[k] < 10) {
        flag = 0;
        int yosi = 0;
        for (int o = 1;; o++) {
          if (a[k - o] >= (10 * o + 10)) {
            yosi++;
            break;
          }
          if ((k - o) == 0) {
            cout << "no" << endl;
            return 0;
          }
        }
        for (int u = 1;; u++) {
          if (a[k + u] >= (10 * u + 10)) {
            yosi++;
            break;
          }
          if ((k + u) == (N - 1)) {
            cout << "no" << endl;
            return 0;
          }
        }
        if (yosi == 2) {
          flag = 1;
        } else {
          cout << "no" << endl;
          return 0;
        }
      }
    }
    flag = 1;
  }

  if (flag == 0) {
    cout << "no" << endl;
  } else {
    cout << "yes" << endl;
  }

  return 0;
}
Problem p00357 (C++)

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

int a[100001];
bool solve1(int n) {
  int p = 0;
  for (int i = 0; i < n; i++) {
    if (i > p)
      return 0;
    p = max(p, i + (a[i] / 10));
  }
  return p >= n - 1;
}

bool solve2(int n) {
  int p = n - 1;
  for (int i = n - 1; i >= 0; i--) {
    if (i < p)
      return 0;
    p = min(p, i - (a[i] / 10));
  }
  return p <= 0;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  bool x = solve1(n);
  bool y = solve2(n);
  if (x && y)
    printf("yes\n");
  else
    printf("no\n");
  return 0;
}


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

int a[300001];
bool solve1(int n) {
  int p = 0;
  for (int i = 0; i < n; i++) {
    if (i > p)
      return 0;
    p = max(p, i + (a[i] / 10));
  }
  return p >= n - 1;
}

bool solve2(int n) {
  int p = n - 1;
  for (int i = n - 1; i >= 0; i--) {
    if (i < p)
      return 0;
    p = min(p, i - (a[i] / 10));
  }
  return p <= 0;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  bool x = solve1(n);
  bool y = solve2(n);
  if (x && y)
    printf("yes\n");
  else
    printf("no\n");
  return 0;
}
Problem p00358 (C++)

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

using namespace std;

int H, N;
int ngmask[1000];
int dp[1000][1 << 4];

int rec(int idx, int upbit) {
  if (idx == H)
    return (0);
  if (~dp[idx][upbit])
    return (dp[idx][upbit]);
  int ret = rec(idx + 1, ngmask[idx]);
  for (int i = 0; i < 3; i++) {
    if ((upbit >> i) & 3)
      continue;
    if ((ngmask[idx] >> i) & 3)
      continue;
    ret = max(ret, rec(idx + 1, (3 << i) | ngmask[idx]) + 1);
  }
  if (ngmask[idx] == 0 && upbit == 0) {
    ret = max(ret, rec(idx + 1, (1 << 4) - 1) + 2);
  }
  return (dp[idx][upbit] = ret);
}

int main() {
  cin >> H >> N;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    ngmask[y] |= 1 << x;
  }
  memset(dp, -1, sizeof(dp));
  cout << rec(1, ngmask[0]) << endl;
}

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

using namespace std;

int H, N;
int ngmask[10000];
int dp[10000][1 << 4];

int rec(int idx, int upbit) {
  if (idx == H)
    return (0);
  if (~dp[idx][upbit])
    return (dp[idx][upbit]);
  int ret = rec(idx + 1, ngmask[idx]);
  for (int i = 0; i < 3; i++) {
    if ((upbit >> i) & 3)
      continue;
    if ((ngmask[idx] >> i) & 3)
      continue;
    ret = max(ret, rec(idx + 1, (3 << i) | ngmask[idx]) + 1);
  }
  if (ngmask[idx] == 0 && upbit == 0) {
    ret = max(ret, rec(idx + 1, (1 << 4) - 1) + 2);
  }
  return (dp[idx][upbit] = ret);
}

int main() {
  cin >> H >> N;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    ngmask[y] |= 1 << x;
  }
  memset(dp, -1, sizeof(dp));
  cout << rec(1, ngmask[0]) << endl;
}
Problem p00359 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int, int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
using namespace std;
//
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
//
//
struct poi {
  int X;
  int Y;
  int Z;
  bool operator<(const poi &R) const {
    return X == R.X ? Y == R.Y ? Z < R.Z : Y < R.Y : X < R.X;
  }
};
//
//
int main() {
  int W, H, N;
  VP V;
  cin >> W >> H >> N;
  FOR(i, 0, N) {
    int X, Y;
    cin >> X >> Y;
    V.PB(MA(X, Y));
  }
  sort(V.begin(), V.end());
  VP mid;
  int now = 0;
  while (now < N - 1) {
    while (now < N - 1 && V[now].FI == V[now + 1].FI) {
      now++;
    }
    mid.PB(V[now]);
    now++;
    if (now == N - 1) {
      mid.PB(V[now]);
    }
  }
  VP ans;
  ans.PB(mid.back());
  ROF(i, 0, (int)mid.size()) {
    if (mid[i].SE > ans.back().SE) {
      ans.PB(mid[i]);
    }
  }
  reverse(ans.begin(), ans.end());
  int a = min(ans[0].SE, ans.back().FI);
  FOR(i, 0, (int)ans.size() - 1) { a = min(a, ans[i].FI + ans[i + 1].SE); }
  cout << a << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int, int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
using namespace std;
//
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
//
//
struct poi {
  int X;
  int Y;
  int Z;
  bool operator<(const poi &R) const {
    return X == R.X ? Y == R.Y ? Z < R.Z : Y < R.Y : X < R.X;
  }
};
//
//
int main() {
  int W, H, N;
  VP V;
  cin >> W >> H >> N;
  FOR(i, 0, N) {
    int X, Y;
    cin >> X >> Y;
    V.PB(MA(X, Y));
  }
  sort(V.begin(), V.end());
  if (N == 1) {
    cout << min(V[0].FI, V[0].SE) << endl;
    return 0;
  }
  VP mid;
  int now = 0;
  while (now < N - 1) {
    while (now < N - 1 && V[now].FI == V[now + 1].FI) {
      now++;
    }
    mid.PB(V[now]);
    now++;
    if (now == N - 1) {
      mid.PB(V[now]);
    }
  }
  VP ans;
  ans.PB(mid.back());
  ROF(i, 0, (int)mid.size()) {
    if (mid[i].SE > ans.back().SE) {
      ans.PB(mid[i]);
    }
  }
  reverse(ans.begin(), ans.end());
  int a = min(ans[0].SE, ans.back().FI);
  FOR(i, 0, (int)ans.size() - 1) { a = min(a, ans[i].FI + ans[i + 1].SE); }
  cout << a << endl;
  return 0;
}
Problem p00359 (C++)

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

int wh[10001] = {};

int main(void) {
  int w, h, n;
  cin >> w >> h >> n;
  int at_most_w = 0, at_most_h = 0;
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    wh[y] = max(wh[y], x);
    at_most_w = max(x, at_most_w);
    at_most_h = max(y, at_most_h);
  }

  int x_position, y_position, MIN;
  MIN = wh[h - 1] + (h - 1);
  x_position = wh[h - 1];
  y_position = h - 1;

  for (int i = 0; i < h - 1; i++) {
    y_position--;
    int a = x_position, b = y_position;
    MIN = min(MIN, a + b);

    if (a < wh[b]) {
      x_position = wh[y_position];
      int a = x_position, b = y_position;

      MIN = min(MIN, a + b);
    }
  }

  cout << min(MIN, min(at_most_w, at_most_h)) << endl;

  return 0;
}


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

int wh[100001] = {};

int main(void) {
  int w, h, n;
  cin >> w >> h >> n;
  int at_most_w = 0, at_most_h = 0;
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    wh[y] = max(wh[y], x);
    at_most_w = max(x, at_most_w);
    at_most_h = max(y, at_most_h);
  }

  int x_position, y_position, MIN;
  MIN = wh[h - 1] + (h - 1);
  x_position = wh[h - 1];
  y_position = h - 1;

  for (int i = 0; i < h - 1; i++) {
    y_position--;
    int a = x_position, b = y_position;
    MIN = min(MIN, a + b);

    if (a < wh[b]) {
      x_position = wh[y_position];
      int a = x_position, b = y_position;

      MIN = min(MIN, a + b);
    }
  }

  cout << min(MIN, min(at_most_w, at_most_h)) << endl;

  return 0;
}
Problem p00367 (C++)

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

int n;
int ax[50], bx[50];
int ay[50], by[50];
int az[50], bz[50];

int input() {
  int fi, se;
  cin >> fi >> se;
  return fi * 60 + se;
}

int main() {
  cin >> n;
  vector<int> X, Y, Z;
  for (int i = 0; i < n; i++) {
    ax[i] = input();
    bx[i] = input();
    ay[i] = input();
    by[i] = input();
    az[i] = input();
    bz[i] = input();
    X.push_back(ax[i]);
    Y.push_back(ay[i]);
    Z.push_back(az[i]);
  }

  typedef pair<int, int> P;
  P t[50];

  int maxm = 0;
  for (int I = 0; I < (int)X.size(); I++) {
    int p = X[I];
    for (int J = 0; J < (int)Y.size(); J++) {
      int q = Y[J];
      int cnt = 0;
      for (int i = 0; i < n; i++) {
        if (ax[i] <= p && p <= bx[i]) {
          if (ay[i] <= q && q <= by[i]) {
            t[cnt++] = P(az[i], 1);
            t[cnt++] = P(bz[i] + 1, -1);
          }
        }
      }
      sort(t, t + cnt);
      int v = 0, sum = 0;
      for (int i = 0; i < cnt; i++) {
        sum += t[i].second;
        v = max(v, sum);
      }
      maxm = max(maxm, v);
    }
  }
  cout << maxm << endl;
  return 0;
}


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

int n;
int ax[50], bx[50];
int ay[50], by[50];
int az[50], bz[50];

int input() {
  int fi, se;
  cin >> fi >> se;
  return fi * 60 + se;
}

int main() {
  cin >> n;
  vector<int> X, Y, Z;
  for (int i = 0; i < n; i++) {
    ax[i] = input();
    bx[i] = input();
    ay[i] = input();
    by[i] = input();
    az[i] = input();
    bz[i] = input();
    X.push_back(ax[i]);
    Y.push_back(ay[i]);
    Z.push_back(az[i]);
  }

  typedef pair<int, int> P;
  P t[100];

  int maxm = 0;
  for (int I = 0; I < (int)X.size(); I++) {
    int p = X[I];
    for (int J = 0; J < (int)Y.size(); J++) {
      int q = Y[J];
      int cnt = 0;
      for (int i = 0; i < n; i++) {
        if (ax[i] <= p && p <= bx[i]) {
          if (ay[i] <= q && q <= by[i]) {
            t[cnt++] = P(az[i], 1);
            t[cnt++] = P(bz[i] + 1, -1);
          }
        }
      }
      sort(t, t + cnt);
      int v = 0, sum = 0;
      for (int i = 0; i < cnt; i++) {
        sum += t[i].second;
        v = max(v, sum);
      }
      maxm = max(maxm, v);
    }
  }
  cout << maxm << endl;
  return 0;
}
Problem p00369 (C++)

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

#define int long long

#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;

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;
int A[111111];

signed main() {
  string s;
  cin >> s;
  N = s.size();
  rep(i, N) A[i] = s[i] - '0';

  int ans = 9;

  chmin(ans, *max_element(A, A + N) - *min_element(A, A + N));

  int ma = 0, mi = INT_MAX;
  for (int i = 0; i < N; i++) {
    if (A[i] == 1 && i + 1 < N) {
      chmax(ma, A[i + 1] + 10);
      i++;
    } else {
      chmin(mi, A[i]);
    }
  }

  if (ma != 0 && mi != INT_MAX)
    chmin(ans, ma - mi);

  for (int i = 2; i < N; i++) {
    string mi(1, '9' + 1);
    string ma(1, '0' - 1);

    for (int j = 0; j < N; j += i) {
      string s;
      for (int k = 0; k < i; k++)
        s += (char)(A[j + k] + '0');
      if (mi > s)
        mi = s;
      if (ma < s)
        ma = s;
    }

    if (mi.substr(0, i - 2) != ma.substr(0, i - 2))
      continue;
    int x = (mi[i - 2] - '0') * 10 + mi[i - 1] - '0';
    int y = (ma[i - 2] - '0') * 10 + ma[i - 1] - '0';
    chmin(ans, y - x);
  }
  cout << ans << endl;
  return 0;
}

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

#define int long long

#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;

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;
int A[111111];

signed main() {
  string s;
  cin >> s;
  N = s.size();
  rep(i, N) A[i] = s[i] - '0';

  int ans = 9;

  chmin(ans, *max_element(A, A + N) - *min_element(A, A + N));

  int ma = 0, mi = INT_MAX;
  for (int i = 0; i < N; i++) {
    if (A[i] == 1 && i + 1 < N) {
      chmax(ma, A[i + 1] + 10);
      i++;
    } else {
      chmin(mi, A[i]);
    }
  }

  if (ma != 0 && mi != INT_MAX)
    chmin(ans, ma - mi);

  for (int i = 2; i < N; i++) {
    if (N % i)
      continue;
    string mi(1, '9' + 1);
    string ma(1, '0' - 1);

    for (int j = 0; j < N; j += i) {
      string s;
      for (int k = 0; k < i; k++)
        s += (char)(A[j + k] + '0');
      if (mi > s)
        mi = s;
      if (ma < s)
        ma = s;
    }

    if (mi.substr(0, i - 2) != ma.substr(0, i - 2))
      continue;
    int x = (mi[i - 2] - '0') * 10 + mi[i - 1] - '0';
    int y = (ma[i - 2] - '0') * 10 + ma[i - 1] - '0';
    chmin(ans, y - x);
  }
  cout << ans << endl;
  return 0;
}
Problem p00373 (C++)

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

int w1, w2, h1, h2, sum;
int hash_a[700][700][13], hash_b[700][13];
int cumo_a[700][700][13], cumo_b[700][13];
char s[700][700], t[700][700];

void make_table() {
  rep(i, h1) rep(j, w1 - w2 + 1) {
    rep(k, w2) {
      rep(l, 8) hash_a[i][j][(k * 8) / 64] =
          hash_a[i][j][(k * 8) / 64] * 2 + (((s[i][j + k] >> l) & 1) ? 1 : 0);
      rep(l, 8) cumo_a[i][j][(k * 8) / 64] =
          cumo_a[i][j][(k * 8) / 64] * 2 + (s[i][j + k] == '?' ? 1 : 0);
    }
  }
  rep(i, h2) {
    rep(j, w2) {
      rep(k, 8) hash_b[i][(j * 8) / 64] =
          hash_b[i][(j * 8) / 64] * 2 + (((t[i][j] >> k) & 1) ? 1 : 0);
      rep(k, 8) cumo_b[i][(j * 8) / 64] =
          cumo_b[i][(j * 8) / 64] * 2 + (t[i][j] == '?' ? 1 : 0);
    }
  }
}

void count_s() {
  rep(i, h1 - h2 + 1) {
    rep(j, w1 - w2 + 1) {
      rep(k, h2) {
        int p1[13] = {}, p2[13] = {}, flag = 0;
        rep(l, 13) {
          p1[l] = hash_a[i + k][j][l] ^ hash_b[k][l];
          p2[l] = cumo_a[i + k][j][l] | cumo_b[k][l];
          if ((p1[l] | p2[l]) != p2[l]) {
            flag++;
            break;
          }
        }
        if (flag)
          break;
        if (k == h2 - 1)
          sum++;
      }
    }
  }
}

signed main() {
  cin >> w1 >> h1 >> w2 >> h2;
  rep(i, h1) scanf("%s", s[i]);
  rep(i, h2) scanf("%s", t[i]);
  make_table();
  count_s();
  cout << sum << endl;
}

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

int w1, w2, h1, h2, sum;
int hash_a[800][800][13], hash_b[800][13];
int cumo_a[800][800][13], cumo_b[800][13];
char s[800][800], t[800][700];

void make_table() {
  rep(i, h1) rep(j, w1 - w2 + 1) {
    rep(k, w2) {
      rep(l, 8) hash_a[i][j][(k * 8) / 64] =
          hash_a[i][j][(k * 8) / 64] * 2 + (((s[i][j + k] >> l) & 1) ? 1 : 0);
      rep(l, 8) cumo_a[i][j][(k * 8) / 64] =
          cumo_a[i][j][(k * 8) / 64] * 2 + (s[i][j + k] == '?' ? 1 : 0);
    }
  }
  rep(i, h2) {
    rep(j, w2) {
      rep(k, 8) hash_b[i][(j * 8) / 64] =
          hash_b[i][(j * 8) / 64] * 2 + (((t[i][j] >> k) & 1) ? 1 : 0);
      rep(k, 8) cumo_b[i][(j * 8) / 64] =
          cumo_b[i][(j * 8) / 64] * 2 + (t[i][j] == '?' ? 1 : 0);
    }
  }
}

void count_s() {
  rep(i, h1 - h2 + 1) {
    rep(j, w1 - w2 + 1) {
      rep(k, h2) {
        int p1[13] = {}, p2[13] = {}, flag = 0;
        rep(l, 13) {
          p1[l] = hash_a[i + k][j][l] ^ hash_b[k][l];
          p2[l] = cumo_a[i + k][j][l] | cumo_b[k][l];
          if ((p1[l] | p2[l]) != p2[l]) {
            flag++;
            break;
          }
        }
        if (flag)
          break;
        if (k == h2 - 1)
          sum++;
      }
    }
  }
}

signed main() {
  cin >> w1 >> h1 >> w2 >> h2;
  rep(i, h1) scanf("%s", s[i]);
  rep(i, h2) scanf("%s", t[i]);
  make_table();
  count_s();
  cout << sum << endl;
}
Problem p00392 (C++)

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

const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
typedef pair<int, int> P;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define mp make_pair

int par[112345];
int rk[112345];

void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    rk[i] = 0;
  }
}

int fd(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = fd(par[x]);
  }
}

void unite(int x, int y) {
  x = fd(x);
  y = fd(y);
  if (x == y)
    return;

  if (rk[x] < rk[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (rk[x] == rk[y])
      rk[x]++;
  }
}

int main() {
  int n;
  scanf("%d", &n);
  init(112345);
  std::vector<int> a(n);
  REP(i, n) scanf("%d", &a[i]);

  for (int i = 2; i < 112345; ++i) {
    int pin = -1;
    REP(j, n) {
      if (a[j] % i == 0) {
        if (pin == -1) {
          pin = a[j];
        } else {
          unite(a[j], pin);
        }
      }
    }
  }

  std::vector<int> sorted(a);
  std::sort(sorted.begin(), sorted.end());

  int ans = 1;

  REP(i, n) {
    if (fd(a[i]) != fd(sorted[i])) {
      ans = 0;
    }
  }

  printf("%d\n", ans);

  return 0;
}


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

const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
typedef pair<int, int> P;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define mp make_pair

int par[112345];
int rk[112345];

void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    rk[i] = 0;
  }
}

int fd(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = fd(par[x]);
  }
}

void unite(int x, int y) {
  x = fd(x);
  y = fd(y);
  if (x == y)
    return;

  if (rk[x] < rk[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (rk[x] == rk[y])
      rk[x]++;
  }
}

int main() {
  int n;
  scanf("%d", &n);
  init(112345);
  std::vector<int> a(n);
  REP(i, n) scanf("%d", &a[i]);

  for (int i = 2; i < 3333; ++i) {
    int pin = -1;
    REP(j, n) {
      if (a[j] % i == 0) {
        if (pin == -1) {
          pin = a[j];
        } else {
          unite(a[j], pin);
        }
      }
    }
  }

  std::vector<int> sorted(a);
  std::sort(sorted.begin(), sorted.end());

  int ans = 1;

  REP(i, n) {
    if (fd(a[i]) != fd(sorted[i])) {
      ans = 0;
    }
  }

  printf("%d\n", ans);

  return 0;
}
Problem p00423 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
int main() {
  int a, b, n;
  while (scanf("%d", &n) != 0) {
    int asum = 0, bsum = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d %d", &a, &b);
      if (a > b) {
        asum += a + b;
      } else if (a < b) {
        bsum += a + b;
      } else {
        asum += a;
        bsum += b;
      }
    }
    printf("%d %d\n", asum, bsum);
  }
  return 0;
}

Fixed submission:
#include <cstdio>
int main() {
  int a, b, n;
  while (scanf("%d", &n), n) {
    int asum = 0, bsum = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d %d", &a, &b);
      if (a > b) {
        asum += a + b;
      } else if (a < b) {
        bsum += a + b;
      } else {
        asum += a;
        bsum += b;
      }
    }
    printf("%d %d\n", asum, bsum);
  }
  return 0;
}
Problem p00423 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int maisuu, a[10], b[10];
  long long int a_p = 0, b_p = 0;
  int anser[2][10];
  int hasi;
  for (int i = 0; i < 5; i++) {
    cin >> maisuu;
    if (maisuu == 0) {
      break;
    }
    for (int i2 = 0; i2 < maisuu; i2++) {
      cin >> a[i2];
      cin >> b[i2];
    }
    for (int i2 = 0; i2 < maisuu; i2++) {
      if (a[i2] < b[i2]) {
        b_p += a[i2] + b[i2];
      } else if (a[i2] > b[i2]) {
        a_p += a[i2] + b[i2];
      } else if (a[i2] == b[i2]) {
        a_p += a[i2];
        b_p += b[i2];
      }
    }
    anser[0][i] = a_p;
    anser[1][i] = b_p;
    maisuu = 0;
    a_p = 0;
    b_p = 0;
    hasi = i;
  }
  for (int i = 0; i <= hasi; i++) {
    cout << anser[0][i] << " " << anser[1][i] << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int maisuu, a[15000], b[15000];
  long long int a_p = 0, b_p = 0;
  int anser[2][10];
  int hasi;
  for (int i = 0; i < 5; i++) {
    cin >> maisuu;
    if (maisuu == 0) {
      break;
    }
    for (int i2 = 0; i2 < maisuu; i2++) {
      cin >> a[i2];
      cin >> b[i2];
    }
    for (int i2 = 0; i2 < maisuu; i2++) {
      if (a[i2] < b[i2]) {
        b_p += a[i2] + b[i2];
      } else if (a[i2] > b[i2]) {
        a_p += a[i2] + b[i2];
      } else if (a[i2] == b[i2]) {
        a_p += a[i2];
        b_p += b[i2];
      }
    }
    anser[0][i] = a_p;
    anser[1][i] = b_p;
    maisuu = 0;
    a_p = 0;
    b_p = 0;
    hasi = i;
  }
  for (int i = 0; i <= hasi; i++) {
    cout << anser[0][i] << " " << anser[1][i] << endl;
  }
  return 0;
}
Problem p00423 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int t;
  while (cin >> t && t > 0) {
    int p1 = 0, p2 = 0;
    while (t > 0) {
      int a = 0, b = 0;
      cin >> a >> b;
      if (a >= 0 && a <= 9 && a >= 0 && a <= 9) {
        continue;
      }
      if (a > b) {
        p1 += a + b;
      } else if (a < b) {
        p2 += a + b;
      } else {
        p1 += a;
        p2 += b;
      }
      t--;
    }
    cout << p1 << " " << p2 << endl;
  }
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int t;
  while (cin >> t && t > 0) {
    int p1 = 0, p2 = 0;
    while (t > 0) {
      int a = 0, b = 0;
      cin >> a >> b;
      if (a < 0 || a > 9 || a < 0 || a > 9) {
        continue;
      }
      if (a > b) {
        p1 += a + b;
      } else if (a < b) {
        p2 += a + b;
      } else {
        p1 += a;
        p2 += b;
      }
      t--;
    }
    cout << p1 << " " << p2 << endl;
  }
  return 0;
}
Problem p00423 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int n[10000000], s1, s2;
int main() {
  int p, a, b;
  while (true) {
    s1 = 0;
    s2 = 0;
    cin >> p;
    for (int i = 0; i < p; i++) {
      cin >> a >> b;
      if (a > b) {
        s1 += a + b;
      } else if (b > a) {
        s2 += a + b;
      } else {
        s1 += a;
        s2 += b;
      }
    }
    cout << s1 << ' ' << s2 << endl;
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int n[10000000], s1, s2;
int main() {
  int p, a, b;
  while (true) {
    s1 = 0;
    s2 = 0;
    cin >> p;
    if (p == 0) {
      break;
    }
    for (int i = 0; i < p; i++) {
      cin >> a >> b;
      if (a > b) {
        s1 += a + b;
      } else if (b > a) {
        s2 += a + b;
      } else {
        s1 += a;
        s2 += b;
      }
    }
    cout << s1 << ' ' << s2 << endl;
  }
}
Problem p00423 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <queue>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
int main(void) {
  int n;
  while (cin >> n, !0) {
    int a = 0;
    int b = 0;
    for (int i = 0; i < n; i++) {
      int r, l;
      cin >> l >> r;
      if (r < l) {
        a += r + l;
      } else if (r > l) {
        b += r + l;
      } else if (r == l) {
        a += l;
        b += r;
      }
    }
    cout << a << " " << b << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
int main(void) {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int a = 0;
    int b = 0;
    for (int i = 0; i < n; i++) {
      int r, l;
      cin >> l >> r;
      if (r < l) {
        a += r + l;
      } else if (r > l) {
        b += r + l;
      } else if (r == l) {
        a += l;
        b += r;
      }
    }
    cout << a << " " << b << endl;
  }
}
Problem p00423 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#include <list>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define REP(i, a, b) for (i = a; i < b; ++i)
#define rep(i, n) REP(i, 0, n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define SQR(X) ((X) * (X))
#define CUBE(X) ((X) * (X) * (X))

// #define int ll

using namespace std;

bool test = 0;

/* ?????????????????¬??¨ */

int main() {
  int i, j, k, l;
  int n;
  while (scanf("%d", &n) != EOF) {
    if (n == 0)
      break;
    int score[2] = {0};
    for (i = 0; i < n; i++) {
      int num[2];
      cin >> num[0] >> num[1];
      auto sum = num[0] + num[1];
      if (num[0] > num[1])
        score[0] += sum;
      else if (num[0] < num[1])
        score[1] += sum;
      else {
        for (j = 0; j < 2; j++)
          score[i] += num[i];
      }
    }
    printf("%d %d\n", score[0], score[1]);
  }
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#include <list>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define REP(i, a, b) for (i = a; i < b; ++i)
#define rep(i, n) REP(i, 0, n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define SQR(X) ((X) * (X))
#define CUBE(X) ((X) * (X) * (X))

// #define int ll

using namespace std;

bool test = 0;

/* ?????????????????¬??¨ */

int main() {
  int i, j, k, l;
  int n;
  while (scanf("%d", &n) != EOF) {
    if (n == 0)
      break;
    int score[2] = {0};
    for (i = 0; i < n; i++) {
      int num[2];
      cin >> num[0] >> num[1];
      auto sum = num[0] + num[1];
      if (num[0] > num[1])
        score[0] += sum;
      else if (num[0] < num[1])
        score[1] += sum;
      else {
        for (j = 0; j < 2; j++)
          score[j] += num[j];
      }
    }
    printf("%d %d\n", score[0], score[1]);
  }
  return 0;
}
Problem p00423 (C++)

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

int main() {
  int n, a, b, at, bt;

loop:
  scanf("%d\n", &n); // 各人のカード枚数
  if (n == 0)
    goto end_scope;
  at = 0;
  bt = 0;

labl_testloop:
  scanf("%d %d\n", a, b);
  if (a > b)
    at += a + b;
  else if (a == b) {
    at += a;
    bt += b;
  } else
    bt += a + b;
  n--;
  if (n > 0)
    goto labl_testloop;

  printf("%d %d\n", at, bt);
  goto loop;
end_scope:
  return 0;
}

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

int main() {
  int n, a, b, at, bt;

loop:
  scanf("%d\n", &n); // 各人のカード枚数
  if (n == 0)
    goto end_scope;
  at = 0;
  bt = 0;

labl_testloop:
  scanf("%d %d\n", &a, &b);
  if (a > b)
    at += a + b;
  else if (a == b) {
    at += a;
    bt += b;
  } else
    bt += a + b;
  n--;
  if (n > 0)
    goto labl_testloop;

  printf("%d %d\n", at, bt);
  goto loop;
end_scope:
  return 0;
}
Problem p00423 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int n, a, b, ap, bp, i;
  while (1) {
    cin >> n;
    ap = bp = 0;
    for (i = 0; i < n; i++) {
      cin >> a >> b;
      if (a > b)
        ap += a + b;
      else if (b > a)
        bp += a + b;
      else
        ap += a, bp += b;
    }
    cout << ap << ' ' << bp << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, a, b, ap, bp, i;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    ap = bp = 0;
    for (i = 0; i < n; i++) {
      cin >> a >> b;
      if (a > b)
        ap += a + b;
      else if (b > a)
        bp += a + b;
      else
        ap += a, bp += b;
    }
    cout << ap << ' ' << bp << endl;
  }
  return 0;
}
Problem p00423 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
int main(void) {
  int n;
  int a[10000];
  int b[10000];
  int i;
  int suma, sumb;

  scanf("%d", &n);
  while (n != 0) {
    suma = 0;
    sumb = 0;
    for (i = 0; i < n; i++) {
      scanf("%d %d", &a[i], &b[i]);
      if (a[i] > b[i]) {
        suma = suma + a[i] + b[i];
      } else if (a[i] < b[i]) {
        sumb = sumb + a[i] + b[i];
      } else {
        suma = suma + a[i];
        sumb = sumb + b[i];
      }
    }
    printf("%d %d\n", suma, sumb);
    scanf("%d %d", &a[i], &b[i]);
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
int main(void) {
  int n;
  int a[10000];
  int b[10000];
  int i;
  int suma, sumb;

  scanf("%d", &n);
  while (n != 0) {
    suma = 0;
    sumb = 0;
    for (i = 0; i < n; i++) {
      scanf("%d %d", &a[i], &b[i]);
      if (a[i] > b[i]) {
        suma = suma + a[i] + b[i];
      } else if (a[i] < b[i]) {
        sumb = sumb + a[i] + b[i];
      } else {
        suma = suma + a[i];
        sumb = sumb + b[i];
      }
    }
    printf("%d %d\n", suma, sumb);
    scanf("%d", &n);
  }
  return 0;
}