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

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

const string cls[] = {"",
                      "light fly",
                      "fly",
                      "bantam",
                      "feather",
                      "light",
                      "light welter",
                      "welter",
                      "light middle",
                      "middle",
                      "light heavy",
                      "heavy"};

const int a[] = {-100, 48, 51, 54, 57, 60, 64, 69, 75, 81, 91};

int main() {
  double w;
  while (cin >> w) {
    int i = 0;
    while (w > a[i])
      i++;
    cout << cls[i] << endl;
  }
}

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

const string cls[] = {"",
                      "light fly",
                      "fly",
                      "bantam",
                      "feather",
                      "light",
                      "light welter",
                      "welter",
                      "light middle",
                      "middle",
                      "light heavy",
                      "heavy"};

const int a[] = {-100, 48, 51, 54, 57, 60, 64, 69, 75, 81, 91, 100000000};

int main() {
  double w;
  while (cin >> w) {
    int i = 0;
    while (w > a[i])
      i++;
    cout << cls[i] << endl;
  }
}
Problem p00048 (C++)

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

int main() {
  float n;
  int m;
  const char *rank[] = {"light fly", "fly",          "bantam", "feather",
                        "light",     "light welter", "welter", "light middle",
                        "middle",    "light heavy",  "heavy"};
  while (scanf("%f\n", &n)) {
    if (n <= 48.0)
      m = 0;
    else if (n <= 51.0)
      m = 1;
    else if (n <= 54.0)
      m = 2;
    else if (n <= 57.0)
      m = 3;
    else if (n <= 60.0)
      m = 4;
    else if (n <= 64.0)
      m = 5;
    else if (n <= 69.0)
      m = 6;
    else if (n <= 75.0)
      m = 7;
    else if (n <= 81.0)
      m = 8;
    else if (n <= 91.0)
      m = 9;
    else
      m = 10;
    puts(rank[m]);
  }
  return 0;
}

Fixed submission:
#include <cstdio>

int main() {
  float n;
  int m;
  const char *rank[] = {"light fly", "fly",          "bantam", "feather",
                        "light",     "light welter", "welter", "light middle",
                        "middle",    "light heavy",  "heavy"};
  while (~scanf("%f\n", &n)) {
    if (n <= 48.0)
      m = 0;
    else if (n <= 51.0)
      m = 1;
    else if (n <= 54.0)
      m = 2;
    else if (n <= 57.0)
      m = 3;
    else if (n <= 60.0)
      m = 4;
    else if (n <= 64.0)
      m = 5;
    else if (n <= 69.0)
      m = 6;
    else if (n <= 75.0)
      m = 7;
    else if (n <= 81.0)
      m = 8;
    else if (n <= 91.0)
      m = 9;
    else
      m = 10;
    puts(rank[m]);
  }
  return 0;
}
Problem p00048 (C++)

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

string s[11] = {"light fly", "fly",          "bantam", "feather",
                "light",     "light welter", "welter", "light middle",
                "middle",    "light heavy",  "heavy"};
double g[] = {48.0, 51.0, 54.0, 57.0, 60.0, 64.0, 69.0, 75.0, 81.0, 91.0};

int main() {
  double n;
  while (cin >> n) {
    int m;
    for (m = 0; m < 11 && n > g[m]; m++)
      ;
    cout << s[m] << endl;
  }
  return 0;
}

/*
60.2
70.2
48.0
80.2
*/

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

string s[11] = {"light fly", "fly",          "bantam", "feather",
                "light",     "light welter", "welter", "light middle",
                "middle",    "light heavy",  "heavy"};
double g[] = {48.0, 51.0, 54.0, 57.0, 60.0, 64.0, 69.0, 75.0, 81.0, 91.0};

int main() {
  double n;
  while (cin >> n) {
    int m;
    for (m = 0; m < 10 && n > g[m]; m++)
      ;
    cout << s[m] << endl;
  }
  return 0;
}

/*
60.2
70.2
48.0
80.2
*/
Problem p00049 (C++)

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

int main(void) {
  int a, b, ab, o;
  int temp;
  char blood[2];

  a = b = ab = o = 0;

  while (scanf("%d,%s", &temp, blood) != EOF) {
    if (strcmp(blood, "AB") == 0)
      ab++;
    else if (strcmp(blood, "A") == 0)
      a++;
    else if (strcmp(blood, "B") == 0)
      b++;
    else if (strcmp(blood, "O") == 0)
      o++;
  }

  printf("%d\n%d\n%d\n%d\n", a, b, ab, o);

  return 0;
}

Fixed submission:
#include <stdio.h>
#include <string.h>

int main(void) {
  int a, b, ab, o;
  int temp;
  char blood[3];

  a = b = ab = o = 0;

  while (scanf("%d,%s", &temp, blood) != EOF) {
    if (strcmp(blood, "AB") == 0)
      ab++;
    else if (strcmp(blood, "A") == 0)
      a++;
    else if (strcmp(blood, "B") == 0)
      b++;
    else if (strcmp(blood, "O") == 0)
      o++;
  }

  printf("%d\n%d\n%d\n%d\n", a, b, ab, o);

  return 0;
}
Problem p00049 (C++)

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

using namespace std;

void solve() {
  int count[4] = {0};
  int num;
  string blood;
  while (scanf("%d,", &num)) {
    cin >> blood;
    if (blood == "A") {
      ++count[0];
    } else if (blood == "B") {
      ++count[1];
    } else if (blood == "AB") {
      ++count[2];
    } else {
      ++count[3];
    }
  }
  cout << count[0] << endl;
  cout << count[1] << endl;
  cout << count[2] << endl;
  cout << count[3] << endl;
}

