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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = 1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
int main() {
  int n;
  while (cin >> n, n) {
    vector<pii> in;
    while (n--) {
      int a, b;
      cin >> a >> b;
      in.pb(pii(a, b));
    }
    cin >> n;
    while (n--) {
      int a, b;
      cin >> a >> b;
      in.pb(pii(a, b));
    }
    sort(all(in));
    n = in.size();
    vi dp(110, 1);
    loop(i, 1, n) {
      int ma = 0;
      rep(j, i) if (in[j].first < in[i].first && in[j].second < in[i].second)
          ma = max(ma, dp[j]);
      dp[i] += ma;
    }
    int ma = 0;
    rep(i, n) ma = max(ma, dp[i]);
    cout << ma << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = 1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
int main() {
  int n;
  while (cin >> n, n) {
    vector<pii> in;
    while (n--) {
      int a, b;
      cin >> a >> b;
      in.pb(pii(a, b));
    }
    cin >> n;
    while (n--) {
      int a, b;
      cin >> a >> b;
      in.pb(pii(a, b));
    }
    sort(all(in));
    n = in.size();
    vi dp(210, 1);
    loop(i, 1, n) {
      int ma = 0;
      rep(j, i) if (in[j].first < in[i].first && in[j].second < in[i].second)
          ma = max(ma, dp[j]);
      dp[i] += ma;
    }
    int ma = 0;
    rep(i, n) ma = max(ma, dp[i]);
    cout << ma << endl;
  }
}
Problem p00157 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  int n[2], c[2];
  while (cin >> n[0], n[0]) {
    int h[2][110], r[2][110], mx[2][110];
    rep(q, 2) {
      rep(i, n[q]) mx[q][i] = 0, cin >> h[q][i] >> r[q][i];
      if (!q)
        cin >> n[1];
    }
    mx[0][0] = (h[0][0] > h[1][0] && r[0][0] > r[1][0]) + 1;
    mx[1][0] = (h[0][0] < h[1][0] && r[0][0] < r[1][0]) + 1;
    int p;
    c[0] = c[1] = p = 0;
    while (c[0] < n[0] || c[1] < n[1]) {
      int tmax = 0, f;
      rep(k, 2) {
        rep(i, n[k]) {
          f = h[k][i] < h[p][c[p]] && r[k][i] < r[p][c[p]];
          if (f && tmax < mx[k][i])
            tmax = mx[k][i];
          if (f && mx[k][i] == 0) {
            p ^= 1;
            goto NEXT;
          }
        }
      }
      mx[p][c[p]++] = tmax + 1;
    NEXT:;
    }
    cout << max(mx[0][n[0] - 1], mx[1][n[1] - 1]) << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  int n[2], c[2];
  while (cin >> n[0], n[0]) {
    int h[2][110], r[2][110], mx[2][110];
    rep(q, 2) {
      rep(i, n[q]) mx[q][i] = 0, cin >> h[q][i] >> r[q][i];
      if (!q)
        cin >> n[1];
    }
    mx[0][0] = (h[0][0] > h[1][0] && r[0][0] > r[1][0]) + 1;
    mx[1][0] = (h[0][0] < h[1][0] && r[0][0] < r[1][0]) + 1;
    int p;
    c[0] = c[1] = p = 0;
    while (c[0] < n[0] || c[1] < n[1]) {
      int tmax = 0, f;
      if (c[p] == n[p]) {
        p ^= 1;
        goto NEXT;
      }
      rep(k, 2) {
        rep(i, n[k]) {
          f = h[k][i] < h[p][c[p]] && r[k][i] < r[p][c[p]];
          if (f && tmax < mx[k][i])
            tmax = mx[k][i];
          if (f && mx[k][i] == 0) {
            p ^= 1;
            goto NEXT;
          }
        }
      }
      mx[p][c[p]++] = tmax + 1;
    NEXT:;
    }
    cout << max(mx[0][n[0] - 1], mx[1][n[1] - 1]) << endl;
  }
  return 0;
}
Problem p00157 (C++)

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

int main() {
  int n, m, h, r;
  while (cin >> n, n) {
    vector<pair<int, int>> v;
    for (int i = 0; i < n; ++i) {
      cin >> h >> r;
      v.push_back(make_pair(h, r));
    }
    cin >> m;
    for (int i = 0; i < m; ++i) {
      cin >> h >> r;
      v.push_back(make_pair(h, r));
    }
    sort(v.begin(), v.end());
    int mx = 0, dp[100];
    for (int i = 0; i < n + m; ++i) {
      dp[i] = 1;
      for (int j = 0; j < i; ++j) {
        if (v[j].first < v[i].first && v[j].second < v[i].second) {
          dp[i] = max(dp[i], dp[j] + 1);
        }
      }
      mx = max(mx, dp[i]);
    }
    cout << mx << endl;
  }
  return 0;
}

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

int main() {
  int n, m, h, r;
  while (cin >> n, n) {
    vector<pair<int, int>> v;
    for (int i = 0; i < n; ++i) {
      cin >> h >> r;
      v.push_back(make_pair(h, r));
    }
    cin >> m;
    for (int i = 0; i < m; ++i) {
      cin >> h >> r;
      v.push_back(make_pair(h, r));
    }
    sort(v.begin(), v.end());
    int mx = 0, dp[200];
    for (int i = 0; i < n + m; ++i) {
      dp[i] = 1;
      for (int j = 0; j < i; ++j) {
        if (v[j].first < v[i].first && v[j].second < v[i].second) {
          dp[i] = max(dp[i], dp[j] + 1);
        }
      }
      mx = max(mx, dp[i]);
    }
    cout << mx << endl;
  }
  return 0;
}
Problem p00157 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e8
#define EPS 1e-9

#define rep2(i, m, n) for (int i = m; i < n; i++)
#define rep(i, n) rep2(i, 0, n)
#define ll long long
#define P pair<int, int>
#define pb push_back

int n, m, h[200], r[200], d[200][200];

int main() {
  while (cin >> n && n) {
    rep(i, n) cin >> h[i] >> r[i];
    cin >> m;
    rep(i, m) cin >> h[i + n] >> r[i + n];
    n += m;
    rep(i, n + m) fill(d[i], d[i] + n + m, INF);
    rep(i, n) rep(j, n) {
      if (i == j)
        d[i][j] = 0;
      if (h[i] > h[j] && r[i] > r[j])
        d[i][j] = -1;
    }
    rep(k, n) rep(i, n) rep(j, n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    int ans = 0;
    rep(i, n) rep(j, n) ans = max(ans, -d[i][j] + 1);
    cout << ans << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e8
#define EPS 1e-9

#define rep2(i, m, n) for (int i = m; i < n; i++)
#define rep(i, n) rep2(i, 0, n)
#define ll long long
#define P pair<int, int>
#define pb push_back

int n, m, h[200], r[200], d[200][200];

int main() {
  while (cin >> n && n) {
    rep(i, n) cin >> h[i] >> r[i];
    cin >> m;
    rep(i, m) cin >> h[i + n] >> r[i + n];
    n += m;
    rep(i, n) fill(d[i], d[i] + n, INF);
    rep(i, n) rep(j, n) {
      if (i == j)
        d[i][j] = 0;
      if (h[i] > h[j] && r[i] > r[j])
        d[i][j] = -1;
    }
    rep(k, n) rep(i, n) rep(j, n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    int ans = 0;
    rep(i, n) rep(j, n) ans = max(ans, -d[i][j] + 1);
    cout << ans << endl;
  }
}
Problem p00157 (C++)

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

const int MAX = 101;
typedef pair<int, int> P;

int main() {
  int n, m, h, r;

  while (cin >> n, n) {
    vector<P> v;
    int dp[MAX] = {0};

    for (int i = 0; i < n; i++) {
      cin >> h >> r;
      v.push_back(P(h, r));
    }

    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> h >> r;
      v.push_back(P(h, r));
    }

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

    int res = 0;
    for (int i = 0; i < n + m; i++) {
      dp[i] = 1;
      for (int j = 0; j < i; j++) {
        if (v[j].first < v[i].first && v[j].second < v[i].second) {
          dp[i] = max(dp[i], dp[j] + 1);
        }
        res = max(res, dp[i]);
      }
    }
    cout << res << endl;
  }

  return 0;
}

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

const int MAX = 1001;
typedef pair<int, int> P;

int main() {
  int n, m, h, r;

  while (cin >> n, n) {
    vector<P> v;
    int dp[MAX] = {0};

    for (int i = 0; i < n; i++) {
      cin >> h >> r;
      v.push_back(P(h, r));
    }

    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> h >> r;
      v.push_back(P(h, r));
    }

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

    int res = 0;
    for (int i = 0; i < n + m; i++) {
      dp[i] = 1;
      for (int j = 0; j < i; j++) {
        if (v[j].first < v[i].first && v[j].second < v[i].second) {
          dp[i] = max(dp[i], dp[j] + 1);
        }
        res = max(res, dp[i]);
      }
    }
    cout << res << endl;
  }

  return 0;
}
Problem p00158 (C++)

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

int main() {
  int n;
  while (cin >> n, n) {
    int cnt = 0;
    while (n != 0) {
      if (n % 2 == 0)
        n /= 2;
      else
        n = n * 3 + 1;
      cnt++;
    }
    cout << cnt << endl;
  }
  return (0);
}

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

int main() {
  int n;
  while (cin >> n, n) {
    int cnt = 0;
    while (n != 1) {
      if (n % 2 == 0)
        n /= 2;
      else
        n = n * 3 + 1;
      cnt++;
    }
    cout << cnt << endl;
  }
  return (0);
}
Problem p00158 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <limits>
#include <vector>
using namespace std;
int main(void) {
  for (;;) {
    int cnt = 0, buf;
    cin >> buf;
    if (!buf)
      return 0;
    for (; buf != 1;) {
      buf = buf % 2 ? buf / 2 : buf * 3 + 1;
      cnt++;
    }
    cout << cnt << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <limits>
#include <vector>
using namespace std;
int main(void) {
  for (;;) {
    int cnt = 0, buf;
    cin >> buf;
    if (!buf)
      return 0;
    for (; buf != 1;) {
      buf = buf % 2 ? buf * 3 + 1 : buf / 2;
      cnt++;
    }
    cout << cnt << endl;
  }
}
Problem p00158 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, l, n) for (int i = l; i < n; i++)
#define rer(i, l, n) for (int i = l; i <= n; i++)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;

int main() {
  int n;
  while (cin >> n) {
    int c = 0;
    while (1) {
      if (n == 1)
        break;
      if (n % 2)
        n = 3 * n + 1;
      else
        n /= 2;
      c++;
    }
    o(c);
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, l, n) for (int i = l; i < n; i++)
#define rer(i, l, n) for (int i = l; i <= n; i++)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;

int main() {
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    int c = 0;
    while (1) {
      if (n == 1)
        break;
      if (n % 2)
        n = 3 * n + 1;
      else
        n /= 2;
      c++;
    }
    o(c);
  }
}
Problem p00159 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

int main(void) {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    vector<pair<double, int>> data;
    REP(i, n) {
      int num;
      double h, w;
      cin >> num >> h >> w;
      data.push_back(pair<double, int>(w * 10000 / (h * h), num));
    }
    sort(data.begin(), data.end());
    vector<pair<double, int>>::iterator itl, itu;
    itl = lower_bound(data.begin(), data.end(), pair<double, int>(22, 0));
    itu = itl - 1;
    if (abs(22 - (*itl).first) > abs(22 - (*itu).first)) {
      cout << (*itu).second << endl;
    } else {
      cout << (*itl).second << endl;
    }
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

int main(void) {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    vector<pair<double, int>> data;
    REP(i, n) {
      int num;
      double h, w;
      cin >> num >> h >> w;
      data.push_back(pair<double, int>(w * 10000 / (h * h), num));
    }
    sort(data.begin(), data.end());
    vector<pair<double, int>>::iterator itl, itu;
    itl = lower_bound(data.begin(), data.end(), pair<double, int>(22, 0));
    itu = (itl != data.begin()) ? itl - 1 : itl;
    if (abs(22 - (*itl).first) > abs(22 - (*itu).first)) {
      cout << (*itu).second << endl;
    } else {
      cout << (*itl).second << endl;
    }
  }

  return 0;
}
Problem p00159 (C++)

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

#define ABS(X) ((X) < 0 ? -(X) : (X))
typedef pair<double, int> Subj;

int main(void) {
  int n;

  while (cin >> n) {
    vector<Subj> v;
    for (int i = 0; i < n; i++) {
      int id;
      double h, w, bmi;
      cin >> id >> h >> w;
      h /= 100;
      bmi = w / (h * h);
      v.push_back(make_pair(ABS(bmi - 22), id));
    }
    sort(v.begin(), v.end());
    cout << v[0].second << endl;
  }

  return 0;
}


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

#define ABS(X) ((X) < 0 ? -(X) : (X))
typedef pair<double, int> Subj;

int main(void) {
  int n;

  while (cin >> n) {
    if (n == 0)
      break;
    vector<Subj> v;
    for (int i = 0; i < n; i++) {
      int id;
      double h, w, bmi;
      cin >> id >> h >> w;
      h /= 100;
      bmi = w / (h * h);
      v.push_back(make_pair(ABS(bmi - 22), id));
    }
    sort(v.begin(), v.end());
    cout << v[0].second << endl;
  }

  return 0;
}
Problem p00160 (C++)

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

int main(void) {
  int x, y, z, w, n, i;
  int sum, l;

  while (scanf("%d", &n) != 0) {
    sum = 0;
    for (i = 0; i < n; i++) {
      scanf("%d %d %d %d", &x, &y, &z, &w);
      l = x + y + z;
      if (l <= 60 && w <= 2)
        sum += 600;
      else if (l <= 80 && w <= 5)
        sum += 800;
      else if (l <= 100 && w <= 10)
        sum += 1000;
      else if (l <= 120 && w <= 15)
        sum += 1200;
      else if (l <= 140 && w <= 20)
        sum += 1400;
      else if (l <= 160 && w <= 25)
        sum += 1600;
    }
    printf("%d\n", sum);
  }
  return 0;
}

Fixed submission:
#include <stdio.h>

int main(void) {
  int x, y, z, w, n, i;
  int sum, l;

  while (0 == 0) {
    scanf("%d", &n);
    if (n == 0)
      break;
    sum = 0;
    for (i = 0; i < n; i++) {
      scanf("%d %d %d %d", &x, &y, &z, &w);
      l = x + y + z;
      if (l <= 60 && w <= 2)
        sum += 600;
      else if (l <= 80 && w <= 5)
        sum += 800;
      else if (l <= 100 && w <= 10)
        sum += 1000;
      else if (l <= 120 && w <= 15)
        sum += 1200;
      else if (l <= 140 && w <= 20)
        sum += 1400;
      else if (l <= 160 && w <= 25)
        sum += 1600;
    }
    printf("%d\n", sum);
  }
  return 0;
}
Problem p00161 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

class Score {
public:
  int num;
  int time;

  Score() {
    this->num = 0;
    this->time = 0;
  }

  Score(int num, int time) {
    this->num = num;
    this->time = time;
  }
};

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

  while (true) {
    int n;
    cin >> n;

    Score max, pre, biri, boobie;

    for (int i = 0; i < n; i++) {
      int c1;
      cin >> c1;
      int sum = 0;
      for (int i = 0; i < 4; i++) {
        int m, s;
        cin >> m >> s;
        sum += 60 * m + s;
      }

      if (max.time == 0 || max.time > sum) {
        pre = max;
        max = Score(c1, sum);
      } else if (pre.time == 0 || pre.time > sum) {
        if (biri.time == 0) {
          biri = pre;
        } else if (boobie.time == 0) {
          boobie = pre;
        }
        pre = Score(c1, sum);
      } else if (biri.time < sum) {
        boobie = biri;
        biri = Score(c1, sum);
      } else if (boobie.time < sum) {
        boobie = Score(c1, sum);
      }
    }

    cout << max.num << endl;
    cout << pre.num << endl;
    cout << boobie.num << endl;
  }

  return 0;
}

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

class Score {
public:
  int num;
  int time;

  Score() {
    this->num = 0;
    this->time = 0;
  }

  Score(int num, int time) {
    this->num = num;
    this->time = time;
  }
};

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

  while (true) {
    int n;
    cin >> n;

    if (n == 0) {
      break;
    }

    Score max, pre, biri, boobie;

    for (int i = 0; i < n; i++) {
      int c1;
      cin >> c1;
      int sum = 0;
      for (int i = 0; i < 4; i++) {
        int m, s;
        cin >> m >> s;
        sum += 60 * m + s;
      }

      if (max.time == 0 || max.time > sum) {
        pre = max;
        max = Score(c1, sum);
      } else if (pre.time == 0 || pre.time > sum) {
        if (biri.time == 0) {
          biri = pre;
        } else if (boobie.time == 0) {
          boobie = pre;
        }
        pre = Score(c1, sum);
      } else if (biri.time < sum) {
        boobie = biri;
        biri = Score(c1, sum);
      } else if (boobie.time < sum) {
        boobie = Score(c1, sum);
      }
    }

    cout << max.num << endl;
    cout << pre.num << endl;
    cout << boobie.num << endl;
  }

  return 0;
}
Problem p00161 (C++)

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

struct hoge {
  int num, timem, times;
};

int main() {
  int n, c, m1, s1, m2, s2, m3, s3, m4, s4;
  hoge set[100];
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      set[i].num = c;
      set[i].timem = m1 + m2 + m3 + m4;
      set[i].times = s1 + s2 + s3 + s4;
      if (set[i].times >= 60) {
        set[i].timem += set[i].times / 60;
        set[i].times %= 60;
      }
    }

    for (int i = 0; i < (n - 1); i++) {
      for (int j = (i + 1); j < n; j++) {
        if (set[j].timem < set[i].timem) {
          swap(set[i].num, set[j].num);
          swap(set[i].timem, set[j].timem);
          swap(set[i].times, set[j].times);
        } else if (set[j].timem == set[i].timem) {
          if (set[j].times < set[i].times) {
            swap(set[i].num, set[j].num);
            swap(set[i].timem, set[j].timem);
            swap(set[i].times, set[j].times);
          }
        }
      }
    }

    cout << set[0].num << endl << set[1].num << endl << set[n - 2].num << endl;
  }
  return 0;
}

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

struct hoge {
  int num, timem, times;
};

int main() {
  int n, c, m1, s1, m2, s2, m3, s3, m4, s4;
  hoge set[1000000];
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      set[i].num = c;
      set[i].timem = m1 + m2 + m3 + m4;
      set[i].times = s1 + s2 + s3 + s4;
      if (set[i].times >= 60) {
        set[i].timem += set[i].times / 60;
        set[i].times %= 60;
      }
    }

    for (int i = 0; i < (n - 1); i++) {
      for (int j = (i + 1); j < n; j++) {
        if (set[j].timem < set[i].timem) {
          swap(set[i].num, set[j].num);
          swap(set[i].timem, set[j].timem);
          swap(set[i].times, set[j].times);
        } else if (set[j].timem == set[i].timem) {
          if (set[j].times < set[i].times) {
            swap(set[i].num, set[j].num);
            swap(set[i].timem, set[j].timem);
            swap(set[i].times, set[j].times);
          }
        }
      }
    }

    cout << set[0].num << endl << set[1].num << endl << set[n - 2].num << endl;
  }
  return 0;
}
Problem p00162 (C++)

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

