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

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

class team {
public:
  int num, ans, time;
  team(int n) {
    num = n;
    ans = time = 0;
  }
  bool operator<(const team &t2) const {
    if (ans != t2.ans)
      return ans > t2.ans;
    else if (time != t2.time)
      return time < t2.time;
    else
      return num > t2.num;
  }
};

int main() {
  int M, T, P, R, m[2001], t[2001], p[2001], r[2001], before;
  while (cin >> M >> T >> P >> R, (M || T || P || R)) {
    vector<team> v;
    vector<team>::iterator pv;
    // 入力
    for (int i = 0; i < R; i++) {
      cin >> m[i] >> t[i] >> p[i] >> r[i];
    }

    // 各チームの時間
    for (int i = 1; i <= T; i++) {
      team te = team(i);
      for (int j = 0; j < R; j++) {
        // 正解時間の計算
        if (t[j] == i && r[j] == 0) {
          te.time += m[j];
          te.ans++;
          // 以前のペナルティを計算
          for (int k = 0; k < j; k++) {
            if (t[k] == i && p[k] == p[j]) {
              te.time += 20;
            }
          }
        }
      }
      v.push_back(te);
    }

    // ソート
    sort(v.begin(), v.end());
    pv = v.begin();
    before = -1;
    while (pv != v.end()) {
      if (before == pv->time)
        cout << "=" << pv->num;
      else {
        if (pv == v.begin())
          cout << pv->num;
        else
          cout << "," << pv->num;
        before = pv->time;
      }
      pv++;
    }
    cout << endl;
    v.~vector();
  }
  return 0;
}

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

class team {
public:
  int num, ans, time;
  team(int n) {
    num = n;
    ans = time = 0;
  }
  bool operator<(const team &t2) const {
    if (ans != t2.ans)
      return ans > t2.ans;
    else if (time != t2.time)
      return time < t2.time;
    else
      return num > t2.num;
  }
};

int main() {
  int M, T, P, R, m[2001], t[2001], p[2001], r[2001], before;
  while (cin >> M >> T >> P >> R, (M || T || P || R)) {
    vector<team> v;
    vector<team>::iterator pv;
    // 入力
    for (int i = 0; i < R; i++) {
      cin >> m[i] >> t[i] >> p[i] >> r[i];
    }

    // 各チームの時間
    for (int i = 1; i <= T; i++) {
      team te = team(i);
      for (int j = 0; j < R; j++) {
        // 正解時間の計算
        if (t[j] == i && r[j] == 0) {
          te.time += m[j];
          te.ans++;
          // 以前のペナルティを計算
          for (int k = 0; k < j; k++) {
            if (t[k] == i && p[k] == p[j]) {
              te.time += 20;
            }
          }
        }
      }
      v.push_back(te);
    }

    // ソート
    sort(v.begin(), v.end());
    pv = v.begin();
    before = -1;
    while (pv != v.end()) {
      if (before == pv->time)
        cout << "=" << pv->num;
      else {
        if (pv == v.begin())
          cout << pv->num;
        else
          cout << "," << pv->num;
        before = pv->time;
      }
      pv++;
    }
    cout << endl;
  }
  return 0;
}
Problem p00768 (C++)

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

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

using namespace std;

int main() {
  int M, T, P, R;
  while (true) {
    cin >> M >> T >> P >> R;
    if (M == 0)
      return 0;
    vector<int> m(R), t(R), p(R), j(R);
    REP(i, R) {
      cin >> m[i] >> t[i] >> p[i] >> j[i];
      t[i]--;
    }
    vector<vector<int>> pena(T, vector<int>(P));
    vector<vector<int>> score(T, vector<int>(2)); // seikai,jikan

    REP(i, R) {
      if (j[i] == 0) {
        score[t[i]][0]++;
        score[t[i]][1] += pena[t[i]][p[i]] + m[i];
      }
      pena[t[i]][p[i]] += 20;
    }

    vector<tuple<int, int, int>> tupleScore(T);
    REP(i, T) { tupleScore[i] = make_tuple(-score[i][0], score[i][1], -1 - i); }
    sort(ALL(tupleScore));

    int top;
    tie(ignore, ignore, top) = tupleScore[0];
    cout << -top;
    REP(i, T - 1) {
      int ans1, tim1, ans2, tim2;
      tie(ans1, tim1, ignore) = tupleScore[i];
      tie(ans2, tim2, top) = tupleScore[i + 1];
      if (ans1 == ans2 && tim1 == tim2) {
        cout << "=" << -top;
      } else {
        cout << "," << -top;
      }
    }

    cout << endl;
  }
  return 0;
}

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

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

using namespace std;

int main() {
  int M, T, P, R;
  while (true) {
    cin >> M >> T >> P >> R;
    if (M == 0)
      return 0;
    vector<int> m(R), t(R), p(R), j(R);
    REP(i, R) {
      cin >> m[i] >> t[i] >> p[i] >> j[i];
      t[i]--;
      p[i]--;
    }
    vector<vector<int>> pena(T, vector<int>(P));
    vector<vector<int>> score(T, vector<int>(2)); // seikai,jikan

    REP(i, R) {
      if (j[i] == 0) {
        score[t[i]][0]++;
        score[t[i]][1] += pena[t[i]][p[i]] + m[i];
      }
      pena[t[i]][p[i]] += 20;
    }

    vector<tuple<int, int, int>> tupleScore(T);
    REP(i, T) { tupleScore[i] = make_tuple(-score[i][0], score[i][1], -1 - i); }
    sort(ALL(tupleScore));

    int top;
    tie(ignore, ignore, top) = tupleScore[0];
    cout << -top;
    REP(i, T - 1) {
      int ans1, tim1, ans2, tim2;
      tie(ans1, tim1, ignore) = tupleScore[i];
      tie(ans2, tim2, top) = tupleScore[i + 1];
      if (ans1 == ans2 && tim1 == tim2) {
        cout << "=" << -top;
      } else {
        cout << "," << -top;
      }
    }

    cout << endl;
  }
  return 0;
}
Problem p00768 (C++)

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