int main() {
  solve();
  return (0);
}

Fixed submission:
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

void solve() {
  int count[4] = {0};
  int num;
  string blood;
  while (scanf("%d,", &num) != EOF) {
    cin >> blood;
    if (blood == "A") {
      ++count[0];
    } else if (blood == "B") {
      ++count[1];
    } else if (blood == "AB") {
      ++count[2];
    } else {
      ++count[3];
    }
  }
  cout << count[0] << endl;
  cout << count[1] << endl;
  cout << count[2] << endl;
  cout << count[3] << endl;
}

int main() {
  solve();
  return (0);
}
Problem p00049 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {
  int num;
  string blood;
  char row[1000];
  map<string, int> type;
  type.insert(make_pair("A", 0));
  type.insert(make_pair("B", 0));
  type.insert(make_pair("O", 0));
  type.insert(make_pair("AB", 0));
  while (cin >> row) {
    if (cin.eof())
      break;
    sscanf(row, "%d,%s", &num, &blood);
    type[blood]++;
  }
  cout << type["A"] << endl;
  cout << type["B"] << endl;
  cout << type["AB"] << endl;
  cout << type["O"] << endl;
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {
  int num;
  char blood[100];
  char row[1000];
  map<string, int> type;
  type.insert(make_pair("A", 0));
  type.insert(make_pair("B", 0));
  type.insert(make_pair("O", 0));
  type.insert(make_pair("AB", 0));
  while (cin >> row) {
    if (cin.eof())
      break;
    sscanf(row, "%d,%s", &num, &blood);
    type[blood]++;
  }
  cout << type["A"] << endl;
  cout << type["B"] << endl;
  cout << type["AB"] << endl;
  cout << type["O"] << endl;
  return 0;
}
Problem p00049 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n;
  string str;
  int blood[4] = {0};
  while (scanf("%d,%s", &n, &str) != EOF) {
    if (str == "A")
      blood[0]++;
    else if (str == "B")
      blood[1]++;
    else if (str == "AB")
      blood[2]++;
    else if (str == "O")
      blood[3]++;
  }
  cout << blood[0] << endl
       << blood[1] << endl
       << blood[2] << endl
       << blood[3] << endl;
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n;
  string str;
  int blood[4] = {0};
  while (scanf("%d,", &n) != EOF) {
    cin >> str;
    if (str == "A")
      blood[0]++;
    else if (str == "B")
      blood[1]++;
    else if (str == "AB")
      blood[2]++;
    else if (str == "O")
      blood[3]++;
  }
  cout << blood[0] << endl
       << blood[1] << endl
       << blood[2] << endl
       << blood[3] << endl;
  return 0;
}
Problem p00049 (C++)

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

int main() {
  int n, a = 0, b = 0, c = 0, o = 0, x, y, z, w;
  char s[2];
  while (scanf("%d,%s", &n, s) != EOF) {
    if (s[1] == 'B')
      c++;
    else if (s[0] == 'A')
      a++;
    else if (s[0] == 'B')
      b++;
    else
      o++;
  }
  cout << a << endl << b << endl << c << endl << o << endl;
}

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

int main() {
  int n, a = 0, b = 0, c = 0, o = 0, x, y, z, w;
  char s[3];
  while (scanf("%d,%s", &n, s) != EOF) {
    if (s[1] == 'B')
      c++;
    else if (s[0] == 'A')
      a++;
    else if (s[0] == 'B')
      b++;
    else
      o++;
  }
  cout << a << endl << b << endl << c << endl << o << endl;
}
Problem p00050 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <time.h>
#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 rp(a) while (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;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define MAX 1000000
bool sosu[MAX];
int main() {
  string s;
  getline(cin, s);
  while (1) {
    int it;
    if ((it = s.find("apple")) != string::npos)
      s.replace(it, 5, "peach");
    else if ((it = s.find("peach")) != string::npos)
      s.replace(it, 5, "apple");
    else
      break;
  }
  cout << s << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <time.h>
#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 rp(a) while (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;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define MAX 1000000
bool sosu[MAX];
int main() {
  string s;
  getline(cin, s);
  if (s.size() < 5) {
    cout << s << endl;
    return 0;
  }

  rep(i, s.size() - 4) {
    string tmp = s.substr(i, 5);
    if (tmp == "apple")
      s.replace(i, 5, "peach");
    else if (tmp == "peach")
      s.replace(i, 5, "apple");
  }
  cout << s << endl;
}
Problem p00050 (C++)

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

int main() {
  char input[2000];
  cin.getline(input, 1000);
  for (int i = 0; input[i] != '\n'; i++) {
    if (!strncmp(&input[i], "apple", 5)) {
      strncpy(&input[i], "peach", 5);
    } else if (!strncmp(&input[i], "peach", 5)) {
      strncpy(&input[i], "apple", 5);
    }
  }
  printf("%s\n", input);
  return 0;
}

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

int main() {
  char input[2000];
  cin.getline(input, 1000);
  for (int i = 0; input[i] != '\0'; i++) {
    if (!strncmp(&input[i], "apple", 5)) {
      strncpy(&input[i], "peach", 5);
    } else if (!strncmp(&input[i], "peach", 5)) {
      strncpy(&input[i], "apple", 5);
    }
  }
  printf("%s\n", input);
  return 0;
}
Problem p00051 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define all(c) c.begin(), c.end()
int main() {
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    sort(all(s));
    int n = stoi(s);
    reverse(all(s));
    int m = stoi(s);
    cerr << m << " " << n << endl;
    cout << m - n << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define all(c) c.begin(), c.end()
int main() {
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    sort(all(s));
    int n = stoi(s);
    reverse(all(s));
    int m = stoi(s);
    cout << m - n << endl;
  }
}
Problem p00051 (C++)

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

int main() {
  int n, max, min, kkk;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string input = "", mmm, mai = "", mii = "";
    int a[8] = {};
    cin >> input;
    for (int j = 0; j < 8; j++) {
      mmm = input[j];
      a[j] = stoi(mmm);
    }
    sort(a, end(a));
    kkk = 0;
    for (int j = 0; j < 8; j++) {
      mai += to_string(a[7 - j]);
      if (a[j] == 0 && kkk == 0) {
      } else {
        mii += to_string(a[j]);
        kkk++;
      }
    }
    max = stoi(mai);
    min = stoi(mii);
    cout << max - min << endl;
  }
  return 0;
}

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