const int MAX_NUM = 1000;

int main() {
  bool list[MAX_NUM + 1] = {0};

  for (int two = 0; two <= 20; two++) {
    for (int three = 0; three <= 13; three++) {
      for (int five = 0; five <= 9; five++) {
        int num = pow(2, two) * pow(3, three) * pow(5, five);
        if (1 <= num && num <= MAX_NUM)
          list[num] = true;
      }
    }
  }
  int m, n;
  while (1) {
    cin >> m;
    if (m == 0)
      break;
    cin >> n;
    int ans = 0;
    for (int i = m; i <= n; i++) {
      if (list[i])
        ans++;
    }
    cout << ans << endl;
  }

  return 0;
}

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

const int MAX_NUM = 1000000;

int main() {
  bool list[MAX_NUM + 1] = {0};

  for (int two = 0; two <= 20; two++) {
    for (int three = 0; three <= 13; three++) {
      for (int five = 0; five <= 9; five++) {
        int num = pow(2, two) * pow(3, three) * pow(5, five);
        if (1 <= num && num <= MAX_NUM)
          list[num] = true;
      }
    }
  }
  int m, n;
  while (1) {
    cin >> m;
    if (m == 0)
      break;
    cin >> n;
    int ans = 0;
    for (int i = m; i <= n; i++) {
      if (list[i])
        ans++;
    }
    cout << ans << endl;
  }

  return 0;
}
Problem p00162 (C++)

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