using namespace std;

int main() {
  int M, T, P, R;

  while (scanf("%d %d %d %d", &M, &T, &P, &R) && M) {
    vector<pair<pair<int, int>, int>> record(T);
    int wa[16][64] = {0};

    for (int i = 0; i < T; i++)
      record[i].second = -(i + 1);

    for (int i = 0; i < R; i++) {
      int m, t, p, j;
      scanf("%d %d %d %d", &m, &t, &p, &j);
      if (j)
        wa[t - 1][p] += 20;
      else {
        record[t - 1].first.first--;
        record[t - 1].first.second += m + wa[t - 1][p];
      }
    }

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

    for (int i = 0; i < T; i++) {
      printf("%d", -record[i].second);
      if (i + 1 < T && record[i].first == record[i + 1].first)
        printf("=");
      else if (i + 1 < T)
        printf(",");
      else
        printf("\n");
    }
  }

  return (0);
}

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

using namespace std;

int main() {
  int M, T, P, R;

  while (scanf("%d %d %d %d", &M, &T, &P, &R) && M) {
    vector<pair<pair<int, int>, int>> record(T);
    int wa[64][16] = {0};

    for (int i = 0; i < T; i++)
      record[i].second = -(i + 1);

    for (int i = 0; i < R; i++) {
      int m, t, p, j;
      scanf("%d %d %d %d", &m, &t, &p, &j);
      if (j)
        wa[t - 1][p] += 20;
      else {
        record[t - 1].first.first--;
        record[t - 1].first.second += m + wa[t - 1][p];
      }
    }

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

    for (int i = 0; i < T; i++) {
      printf("%d", -record[i].second);
      if (i + 1 < T && record[i].first == record[i + 1].first)
        printf("=");
      else if (i + 1 < T)
        printf(",");
      else
        printf("\n");
    }
  }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define reps(i, f, n) for (int i = f; i < int(n); i++)
#define rep(i, n) reps(i, 0, n)

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

piii mk(int a, int b, int c) { return piii(pii(a, b), c); }

int main() {
A:;

  int teemwrong[55][11] = {0};
  int teemcost[11] = {0};
  int teemac[11] = {0};

  int M, T, P, R;
  cin >> M >> T >> P >> R;

  if (M == 0 && T == 0 && R == 0 && P == 0)
    return 0;

  rep(i, R) {
    int m, t, p, j;
    cin >> m >> t >> p >> j;

    if (j == 0) {
      teemac[t]++;
      teemcost[t] += m + teemwrong[t][p] * 20;
    } else {
      teemwrong[t][p]++;
    }
  }

  vector<piii> rank;
  reps(i, 1, T + 1) { rank.push_back(mk(teemac[i], -teemcost[i], i)); }

  sort(rank.begin(), rank.end());
  reverse(rank.begin(), rank.end());

  rep(i, rank.size()) {
    if (i != 0) {
      if (rank[i].first == rank[i - 1].first)
        printf("=");
      else
        printf(",");
    }
    printf("%d", rank[i].second);
  }
  puts("");

  goto A;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define reps(i, f, n) for (int i = f; i < int(n); i++)
#define rep(i, n) reps(i, 0, n)

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

piii mk(int a, int b, int c) { return piii(pii(a, b), c); }

int main() {
A:;

  int teemwrong[55][11] = {0};
  int teemcost[55] = {0};
  int teemac[55] = {0};

  int M, T, P, R;
  cin >> M >> T >> P >> R;

  if (M == 0 && T == 0 && R == 0 && P == 0)
    return 0;

  rep(i, R) {
    int m, t, p, j;
    cin >> m >> t >> p >> j;

    if (j == 0) {
      teemac[t]++;
      teemcost[t] += m + teemwrong[t][p] * 20;
    } else {
      teemwrong[t][p]++;
    }
  }

  vector<piii> rank;
  reps(i, 1, T + 1) { rank.push_back(mk(teemac[i], -teemcost[i], i)); }

  sort(rank.begin(), rank.end());
  reverse(rank.begin(), rank.end());

  rep(i, rank.size()) {
    if (i != 0) {
      if (rank[i].first == rank[i - 1].first)
        printf("=");
      else
        printf(",");
    }
    printf("%d", rank[i].second);
  }
  puts("");

  goto A;
}
Problem p00768 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;
int main() {
  while (true) {
    int m, t, p, r;
    scanf("%d%d%d%d", &m, &t, &p, &r);
    if (m == 0)
      break;
    int tim[50][10] = {}, wa[50][10] = {};
    rep(i, 50) rep(j, 10) tim[i][j] = -1;
    rep(i, r) {
      int mm, tt, pp, jj;
      scanf("%d%d%d%d", &mm, &tt, &pp, &jj);
      tt--, pp--;
      if (jj == 0)
        tim[tt][pp] = mm + wa[tt][pp] * 20;
      else
        wa[tt][pp]++;
    }
    int pen[10] = {}, acp[10] = {};
    rep(i, t) rep(j, p) {
      if (tim[i][j] == -1)
        continue;
      acp[i]++;
      pen[i] += tim[i][j];
    }
    vector<PP> vc;
    rep(i, t) vc.push_back(PP(P(acp[i], -pen[i]), i + 1));
    sort(vc.begin(), vc.end(), greater<PP>());
    rep(i, t) {
      if (i == 0) {
        printf("%d", vc[i].second);
        continue;
      }
      if (vc[i].first == vc[i - 1].first)
        printf("=%d", vc[i].second);
      else
        printf(",%d", vc[i].second);
      //			cout << vc[i].second << " acp " <<
      //vc[i].first.first << " pen " << vc[i].first.second << endl;
    }
    printf("\n");
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;
int main() {
  while (true) {
    int m, t, p, r;
    scanf("%d%d%d%d", &m, &t, &p, &r);
    if (m == 0)
      break;
    int tim[50][10] = {}, wa[50][10] = {};
    rep(i, 50) rep(j, 10) tim[i][j] = -1;
    rep(i, r) {
      int mm, tt, pp, jj;
      scanf("%d%d%d%d", &mm, &tt, &pp, &jj);
      tt--, pp--;
      if (jj == 0)
        tim[tt][pp] = mm + wa[tt][pp] * 20;
      else
        wa[tt][pp]++;
    }
    int pen[50] = {}, acp[50] = {};
    rep(i, t) rep(j, p) {
      if (tim[i][j] == -1)
        continue;
      acp[i]++;
      pen[i] += tim[i][j];
    }
    vector<PP> vc;
    rep(i, t) vc.push_back(PP(P(acp[i], -pen[i]), i + 1));
    sort(vc.begin(), vc.end(), greater<PP>());
    rep(i, t) {
      if (i == 0) {
        printf("%d", vc[i].second);
        continue;
      }
      if (vc[i].first == vc[i - 1].first)
        printf("=%d", vc[i].second);
      else
        printf(",%d", vc[i].second);
      //			cout << vc[i].second << " acp " <<
      //vc[i].first.first << " pen " << vc[i].first.second << endl;
    }
    printf("\n");
  }
  return 0;
}
Problem p00769 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int n;
string s;
int calc(int l, int r) {
  int d = 0, c = 0, w = l;
  for (int i = l; i < r; i++)
    c += (s[i] == '[' || s[i] == ']' ? 1 : 0);
  if (c == 0)
    return stoi(s.substr(l + 1, r - l - 2));
  vector<int> v;
  for (int i = l; i < r; i++) {
    if (s[i] == '[')
      d++;
    if (s[i] == ']')
      d--;
    if (d == 0)
      v.push_back(calc(w + 1, i)), w = i + 1;
  }
  sort(v.begin(), v.end());
  int ret = 0;
  for (int i = 0; i <= v.size() / 2; i++)
    ret += v[i];
  return ret;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    cout << calc(0, s.size()) << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int n;
string s;
int calc(int l, int r) {
  int d = 0, c = 0, w = l;
  for (int i = l; i < r; i++)
    c += (s[i] == '[' || s[i] == ']' ? 1 : 0);
  if (c == 0)
    return stoi(s.substr(l, r)) / 2 + 1;
  vector<int> v;
  for (int i = l; i < r; i++) {
    if (s[i] == '[')
      d++;
    if (s[i] == ']')
      d--;
    if (d == 0)
      v.push_back(calc(w + 1, i)), w = i + 1;
  }
  sort(v.begin(), v.end());
  int ret = 0;
  for (int i = 0; i <= v.size() / 2; i++)
    ret += v[i];
  return ret;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    cout << calc(0, s.size()) << endl;
  }
  return 0;
}
Problem p00769 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int a[10][100], n, cnt[10], u, sum, chain;
string S, T;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S;
    u = 0;
    sum = 0;
    for (int i = 0; i < 10; i++) {
      cnt[i] = 0;
    }
    for (int i = 0; i < S.size(); i++) {
      if (S[i] == '[') {
        u++;
        T = "";
        chain = 0;
      } else if (S[i] == ']') {
        if (T != "") {
          cnt[u] = 0;
          u--;
          a[u][cnt[u]] = stoi(T);
          cnt[u]++;
          T = "";
        } else {
          chain++;
          sum = 0;
          sort(a[u], a[u] + cnt[u]);
          if (chain == 1) {
            for (int i = 0; i < cnt[u] / 2 + 1; i++) {
              sum += a[u][i] / 2 + 1;
            }
            cnt[u] = 0;
            u--;
            a[u][cnt[u]] = sum;
          } else {
            sum = 0;
            for (int i = 0; i < cnt[u] / 2 + 1; i++) {
              sum += a[u][i];
            }
            cnt[u] = 0;
            u--;
            a[u][cnt[u]] = sum;
          }
          cnt[u]++;
        }
      } else {
        T += S[i];
        chain = 0;
      }
    }
    u = 0;
    cout << sum << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int a[100][1000], n, cnt[100], u, sum, chain;
string S, T;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S;
    u = 0;
    sum = 0;
    for (int i = 0; i < 10; i++) {
      cnt[i] = 0;
    }
    for (int i = 0; i < S.size(); i++) {
      if (S[i] == '[') {
        u++;
        T = "";
        chain = 0;
      } else if (S[i] == ']') {
        if (T != "") {
          cnt[u] = 0;
          u--;
          a[u][cnt[u]] = stoi(T);
          cnt[u]++;
          T = "";
        } else {
          chain++;
          sum = 0;
          sort(a[u], a[u] + cnt[u]);
          if (chain == 1) {
            for (int i = 0; i < cnt[u] / 2 + 1; i++) {
              sum += a[u][i] / 2 + 1;
            }
            cnt[u] = 0;
            u--;
            a[u][cnt[u]] = sum;
          } else {
            sum = 0;
            for (int i = 0; i < cnt[u] / 2 + 1; i++) {
              sum += a[u][i];
            }
            cnt[u] = 0;
            u--;
            a[u][cnt[u]] = sum;
          }
          cnt[u]++;
        }
      } else {
        T += S[i];
        chain = 0;
      }
    }
    u = 0;
    cout << sum << endl;
  }
}
Problem p00773 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int max(int m1, int m2) { return m1 < m2 ? m2 : m1; }

int main() {
  int t1, t2, sum, a, i, j;
  for (; scanf("%d %d %d", &t1, &t2, &sum), sum;) {
    static int A[1001];
    for (j = 0; j < 1001; j++)
      A[j] = 0;
    int m = 0;
    for (i = 1; i < sum; i++) {
      a = i * (100 + t1) / 100;
      A[a] = i;
    }
    for (i = 1; i < sum; i++) {
      if (A[i] == 0 && A[sum - i] == 0)
        continue;
      m = max(A[i] * (100 + t2) / 100 + A[sum - i] * (100 + t2) / 100, m);
    }
    printf("%d\n", m);
  }
  return 0;
}

Fixed submission:
#include <stdio.h>

int max(int m1, int m2) { return m1 < m2 ? m2 : m1; }

int main() {
  int t1, t2, sum, a, i, j;
  for (; scanf("%d %d %d", &t1, &t2, &sum), sum;) {
    static int A[10000];
    for (j = 0; j < 1001; j++)
      A[j] = 0;
    int m = 0;
    for (i = 1; i < sum; i++) {
      a = i * (100 + t1) / 100;
      A[a] = i;
    }
    for (i = 1; i < sum; i++) {
      if (A[i] == 0 && A[sum - i] == 0)
        continue;
      m = max(A[i] * (100 + t2) / 100 + A[sum - i] * (100 + t2) / 100, m);
    }
    printf("%d\n", m);
  }
  return 0;
}
Problem p00773 (C++)

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

int main() {
  int a[100];
  int i, j, k, n = 0, t;
  int m1, m2;
  int mm1, mm2;
  int temp;

  while (1) {
    int x, y, s; // x???????¨????,y??´??°???????¨????,z??????????¨?

    cin >> x >> y >> s;

    if (x == 0 && y == 0 && s == 0)
      break;

    int max = 0;

    for (m1 = 1; m1 < s; m1++) {
      for (m2 = 1; m2 < s; m2++) {
        if (m1 >= m2) {
          //			mm1 = (m1 * (100 + x)) / 100;
          //			mm2 = s - mm1;

          //			m2 = (100 * (mm2 + 0.5)) / (100 + x);
          temp = 0;
          if ((((m1 * (100 + x)) / 100) + ((m2 * (100 + x)) / 100)) == s) {
            //			cout << m1 << ' ' << m2 << endl;

            temp = (m1 * (100 + y)) / 100;
            temp += (m2 * (100 + y)) / 100;
            if (temp > max) {
              max = temp;
              // cout << max << endl;
            }
          }
        }
      }
    }
    //		cout << max << endl;
    a[n++] = max;
  }

  for (i = 0; i < n; i++)
    cout << a[i] << endl;

  return (0);
}

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

int main() {
  int a[1000];
  int i, j, k, n = 0, t;
  int m1, m2;
  int mm1, mm2;
  int temp;

  while (1) {
    int x, y, s; // x???????¨????,y??´??°???????¨????,z??????????¨?

    cin >> x >> y >> s;

    if (x == 0 && y == 0 && s == 0)
      break;

    int max = 0;

    for (m1 = 1; m1 < s; m1++) {
      for (m2 = 1; m2 < s; m2++) {
        if (m1 >= m2) {
          //			mm1 = (m1 * (100 + x)) / 100;
          //			mm2 = s - mm1;

          //			m2 = (100 * (mm2 + 0.5)) / (100 + x);
          temp = 0;
          if ((((m1 * (100 + x)) / 100) + ((m2 * (100 + x)) / 100)) == s) {
            //			cout << m1 << ' ' << m2 << endl;

            temp = (m1 * (100 + y)) / 100;
            temp += (m2 * (100 + y)) / 100;
            if (temp > max) {
              max = temp;
              // cout << max << endl;
            }
          }
        }
      }
    }
    //		cout << max << endl;
    a[n++] = max;
  }

  for (i = 0; i < n; i++)
    cout << a[i] << endl;

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

Buggy submission (status: Runtime Error):
// 1192_TaxRateChanged.cpp
// 税率がx%の価格でループを回すのではなく、税抜き価格でループを回すのがポイント
#include <bits/stdc++.h>
using namespace std;
const int MAX_S = 1010;
int x, y, s;
int p[MAX_S / 2];
void solve() {
  memset(p, 0, sizeof(p));
  for (int i = 1; i < s; ++i)
    for (int j = 1; j < s; ++j)
      if (i * (100 + x) / 100 + j * (100 + x) / 100 == s)
        p[i] = i * (100 + y) / 100 + j * (100 + y) / 100;

  cout << *max_element(p, p + s) << endl;
}
int main() {
  while (cin >> x >> y >> s) {
    if (x == 0 && y == 0 && s == 0)
      break;
    solve();
  }
  return 0;
}


Fixed submission:
// 1192_TaxRateChanged.cpp
// 税率がx%の価格でループを回すのではなく、税抜き価格でループを回すのがポイント
#include <bits/stdc++.h>
using namespace std;
const int MAX_S = 1010;
int x, y, s;
int p[MAX_S];
void solve() {
  memset(p, 0, sizeof(p));
  for (int i = 1; i < s; ++i)
    for (int j = 1; j < s; ++j)
      if (i * (100 + x) / 100 + j * (100 + x) / 100 == s)
        p[i] = i * (100 + y) / 100 + j * (100 + y) / 100;

  cout << *max_element(p, p + s) << endl;
}
int main() {
  while (cin >> x >> y >> s) {
    if (x == 0 && y == 0 && s == 0)
      break;
    solve();
  }
  return 0;
}
Problem p00773 (C++)

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

using namespace std;
using i64 = long long int;
using ui64 = unsigned long long int;

//////

int intax(int i, int p) { return floor((double)i * (100 + p) / 100); }

int main() {
  int x, y, s;
  while (cin >> x >> y >> s, x && y && s) {
    int res = -1;
    int mi, mj = 0;
    for (int i = 1; i < s; i++) {
      int xi = intax(i, x);
      if (xi > s)
        break;
      int j = 1;
      while (intax(j, x) + xi < s)
        j++;
      while (true) {
        int xj = intax(j, x);
        if (xi + xj > s)
          break;
        int yi = intax(i, y);
        int yj = intax(j, y);
        if (res < yi + yj) {
          mi = i, mj = j;
        }
        // cerr << i << " " << j << " " << yi + yj << endl;
        res = max(yi + yj, res);
        j++;
      }
    }
    cerr << mi << " " << mj << endl;
    cout << res << endl;
  }
}


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

using namespace std;
using i64 = long long int;
using ui64 = unsigned long long int;

//////

int intax(int i, int p) { return floor((double)i * (100 + p) / 100); }

int main() {
  int x, y, s;
  while (cin >> x >> y >> s, x && y && s) {
    int res = -1;
    int mi, mj = 0;
    for (int i = 1; i < s; i++) {
      int xi = intax(i, x);
      if (xi > s)
        break;
      int j = 1;
      while (intax(j, x) + xi < s)
        j++;
      while (true) {
        int xj = intax(j, x);
        if (xi + xj > s)
          break;
        int yi = intax(i, y);
        int yj = intax(j, y);
        if (res < yi + yj) {
          mi = i, mj = j;
        }
        // cerr << i << " " << j << " " << yi + yj << endl;
        res = max(yi + yj, res);
        j++;
      }
    }
    // cerr << mi << " " << mj << endl;
    cout << res << endl;
  }
}
Problem p00774 (C++)

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

int H;
int b[10][5];

struct range {
  int row;
  int left;
  int right;
};

void drop(int row, int col) {
  for (int i = row; i > 0; i--) {
    b[i][col] = b[i - 1][col];
  }
  b[0][col] = -1;
}

void print_board() {
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < 5; j++) {
      cerr << b[i][j] << ' ';
    }
    cerr << endl;
  }
  cerr << endl;
}

void solve() {
  int ans = 0;
  while (1) {
    print_board();
    vector<range> deleted;
    for (int i = 0; i < H; i++) {
      int left = 0;
      for (int j = 1; j < 6; j++) {
        if (j == 5 || b[i][j] != b[i][j - 1]) {
          if (j >= left + 3) {
            if (b[i][j - 1] != -1) {
              range tmp = {i, left, j - 1};
              deleted.push_back(tmp);
              ans += b[i][j - 1] * (j - left);
            }
            break;
          } else {
            left = j;
          }
        }
      }
    }
    if (deleted.size() == 0) {
      break;
    }
    for (int k = 0; k < deleted.size(); k++) {
      range d = deleted[k];
      for (int j = d.left; j <= d.right; j++) {
        drop(d.row, j);
      }
    }
  }
  cout << ans << endl;
}

int main() {
  while (1) {
    cin >> H;
    if (H == 0) {
      break;
    }
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < 5; j++) {
        cin >> b[i][j];
      }
    }
    solve();
  }
}


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