int main() {
  int n, max, min, kkk;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string input = "", mmm, mai = "", mii = "";
    int a[8] = {};
    cin >> input;
    for (int j = 0; j < 8; j++) {
      mmm = input[j];
      a[j] = stoi(mmm);
    }
    sort(a, end(a));
    kkk = 0;
    for (int j = 0; j < 8; j++) {
      if (a[7] == 0) {
        mai = "0";
        mii = "0";
        break;
      }
      mai += to_string(a[7 - j]);
      if (a[j] == 0 && kkk == 0) {
      } else {
        mii += to_string(a[j]);
        kkk++;
      }
    }
    max = stoi(mai);
    min = stoi(mii);
    cout << max - min << endl;
  }
  return 0;
}
Problem p00051 (C++)

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

int main() {
  int n;
  int ret[8];
  cin >> n;
  while (n-- > 0) {
    string s;
    cin >> s;
    for (int i = 0; i < 8; i++)
      ret[i] = s[i - '0'];
    int Min = 0, Max = 0;
    sort(ret, ret + 8);
    for (int i = 0; i < 8; i++) {
      Max += pow(10, i) * ret[i];
    }

    for (int i = 7; i >= 0; i--) {
      Min += pow(10, i) * ret[7 - i];
    }
    int differential = Max - Min;

    cout << differential << endl;
  }
  return 0;
}

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