const int HAMMING_MAX = 100001;

int main() {
  bool hamming[HAMMING_MAX];
  memset(hamming, 0, sizeof(hamming));

  for (int x = 1; x < HAMMING_MAX; x *= 2) {
    for (int y = 1; x * y < HAMMING_MAX; y *= 3) {
      for (int z = 1; x * y * z < HAMMING_MAX; z *= 5) {
        int h = x * y * z;
        hamming[h] = true;
      }
    }
  }

  int n, m;
  while (cin >> n && n) {
    cin >> m;
    int count = 0;
    for (int i = n; i <= m; ++i) {
      if (hamming[i]) {
        ++count;
      }
    }
    cout << count << endl;
  }

  return 0;
}

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

const int HAMMING_MAX = 1000001;

int main() {
  bool hamming[HAMMING_MAX];
  memset(hamming, 0, sizeof(hamming));

  for (int x = 1; x < HAMMING_MAX; x *= 2) {
    for (int y = 1; x * y < HAMMING_MAX; y *= 3) {
      for (int z = 1; x * y * z < HAMMING_MAX; z *= 5) {
        int h = x * y * z;
        hamming[h] = true;
      }
    }
  }

  int n, m;
  while (cin >> n && n) {
    cin >> m;
    int count = 0;
    for (int i = n; i <= m; ++i) {
      if (hamming[i]) {
        ++count;
      }
    }
    cout << count << endl;
  }

  return 0;
}
Problem p00162 (C++)

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