int H;
int b[10][5];

struct range {
  int row;
  int left;
  int right;
};

void drop(int row, int col) {
  for (int i = row; i > 0; i--) {
    b[i][col] = b[i - 1][col];
  }
  b[0][col] = -1;
}

void print_board() {
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < 5; j++) {
      cerr << b[i][j] << ' ';
    }
    cerr << endl;
  }
  cerr << endl;
}

void solve() {
  int ans = 0;
  while (1) {
    /* print_board(); */
    vector<range> deleted;
    for (int i = 0; i < H; i++) {
      int left = 0;
      for (int j = 1; j < 6; j++) {
        if (j == 5 || b[i][j] != b[i][j - 1]) {
          if (j >= left + 3) {
            if (b[i][j - 1] != -1) {
              range tmp = {i, left, j - 1};
              deleted.push_back(tmp);
              ans += b[i][j - 1] * (j - left);
            }
            break;
          } else {
            left = j;
          }
        }
      }
    }
    if (deleted.size() == 0) {
      break;
    }
    for (int k = 0; k < deleted.size(); k++) {
      range d = deleted[k];
      for (int j = d.left; j <= d.right; j++) {
        drop(d.row, j);
      }
    }
  }
  cout << ans << endl;
}

int main() {
  while (1) {
    cin >> H;
    if (H == 0) {
      break;
    }
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < 5; j++) {
        cin >> b[i][j];
      }
    }
    solve();
  }
}
Problem p00774 (C++)

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

