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

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

#include <string.h>

using namespace std;

bool prime_check(int n) {
  if (n == 1) {
    return false;
  }

  if (n % 2 == 0) {
    if (n == 2) {
      return true;
    }

    else {
      return false;
    }
  }

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

  return true;
}

int main() {
  const int DATA_SETS = 1000;
  const int MAX_PRIME = 50000;

  int N[DATA_SETS], P[DATA_SETS], C = 0;

  bool I[MAX_PRIME + 1];

  memset(N, 0, sizeof(N));
  memset(P, 0, sizeof(P));
  memset(I, 0, sizeof(I));

  for (int i = 1; i <= MAX_PRIME; i++) {
    if (prime_check(i) == true) {
      I[i] = true;
    } else {
      I[i] = false;
    }
  }

  while (true) {
    cin >> N[C];

    if (N[C] == 0) {
      goto Exit;
    }

    C++;
  }

Exit:;

  for (int i = 0; i < C; i++) {
    for (int j = 2; j <= N[i] / 2; j++) {
      if (I[j] == true && I[N[i] - j] == true) {
        P[i]++;
      }
    }

    cout << P[i] << endl;
  }

  return 0;
}

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

#include <string.h>

using namespace std;

bool prime_check(int n) {
  if (n == 1) {
    return false;
  }

  if (n % 2 == 0) {
    if (n == 2) {
      return true;
    }

    else {
      return false;
    }
  }

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

  return true;
}

int main() {
  const int DATA_SETS = 10000;
  const int MAX_PRIME = 50000;

  int N[DATA_SETS], P[DATA_SETS], C = 0;

  bool I[MAX_PRIME + 1];

  memset(N, 0, sizeof(N));
  memset(P, 0, sizeof(P));
  memset(I, 0, sizeof(I));

  for (int i = 1; i <= MAX_PRIME; i++) {
    if (prime_check(i) == true) {
      I[i] = true;
    } else {
      I[i] = false;
    }
  }

  while (true) {
    cin >> N[C];

    if (N[C] == 0) {
      goto Exit;
    }

    C++;
  }

Exit:;

  for (int i = 0; i < C; i++) {
    for (int j = 2; j <= N[i] / 2; j++) {
      if (I[j] == true && I[N[i] - j] == true) {
        P[i]++;
      }
    }

    cout << P[i] << endl;
  }

  return 0;
}
Problem p00056 (C++)

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