using namespace std;

int main() {

  int m, n;

  while (cin >> m >> n, m || n) {

    int count = 0;

    for (int i = m; i <= n; ++i) {

      int result = i;

      while (1) {

        if (result % 2 == 0)
          result = result / 2;
        else if (result % 3 == 0)
          result = result / 3;
        else if (result % 5 == 0)
          result = result / 5;
        else
          break;
      }

      if (result == 1)
        count++;
    }

    cout << count << endl;
  }
}


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

using namespace std;

int main() {

  int m, n;

  while (1) {

    cin >> m;

    if (m == 0)
      break;

    cin >> n;

    int count = 0;

    for (int i = m; i <= n; ++i) {

      int result = i;

      while (1) {

        if (result % 2 == 0)
          result = result / 2;
        else if (result % 3 == 0)
          result = result / 3;
        else if (result % 5 == 0)
          result = result / 5;
        else
          break;
      }

      if (result == 1)
        count++;
    }

    cout << count << endl;
  }
}
Problem p00162 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int m;
  vector<int> count;
  for (int i = 0; i < 6; i++)
    count.push_back(i);
  for (int i = 6; i < 10000001; i++) {
    if ((i % 2 == 0 && count[i / 2] - count[(i / 2) - 1] != 0) ||
        (i % 3 == 0 && count[i / 3] - count[(i / 3) - 1] != 0) ||
        (i % 5 == 0 && count[i / 5] - count[(i / 5) - 1] != 0))
      count.push_back(count[i - 1] + 1);
    else
      count.push_back(count[i - 1]);
  }
  for (; cin >> m, m;) {
    int n;
    cin >> n;
    cout << count[n] - count[m - 1] << endl;
  }
}

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