using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)

int tile[11][5];

int main() {
  int h;

  while (cin >> h, h) {
    REP(i, 11) REP(j, 5) { tile[i][j] = -1; }
    REP(i, h) REP(j, 5) { cin >> tile[h - 1 - i][j]; }
    int ans = 0;
    bool update = false;
    while (true) {
      update = false;
      REP(it, 11) {
        bool t1 = tile[it][0] == tile[it][1] && tile[it][0] != -1;
        bool t2 = tile[it][1] == tile[it][2] && tile[it][1] != -1;
        bool t3 = tile[it][2] == tile[it][3] && tile[it][2] != -1;
        bool t4 = tile[it][3] == tile[it][4] && tile[it][3] != -1;
        bool y1 = t1 && t2;
        bool y2 = t2 && t3;
        bool y3 = t3 && t4;
        if (y1 && y2 && y3) {
          ans += tile[it][0] * 5;
          REP(i, 5) { tile[it][i] = -1; }
          update = true;
        } else if (y1 && y2 || y2 && y3) {
          ans += tile[it][y3] * 4;
          REP(i, 4) { tile[it][i + y3] = -1; }
          update = true;
        } else if (y1 || y2 || y3) {
          ans += tile[it][2] * 3;
          REP(i, 3) { tile[it][i + y2 + ((int)y3) * 2] = -1; }
          update = true;
        }
      }
      REP(it, 11) {
        REP(i, 5) {
          if (tile[it][i] == -1) {
            int itt = it;
            while (tile[++itt][i] == -1 && itt != 10)
              ;
            swap(tile[it][i], tile[itt][i]);
          }
        }
      }
      if (!update)
        break;
    }
    cout << ans << endl;
  }
}

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