int main() {
  int n;
  int ret[8];
  cin >> n;
  while (n-- > 0) {
    string s;
    cin >> s;
    for (int i = 0; i < 8; i++)
      ret[i] = s[i] - '0';
    int Min = 0, Max = 0;
    sort(ret, ret + 8);
    for (int i = 0; i < 8; i++) {
      Max += pow(10, i) * ret[i];
    }

    for (int i = 7; i >= 0; i--) {
      Min += pow(10, i) * ret[7 - i];
    }
    int differential = Max - Min;

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

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

int main() {
  string str;
  int n, a[8], i, max, min;
  cin >> n;
  while (n--) {
    max = 0;
    min = 0;
    cin >> str;
    for (i = 0; i < 9; i++) {
      a[i] = str[i] - '0';
    }

    sort(a, a + 8, greater<int>());
    for (i = 0; i < 8; i++) {
      max += a[i] * pow(10, 7 - i);
    }
    sort(a, a + 8);
    for (i = 0; i < 8; i++) {
      min += a[i] * pow(10, 7 - i);
    }
    cout << max - min << endl;
  }
  return 0;
}

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

int main() {
  string str;
  int n, a[8], i, max, min;
  cin >> n;
  while (n--) {
    max = 0;
    min = 0;
    cin >> str;
    for (i = 0; i < 8; i++) {
      a[i] = str[i] - '0';
    }

    sort(a, a + 8, greater<int>());
    for (i = 0; i < 8; i++) {
      max += a[i] * pow(10, 7 - i);
    }
    sort(a, a + 8);
    for (i = 0; i < 8; i++) {
      min += a[i] * pow(10, 7 - i);
    }
    cout << max - min << endl;
  }
  return 0;
}
Problem p00052 (C++)

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

using namespace std;

int main() {
  int n;
  while (1) {
    int ct = 0;
    cin >> n;
    if (!n)
      break;
    while (n / 5)
      ct += n;
    cout << ct << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int n;
  while (1) {
    int ct = 0;
    cin >> n;
    if (!n)
      break;
    while (n /= 5)
      ct += n;
    cout << ct << endl;
  }
  return 0;
}
Problem p00052 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a;
  while (cin >> n, n) {
    a = 0;
    while (n != 1) {
      a += n / 5;
      n /= 5;
    }
    cout << a << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a;
  while (cin >> n, n) {
    a = 0;
    while (n > 1) {
      a += n / 5;
      n /= 5;
    }
    cout << a << endl;
  }
}
Problem p00052 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
inline void DPri(int n) { std::cout << n << std::endl; }
int recsion(int n, int a, int c) {
  if (n == 1)
    return c;
  int d = n;
  while (!(d % a)) {
    if (!(d % a))
      d /= a, c++;
  }
  recsion(n - 1, a, c);
}

int main() {
  int n;
  while (std::cin >> n) {
    if (std::cin.eof())
      break;
    int c = recsion(n, 10, 0), a = recsion(n, 2, 0) - c,
        b = recsion(n, 5, 0) - c, res = 0;
    a > b ? res += (b + c) : res += (a + c);
    std::cout << res << std::endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
inline void DPri(int n) { std::cout << n << std::endl; }
int recsion(int n, int a, int c) {
  if (n == 1)
    return c;
  int d = n;
  while (!(d % a)) {
    if (!(d % a))
      d /= a, c++;
  }
  recsion(n - 1, a, c);
}

int main() {
  int n;
  while (std::cin >> n) {
    if (!n)
      break;
    int c = recsion(n, 10, 0), a = recsion(n, 2, 0) - c,
        b = recsion(n, 5, 0) - c, res = 0;
    a > b ? res += (b + c) : res += (a + c);
    std::cout << res << std::endl;
  }
  return 0;
}
Problem p00052 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

int main() {

  vector<int> zeronum;
  zeronum.push_back(0);
  int count = 0;
  for (int i = 1; i <= 20000000; i++) {
    int tmp = i;
    while (tmp % 5 == 0) {
      count++;
      tmp /= 5;
    }
    zeronum.push_back(count);
  }

  int n = 0;
  while (cin >> n && n != 0) {
    cout << zeronum[n] << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

int main() {

  vector<int> zeronum;
  zeronum.push_back(0);
  int count = 0;
  for (int i = 1; i <= 5000000; i++) {
    int tmp = i;
    while (tmp % 5 == 0) {
      count++;
      tmp /= 5;
    }
    zeronum.push_back(count);
  }

  int n = 0;
  while (cin >> n && n != 0) {
    cout << zeronum[n] << endl;
  }
  return 0;
}
Problem p00052 (C++)

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

int s(int x) {
  int ans, y = x;
  y %= 5;
  x = (x - y) / 5;
  ans = s(x) + x;
  return ans;
}

int main() {
  int n, ans;
  while (cin >> n) {
    if (n == 0) {
      break;
    }
    ans = s(n);
    cout << ans << endl;
  }
}

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

int s(int x) {
  int ans, y = x;
  y %= 5;
  x = (x - y) / 5;
  if (x < 5)
    ans = x;
  if (x >= 5)
    ans = s(x) + x;
  return ans;
}

int main() {
  int n, ans;
  while (cin >> n) {
    if (n == 0) {
      break;
    }
    ans = s(n);
    cout << ans << endl;
  }
}
Problem p00052 (C++)

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

using namespace std;

int main() {
  int N;
  while (cin >> N, N) {
    int res = 0;
    while (N > 0) {
      res += N / 5;
    }
    cout << res << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  int N;
  while (cin >> N, N) {
    int res = 0;
    while (N > 0) {
      res += N /= 5;
    }
    cout << res << endl;
  }
  return 0;
}
Problem p00053 (C++)

Buggy submission (status: Runtime Error):
#include <math.h>
#include <stdio.h>
int isprime(int x) {
  int i;
  if (x == 2) {
    return 1;
  }
  if (x < 2 || x % 2 == 0) {
    return 0;
  }
  i = 3;
  while (i <= sqrt(x)) {
    if (x % i == 0) {
      return 0;
    }
    i = i + 2;
  }
  return 1;
}
int main() {
  int n, c = 0, l[10001] = {0}, j = 0;
  for (int i = 0; i <= 10000000; i++) {
    if (isprime(i)) {
      c += i;
      l[j] = c;
      j++;
    }
  }
  while (1) {
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    printf("%d\n", l[n - 1]);
  }
  return 0;
}

Fixed submission:
#include <math.h>
#include <stdio.h>
int isprime(int x) {
  int i;
  if (x == 2) {
    return 1;
  }
  if (x < 2 || x % 2 == 0) {
    return 0;
  }
  i = 3;
  while (i <= sqrt(x)) {
    if (x % i == 0) {
      return 0;
    }
    i = i + 2;
  }
  return 1;
}
int main() {
  int n, c = 0, l[10001] = {0}, j = 0;
  for (int i = 0; i <= 104730; i++) {
    if (isprime(i)) {
      c += i;
      l[j] = c;
      j++;
    }
  }
  while (1) {
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    printf("%d\n", l[n - 1]);
  }
  return 0;
}
Problem p00053 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  bool f[105000];
  int n;
  long long int sum[105000];
  memset(f, false, sizeof(f));
  sum[0] = 0;
  for (int i = 2; i <= 105000; i++) {
    if (f[i])
      continue;
    for (int j = i * i; j < 105000; j += i)
      f[j] = true;
  }
  int k = 1;
  for (int j = 2; j <= 105000; j++) {
    if (!f[j]) {
      sum[k] = sum[k - 1] + j;
      k++;
    }
  }
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    cout << sum[n] << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  bool f[105000];
  int n;
  long long int sum[105000];
  memset(f, false, sizeof(f));
  sum[0] = 0;
  for (int i = 2; i * i <= 105000; i++) {
    if (f[i])
      continue;
    for (int j = i * i; j < 105000; j += i)
      f[j] = true;
  }
  int k = 1;
  for (int j = 2; j <= 105000; j++) {
    if (!f[j]) {
      sum[k] = sum[k - 1] + j;
      k++;
    }
  }
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    cout << sum[n] << endl;
  }
  return 0;
}
Problem p00053 (C++)

Buggy submission (status: Runtime Error):

#include <cmath>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 105000
using namespace std;

int main() {
  /*for(int k = 1; k<MAX;k++)
  {
          if(PrimeCheck(v[k+1]))
          {
                  //cout << v[k+1] << " ";
                  v2[d] = v[k+1];
                  d++;
          }
  }
  //rep(i,d) cout << v2[i] << " ";
  //cout << d << endl;*/
  int number;
  while (cin >> number, number) {

    int counter = 0;
    vector<bool> v(MAX + 1, 0);
    vector<int> v2(10008, 0);
    rep(i, MAX) v[i + 1] = true;
    long long answer = 0;
    int lim = (int)sqrt(number);
    int d = 0;
    //		cout << lim <<" ";
    for (int i = 2; i < MAX; i++) {
      if (v[i]) {
        for (int j = 2; j < MAX / i; j++) {
          v[j * i] = false;
          // cout << " " << i << "i*j=  " << i*j;
        }
        v2[d] = i;
        d++;
      }
    }
    // rep(i,number) cout << v[i+1] << " ";
    for (int i = 2; i < MAX + 1; i++) {
      if (v[i]) {
        answer += i;
        counter++;
        // cout << " " << i;
        if (counter == number)
          break;
      }
    }
    cout /*<< " answer is "*/ << answer << endl;
  }
  return 0;
}

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 105000
using namespace std;

int main() {
  /*for(int k = 1; k<MAX;k++)
  {
          if(PrimeCheck(v[k+1]))
          {
                  //cout << v[k+1] << " ";
                  v2[d] = v[k+1];
                  d++;
          }
  }
  //rep(i,d) cout << v2[i] << " ";
  //cout << d << endl;*/
  int number;
  while (cin >> number, number) {

    int counter = 0;
    vector<bool> v(MAX + 1, 0);
    vector<int> v2(MAX, 0);
    rep(i, MAX) v[i + 1] = true;
    long long answer = 0;
    int lim = (int)sqrt(number);
    int d = 0;
    //		cout << lim <<" ";
    for (int i = 2; i < MAX; i++) {
      if (v[i]) {
        for (int j = 2; j < MAX / i; j++) {
          v[j * i] = false;
          // cout << " " << i << "i*j=  " << i*j;
        }
        v2[d] = i;
        d++;
      }
    }
    // rep(i,number) cout << v[i+1] << " ";
    for (int i = 2; i < MAX + 1; i++) {
      if (v[i]) {
        answer += i;
        counter++;
        // cout << " " << i;
        if (counter == number)
          break;
      }
    }
    cout /*<< " answer is "*/ << answer << endl;
  }
  return 0;
}
Problem p00053 (C++)

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

bool isPrime(int n) {
  if (n == 2)
    return true;
  if (n % 2 == 0)
    return false;

  for (int i = 3; i < n / 2; i += 2) {
    if (n % i == 0)
      return false;
  }
  return true;
}

int main() {

  int input;
  while (cin >> input, input) {
    int count = 0;
    int sum = 0;
    for (int i = 2;; ++i) {
      if (isPrime(i)) {
        count++;
        sum += i;
        if (count == input) {
          cout << sum << endl;
          break;
        }
      }
    }
  }

  return 0;
}


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

bool isPrime(int n) {
  if (n == 2)
    return true;
  if (n % 2 == 0)
    return false;

  double sqrtNum = sqrt(n);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (n % i == 0)
      return false;
  }
  return true;
}

int main() {

  int input;
  while (cin >> input, input) {
    int count = 0;
    int sum = 0;
    for (int i = 2;; ++i) {
      if (isPrime(i)) {
        count++;
        sum += i;
        if (count == input) {
          cout << sum << endl;
          break;
        }
      }
    }
  }

  return 0;
}
Problem p00053 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
unsigned long long a[10001], b[200000], c, n;
using namespace std;
int main() {
  for (int i = 2; i < 200000; i++)
    for (int j = i * 2; j < 200000; j += i)
      b[j]++;
  for (int i = 2; i < 200000; i++)
    if (!b[i]) {
      a[c + 1] += i + a[c];
      c++;
    }
  while (cin >> n, n)
    cout << a[n] << endl;
}

Fixed submission:
#include <iostream>
unsigned long long a[100000], b[200000], c, n;
using namespace std;
int main() {
  for (int i = 2; i < 200000; i++)
    for (int j = i * 2; j < 200000; j += i)
      b[j]++;
  for (int i = 2; i < 200000; i++)
    if (!b[i]) {
      a[c + 1] += i + a[c];
      c++;
    }
  while (cin >> n, n)
    cout << a[n] << endl;
}
Problem p00053 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back

const double EPS = 1e-10;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

int main() {
  int N = 200000;
  vi p(N, 1);
  p[0] = p[1] = 0;
  rep(i, N) if (p[i]) for (int j = i + i; j < N; j += i) p[j] = 0;
  vi ps;
  rep(i, N) if (p[i]) ps.pb(i);

  debug(ps.size()) for (int n; cin >> n, n != 0;) {
    int sum = 0;
    rep(i, n) sum += ps[i];
    cout << sum << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back

const double EPS = 1e-10;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

int main() {
  int N = 200000;
  vi p(N, 1);
  p[0] = p[1] = 0;
  rep(i, N) if (p[i]) for (int j = i + i; j < N; j += i) p[j] = 0;
  vi ps;
  rep(i, N) if (p[i]) ps.pb(i);

  for (int n; cin >> n, n != 0;) {
    int sum = 0;
    rep(i, n) sum += ps[i];
    cout << sum << endl;
  }
  return 0;
}
Problem p00053 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

int main() {
  int prime[10001], p = 3, psum[10001], n;
  prime[1] = 2, prime[2] = 3;
  for (int i = 5; p < 10001; i++) {
    int f = 0;
    for (int j = 1; prime[j] * prime[j] <= i; j++)
      if (i % prime[j] == 0) {
        f = 1;
        break;
      }
    if (!f)
      prime[p++] = i;
  }
  psum[1] = 2;
  for (int i = 2; i < 100001; i++)
    psum[i] = psum[i - 1] + prime[i];
  while (1) {
    cin >> n;
    if (!n)
      break;
    cout << psum[n] << endl;
  }

  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int prime[10001], p = 3, psum[10001], n;
  prime[1] = 2, prime[2] = 3;
  for (int i = 5; p < 10001; i++) {
    int f = 0;
    for (int j = 1; prime[j] * prime[j] <= i; j++)
      if (i % prime[j] == 0) {
        f = 1;
        break;
      }
    if (!f)
      prime[p++] = i;
  }
  psum[1] = 2;
  for (int i = 2; i < 10001; i++)
    psum[i] = psum[i - 1] + prime[i];
  while (1) {
    cin >> n;
    if (!n)
      break;
    cout << psum[n] << endl;
  }

  return 0;
}
Problem p00053 (C++)

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

int main() {
  const int NUM = 10000;
  bool prime[NUM];
  for (int i = 2; i < NUM; i++)
    prime[i] = true;
  for (int i = 2; i * i < NUM; i++)
    for (int k = 2; i * k < NUM; k++)
      prime[i * k] = false;
  int n, c;
  while (cin >> n) {
    if (!n)
      break;
    c = 0;
    for (int i = 2, k = 0; k < n; i++)
      if (prime[i])
        c += i, k++;
    cout << c << endl;
  }
}

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

int main() {
  const int NUM = 1e6;
  bool prime[NUM];
  for (int i = 2; i < NUM; i++)
    prime[i] = true;
  for (int i = 2; i * i < NUM; i++)
    for (int k = 2; i * k < NUM; k++)
      prime[i * k] = false;
  int n, c;
  while (cin >> n) {
    if (!n)
      break;
    c = 0;
    for (int i = 2, k = 0; k < n; i++)
      if (prime[i])
        c += i, k++;
    cout << c << endl;
  }
}
Problem p00054 (C++)

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

using namespace std;

int func(int a, int b, int n) {
  if (n == 0) {
    return 0;
  }
  int u = 10 * a;

  return (u / b + func(u % b, b, n - 1));
}

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

  while (cin >> a >> b >> n) {
    while (a >= b) {
      a /= b;
    }
    cout << func(a, b, n) << endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int func(int a, int b, int n) {
  if (n == 0) {
    return 0;
  }
  int u = 10 * a;

  return (u / b + func(u % b, b, n - 1));
}

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

  while (cin >> a >> b >> n) {
    a %= b;
    cout << func(a, b, n) << endl;
  }

  return 0;
}
Problem p00055 (C++)

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

  double a;

  while (cin >> a) {
    double ans = 0;
    ans += a;
    for (int i = 2; i <= 10; i++) {
      if (i % 2 == 0)
        a *= 2;
      else
        a /= 3;
      ans += a;
    }
    printf("%llf\n", ans);
  }
  return 0;
}

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

  double a;

  while (cin >> a) {
    double ans = 0;
    ans += a;
    for (int i = 2; i <= 10; i++) {
      if (i % 2 == 0)
        a *= 2;
      else
        a /= 3;
      ans += a;
    }
    printf("%lf\n", ans);
  }
  return 0;
}
Problem p00055 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(), vec.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1000000007;
const ll INF = 1000000010;
const ll LINF = 4000000000000000010LL;
const int MAX = 310;
const double EPS = 1e-9;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
  double b;
  while (cin >> b, b) {
    double a[11];
    a[1] = b;
    double sum = b;
    for (int i = 2; i <= 10; i++) {
      if (i % 2) {
        a[i] = a[i - 1] / 3;
      } else {
        a[i] = a[i - 1] * 2;
      }
      sum += a[i];
    }
    printf("%.9lf\n", sum);
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(), vec.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1000000007;
const ll INF = 1000000010;
const ll LINF = 4000000000000000010LL;
const int MAX = 310;
const double EPS = 1e-9;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
  double b;
  while (cin >> b) {
    double a[11];
    a[1] = b;
    double sum = b;
    for (int i = 2; i <= 10; i++) {
      if (i % 2) {
        a[i] = a[i - 1] / 3;
      } else {
        a[i] = a[i - 1] * 2;
      }
      sum += a[i];
    }
    printf("%.9lf\n", sum);
  }
}
Problem p00055 (C++)

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

int main() {
  double a, S = 0.0;
  while (scanf("%lf", &a)) {
    S += a;
    for (int i = 2; i <= 10; i++) {
      if (i % 2)
        a /= 3.0;
      else
        a *= 2.0;
      S += a;
    }
    printf("%.8f\n", S);
  }
  return 0;
}

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

int main() {
  double a;
  while (scanf("%lf", &a) == 1) {
    double S = a;
    for (int i = 2; i <= 10; i++) {
      if (i % 2)
        a /= 3.0;
      else
        a *= 2.0;
      S += a;
    }
    printf("%.8f\n", S);
  }
  return 0;
}
Problem p00055 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  long double a, b, sum;
  while (1) {
    cin >> a;
    sum = a;
    for (int i = 0; i < 9; i++) {
      if (i % 2 == 0) {
        b = a * 2;
        sum = sum + b;
      } else {
        b = a / 3;
        sum = sum + b;
      }
      a = b;
    }
    cout << fixed << setprecision(8) << sum << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  long double a, b, sum;
  while (cin >> a) {
    sum = a;
    for (int i = 0; i < 9; i++) {
      if (i % 2 == 0) {
        b = a * 2;
        sum = sum + b;
      } else {
        b = a / 3;
        sum = sum + b;
      }
      a = b;
    }
    cout << fixed << setprecision(8) << sum << endl;
  }

  return 0;
}
Problem p00055 (C++)

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

int main() {
  double d[10];
  double a;
  while (cin >> a) {
    d[0] = a;
    d[1] = d[0] * 2;
    for (int i = 2; i < 10; i + 2) {
      d[i] = d[i - 1] / 3;
      d[i + 1] = d[i] * 2;
    }
    int ca = 0;
    for (int i = 0; i < 10; i++) {
      ca += d[i];
    }
    cout << fixed << setprecision(9) << ca << endl;
  }
  return 0;
}

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

int main() {
  double d[10];
  double a;
  while (cin >> a) {
    d[0] = a;
    d[1] = d[0] * 2;
    d[2] = d[1] / 3;
    d[3] = d[2] * 2;
    d[4] = d[3] / 3;
    d[5] = d[4] * 2;
    d[6] = d[5] / 3;
    d[7] = d[6] * 2;
    d[8] = d[7] / 3;
    d[9] = d[8] * 2;
    double ca = 0;
    for (int i = 0; i < 10; i++) {
      ca += d[i];
    }
    cout << fixed << setprecision(9) << ca << endl;
  }
  return 0;
}
Problem p00055 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iomanip>
#include <iostream>
int main() {
  while (true) {
    double a;
    std::cin >> a;
    std::cout << std::fixed << std::setprecision(10) << a * 211 / 27
              << std::endl;
  }
  return 0;
}


Fixed submission:
#include <iomanip>
#include <iostream>
int main() {
  while (true) {
    double a;
    std::cin >> a;
    if (std::cin.eof()) {
      break;
    }
    std::cout << std::fixed << std::setprecision(10) << a * 211 / 27
              << std::endl;
  }
  return 0;
}
Problem p00055 (C++)

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

int main() {
  double a;
  while (1) {
    cin >> a;
    printf("%.8f\n", 211.0 / 27.0 * a);
  }
  return 0;
}

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

int main() {
  double a;
  while (1) {
    cin >> a;
    if (cin.eof())
      break;
    printf("%.8f\n", 211.0 / 27.0 * a);
  }
  return 0;
}
Problem p00056 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  int n, x, m;
  x = 0;
  m = 0;
  vector<int> v;
  scanf("%d", &n);
  while (n) {
    v.push_back(n);
    if (n > x) {
      x = n;
    }
    scanf("%d", &n);
    m++;
  }
  vector<int> res;
  vector<int> p(x + 1, 1);
  p[0] = 0;
  p[1] = 0;
  for (int t = 2; t <= x; t++) {
    if (p[t] == 0)
      continue;
    // p の倍数を全て消す。
    for (int k = t * 2; k <= x; k += t) {
      p[k] = 0;
    }
    res.push_back(t);
  }
  int a = 0;
  int s;
  for (int t = 0; t < m; t++) {
    a = 0;
    s = res.size();
    for (int k = 0; k < s; k++) {
      if (p[v[t] - res[k]] == 1) {
        a++;
      }
    }
    a = a / 2 + a % 2;
    printf("%d\n", a);
  }
}


Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  int n, x, m;
  x = 0;
  m = 0;
  vector<int> v;
  scanf("%d", &n);
  while (n) {
    v.push_back(n);
    if (n > x) {
      x = n;
    }
    scanf("%d", &n);
    m++;
  }
  vector<int> res;
  vector<int> p(x + 1, 1);
  p[0] = 0;
  p[1] = 0;
  for (int t = 2; t <= x; t++) {
    if (p[t] == 0)
      continue;
    // p の倍数を全て消す。
    for (int k = t * 2; k <= x; k += t) {
      p[k] = 0;
    }
    res.push_back(t);
  }
  int a = 0;
  int s;
  for (int t = 0; t < m; t++) {
    a = 0;
    s = res.size();
    for (int k = 0; k < s; k++) {
      if (v[t] - res[k] >= 1) {
        if (p[v[t] - res[k]] == 1) {
          a++;
        }
      }
    }
    a = a / 2 + a % 2;
    printf("%d\n", a);
  }
}
Problem p00056 (C++)

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

int main() {
  bool is_prime[100000];
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < 100000; i++) {
    is_prime[i] = true;
  }

  for (int i = 2; i * i < 100000; i++) {
    if (is_prime[i]) {
      for (int j = i * i; j < 100000; j += i) {
        is_prime[j] = false;
      }
    }
  }

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

    if (n == 0)
      break;

    int cnt = 0;

    for (int i = 0; i < n; i++) {
      if (!is_prime[i])
        continue;

      for (int j = i; j < n; j++) {
        if (is_prime[j])
          if (i + j == n)
            cnt++;
      }
    }

    cout << cnt << endl;
  }
}


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

int main() {
  bool is_prime[100000];
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < 100000; i++) {
    is_prime[i] = true;
  }

  for (int i = 2; i * i < 100000; i++) {
    if (is_prime[i]) {
      for (int j = i * i; j < 100000; j += i) {
        is_prime[j] = false;
      }
    }
  }

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

    if (n == 0)
      break;

    int cnt = 0;

    for (int i = 0; i <= n / 2; i++) {
      if (is_prime[i] && is_prime[n - i])
        if (i + (n - i) == n)
          cnt++;
    }

    cout << cnt << endl;
  }
}
Problem p00056 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  bool p[50000];
  p[1] = false;
  for (int i = 2; i < 50000; i++) {
    p[i] = true;
  }
  for (int j = 2; j < 50000; j++) {
    if (p[j]) {
      for (int k = j * 2; k < 50000; k += j) {
        p[k] = false;
      }
    }
  }
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int count = 0;
    if (p[n - 2])
      count++;
    for (int l = 3; l <= n / 2; l += 2) {
      if (p[l]) {
        for (int m = l; m <= n; m++) {
          if (p[m] == true && l + m == n)
            count++;
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  bool p[50000];
  p[1] = false;
  for (int i = 2; i < 50000; i++) {
    p[i] = true;
  }
  for (int j = 2; j < 50000; j++) {
    if (p[j]) {
      for (int k = j * 2; k < 50000; k += j) {
        p[k] = false;
      }
    }
  }
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int count = 0;
    if (p[n - 2])
      count++;
    for (int l = 3; l <= n / 2; l += 2) {
      if (p[l] && p[n - l])
        count++;
    }
    cout << count << endl;
  }
  return 0;
}
Problem p00056 (C++)

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

#define SIZE 50001

int main() {
  bool prime[SIZE];
  fill(prime, prime + SIZE, true);
  prime[0] = prime[1] = false;
  for (int i = 2; i * i < SIZE; i++) {
    for (int j = 2; j * i < SIZE; j++) {
      if (!prime[i * j])
        continue;
      prime[i * j] = false;
    }
  }

  int n, count;
  while (cin >> n) {
    if (n == 0)
      break;

    count = 0;
    for (int i = 2; i < n; i++) {
      if (!prime[i])
        continue;
      for (int j = i; j < n; j++) {
        if (!prime[j])
          continue;
        if (i + j == n)
          count++;
        if (i + j > n)
          break;
      }
    }
    cout << count << endl;
  }
  return 0;
}

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

#define SIZE 50001

int main() {
  bool prime[SIZE];
  fill(prime, prime + SIZE, true);
  prime[0] = prime[1] = false;
  for (int i = 2; i * i < SIZE; i++) {
    for (int j = 2; j * i < SIZE; j++) {
      if (!prime[i * j])
        continue;
      prime[i * j] = false;
    }
  }

  int n, count;
  while (cin >> n) {
    if (n == 0)
      break;

    count = 0;
    for (int i = 0; i <= n / 2; i++) {
      if (prime[i] && prime[n - i])
        count++;
    }
    cout << count << endl;
  }
  return 0;
}
Problem p00056 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>
using namespace std;
int x[100000], y[100000], n, sum;
int main() {
  for (int i = 2; i < 100000; i++) {
    for (int j = 2; j <= sqrt(i); j++) {
      if (i % j == 0) {
        goto E;
      }
    }
    x[i] = 1;
  E:;
  }
  while (true) {
    cin >> n;
    sum = 0;
    for (int i = 2; i < n; i++) {
      if (x[i] == 1 && x[n - i] == 1) {
        sum++;
      }
    }
    cout << sum << endl;
  }
}

Fixed submission:
#include <cmath>
#include <iostream>
using namespace std;
int x[100000], y[100000], n, sum;
int main() {
  for (int i = 2; i < 100000; i++) {
    for (int j = 2; j <= sqrt(i); j++) {
      if (i % j == 0) {
        goto E;
      }
    }
    x[i] = 1;
  E:;
  }
  while (true) {
    cin >> n;
    sum = 0;
    if (!n) {
      break;
    }
    for (int i = 2; i <= n / 2; i++) {
      if (x[i] == 1 && x[n - i] == 1) {
        sum++;
      }
    }
    cout << sum << endl;
  }
}
Problem p00056 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define dump(n) cout << "# " << #n << "=" << (n) << endl
#define debug(n)                                                               \
  cout << __FILE__ << "," << __LINE__ << ": # " << #n << "=" << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, n) repi(i, 0, n)
#define iter(c) __typeof((c).begin())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define allof(c) (c).begin(), (c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

int main() {
  vi prime(1, 2);
  for (int i = 3; prime.back() <= 50000; i += 2) {
    bool ok = true;
    for (int j = 0; prime[j] * prime[j] <= i; j++)
      if (i % prime[j] == 0) {
        ok = false;
        break;
      }
    if (ok)
      prime.push_back(i);
  }

  for (int n; cin >> n, n;) {
    int res = 0;
    for (int i = 2; i <= n / 2; i++)
      if (binary_search(allof(prime), i) && binary_search(allof(prime), n - i))
        res++;
    cout << res << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define dump(n) cout << "# " << #n << "=" << (n) << endl
#define debug(n)                                                               \
  cout << __FILE__ << "," << __LINE__ << ": # " << #n << "=" << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, n) repi(i, 0, n)
#define iter(c) __typeof((c).begin())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define allof(c) (c).begin(), (c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

int main() {
  vi prime(1, 2);
  for (int i = 3; prime.back() <= 50000; i += 2) {
    bool ok = true;
    for (int j = 0; prime[j] * prime[j] <= i; j++)
      if (i % prime[j] == 0) {
        ok = false;
        break;
      }
    if (ok)
      prime.push_back(i);
  }

  for (int n; cin >> n, n;) {
    int res = 0;
    for (int i = 0; prime[i] <= n / 2; i++)
      if (binary_search(allof(prime), n - prime[i]))
        res++;
    cout << res << endl;
  }

  return 0;
}