using namespace std;

int main() {
  int m;
  vector<unsigned short> count;
  for (int i = 0; i < 6; i++)
    count.push_back(i);
  for (int i = 6; i < 10000001; i++) {
    if ((i % 2 == 0 && count[i / 2] - count[(i / 2) - 1] != 0) ||
        (i % 3 == 0 && count[i / 3] - count[(i / 3) - 1] != 0) ||
        (i % 5 == 0 && count[i / 5] - count[(i / 5) - 1] != 0))
      count.push_back(count[i - 1] + 1);
    else
      count.push_back(count[i - 1]);
  }
  for (; cin >> m, m;) {
    int n;
    cin >> n;
    cout << count[n] - count[m - 1] << endl;
  }
}
Problem p00162 (C++)

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

int x[2000000];
long long p;
int a, b, sum;

int main() {
  for (int i = 0; i < 20; i++) {
    for (int j = 0; j < 13; j++) {
      for (int k = 0; k < 9; k++) {
        p = (int)pow(2, i) * (int)pow(3, j) * (int)pow(5, k);
        if (p < 2000000) {
          x[p] = 1;
        }
      }
    }
  }
  while (true) {
    sum = 0;
    cin >> a;
    if (a == 0) {
      break;
    }
    cin >> b;
    for (int i = a; i <= b; i++) {
      sum += x[i];
    }
    cout << sum << endl;
  }
}

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

int x[2000000];
long long p;
int a, b, sum;

int main() {
  for (int i = 0; i < 20; i++) {
    for (int j = 0; j < 13; j++) {
      for (int k = 0; k < 9; k++) {
        p = (long long)pow(2, i) * (long long)pow(3, j) * (long long)pow(5, k);
        if (p < 2000000) {
          x[p] = 1;
        }
      }
    }
  }
  while (true) {
    sum = 0;
    cin >> a;
    if (a == 0) {
      break;
    }
    cin >> b;
    for (int i = a; i <= b; i++) {
      sum += x[i];
    }
    cout << sum << endl;
  }
}
Problem p00162 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#define D 100
using namespace std;
bool flg[D];
int ans[D];
int main() {

  int m, n;
  flg[1] = true;
  for (int i = 0; i <= D; i++) {
    if (flg[i]) {
      if (2 * i <= D)
        flg[2 * i] = true;
      if (3 * i <= D)
        flg[3 * i] = true;
      if (5 * i <= D)
        flg[5 * i] = true;
      // cout<<i<<endl;
    }
  }
  int cnt = 0;
  for (int i = 0; i <= D; i++) {
    if (flg[i])
      cnt++;
    ans[i] = cnt;
    // cout<<ans[i]<<endl;
  }
  while (cin >> m, m) {
    cin >> n;
    cout << ans[n] - ans[m - 1] << endl;
  }
}

Fixed submission:
#include <iostream>
#define D 1000000
using namespace std;
bool flg[D];
int ans[D];
int main() {

  int m, n;
  flg[1] = true;
  for (int i = 0; i <= D; i++) {
    if (flg[i]) {
      if (2 * i <= D)
        flg[2 * i] = true;
      if (3 * i <= D)
        flg[3 * i] = true;
      if (5 * i <= D)
        flg[5 * i] = true;
      // cout<<i<<endl;
    }
  }
  int cnt = 0;
  for (int i = 0; i <= D; i++) {
    if (flg[i])
      cnt++;
    ans[i] = cnt;
    // cout<<ans[i]<<endl;
  }
  while (cin >> m, m) {
    cin >> n;
    cout << ans[n] - ans[m - 1] << endl;
  }
}
Problem p00162 (C++)

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define all(n) n.begin(), n.end()

const int MAXN = 100 * 1000 + 10;

bool ham[MAXN];