using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)

int tile[11][5];

int main() {
  int h;

  while (cin >> h, h) {
    REP(i, 11) REP(j, 5) { tile[i][j] = -1; }
    REP(i, h) REP(j, 5) { cin >> tile[h - 1 - i][j]; }
    int ans = 0;
    bool update = false;
    while (true) {
      update = false;
      REP(it, 11) {
        bool t1 = tile[it][0] == tile[it][1] && tile[it][0] != -1;
        bool t2 = tile[it][1] == tile[it][2] && tile[it][1] != -1;
        bool t3 = tile[it][2] == tile[it][3] && tile[it][2] != -1;
        bool t4 = tile[it][3] == tile[it][4] && tile[it][3] != -1;
        bool y1 = t1 && t2;
        bool y2 = t2 && t3;
        bool y3 = t3 && t4;
        if (y1 && y2 && y3) {
          ans += tile[it][0] * 5;
          REP(i, 5) { tile[it][i] = -1; }
          update = true;
        } else if (y1 && y2 || y2 && y3) {
          ans += tile[it][y3] * 4;
          REP(i, 4) { tile[it][i + y3] = -1; }
          update = true;
        } else if (y1 || y2 || y3) {
          ans += tile[it][2] * 3;
          REP(i, 3) { tile[it][i + y2 + ((int)y3) * 2] = -1; }
          update = true;
        }
      }
      REP(it, 10) {
        REP(i, 5) {
          if (tile[it][i] == -1) {
            int itt = it;
            while (tile[++itt][i] == -1 && itt != 10)
              ;
            swap(tile[it][i], tile[itt][i]);
          }
        }
      }
      if (!update)
        break;
    }
    cout << ans << endl;
  }
}
Problem p00774 (C++)

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