using namespace std;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_str(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef long long ll;

int main() {
  vector<int> primeList;
  bool used[50002];

  memset(used, true, sizeof(used));

  for (int i = 2; i <= sqrt(50000); i++) {
    if (used[i] == false) {
      continue;
    }
    for (int j = i * 2; j <= 50000; j += i) {
      used[j] = false;
    }
  }
  for (int i = 2; i < 50000; i++) {
    if (used[i] == true) {
      primeList.push_back(i);
    }
  }
  int num, ans;
  while (cin >> num) {
    if (num == 0) {
      break;
    }
    ans = 0;

    for (int i = 0; i < primeList.size(); i++) {
      if (num % 2 != 0 && i >= 1) {
        break;
      }
      for (int j = i; j < primeList.size(); j++) {
        if (primeList[i] + primeList[j] > num) {
          break;
        }
        if (primeList[i] + primeList[j] == num) {
          ans++;
        }
      }
    }

    cout << ans << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_str(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef long long ll;

int main() {
  vector<int> primeList;
  bool used[50002];

  memset(used, true, sizeof(used));

  for (int i = 2; i <= sqrt(50000); i++) {
    if (used[i] == false) {
      continue;
    }
    for (int j = i * 2; j <= 50000; j += i) {
      used[j] = false;
    }
  }
  for (int i = 2; i < 50000; i++) {
    if (used[i] == true) {
      primeList.push_back(i);
    }
  }
  int num, ans;
  while (cin >> num) {
    if (num == 0) {
      break;
    }
    ans = 0;

    for (int i = 0; i < primeList.size() && primeList[i] <= (num / 2); i++) {
      if (used[num - primeList[i]] == true) {
        ans++;
      }
    }

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

Buggy submission (status: Time Limit Exceeded):
#define _CRT_SECURE_NO_WARNINGS 1
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0 * M_PI / 360.0
#define inin(x)                                                                \
  int x;                                                                       \
  cin >> x;
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " " << x << endl;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define pri_max 60000
typedef pair<int, int> pii;

bool memo[pri_max] = {};
vector<int> pri;
void calc() {
  for (int i = 2; i < pri_max; i++) {
    if (memo[i] == false) {
      pri.push_back(i);
      for (int l = i; l < pri_max; l += i) {
        memo[l] = true;
      }
    }
  }
}
int main() {
  calc();
  int n;
  while (cin >> n && n) {
    int ans = 0;
    for (int i = 0; i < pri.size(); i++) {
      ans += binary_search(all(pri), n - pri[i]);
    }
    ans /= 2;
    if (n % 2 == 0 && binary_search(all(pri), n / 2))
      ans++;
    cout << ans << endl;
  }
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS 1
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0 * M_PI / 360.0
#define inin(x)                                                                \
  int x;                                                                       \
  cin >> x;
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " " << x << endl;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define pri_max 60000
typedef pair<int, int> pii;

bool memo[pri_max] = {};
vector<int> pri;
void calc() {
  for (int i = 2; i < pri_max; i++) {
    if (memo[i] == false) {
      pri.push_back(i);
      for (int l = i; l < pri_max; l += i) {
        memo[l] = true;
      }
    }
  }
}
int main() {
  calc();
  int n;
  while (cin >> n && n) {
    int ans = 0;
    for (int i = 0; i < pri.size(); i++) {
      if (n - pri[i] <= 0)
        break;
      ans += binary_search(all(pri), n - pri[i]);
    }
    ans /= 2;
    if (n % 2 == 0 && binary_search(all(pri), n / 2))
      ans++;
    cout << ans << endl;
  }
}
Problem p00056 (C++)

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

void sieve(int n, vector<char> &v) {
  v.resize(n + 1);
  fill(v.begin(), v.end(), true);
  v[0] = v[1] = false;

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

int main() {
  vector<char> is_prime;
  vector<int> prime_list;

  sieve(50000, is_prime);

  for (int i = 0; i < is_prime.size(); i++) {
    if (is_prime[i]) {
      prime_list.push_back(i);
    }
  }

  int n;

  while (cin >> n, n) {
    int pr = 0;

    for (int i = 0; i < prime_list.size(); i++) {
      if (prime_list[i] + prime_list[i] > n)
        break;

      if (find(prime_list.begin(), prime_list.end(), n - prime_list[i]) !=
          prime_list.end()) {
        pr++;
      }
    }

    cout << pr << endl;
  }

  return 0;
}

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

void sieve(int n, vector<char> &v) {
  v.resize(n + 1);
  fill(v.begin(), v.end(), true);
  v[0] = v[1] = false;

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

int main() {
  vector<char> is_prime;
  vector<int> prime_list;

  sieve(50000, is_prime);

  for (int i = 0; i < is_prime.size(); i++) {
    if (is_prime[i]) {
      prime_list.push_back(i);
    }
  }

  int n;

  while (cin >> n, n) {
    int pr = 0;

    for (int i = 0; i < prime_list.size(); i++) {
      if (prime_list[i] + prime_list[i] > n)
        break;

      if (binary_search(prime_list.begin(), prime_list.end(),
                        n - prime_list[i])) {
        pr++;
      }
    }

    cout << pr << endl;
  }

  return 0;
}
Problem p00056 (C++)

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

bool a[60000]{};
int main() {
  for (int b = 2; b < 60000; b++) {
    if (!(a[b])) {
      for (int c = b * 2; c <= 150000; c += b)
        a[c] = true;
    }
  }
  int e;
  while (cin >> e, e) {
    int s = 0;
    for (int f = 2; f <= e / 2; f++) {
      if (!a[f] && !a[e - f])
        s++;
    }
    cout << s << endl;
  }
}

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

bool a[60000]{};
int main() {
  for (int b = 2; b < 60000; b++) {
    if (!(a[b])) {
      for (int c = b * 2; c < 60000; c += b)
        a[c] = true;
    }
  }
  int e;
  while (cin >> e, e) {
    int s = 0;
    for (int f = 2; f <= e / 2; f++) {
      if (!a[f] && !a[e - f])
        s++;
    }
    cout << s << endl;
  }
}
Problem p00056 (C++)

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

vector<int> p;
int ans[50001];

void solve() {
  int ret = 0;
  for (int i = 0; i < p.size(); i++)
    for (int j = i; j < p.size(); j++) {
      if (p[i] + p[j] > 50000)
        break;
      ans[p[i] + p[j]]++;
    }
}

int main() {
  p.push_back(2);
  for (int i = 3; i < 50000; i += 2) {
    bool flag = true;
    for (int j = 0; j < p.size(); j++)
      if (i % p[j] == 0) {
        flag = false;
        break;
      }
    if (flag) {
      p.push_back(i);
    }
  }
  solve();

  int n;
  while (true) {
    cin >> n;
    cout << ans[n] << endl;
  }
  return 0;
}

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

vector<int> p;
int ans[50001];

void solve() {
  int ret = 0;
  for (int i = 0; i < p.size(); i++)
    for (int j = i; j < p.size(); j++) {
      if (p[i] + p[j] > 50000)
        break;
      ans[p[i] + p[j]]++;
    }
}

int main() {
  p.push_back(2);
  for (int i = 3; i < 50000; i += 2) {
    bool flag = true;
    for (int j = 0; j < p.size(); j++)
      if (i % p[j] == 0) {
        flag = false;
        break;
      }
    if (flag) {
      p.push_back(i);
    }
  }
  solve();

  int n;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    cout << ans[n] << endl;
  }
  return 0;
}
Problem p00056 (C++)

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

/** Problem0056 : Goldbach's Conjecture **/
#define MAX 50000
int main() {
  bool prime[MAX];
  int input, count;

  for (int i = 0; i < MAX; i++)
    prime[i] = true;

  prime[0] = false;
  prime[1] = false;

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

  while (1) {
    cin >> input;
    if (input == 0)
      break;

    count = 0;
    for (int i = input; i > 1; i--) {
      if (!prime[i])
        continue;
      for (int j = input; j >= i; j--) {
        if (!prime[j])
          continue;
        if (i + j == input)
          count++;
      }
    }

    cout << count << endl;
  }

  return 0;
}

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

/** Problem0056 : Goldbach's Conjecture **/
#define MAX 50000
int main() {
  bool prime[MAX];
  int input, count;

  for (int i = 0; i < MAX; i++)
    prime[i] = true;

  prime[0] = false;
  prime[1] = false;

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

  while (1) {
    cin >> input;
    if (input == 0)
      break;

    count = 0;
    for (int i = 2; i <= input / 2; i++) {
      if (prime[i] && prime[input - i])
        count++;
    }

    cout << count << endl;
  }

  return 0;
}
Problem p00056 (C++)

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

using namespace std;

int main() {

  int *data;
  data = new int[50001];

  data[0] = 0;
  data[1] = 0;
  data[2] = 1;
  data[3] = 1;

  for (int i = 3; i <= 50000; i++) {
    int flag = 0;
    for (int j = 3; j * j <= i; j += 2) {
      if (i % j == 0) {
        flag = 1;
        break;
      }
    }
    if (flag == 1) {
      data[i] = 0;
    } else {
      data[i] = 1;
    }
  }

  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    if (n <= 3) {
      cout << 0 << endl;
      continue;
    } else if (n % 2 == 1) {
      if (data[n - 2] == 1) {
        cout << 1 << endl;
      } else {
        cout << 0 << endl;
      }
      continue;
    } else if (n == 4) {
      cout << 1 << endl;
    } else {
      int cnt = 0;
      for (int i = 3; i <= n / 2; i += 2) {
        if (data[i] == 1 && data[n - i] == 1) {
          cout << i << " " << n - i << endl;
          cnt++;
        }
      }
      cout << cnt << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {

  int *data;
  data = new int[50001];

  data[0] = 0;
  data[1] = 0;
  data[2] = 1;
  data[3] = 1;

  for (int i = 3; i <= 50000; i++) {
    int flag = 0;
    for (int j = 3; j * j <= i; j += 2) {
      if (i % j == 0) {
        flag = 1;
        break;
      }
    }
    if (flag == 1) {
      data[i] = 0;
    } else {
      data[i] = 1;
    }
  }

  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    if (n <= 3) {
      cout << 0 << endl;
      continue;
    } else if (n % 2 == 1) {
      if (data[n - 2] == 1) {
        cout << 1 << endl;
      } else {
        cout << 0 << endl;
      }
      continue;
    } else if (n == 4) {
      cout << 1 << endl;
    } else {
      int cnt = 0;
      for (int i = 3; i <= n / 2; i += 2) {
        if (data[i] == 1 && data[n - i] == 1) {
          //	cout<<i<<" "<<n-i<<endl;
          cnt++;
        }
      }
      cout << cnt << endl;
    }
  }
  return 0;
}
Problem p00056 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define rep(i, n) for ((i) = 0; (i) < (int)(n); (i)++)
#define foreach(itr, c)                                                        \
  for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); itr++)
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}

bool isprime[50000];

void sieve(int n) {
  memset(isprime, 1, sizeof(isprime));
  isprime[0] = isprime[1] = false;
  for (int i = 2; i * i <= n; i++)
    if (isprime[i]) {
      for (int j = 2 * i; j <= n; j += i)
        isprime[j] = false;
    }
}

int main() {
  int i, j, k;
  int n;
  int res;

  sieve(50000);
  while (scanf("%d", &n)) {
    if (n == 0)
      break;

    res = 0;
    rep(i, n) if (isprime[i]) {
      for (j = i; j < n; j++)
        if (isprime[j]) {
          if (i + j == n)
            res++;
        }
    }
    printf("%d\n", res);
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define rep(i, n) for ((i) = 0; (i) < (int)(n); (i)++)
#define foreach(itr, c)                                                        \
  for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); itr++)
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}

bool isprime[50000];

void sieve(int n) {
  memset(isprime, 1, sizeof(isprime));
  isprime[0] = isprime[1] = false;
  for (int i = 2; i * i <= n; i++)
    if (isprime[i]) {
      for (int j = 2 * i; j <= n; j += i)
        isprime[j] = false;
    }
}

int main() {
  int i, j, k;
  int n;
  int res;

  sieve(50000);
  while (scanf("%d", &n)) {
    if (n == 0)
      break;

    res = 0;
    for (i = 2; 2 * i <= n; i++)
      if (isprime[i] && isprime[n - i])
        res++;
    printf("%d\n", res);
  }

  return 0;
}
Problem p00056 (C++)

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

using namespace std;

void MakePrimeArray(deque<bool> &A, int n) {

  A[0] = A[1] = false;
  for (int i = 2; i < n; i++) {
    A[i] = true;
  }

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

inline int GoldBach(const deque<int> &prime, int n) {

  int count = 0;
  deque<int> clear;
  bool ok = true;

  for (int i = 0; prime[i] < n; i++) {

    if (std::binary_search(clear.begin(), clear.end(), prime[i])) {
      break;
    }

    int num = n - prime[i];

    if (std::binary_search(prime.begin(), prime.end(), num)) {
      count++;
      clear.insert(clear.begin(), num);
    }
  }
  return count;
}

int main() {

  int n = 50001;

  deque<bool> primearray;

  primearray.resize(n);

  MakePrimeArray(primearray, n);

  deque<int> prime;

  for (int i = 2; i < n; i++) {
    if (primearray[i]) {
      prime.push_back(i);
    }
  }

  while (true) {
    int innum;
    cin >> innum;
    // scanf("%d",&innum);

    if (innum == 0)
      break;
    int answer = GoldBach(prime, innum);
    // printf("%d \n",answer);
    cout << GoldBach(prime, innum) << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <deque>
#include <iostream>
#include <stdio.h>

using namespace std;

void MakePrimeArray(deque<bool> &A, int n) {

  A[0] = A[1] = false;
  for (int i = 2; i < n; i++) {
    A[i] = true;
  }

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

inline int GoldBach(const deque<int> &prime, int n) {

  int count = 0;
  deque<int> clear;
  bool ok = true;

  for (int i = 0; prime[i] < n; i++) {

    if (std::binary_search(clear.begin(), clear.end(), prime[i])) {
      break;
    }

    int num = n - prime[i];

    if (std::binary_search(prime.begin(), prime.end(), num)) {
      count++;
      clear.insert(clear.begin(), num);
    }
  }
  return count;
}

int main() {

  int n = 50001;

  deque<bool> primearray;

  primearray.resize(n);

  MakePrimeArray(primearray, n);

  deque<int> prime;

  for (int i = 2; i < n; i++) {
    if (primearray[i]) {
      prime.push_back(i);
    }
  }

  while (true) {
    int innum;
    cin >> innum;
    // scanf("%d",&innum);

    if (innum == 0)
      break;
    int answer = GoldBach(prime, innum);
    // printf("%d \n",answer);
    cout << answer << endl;
  }

  return 0;
}
Problem p00056 (C++)

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

int prime[50001];

int main() {
  int n;
  int cnt;
  for (int i = 2; i <= STA / 2; i++) {
    for (int j = 2; i * j <= STA; j++) {
      prime[i * j] = 1;
    }
  }
  while (1) {
    cnt = 0;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 2; i <= n / 2; i++) {
      if (prime[i] == 0) {
        for (int j = i; j <= n; j++) {
          if (i + j == n && prime[j] == 0)
            cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
}

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

int prime[50001];

int main() {
  int n;
  int cnt;
  for (int i = 2; i <= STA / 2; i++) {
    for (int j = 2; i * j <= STA; j++) {
      prime[i * j] = 1;
    }
  }
  while (1) {
    cnt = 0;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 2; i <= n / 2; i++) {
      if (prime[i] == 0 && prime[n - i] == 0)
        cnt++;
    }
    cout << cnt << endl;
  }
}
Problem p00056 (C++)

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

#define N 50

using namespace std;

int main(void) {
  int p[N + 1] = {0};
  int n, ans;

  for (int i = 2; i < N; i++) {
    if (p[i] == -1)
      continue;
    p[i] = 1;
    for (int j = i * 2; j < N; j += i) {
      p[j] = -1;
    }
  }
  while (scanf("%d", &n), n) {
    ans = 0;
    for (int i = 2; i <= n / 2; i++) {
      if (p[i] == 1 && p[n - i] == 1) {
        ans++;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}


Fixed submission:
#include <cstdio>
#include <cstring>

#define N 50000

using namespace std;

int main(void) {
  int p[N + 1] = {0};
  int n, ans;

  for (int i = 2; i < N; i++) {
    if (p[i] == -1)
      continue;
    p[i] = 1;
    for (int j = i * 2; j < N; j += i) {
      p[j] = -1;
    }
  }
  while (scanf("%d", &n), n) {
    ans = 0;
    for (int i = 2; i <= n / 2; i++) {
      if (p[i] == 1 && p[n - i] == 1) {
        ans++;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
Problem p00056 (C++)

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

using namespace std;

bool is_prime[MAX];

void tenes(void) {

  for (int i = 0; i < MAX; i++) {
    is_prime[i] = true;
  }
  is_prime[0] = is_prime[1] = false;

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

int main(void) {

  tenes();

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

    int cnt = 0;
    int N;
    for (int i = 2; i < MAX / 2; i++) {
      if (is_prime[i]) {
        if (n - i > 0) {
          N = n - i;
          if (is_prime[N] && N >= n / 2) {
            cout << N << endl;
            cnt++;
          }
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
#define MAX 50000

using namespace std;

bool is_prime[MAX];

void tenes(void) {

  for (int i = 0; i < MAX; i++) {
    is_prime[i] = true;
  }
  is_prime[0] = is_prime[1] = false;

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

int main(void) {

  tenes();

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

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

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  bool p[50001];
  memset(p, 1, sizeof(p));
  p[0] = p[1] = 0;
  for (int i = 0; i < 50001; i++) {
    if (p[i]) {
      for (int j = 2 * i; j < 50001; j += i) {
        p[j] = 0;
      }
    }
  }

  int n, sum;
  while (cin >> n, n) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++) {
        if (p[i] == 1 && p[j] == 1) {
          sum = i + j;
          if (sum == n)
            cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  bool p[50001];
  memset(p, 1, sizeof(p));
  p[0] = p[1] = 0;
  for (int i = 0; i < 50001; i++) {
    if (p[i]) {
      for (int j = 2 * i; j < 50001; j += i) {
        p[j] = 0;
      }
    }
  }

  int n, sum;
  while (cin >> n, n) {
    int cnt = 0;
    for (int i = 0; i <= n / 2; i++) {
      if (p[i] == 1 && p[n - i] == 1)
        cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00056 (C++)

Buggy submission (status: Runtime Error):
#include <bitset>
#include <stdio.h>
int main() {
  const int N = 5001;
  int i, j, n, c;
  std::bitset<N> p(3);
  p.flip();
  for (i = 2; i * i < N; ++i)
    if (p[i])
      for (j = i * 2; j < N; j += i)
        p[j] = 0;
  while (scanf("%d", &n), n) {
    for (c = i = 0, j = n; i <= j; ++i, --j)
      if (p[i] && p[j])
        ++c;
    printf("%d\n", c);
  }
  return 0;
}

Fixed submission:
#include <bitset>
#include <stdio.h>
int main() {
  const int N = 50001;
  int i, j, n, c;
  std::bitset<N> p(3);
  p.flip();
  for (i = 2; i * i < N; ++i)
    if (p[i])
      for (j = i * 2; j < N; j += i)
        p[j] = 0;
  while (scanf("%d", &n), n) {
    for (c = i = 0, j = n; i <= j; ++i, --j)
      if (p[i] && p[j])
        ++c;
    printf("%d\n", c);
  }
  return 0;
}
Problem p00056 (C++)

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

using namespace std;

const int MAX = 1000100;
bool prime[MAX];

void sieve() {
  fill(prime, prime + MAX, true);
  prime[0] = prime[1] = false;

  for (int i = 2; i * i < MAX; i++) {
    if (!prime[i])
      continue;
    for (int j = i * i; j < MAX; j += i)
      prime[j] = false;
  }
}

int main() {
  sieve();
  int n;
  while (cin >> n, n) {
    int ret = 0;
    for (int i = 0; i < n; i++)
      for (int j = i; j < n; j++)
        if (prime[i] && prime[j] && i + j == n)
          ret++;
    cout << ret << endl;
  }
}

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

using namespace std;

const int MAX = 1000100;
bool prime[MAX];

void sieve() {
  fill(prime, prime + MAX, true);
  prime[0] = prime[1] = false;

  for (int i = 2; i * i < MAX; i++) {
    if (!prime[i])
      continue;
    for (int j = i * i; j < MAX; j += i)
      prime[j] = false;
  }
}

int main() {
  sieve();
  int n;
  while (cin >> n, n) {
    int ret = 0;
    for (int i = 0; i <= n / 2; i++)
      if (prime[i] && prime[n - i]) {
        ret++;
      }
    cout << ret << endl;
  }
}
Problem p00056 (C++)

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

using namespace std;

const int MAX = 1000100;
bool prime[MAX];

void sieve() {
  fill(prime, prime + MAX, true);
  prime[0] = prime[1] = false;

  for (int i = 2; i * i < MAX; i++) {
    if (!prime[i])
      continue;
    for (int j = i * i; j < MAX; j += i)
      prime[j] = false;
  }
}

int main() {
  sieve();
  int n;
  while (cin >> n, n) {
    int ret = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++)
        if (prime[i] && prime[j] && i + j == n)
          ret++;
    }
    cout << ret << endl;
  }
}

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

using namespace std;

const int MAX = 1000100;
bool prime[MAX];

void sieve() {
  fill(prime, prime + MAX, true);
  prime[0] = prime[1] = false;

  for (int i = 2; i * i < MAX; i++) {
    if (!prime[i])
      continue;
    for (int j = i * i; j < MAX; j += i)
      prime[j] = false;
  }
}

int main() {
  sieve();
  int n;
  while (cin >> n, n) {
    int ret = 0;
    for (int i = 0; i <= n / 2; i++) {
      if (prime[i] && prime[n - i])
        ret++;
    }
    cout << ret << endl;
  }
}
Problem p00056 (C++)

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

using namespace std;

const int max_lim = 50001;
bool prime[max_lim];

void init() {
  for (int i = 0; i < max_lim; i++)
    prime[i] = true;
  prime[0] = prime[1] = false;

  for (int i = 2; i * i < max_lim; i++)
    for (int j = 2 * i; j < max_lim; j += i)
      prime[j] = false;
}

int main() {
  int n;

  init();
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 2; i <= n; i++)
      for (int j = i; j <= n; j++)
        if (i + j == n && prime[i] && prime[j])
          ans++;
    cout << ans << endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

const int max_lim = 50001;
bool prime[max_lim];

void init() {
  for (int i = 0; i < max_lim; i++)
    prime[i] = true;
  prime[0] = prime[1] = false;

  for (int i = 2; i * i < max_lim; i++)
    for (int j = 2 * i; j < max_lim; j += i)
      prime[j] = false;
}

int main() {
  int n;

  init();
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 2; 2 * i <= n; i++)
      if (n - i > 0 && prime[i] && prime[n - i])
        ans++;
    cout << ans << endl;
  }

  return 0;
}
Problem p00056 (C++)

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

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 1000000
#define pb push_back

using namespace std;

int prime[MAX];

int main() {
  prime[0] = prime[1] = 0;

  REP(i, 2, MAX) { prime[i] = 1; }

  REP(i, 2, MAX) {
    if (prime[i]) {
      for (int j = i * 2; j < MAX; j += i) {
        prime[j] = 0;
      }
    }
  }

  int n;
  while (cin >> n && n) {
    int count = 0;
    vector<int> a;
    rep(i, n) {
      rep(j, n) {
        if (prime[i] == 1 && prime[j] == 1 && i + j == n) {
          if (a.empty()) {
            a.pb(i);
            a.pb(j);
            count++;
          } else {
            vector<int>::iterator ite = find(a.begin(), a.end(), i);
            vector<int>::iterator ite2 = find(a.begin(), a.end(), j);

            if (ite == a.end() && ite == a.end()) {
              a.pb(i);
              a.pb(j);
              count++;
            }
          }
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}

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

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 1000000
#define pb push_back

using namespace std;

int prime[MAX];

int main() {
  prime[0] = prime[1] = 0;

  REP(i, 2, MAX) { prime[i] = 1; }

  REP(i, 2, MAX) {
    if (prime[i]) {
      for (int j = i * 2; j < MAX; j += i) {
        prime[j] = 0;
      }
    }
  }

  int n;
  while (cin >> n && n) {
    int count = 0;
    rep(i, (n / 2) + 1) {
      if (prime[i] == 1 && prime[n - i] == 1) {
        count++;
      }
    }
    cout << count << endl;
  }
  return 0;
}
Problem p00056 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
#define MAX 50004
#define MAXL 3000
int dp[MAX], d[MAX];

int main() {
  int n, m = 0;
  static bool c[MAX] = {true, true};
  for (int i = 2; m < MAXL; i++) {
    if (!c[i]) {
      for (int j = 2; i * j < MAX; j++)
        c[i * j] = true;
      d[m++] = i;
    }
  }

  for (int i = 0; i < MAXL; i++)
    for (int j = i; d[i] + d[j] < MAX - 3; j++)
      dp[d[i] + d[j]]++;
  while (cin >> n, n)
    cout << dp[n] << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
#define MAX 50004
#define MAXL 3000
int dp[MAX], d[MAX];

int main() {
  int n, m = 0;
  static bool c[MAX] = {true, true};
  for (int i = 2; i < MAX; i++) {
    if (!c[i]) {
      for (int j = 2; i * j < MAX; j++)
        c[i * j] = true;
      d[m++] = i;
    }
  }

  for (int i = 0; i < MAXL; i++)
    for (int j = i; d[i] + d[j] < MAX - 3; j++)
      dp[d[i] + d[j]]++;
  while (cin >> n, n)
    cout << dp[n] << endl;
  return 0;
}
Problem p00057 (C++)

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

using namespace std;

int keisan(int a) {
  if (a == 1) {
    return 2;
  } else {
    return a + keisan(a - 1);
  }
}

int main() {
  int n;
  while (1) {
    cin >> n;
    cout << keisan(n) << endl;
  }
  return 0;
}

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

using namespace std;

int keisan(int a) {
  if (a == 1) {
    return 2;
  } else {
    return a + keisan(a - 1);
  }
}

int main() {
  int n;
  while (cin >> n) {
    cout << keisan(n) << endl;
  }
  return 0;
}
Problem p00057 (C++)

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

using namespace std;

int main(void) {
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    cout << 1 + n * (n + 1) / 2 << endl;
  }
}

Fixed submission:
#include <iostream>

using namespace std;

int main(void) {
  while (1) {
    int n;
    if (!(cin >> n))
      break;
    cout << 1 + n * (n + 1) / 2 << endl;
  }
}
Problem p00057 (C++)

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

using namespace std;

typedef long long ll;

int main() {
  vector<ll> vec;
  vec[0] = 1;
  for (int i = 1; i <= 10000; i++) {
    vec[i] = vec[i - 1] + i;
  }
  int n;
  while (cin >> n) {
    cout << vec[n] << endl;
  }
  return 0;
}
// int main(){
//      int n;
//      while(cin >> n){
//          cout << n*(n-1)/2 +1 << endl;
//      }
//      return 0;
// }

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

using namespace std;

typedef long long ll;

int main() {
  vector<ll> vec(10001);
  vec[0] = 1;
  for (int i = 1; i <= 10000; i++) {
    vec[i] = vec[i - 1] + i;
  }
  int n;
  while (cin >> n) {
    cout << vec[n] << endl;
  }
  return 0;
}
// int main(){
//      int n;
//      while(cin >> n){
//          cout << n*(n-1)/2 +1 << endl;
//      }
//      return 0;
// }
Problem p00057 (C++)

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

int heimen(int nn) {
  int a;
  a = ((nn * nn) + nn + 2) / 2;
  return a;
}
using namespace std;

int main() {
  int n, ans;
  while (cin >> n, n) {
    ans = heimen(n);
    cout << ans << endl;
  }
}

Fixed submission:
#include <iostream>

int heimen(int nn) {
  int a;
  a = ((nn * nn) + nn + 2) / 2;
  return a;
}
using namespace std;

int main() {
  int n, ans;
  while (cin >> n) {
    ans = heimen(n);
    cout << ans << endl;
  }
}
Problem p00058 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
int main() {
  float xA, yA, xB, yB, xC, yC, xD, yD;
  while (scanf("%f%f%f%f%f%f%f%f", xA, yA, xB, yB, xC, yC, xD, yD) != EOF) {
    if ((xA == xB && yC == yD) || (yA == yB && xC == xD)) {
      puts("YES");
      continue;
    } else if (xA == xB || yC == yD || yA == yB || xC == xD) {
      puts("NO");
      continue;
    }
    double AB = (yA - yB) / (xA - xB);
    double CD = (yC - yD) / (xC - xD);
    if (-1 * AB == CD) {
      puts("YES");
    } else {
      puts("NO");
    }
  }
}

Fixed submission:
#include <cstdio>
int main() {
  double xA, yA, xB, yB, xC, yC, xD, yD;
  while (scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &xA, &yA, &xB, &yB, &xC, &yC, &xD,
               &yD) != EOF) {
    if ((xA - xB) * (xC - xD) + (yA - yB) * (yC - yD) == 0) {
      puts("YES");
    } else {
      puts("NO");
    }
  }
}
Problem p00058 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int inf = 1e9;

int main() {

  vector<double> x(4);
  vector<double> y(4);
  while (cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> x[3] >> y[3]) {
    double ax = x[1] - x[0];
    double ay = y[1] - y[0];
    double bx = x[3] - x[2];
    double by = y[3] - y[2];
    cerr << ax * bx + ay * by << endl;
    if (ax * bx + ay * by < 1e-10) {
      cout << "YES" << endl;
    } else
      cout << "NO" << endl;
  }

  return 0;
}

// EOF

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int inf = 1e9;

int main() {

  vector<double> x(4);
  vector<double> y(4);
  while (cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> x[3] >> y[3]) {
    double ax = x[1] - x[0];
    double ay = y[1] - y[0];
    double bx = x[3] - x[2];
    double by = y[3] - y[2];
    if (fabs(ax * bx + ay * by) < 1e-10) {
      cout << "YES" << endl;
    } else
      cout << "NO" << endl;
  }

  return 0;
}

// EOF
Problem p00059 (C++)

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

typedef complex<double> P;

int main(void) {
  P p[4];
  while (1) {
    rep(i, 4) {
      double x, y;
      cin >> x >> y;
      p[i] = {x, y};
    }
    bool ok = true;
    if (p[1].real() < p[2].real())
      ok = false;
    if (p[3].real() < p[0].real())
      ok = false;
    if (p[1].imag() < p[2].imag())
      ok = false;
    if (p[3].imag() < p[0].imag())
      ok = false;
    if (ok)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}

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

typedef complex<double> P;

int main(void) {
  P p[4];
  while (1) {
    rep(i, 4) {
      double x, y;
      cin >> x >> y;
      p[i] = {x, y};
    }
    if (cin.eof())
      break;
    bool ok = true;
    if (p[1].real() < p[2].real())
      ok = false;
    if (p[3].real() < p[0].real())
      ok = false;
    if (p[1].imag() < p[2].imag())
      ok = false;
    if (p[3].imag() < p[0].imag())
      ok = false;
    if (ok)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
Problem p00059 (C++)

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

using namespace std;

typedef struct {
  double x, y;
} _z;

int main() {

  _z p[4];

  while (1) {
    for (int i = 0; i < 4; i++) {
      cin >> p[i].x >> p[i].y;
    }

    if (p[3].x < p[0].x || p[2].x > p[1].x || p[2].y > p[1].y ||
        p[3].y < p[0].y) {
      cout << "NO" << endl;
    } else
      cout << "YES" << endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

typedef struct {
  double x, y;
} _z;

int main() {

  _z p[4];

  while (cin >> p[0].x >> p[0].y) {
    for (int i = 1; i < 4; i++) {
      cin >> p[i].x >> p[i].y;
    }

    if (p[3].x < p[0].x || p[2].x > p[1].x || p[2].y > p[1].y ||
        p[3].y < p[0].y) {
      cout << "NO" << endl;
    } else
      cout << "YES" << endl;
  }

  return 0;
}
Problem p00060 (C++)

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

int main(void) {
  char buf;
  int buf_cnt = 0;
  int c[3];
  int my_cards;
  int ok = 0;
  int cnt = 0;
  double probability;
  for (int i = 0; i < 3; i++) {
    c[i] = 0;
  }

  while ((buf = getchar()) != EOF) {
    if (buf >= '0' && buf <= '9') {
      buf -= '0';
      c[buf_cnt] = c[buf_cnt] * 10 + buf;
      continue;
    } else if (buf != '\n') {
      if (c[buf_cnt] != 0) {
        buf_cnt++;
        continue;
      } else if (buf_cnt < 3) {
        continue;
      }
    } else {
      if (c[2] == 0) {
        for (int i = 0; i < 3; i++) {
          c[i] = 0;
        }
        continue;
      }
    }

    my_cards = c[0] + c[1];

    for (int i = 1; i <= 10; i++) {
      // c[0],2,c3??¨?¢??????´???????????????
      if (i == c[0] || i == c[1] || i == c[2]) {
        continue;
      }

      if (my_cards + i <= 20) {
        ok++;
      }
      cnt++;
    }
    probability = (double)ok / (double)cnt;

    if (probability >= 0.5) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
    for (int i = 0; i < 3; i++) {
      c[i] = 0;
    }
    ok = 0;
    cnt = 0;
    buf_cnt = 0;
    rewind(stdin);
  }

  return 0;
}

Fixed submission:
#include <stdio.h>

int main(void) {
  char buf;
  int buf_cnt = 0;
  int c[3];
  int my_cards;
  int ok = 0;
  int cnt = 0;
  double probability;
  for (int i = 0; i < 3; i++) {
    c[i] = 0;
  }

  while ((buf = getchar()) != EOF) {
    if (buf >= '0' && buf <= '9') {
      buf -= '0';
      c[buf_cnt] = c[buf_cnt] * 10 + buf;
      continue;
    } else if (buf != '\n') {
      if (c[buf_cnt] != 0) {
        buf_cnt++;
        continue;
      } else if (buf_cnt < 3) {
        continue;
      }
    } else {
      if (c[2] == 0) {
        for (int i = 0; i < 3; i++) {
          c[i] = 0;
        }
        continue;
      }
    }

    my_cards = c[0] + c[1];

    for (int i = 1; i <= 10; i++) {
      // c[0],2,c3??¨?¢??????´???????????????
      if (i == c[0] || i == c[1] || i == c[2]) {
        continue;
      }

      if (my_cards + i <= 20) {
        ok++;
      }
      cnt++;
    }
    probability = (double)ok / (double)cnt;

    if (probability >= 0.5) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
    for (int i = 0; i < 3; i++) {
      c[i] = 0;
    }
    ok = 0;
    cnt = 0;
    buf_cnt = 0;
  }

  return 0;
}
Problem p00061 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;

int main() {
  int number, suu, in;
  // result = 整理番号と正解数の対応
  map<int, int> result;
  // rank = 順位表   need to include <functional>
  set<int, greater<int>> rank;

  while (scanf("%d,%d", &number, &suu), number && suu) {
    result.insert(std::pair<int, int>(number, suu));
    rank.insert(suu);
  }
  while (cin >> in, !cin.eof()) {
    // 整理番号が入力されるのでresultで正解数調べてrankを参照する.

    int place = 0;
    set<int>::iterator it = rank.begin();
    // set<int> rank; のときに
    //   set<int>::reverse_iretator it = rank.rbegin();とする方法もある.

    int thisSuu = result[in];
    // mapは[]使える. 以下は[]じゃなくiterator使う方法.
    // map<int, int>::iterator it_map = result.find(in);
    // int thisSuu = (*it_map).second;

    while (it != rank.end()) {
      place++;
      if (thisSuu == *it) {
        cout << place << endl;
        break;
      }
      it++;
    }
  }
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;

int main() {
  int number, suu, in;
  // result = 整理番号と正解数の対応
  map<int, int> result;
  // rank = 順位表   need to include <functional>
  set<int, greater<int>> rank;

  while (scanf("%d,%d", &number, &suu), number || suu) {
    result.insert(std::pair<int, int>(number, suu));
    rank.insert(suu);
  }
  while (cin >> in, !cin.eof()) {
    // 整理番号が入力されるのでresultで正解数調べてrankを参照する.

    int place = 0;
    set<int>::iterator it = rank.begin();
    // set<int> rank; のときに
    //   set<int>::reverse_iretator it = rank.rbegin();とする方法もある.

    int thisSuu = result[in];
    // mapは[]使える. 以下は[]じゃなくiterator使う方法.
    // map<int, int>::iterator it_map = result.find(in);
    // int thisSuu = (*it_map).second;

    while (it != rank.end()) {
      place++;
      if (thisSuu == *it) {
        cout << place << endl;
        break;
      }
      it++;
    }
  }
  return 0;
}
Problem p00061 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
  map<int, int> M;
  vector<pair<int, int>> V;
  int a, b;
  while (scanf("%d,%d", &a, &b), a && b) {
    V.push_back(make_pair(b, a));
  }
  sort(V.begin(), V.end());
  reverse(V.begin(), V.end());
  int buf = 100, cnt = 0;
  for (int i = 0; i < V.size(); i++) {
    if (buf > V[i].first) {
      buf = V[i].first;
      cnt++;
    }
    M[buf] = cnt;
  }
  int n;
  while (cin >> n) {
    int p;
    for (int j = 0; j < V.size(); j++) {
      if (V[j].second == n) {
        p = j;
        break;
      }
    }
    cout << M[V[p].first] << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
  map<int, int> M;
  vector<pair<int, int>> V;
  int a, b;
  while (scanf("%d,%d", &a, &b), a || b) {
    V.push_back(make_pair(b, a));
  }
  sort(V.begin(), V.end());
  reverse(V.begin(), V.end());
  int buf = 100, cnt = 0;
  for (int i = 0; i < V.size(); i++) {
    if (buf > V[i].first) {
      buf = V[i].first;
      cnt++;
    }
    M[buf] = cnt;
  }
  int n;
  while (cin >> n) {
    int p;
    for (int j = 0; j < V.size(); j++) {
      if (V[j].second == n) {
        p = j;
        break;
      }
    }
    cout << M[V[p].first] << endl;
  }
}
Problem p00061 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int a, b, x[1000], y[1000], p, sum, ok;
char c;
int main() {
  while (cin >> a >> c >> b) {
    if (a + b == 0) {
      break;
    }
    x[a] = b;
    p++;
  }
  sum = 1;
  for (int i = 30; i >= 0; i++) {
    ok = 0;
    for (int j = 1; j <= p; j++) {
      if (x[j] == i) {
        y[j] = sum;
        ok = 1;
      }
    }
    if (ok) {
      sum++;
    }
  }
  while (cin >> a) {
    cout << y[a] << endl;
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int a, b, x[1000], y[1000], p, sum, ok;
char c;
int main() {
  while (cin >> a >> c >> b) {
    if (a + b == 0) {
      break;
    }
    x[a] = b;
    p++;
  }
  sum = 1;
  for (int i = 30; i >= 0; i--) {
    ok = 0;
    for (int j = 1; j <= p; j++) {
      if (x[j] == i) {
        y[j] = sum;
        ok = 1;
      }
    }
    if (ok) {
      sum++;
    }
  }
  while (cin >> a) {
    cout << y[a] << endl;
  }
}
Problem p00061 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  pair<int, int> a[1000];
  int c = 0, t[1000];
  char cc;
  while (1) {
    scanf("%d,%d", &a[c].second, &a[c].first);
    c++;
    if (a[c - 1].first == 0 && a[c - 1].second == 0)
      goto L;
  }
L:
  c--;
  stable_sort(a, a + c);
  int r = 1;
  t[a[c - 1].second] = 1;
  for (int i = c - 2; i >= 0; i--) {
    if (a[i + 1].first != a[i].first) {
      t[a[i].second] = (++r);
    } else {
      t[a[i].second] = r;
    }
  }
  while (cin >> c, c)
    cout << t[c] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  pair<int, int> a[1000];
  int c = 0, t[1000];
  char cc;
  while (1) {
    scanf("%d,%d", &a[c].second, &a[c].first);
    c++;
    if (a[c - 1].first == 0 && a[c - 1].second == 0)
      goto L;
  }
L:
  c--;
  stable_sort(a, a + c);
  int r = 1;
  t[a[c - 1].second] = 1;
  for (int i = c - 2; i >= 0; i--) {
    if (a[i + 1].first != a[i].first) {
      t[a[i].second] = (++r);
    } else {
      t[a[i].second] = r;
    }
  }
  while (cin >> c)
    cout << t[c] << endl;
}
Problem p00061 (C++)

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

int main() {
  int id, num;
  map<int, int> m;
  vector<int> v;
  while (1) {
    scanf("%d,%d", &id, &num);
    if (id | num)
      ;
    else
      break;
    m[id] = num;
    v.push_back(-num);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  while (scanf("%d", &id)) {
    cout << lower_bound(v.begin(), v.end(), -m[id]) - v.begin() + 1 << endl;
  }
  return 0;
}

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

int main() {
  int id, num;
  map<int, int> m;
  vector<int> v;
  while (1) {
    scanf("%d,%d", &id, &num);
    if (id | num)
      ;
    else
      break;
    m[id] = num;
    v.push_back(-num);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  while (scanf("%d", &id) != EOF) {
    cout << lower_bound(v.begin(), v.end(), -m[id]) - v.begin() + 1 << endl;
  }
  return 0;
}