int main() {
  ham[1] = 1;
  REP(MAXN) if (ham[i]) {
    for (int j = i * 2; j < MAXN; j *= 2)
      ham[j] = 1;
    for (int j = i * 3; j < MAXN; j *= 3)
      ham[j] = 1;
    for (int j = i * 5; j < MAXN; j *= 5)
      ham[j] = 1;
  }
  int m, n;
  while (cin >> m && m) {
    cin >> n;
    int ans = 0;
    for (int i = m; i <= n; i++)
      if (ham[i])
        ans++;
    cout << ans << endl;
  }

  return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define all(n) n.begin(), n.end()

const int MAXN = 1000000 + 10;

bool ham[MAXN];

int main() {
  ham[1] = 1;
  REP(MAXN) if (ham[i]) {
    for (int j = i * 2; j < MAXN; j *= 2)
      ham[j] = 1;
    for (int j = i * 3; j < MAXN; j *= 3)
      ham[j] = 1;
    for (int j = i * 5; j < MAXN; j *= 5)
      ham[j] = 1;
  }
  int m, n;
  while (cin >> m && m) {
    cin >> n;
    int ans = 0;
    for (int i = m; i <= n; i++)
      if (ham[i])
        ans++;
    cout << ans << endl;
  }

  return 0;
}
Problem p00162 (C++)

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

int dp[1000001] = {0};
int main() {
  int k, m, n;
  dp[1] = 1;
  for (int i = 1; i <= 500000; i++) {
    dp[i * 2] |= 1;
    dp[i * 3] |= 1;
    dp[i * 5] |= 1;
  }
  for (int i = 1; i <= 1000000; i++) {
    dp[i] += dp[i - 1];
  }
  while (cin >> m && m) {
    cin >> n;
    cout << dp[n] - dp[m - 1] << endl;
  }
  return 0;
}

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

int dp[1000001] = {0};
int main() {
  int a = 1, n, m;
  for (int i = 0; a <= 1000000; i++) {
    int b = 1;
    for (int j = 0; a * b <= 1000000; j++) {
      int c = 1;
      for (int k = 0; a * b * c <= 1000000; k++) {
        dp[a * b * c] = true;
        c *= 5;
      }
      b *= 3;
    }
    a *= 2;
  }
  for (int i = 1; i <= 1000000; i++) {
    dp[i] += dp[i - 1];
  }
  while (cin >> m && m) {
    cin >> n;
    cout << dp[n] - dp[m - 1] << endl;
  }
  return 0;
}
Problem p00162 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
/*
bool sw[1000001];
int i;

void sws(int k){
        if(k==1){
                sw[i]=true;
                return;
        }
        if(k%2==0) sws(k/2);
        else if(k%3==0) sws(k/3);
        else if(k%5==0) sws(k/5);
        return;
}
*/
// korenisuru
int dp[1000001];
int f(int n) {
  if (~dp[n])
    return dp[n];
  int ans = 0;
  if (n % 2 == 0)
    ans |= f(n / 2);
  else if (n % 3 == 0)
    ans |= f(n / 3);
  else if (n % 5 == 0)
    ans |= f(n / 5);
  return dp[n] = ans;
}

int main() {
  int m, n;
  for (int i = 0; i <= 1000000; i++)
    dp[i] = -1;
  dp[1] = 1;
  for (int i = 1000000; i >= 1; i++)
    f(i);
  while (cin >> m && m) {
    cin >> n;
    int ans = 0;
    for (int i = m; i <= n; i++)
      ans += dp[i];
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
/*
bool sw[1000001];
int i;

void sws(int k){
        if(k==1){
                sw[i]=true;
                return;
        }
        if(k%2==0) sws(k/2);
        else if(k%3==0) sws(k/3);
        else if(k%5==0) sws(k/5);
        return;
}
*/
// korenisuru
int dp[1000001];
int f(int n) {
  if (~dp[n])
    return dp[n];
  int ans = 0;
  if (n % 2 == 0)
    ans |= f(n / 2);
  else if (n % 3 == 0)
    ans |= f(n / 3);
  else if (n % 5 == 0)
    ans |= f(n / 5);
  return dp[n] = ans;
}

int main() {
  int m, n;
  for (int i = 0; i <= 1000000; i++)
    dp[i] = -1;
  dp[1] = 1;
  for (int i = 1000000; i >= 1; i--)
    f(i);
  while (cin >> m && m) {
    cin >> n;
    int ans = 0;
    for (int i = m; i <= n; i++)
      ans += dp[i];
    cout << ans << endl;
  }
  return 0;
}
Problem p00163 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

vector<vector<int>> money{
    {0, 300, 500, 600, 700, 1350, 1650},
    {0, 0, 350, 450, 600, 1150, 1500},
    {0, 0, 0, 250, 400, 1000, 1350},
    {0, 0, 0, 0, 250, 850, 1300},
    {0, 0, 0, 0, 0, 600, 1150},
    {0, 0, 0, 0, 0, 0, 500},
    {0, 0, 0, 0, 0, 0, 0},

};
vector<int> dis{6, 7, 5, 5, 20, 15};

int main() {
  while (1) {
    int d;
    cin >> d;
    int start, goal;
    {

      int h, m;
      cin >> h >> m;
      start = h * 60 + m;
    }
    int a;
    cin >> a;
    {

      int h, m;
      cin >> h >> m;
      goal = h * 60 + m;
    }
    d--;
    a--;
    if (d < a)
      swap(d, a);
    int cost = money[a][d];
    cost /= 50;
    int distance = 0;
    for (int i = a; i < d; ++i) {
      distance += dis[i];
    }
    bool flag = false;
    if ((start <= 1170 || 1050 <= goal) && !(start < 1050 && 1170 < goal))
      flag = true;
    if (distance <= 40 && flag)
      cost = (cost + 1) / 2;
    cost *= 50;
    cout << cost << endl;
  }
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

vector<vector<int>> money{
    {0, 300, 500, 600, 700, 1350, 1650},
    {0, 0, 350, 450, 600, 1150, 1500},
    {0, 0, 0, 250, 400, 1000, 1350},
    {0, 0, 0, 0, 250, 850, 1300},
    {0, 0, 0, 0, 0, 600, 1150},
    {0, 0, 0, 0, 0, 0, 500},
    {0, 0, 0, 0, 0, 0, 0},

};
vector<int> dis{6, 7, 5, 5, 20, 15};

int main() {
  while (1) {
    int d;
    cin >> d;
    if (!d)
      break;
    int start, goal;
    {

      int h, m;
      cin >> h >> m;
      start = h * 60 + m;
    }
    int a;
    cin >> a;
    {

      int h, m;
      cin >> h >> m;
      goal = h * 60 + m;
    }
    d--;
    a--;
    if (d < a)
      swap(d, a);
    int cost = money[a][d];
    cost /= 50;
    int distance = 0;
    for (int i = a; i < d; ++i) {
      distance += dis[i];
    }
    bool flag = false;
    if ((start <= 1170 || 1050 <= goal) && !(start < 1050 && 1170 < goal))
      flag = true;
    if (distance <= 40 && flag)
      cost = (cost + 1) / 2;
    cost *= 50;
    cout << cost << endl;
  }
  return 0;
}
Problem p00164 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main() {
  int n, a[4], s, t, p;

  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    s = 32;
    p = 0;
    while (s > 0) {
      t = (s - 1) % 5;
      s -= t;
      cout << s << endl;

      s -= a[p % n];
      p++;
      if (s < 0) {
        s = 0;
      }
      cout << s << endl;
    }
  }

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int n, a[26], s, t, p;

  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    s = 32;
    p = 0;
    while (s > 0) {
      t = (s - 1) % 5;
      s -= t;
      cout << s << endl;

      s -= a[p % n];
      p++;
      if (s < 0) {
        s = 0;
      }
      cout << s << endl;
    }
  }

  return 0;
}
Problem p00164 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>
using namespace std;
int main() {
  int m, n[100];
  while (true) {
    cin >> m;
    if (m == 0)
      break;
    for (int i = 0; i < m; i++)
      cin >> n[i];
    int ans = 31;
    int count = 0;
    cout << "31" << endl;
    while (true) {
      if (ans < n[count]) {
        cout << "0" << endl;
        break;
      }
      ans -= n[count];
      cout << ans << endl;
      ans -= (ans - 1) % 5;
      cout << ans << endl;
      count++;
      count %= m;
    }
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  int m, n[100];
  while (true) {
    cin >> m;
    if (m == 0)
      break;
    for (int i = 0; i < m; i++)
      cin >> n[i];
    int ans = 31;
    int count = 0;
    cout << "31" << endl;
    while (true) {
      if (ans <= n[count]) {
        cout << "0" << endl;
        break;
      }
      ans -= n[count];
      cout << ans << endl;
      ans -= (ans - 1) % 5;
      cout << ans << endl;
      count++;
      count %= m;
    }
  }
  return 0;
}
Problem p00164 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

void loop(int remain, int *jiro_rule, int rule_size, int cur) {
  remain -= (remain - 1) % 5;
  cout << remain << endl;
  if (remain == 0)
    return;
  if (remain < *(jiro_rule + cur)) {
    cout << 0 << endl;
    return;
  }
  remain -= *(jiro_rule + cur);
  cout << remain << endl;
  cur++;
  if (cur == rule_size)
    cur = 0;
  loop(remain, jiro_rule, rule_size, cur);
}

int main() {
  int i;
  while (cin >> i) {
    if (i == 0)
      break;
    int a[i];
    for (int p = 0; p < i; p++) {
      cin >> a[p];
    }
    loop(32, a, i, 0);
  }
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

void loop(int remain, int *jiro_rule, int rule_size, int cur) {
  remain -= (remain - 1) % 5;
  cout << remain << endl;
  if (remain == 0)
    return;
  if (remain <= *(jiro_rule + cur)) {
    cout << 0 << endl;
    return;
  }
  remain -= *(jiro_rule + cur);
  cout << remain << endl;
  cur++;
  if (cur == rule_size)
    cur = 0;
  loop(remain, jiro_rule, rule_size, cur);
}

int main() {
  int i;
  while (cin >> i) {
    if (i == 0)
      break;
    int a[i];
    for (int p = 0; p < i; p++) {
      cin >> a[p];
    }
    loop(32, a, i, 0);
  }
  return 0;
}
Problem p00164 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int k;
  while (cin >> k) {
    int n = 32, a[30];
    for (int i = 0; i < k; i++)
      cin >> a[i];
    for (int i = 0; n; i++) {
      int p;
      p = (n - 1) % 5;
      n -= p;
      cout << n << endl;
      p = a[i % k];
      n -= p;
      if (n < 0)
        n = 0;
      cout << n << endl;
    }
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int k;
  while (cin >> k, k) {
    int n = 32, a[30];
    for (int i = 0; i < k; i++)
      cin >> a[i];
    for (int i = 0; n; i++) {
      int p;
      p = (n - 1) % 5;
      n -= p;
      cout << n << endl;
      p = a[i % k];
      n -= p;
      if (n < 0)
        n = 0;
      cout << n << endl;
    }
  }
}
Problem p00164 (C++)

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

int main() {

  int n[5] = {};
  int N;
  int r = 0;
  while (1) {
    scanf("%d", &N);
    if (N == 0)
      break;

    for (int i = 0; i < N; i++)
      scanf("%d", &n[i]);

    int P = 32;
    int j = 0;
    while (1) {
      if (P <= 0)
        break;
      P -= (P - 1) % 5;
      printf("%d\n", P);
      if (P == 1)
        break;
      P -= n[j];
      printf("%d\n", P);
      j++;
      j = j % N;
    }
    P = 0;
    printf("%d\n", P);
  }
  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {

  int n[30] = {};
  int N;
  int r = 0;
  while (1) {
    scanf("%d", &N);
    if (N == 0)
      break;

    for (int i = 0; i < N; i++)
      scanf("%d", &n[i]);

    int P = 32;
    int j = 0;
    while (1) {
      if (P <= 0)
        break;
      P -= (P - 1) % 5;
      printf("%d\n", P);
      if (P == 1)
        break;
      P -= n[j];
      printf("%d\n", P);
      j++;
      j = j % N;
    }
    P = 0;
    printf("%d\n", P);
  }
  return 0;
}
Problem p00164 (C++)

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

int main() {

  int n, v[26];
  int w[7] = {31, 26, 21, 16, 11, 6, 1};

  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      cin >> v[i];
    }

    cout << 31 << endl;
    for (int i = 0; i < 6; i++) {
      cout << w[i] - v[i % n] << endl;
      cout << w[i + 1] << endl;
    }
    cout << 0 << endl;
  }

  return 0;
}

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

int main() {

  int n, v[26];
  int w[7] = {31, 26, 21, 16, 11, 6, 1};

  while (cin >> n) {
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> v[i];
    }

    cout << 31 << endl;
    for (int i = 0; i < 6; i++) {
      cout << w[i] - v[i % n] << endl;
      cout << w[i + 1] << endl;
    }
    cout << 0 << endl;
  }

  return 0;
}
Problem p00164 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int len;

  while (scanf("%d", &len), len) {
    int a[4];
    for (int i = 0; i < len; i++) {
      scanf("%d", &a[i]);
    }
    int n = 32;
    for (int i = 0, j = 0;; i++) {
      if (i % 2 == 0) {
        n -= (n - 1) % 5;
      } else {
        n -= a[j % len];
        j++;
      }
      if (n <= 0) {
        n = 0;
        printf("%d\n", n);
        break;
      }
      printf("%d\n", n);
    }
  }

  return (0);
}

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

int main() {
  int len;

  while (scanf("%d", &len), len) {
    int a[25];
    for (int i = 0; i < len; i++) {
      scanf("%d", &a[i]);
    }
    int n = 32;
    for (int i = 0, j = 0;; i++) {
      if (i % 2 == 0) {
        n -= (n - 1) % 5;
      } else {
        n -= a[j % len];
        j++;
      }
      if (n <= 0) {
        n = 0;
        printf("%d\n", n);
        break;
      }
      printf("%d\n", n);
    }
  }

  return (0);
}
Problem p00165 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using namespace std;

const int MAX = 999984;
bool isPrime[MAX];

void createIsPrime() {
  fill_n(isPrime, MAX, true);
  isPrime[0] = false;
  isPrime[1] = false;
  for (int i = 4; i < MAX; i += 2) {
    isPrime[i] = false;
  }
  for (int i = 3; i * i <= MAX; i += 2) {
    if (isPrime[i]) {
      for (int j = i * 2; j < MAX; j += i) {
        isPrime[j] = false;
      }
    }
  }
}

int main() {
  createIsPrime();
  while (true) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    int bill = 0;
    while (n--) {
      int p, m;
      cin >> p >> m;
      int prime = 0;
      for (int i = max(p - m, 2), end = min(p + m, MAX - 1); i <= end; i++) {
        if (isPrime[i]) {
          prime++;
        }
      }
      if (prime > 0) {
        bill += prime - 1;
      } else {
        bill--;
      }
    }
    cout << bill << endl;
  }
}

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