#pragma warning(disable : 4996)

using namespace std;

int main() {
  int H;

  while (true) {
    scanf("%d", &H);

    if (H == 0) {
      break;
    }

    vector<vector<int>> M(H, vector<int>(5));

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < 5; j++) {
        scanf("%d", &M[i][j]);
      }
    }

    int ret = 0;

    while (true) {
      for (int i = 0; i < H; i++) {
        for (int j = 5; j >= 3; j--) {
          for (int k = 0; k <= 5 - j; k++) {
            bool ok = (M[i][k] != 0);

            for (int l = k + 1; l < k + j; l++) {
              if (M[i][l - 1] != M[i][l] || M[i][l] == 0) {
                ok = false;
              }
            }

            if (ok) {
              ret += M[i][k] * j;

              for (int l = k; l < k + j; l++) {
                M[i][l] = 0;
              }
            }
          }
        }
      }

      bool ok = false;

      for (int i = H - 1; i >= 1; i--) {
        for (int j = 0; j < 5; j++) {
          if (M[i][j] == 0) {
            M[i][j] = M[i - 1][j];
            M[i - 1][j] = 0;
            ok = true;
          }
        }
      }

      if (!ok) {
        break;
      }
    }

    printf("%d\n", ret);
  }

  return 0;
}

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

#pragma warning(disable : 4996)

using namespace std;

int main() {
  int H;

  while (true) {
    scanf("%d", &H);

    if (H == 0) {
      break;
    }

    vector<vector<int>> M(H, vector<int>(5));

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < 5; j++) {
        scanf("%d", &M[i][j]);
      }
    }

    int ret = 0;

    while (true) {
      for (int i = 0; i < H; i++) {
        for (int j = 5; j >= 3; j--) {
          for (int k = 0; k <= 5 - j; k++) {
            bool ok = (M[i][k] != 0);

            for (int l = k + 1; l < k + j; l++) {
              if (M[i][l - 1] != M[i][l] || M[i][l] == 0) {
                ok = false;
              }
            }

            if (ok) {
              ret += M[i][k] * j;

              for (int l = k; l < k + j; l++) {
                M[i][l] = 0;
              }
            }
          }
        }
      }

      bool ok = false;

      for (int rep = 0; rep < H; rep++) {
        for (int i = H - 1; i >= 1; i--) {
          for (int j = 0; j < 5; j++) {
            if (M[i][j] == 0 && M[i - 1][j] != 0) {
              M[i][j] = M[i - 1][j];
              M[i - 1][j] = 0;
              ok = true;
            }
          }
        }
      }

      if (!ok) {
        break;
      }
    }

    printf("%d\n", ret);
  }

  return 0;
}
Problem p00775 (C++)

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a <= x && x < b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
// #define int ll

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int xl[25], xr[25], h[25];
signed main(void) {
  while (true) {
    int r, n;
    cin >> r >> n;
    if (!r && !n)
      break;
    REP(i, n) cin >> xl[i] >> xr[i] >> h[i];

    double hi = 60, low = 0;
    REP(i, 20) {
      double mid = (hi + low) / 2;
      // cout << hi << " " << mid << " " << low << endl;
      bool flag = true;
      REP(j, 300000) {
        double x = -r + (double)(2 + r) * j / 300000;
        int ma = 0;
        REP(k, n) {
          if (xl[k] <= x && x <= xr[k]) {
            ma = max(ma, h[k]);
          }
        }
        double H = sqrt(r * r - x * x) + mid - r;
        // cout << ma << " " << H << endls
        if (ma < H) {
          flag = false;
          break;
        }
      }
      if (flag) {
        low = mid;
      } else {
        hi = mid;
      }
    }
    cout << fixed << setprecision(10) << low << endl;
  }

  return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a <= x && x < b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
// #define int ll

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int xl[25], xr[25], h[25];
signed main(void) {
  while (true) {
    int r, n;
    cin >> r >> n;
    if (!r && !n)
      break;
    REP(i, n) cin >> xl[i] >> xr[i] >> h[i];

    double hi = 60, low = 0;
    REP(i, 20) {
      double mid = (hi + low) / 2;
      // cout << hi << " " << mid << " " << low << endl;
      bool flag = true;
      REP(j, 200000) {
        double x = -r + (double)(2 * r) * j / 200000;
        int ma = 0;
        REP(k, n) {
          if (xl[k] <= x && x <= xr[k]) {
            ma = max(ma, h[k]);
          }
        }
        double H = sqrt(r * r - x * x) + mid - r;
        // cout << ma << " " << H << endls
        if (ma < H) {
          flag = false;
          break;
        }
      }
      if (flag) {
        low = mid;
      } else {
        hi = mid;
      }
    }
    cout << fixed << setprecision(10) << low << endl;
  }

  return 0;
}
Problem p00776 (C++)

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

using namespace std;

string S;

bool ok2(string T) {
  bool used[26];

  for (int i = 0; i < 26; i++)
    used[i] = false;

  for (int i = 0; i < S.size(); i++) {
    if (!used[T[i] - 97] && T[i] != 'a') {
      used[T[i] - 97] = true;
      T[i]--;
    }
  }

  return S == T;
}

int main() {
  while (true) {
    cin >> S;

    if (S == "#")
      break;

    vector<string> lists;

    for (int i = 0; i < (1 << S.size()); i++) {
      string T = S;
      bool ok = true;

      for (int j = 0; j < S.size(); j++) {
        if (i & (1 << j)) {
          if (S[j] == 'z') {
            ok = false;
            break;
          }

          T[j]++;
        }
      }

      if (ok) {
        if (ok2(T)) {
          lists.push_back(T);
        }
      }
    }

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

    printf("%u\n", lists.size());

    if (lists.size() < 10) {
      for (int i = 0; i < lists.size(); i++) {
        printf("%s\n", lists[i].c_str());
      }
    } else {
      for (int i = 0; i < 5; i++) {
        printf("%s\n", lists[i].c_str());
      }

      for (int i = lists.size() - 5; i < lists.size(); i++) {
        printf("%s\n", lists[i].c_str());
      }
    }
  }

  return 0;
}

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

using namespace std;

string S;

inline bool ok2(string T) {
  bool used[26];

  for (int i = 0; i < 26; i++)
    used[i] = false;

  for (int i = 0; i < S.size(); i++) {
    if (!used[T[i] - 97] && T[i] != 'a') {
      used[T[i] - 97] = true;
      T[i]--;
    }
  }

  return S == T;
}

int main() {
  while (true) {
    cin >> S;

    if (S == "#")
      break;

    vector<string> lists;

    for (int i = 0; i < (1 << S.size()); i++) {
      string T = S;
      bool ok = true;

      for (int j = 0; j < S.size(); j++) {
        if (i & (1 << j)) {
          if (S[j] == 'z') {
            ok = false;
            break;
          }

          T[j]++;
        }
      }

      if (ok) {
        if (ok2(T)) {
          lists.push_back(T);
        }
      }
    }

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

    printf("%u\n", lists.size());

    if (lists.size() < 10) {
      for (int i = 0; i < lists.size(); i++) {
        printf("%s\n", lists[i].c_str());
      }
    } else {
      for (int i = 0; i < 5; i++) {
        printf("%s\n", lists[i].c_str());
      }

      for (int i = lists.size() - 5; i < lists.size(); i++) {
        printf("%s\n", lists[i].c_str());
      }
    }
  }

  return 0;
}
Problem p00777 (C++)

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

const int INF = 1 << 30;
vector<vector<pair<int, int>>> graph;
int sum, D;

int dfs(int v, int r) {
  vector<int> ch = {0, 0};
  for (auto p : graph[v]) {
    int sv, d;
    tie(sv, d) = p;
    if (sv == r)
      continue;
    int res = dfs(sv, v);
    if (res < 0) {
      ch.push_back(0);
      sum += d;
    } else {
      sum += d * 3;
      ch.push_back(res + d);
    }
  }

  if (ch.size() <= 2)
    return -1;
  sort(ch.rbegin(), ch.rend());
  D = max(D, ch[0] + ch[1]);
  return ch[0];
}

bool solve() {
  int N;
  cin >> N;
  if (N == 0)
    return false;

  vector<int> p(N - 1), d(N - 1);
  for (int i = 1; i < N; ++i) {
    cin >> p[i];
    --p[i];
  }
  for (int i = 1; i < N; ++i) {
    cin >> d[i];
  }

  graph.clear();
  graph.resize(N);
  for (int i = 1; i < N; ++i) {
    graph[i].emplace_back(p[i], d[i]);
    graph[p[i]].emplace_back(i, d[i]);
  }

  sum = 0, D = 0;
  for (int v = 0; v < N; ++v) {
    if (graph[v].size() <= 1)
      continue;
    dfs(v, -1);
    break;
  }

  cout << sum - D << endl;
  return true;
}
int main() {
  while (solve()) {
  }
  return 0;
}


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

const int INF = 1 << 30;
vector<vector<pair<int, int>>> graph;
int sum, D;

int dfs(int v, int r) {
  vector<int> ch = {0, 0};
  for (auto p : graph[v]) {
    int sv, d;
    tie(sv, d) = p;
    if (sv == r)
      continue;
    int res = dfs(sv, v);
    if (res < 0) {
      ch.push_back(0);
      sum += d;
    } else {
      sum += d * 3;
      ch.push_back(res + d);
    }
  }

  if (ch.size() <= 2)
    return -1;
  sort(ch.rbegin(), ch.rend());
  D = max(D, ch[0] + ch[1]);
  return ch[0];
}

bool solve() {
  int N;
  cin >> N;
  if (N == 0)
    return false;

  vector<int> p(N), d(N);
  for (int i = 1; i < N; ++i) {
    cin >> p[i];
    --p[i];
  }
  for (int i = 1; i < N; ++i) {
    cin >> d[i];
  }

  graph.clear();
  graph.resize(N);
  for (int i = 1; i < N; ++i) {
    graph[i].emplace_back(p[i], d[i]);
    graph[p[i]].emplace_back(i, d[i]);
  }

  sum = 0, D = 0;
  for (int v = 0; v < N; ++v) {
    if (graph[v].size() <= 1)
      continue;
    dfs(v, -1);
    break;
  }

  cout << sum - D << endl;
  return true;
}
int main() {
  while (solve()) {
  }
  return 0;
}
Problem p00780 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define f first
#define s second
#define mp make_pair

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, c)                                                              \
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

template <int m> class Prime {
  std::vector<bool> p;
  std::vector<int> ps;

public:
  Prime() {
    p = std::vector<bool>(m, true);
    assert(m > 1);
    p[0] = p[1] = false;
    for (int i = 4; i < m; i += 2)
      p[i] = false;
    ps.push_back(2);
    for (int i = 3; i < m; i += 2) {
      if (p[i]) {
        ps.push_back(i);
        for (int j = i + i; j < m; j += i)
          p[j] = false;
      }
    }
  }

  bool isPrime(int n) {
    assert(m > n);
    return p[n];
  }

  int operator[](int n) {
    if (n < ps.size())
      return ps[n];
    else
      return 0;
  }

  int size() { return ps.size(); }
};