const int MAX = 999984;
bool isPrime[MAX];

void createIsPrime() {
  fill_n(isPrime, MAX, true);
  isPrime[0] = false;
  isPrime[1] = false;
  for (int i = 4; i < MAX; i += 2) {
    isPrime[i] = false;
  }
  for (int i = 3; i * i <= MAX; i += 2) {
    if (isPrime[i]) {
      for (int j = i * 2; j < MAX; j += i) {
        isPrime[j] = false;
      }
    }
  }
}

int main() {
  createIsPrime();
  while (true) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    int bill = 0;
    while (n--) {
      int p, m;
      cin >> p >> m;
      int prime = 0, start = p - m;
      if ((p - m) % 2 == 0) {
        start++;
      }
      if (p - m <= 2) {
        bill++;
      }
      for (int i = max(start, 3), end = min(p + m, MAX - 1); i <= end; i += 2) {
        if (isPrime[i]) {
          prime++;
        }
      }
      if (prime > 0) {
        bill += prime - 1;
      } else {
        bill--;
      }
    }
    cout << bill << endl;
  }
}
Problem p00166 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP((i), 0, (n))
#define RREP(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define rrep(i, n) RREP(i, n, 0)
#define each(it, X)                                                            \
  for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#define all(v) ((v).begin(), (v).end())
#define fi first
#define se second
#define pb push_back
typedef pair<int, int> pr;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
const int INF = 1070000000ll;
const int mod = 1000000007ll;
const double EPS = 1e-9;
const double PI = 3.14159265;
double getS(int x) {
  int d = 360;
  double S = 0;
  rep(i, x - 1) {
    int z;
    cin >> z;
    d -= z;
    S += fabs(sin(1.0 * z / 180 * PI));
  }
  S += fabs(sin(1.0 * d / 180 * PI));
  return S;
}
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  double S[2];

  int x;
  while (cin >> x, x) {
    S[0] = getS(x);
    scanf("%d", &x);
    S[1] = getS(x);
    if (fabs(S[0] - S[1]) < EPS)
      cout << 0 << endl;
    else if (S[0] > S[1])
      cout << 1 << endl;
    else
      cout << 2 << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP((i), 0, (n))
#define RREP(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define rrep(i, n) RREP(i, n, 0)
#define each(it, X)                                                            \
  for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#define all(v) ((v).begin(), (v).end())
#define fi first
#define se second
#define pb push_back
typedef pair<int, int> pr;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
const int INF = 1070000000ll;
const int mod = 1000000007ll;
const double EPS = 1e-9;
const double PI = 3.14159265;
double getS(int x) {
  int d = 360;
  double S = 0;
  rep(i, x - 1) {
    int z;
    cin >> z;
    d -= z;
    S += fabs(sin(1.0 * z / 180 * PI));
  }
  S += fabs(sin(1.0 * d / 180 * PI));
  return S;
}
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  double S[2];

  int x;
  while (cin >> x, x) {
    S[0] = getS(x);
    cin >> x;
    S[1] = getS(x);
    if (fabs(S[0] - S[1]) < EPS)
      cout << 0 << endl;
    else if (S[0] > S[1])
      cout << 1 << endl;
    else
      cout << 2 << endl;
  }
  return 0;
}