int main() {
  Prime<(1 << 14) + 100> p;
  int n;
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 0; p[i] + p[i] <= n; i++) {
      if (p.isPrime(n - p[i]))
        ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define f first
#define s second
#define mp make_pair

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, c)                                                              \
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

template <int m> class Prime {
  std::vector<bool> p;
  std::vector<int> ps;

public:
  Prime() {
    p = std::vector<bool>(m, true);
    assert(m > 1);
    p[0] = p[1] = false;
    for (int i = 4; i < m; i += 2)
      p[i] = false;
    ps.push_back(2);
    for (int i = 3; i < m; i += 2) {
      if (p[i]) {
        ps.push_back(i);
        for (int j = i + i; j < m; j += i)
          p[j] = false;
      }
    }
  }

  bool isPrime(int n) {
    assert(m > n);
    return p[n];
  }

  int operator[](int n) {
    if (n < ps.size())
      return ps[n];
    else
      return 0;
  }

  int size() { return ps.size(); }
};

int main() {
  Prime<(1 << 15) + 100> p;
  int n;
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 0; p[i] + p[i] <= n; i++) {
      if (p.isPrime(n - p[i]))
        ans++;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00780 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
bool primes[100000];

void Sieve() {
  for (int i = 2; i < 1000000; i++) {
    primes[i] = true;
  }
  primes[1] = false;

  for (int i = 2; i <= 1000; i++) {
    if (primes[i] == true)
      for (int j = i; j * i <= 1000000; j++) {
        primes[j * i] = false;
      }
  }
}

bool IsPrime(int x) { return primes[x]; }

int main(void) {
  int k;
  for (k = 1; k > 0; k++) {
    Sieve();
    int n, c = 0;
    cin >> n;
    if (n == 0)
      break;
    else {
      for (int i = 0; i <= n / 2; i++) {
        if (IsPrime(i) == true) {
          if (IsPrime(n - i) == true)
            c++;
        }
      }
      cout << c << endl;
    }
  }

  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
bool primes[1000000];

void Sieve() {
  for (int i = 2; i < 1000000; i++) {
    primes[i] = true;
  }
  primes[1] = false;

  for (int i = 2; i <= 1000; i++) {
    if (primes[i] == true)
      for (int j = i; j * i <= 1000000; j++) {
        primes[j * i] = false;
      }
  }
}

bool IsPrime(int x) { return primes[x]; }

int main(void) {
  int k;
  for (k = 1; k > 0; k++) {
    Sieve();
    int n, c = 0;
    cin >> n;
    if (n == 0)
      break;
    else {
      for (int i = 0; i <= n / 2; i++) {
        if (IsPrime(i) == true) {
          if (IsPrime(n - i) == true)
            c++;
        }
      }
      cout << c << endl;
    }
  }

  return 0;
}
Problem p00788 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

long long gcd(long long a, long long b) { // Ååöñ
  if (a == 0 || b == 0)
    return 0;
  if (b > a)
    swap(a, b);
  long long tmp;
  while ((tmp = a % b) != 0) {
    a = b;
    b = tmp;
  }
  return b;
}

int main() {
  for (;;) {
    int p, n;
    cin >> p >> n;
    if (p == 0)
      return 0;

    int u = 0;
    int v = 1;
    int x = INT_MAX / 2;
    int y = 1;

    for (int i = 1; i <= n; ++i) {   // ªq
      for (int j = 1; j <= n; ++j) { // ªê
        if (gcd(i, j) != 1)
          continue;
        if (i * i > p * j * j) {
          if (i * y < j * x) {
            x = i;
            y = j;
          }
        } else {
          if (i * v > j * u) {
            u = i;
            v = j;
          }
        }
      }
    }
    cout << x << '/' << y << ' ' << u << '/' << v << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

long long gcd(long long a, long long b) { // Ååöñ
  if (a == 0 || b == 0)
    return 0;
  if (b > a)
    swap(a, b);
  long long tmp;
  while ((tmp = a % b) != 0) {
    a = b;
    b = tmp;
  }
  return b;
}

int main() {
  for (;;) {
    int p, n;
    cin >> p >> n;
    if (p == 0)
      return 0;

    int u = 0;
    int v = 1;
    int x = INT_MAX / 2;
    int y = 1;

    for (int i = 1; i <= n; ++i) { // ªê
      int j = i * sqrt(double(p)); // ªq
      if (j > n)
        break;
      if (gcd(i, j) == 1 && i * u < j * v) {
        u = j;
        v = i;
      }

      ++j;
      if (j > n)
        break;
      if (gcd(i, j) == 1 && i * x > j * y) {
        x = j;
        y = i;
      }
    }
    cout << x << '/' << y << ' ' << u << '/' << v << endl;
  }
}
Problem p00789 (C++)

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

int dp[301][18];
int solve(int amount, int num) {
  // cerr << "solve(" << amount << "," << num << ")" << endl;
  if (amount == 0)
    return 1;
  if (num < 0)
    return 0;
  int &res = dp[amount][num];
  if (res != -1)
    return res;
  res = 0;
  for (int k = num; k >= 1; --k) {
    if (amount - k * k >= 0)
      res += solve(amount - k * k, k);
  }
  return res;
}

int main() {
  memset(dp, -1, sizeof(dp));
  while (true) {
    int N;
    cin >> N;
    cout << solve(N, 17) << endl;
  }
}

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

int dp[301][18];
int solve(int amount, int num) {
  // cerr << "solve(" << amount << "," << num << ")" << endl;
  if (amount == 0)
    return 1;
  if (num < 0)
    return 0;
  int &res = dp[amount][num];
  if (res != -1)
    return res;
  res = 0;
  for (int k = num; k >= 1; --k) {
    if (amount - k * k >= 0)
      res += solve(amount - k * k, k);
  }
  return res;
}

int main() {
  memset(dp, -1, sizeof(dp));
  while (true) {
    int N;
    cin >> N;
    if (N == 0)
      break;
    cout << solve(N, 17) << endl;
  }
}