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

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

#define MAX 10000000
int a[MAX];

int main() {
  int n;
  a[0] = a[1] = 0;
  a[2] = 1;
  a[3] = 2;
  for (int i = 4; i < MAX; i++) {
    bool ok = true;
    for (int j = 2; j < sqrt(i) + 0.1; j++) {
      if (i % j == 0) {
        a[i] = a[i - 1];
        ok = false;
        break;
      }
    }
    if (ok)
      a[i] = a[i - 1] + 1;
  }

  while (cin >> n)
    cout << a[n] << endl;

  return 0;
}

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

#define MAX 1000000
int a[MAX];

int main() {
  int n;
  a[0] = a[1] = 0;
  a[2] = 1;
  a[3] = 2;
  for (int i = 4; i < MAX; i++) {
    bool ok = true;
    for (int j = 2; j < sqrt(i) + 0.1; j++) {
      if (i % j == 0) {
        a[i] = a[i - 1];
        ok = false;
        break;
      }
    }
    if (ok)
      a[i] = a[i - 1] + 1;
  }

  while (cin >> n)
    cout << a[n] << endl;

  return 0;
}
Problem p00009 (C++)

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

using namespace std;

int main() {
  int n;

  while (cin >> n) {
    bool *isPrime = new bool[n + 1];
    isPrime[0] = false;
    isPrime[1] = false;
    for (int i = 2; i < n + 1; i++) {
      isPrime[i] = true;
    }
    for (int i = 2; i <= (int)sqrt(n); i++) {
      if (isPrime[i]) {
        for (int j = i + 1; j <= n; j++) {
          if (isPrime[j]) {
            if (!(j % i)) {
              isPrime[j] = false;
            }
          }
        }
      }
    }
    int ans = 0;
    for (int i = 2; i <= n; i++) {
      if (isPrime[i]) {
        ans++;
      }
    }
    cout << ans << endl;
    delete[] isPrime;
  }

  return 0;
}

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

using namespace std;

int main() {
  int n;

  while (cin >> n) {
    bool *isPrime = new bool[n + 1];
    isPrime[0] = false;
    isPrime[1] = false;
    for (int i = 2; i < n + 1; i++) {
      isPrime[i] = true;
    }
    for (int i = 2; i <= (int)sqrt(n); i++) {
      if (isPrime[i]) {
        for (int j = 2; j <= n / i; j++) {
          isPrime[i * j] = false;
        }
      }
    }
    int ans = 0;
    for (int i = 2; i <= n; i++) {
      if (isPrime[i]) {
        ans++;
      }
    }
    cout << ans << endl;
    delete[] isPrime;
  }

  return 0;
}
Problem p00009 (C++)

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

using namespace std;

int main() {
  int n;
  int nums[100000] = {0};
  while (cin >> n) {
    int count = 0;
    int qf = 0;
    int qe = 0;
    for (int i = 2; i <= n; i++) {
      bool f = false;
      for (int qe = 0; qe < qf; qe++) {
        if (i % nums[qe] == 0) {
          f = true;
          break;
        }
      }
      if (!f) {
        count++;
        nums[qf] = i;
        qf++;
      }
    }
    cout << count << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main() {
  int n;
  int nums[100000] = {0};
  while (cin >> n) {
    int count = 0;
    int qf = 0;
    int qe = 0;
    for (int i = 2; i <= n; i++) {
      bool f = false;
      for (int qe = 0; qe < qf; qe++) {
        if (i < nums[qe] * nums[qe])
          break;
        if (i % nums[qe] == 0) {
          f = true;
          break;
        }
      }
      if (!f) {
        count++;
        nums[qf] = i;
        qf++;
      }
    }
    cout << count << endl;
  }
  return 0;
}
Problem p00009 (C++)

Buggy submission (status: Time Limit Exceeded):
//
//  main.cpp
//  CppTest
//
//  Created by Ryu on 2017/02/08.
//  Copyright ?? 2017??´ Ryu. All rights reserved.
//

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;

int main(int argc, const char *argv[]) {
  // insert code here...
  cin.tie(0);
  ios::sync_with_stdio(false);

  long in[30];
  long out[30];
  int n = 0;
  long max = 0;
  while (cin >> in[n]) {
    if (max < in[n]) {
      max = in[n];
    }
    n++;
  }
  // printf("%d", n);

  long p[100000];
  p[0] = 2;
  int m = 1;
  for (int i = 3; i <= max; i += 2) {
    bool prime = true;
    for (int j = 0; j < m; j++) {
      if (i % p[j] == 0) {
        prime = false;
        break;
      }
      if (i / 5 < p[j]) {
        break;
      }
    }
    if (prime) {
      p[m] = i;
      // printf("%ld\n", p[m]);
      m++;
    }
  }

  for (int i = 0; i < n; i++) {
    int s = 0;
    while (in[i] >= p[s] && p[s] != 0) {
      // printf("in: %ld, p: %ld\n", in[i], p[s]);
      s++;
    }
    out[i] = s;
    printf("%ld\n", out[i]);
  }

  return 0;
}

Fixed submission:
//
//  main.cpp
//  CppTest
//
//  Created by Ryu on 2017/02/08.
//  Copyright ?? 2017??´ Ryu. All rights reserved.
//

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;

int main(int argc, const char *argv[]) {
  // insert code here...
  cin.tie(0);
  ios::sync_with_stdio(false);

  long in[30];
  long out[30];
  int n = 0;
  long max = 0;
  while (cin >> in[n]) {
    if (max < in[n]) {
      max = in[n];
    }
    n++;
  }
  // printf("%d", n);

  long p[100000];
  p[0] = 2;
  int m = 1;
  for (int i = 3; i <= max; i += 2) {
    bool prime = true;
    for (int j = 0; j < m; j++) {
      if (i % p[j] == 0) {
        prime = false;
        break;
      }
      if (i < pow(p[j], 2)) {
        break;
      }
    }
    if (prime) {
      p[m] = i;
      // printf("%ld\n", p[m]);
      m++;
    }
  }

  for (int i = 0; i < n; i++) {
    int s = 0;
    while (in[i] >= p[s] && p[s] != 0) {
      // printf("in: %ld, p: %ld\n", in[i], p[s]);
      s++;
    }
    out[i] = s;
    printf("%ld\n", out[i]);
  }

  return 0;
}
Problem p00009 (C++)

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

int main() {
  vector<bool> hantei(1000000, true);
  vector<int> sosuu(1000000);
  int s = 0;
  for (int a = 2; a < 1000000; a++) {
    if (hantei[a]) {
      s++;
      for (int b = a * 2; b < 1000000; b += a)
        hantei[b] = false;
    }
    sosuu[a] = s;
  }
  int c;
  while (cin >> c, c) {
    cout << sosuu[c] << endl;
  }
}

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

int main() {
  vector<bool> hantei(1000000, true);
  vector<int> sosuu(1000000);
  int s = 0;
  for (int a = 2; a < 1000000; a++) {
    if (hantei[a]) {
      s++;
      for (int b = a * 2; b < 1000000; b += a)
        hantei[b] = false;
    }
    sosuu[a] = s;
  }
  int c;
  while (cin >> c) {
    cout << sosuu[c] << endl;
  }
}
Problem p00009 (C++)

Buggy submission (status: Runtime Error):
// AOJ 009

#include <iostream>
#define MAX_NUMBER 50 // 1000000
using namespace std;

bool isPrime[MAX_NUMBER];

void SetFalseToMultiples(int prime) {
  for (int i = prime * 2; i < MAX_NUMBER; i += prime) {
    isPrime[i] = false;
  }
  return;
}

int CountPrimes(int n) {
  int count = 0;
  for (int i = 1; i <= n; i++) {
    if (isPrime[i])
      count++;
  }
  return count;
}

int main() {
  for (int i = 0; i < MAX_NUMBER; i++) {
    isPrime[i] = true;
  }
  isPrime[1] = false;

  for (int i = 1; i < MAX_NUMBER; i++) {
    if (isPrime[i]) {
      SetFalseToMultiples(i);
    }
  }
  int n;
  while (cin >> n) {
    cout << CountPrimes(n) << endl;
  }
  return 0;
}

Fixed submission:
// AOJ 009

#include <iostream>
#define MAX_NUMBER 1000000
using namespace std;

bool isPrime[MAX_NUMBER];

void SetFalseToMultiples(int prime) {
  for (int i = prime * 2; i < MAX_NUMBER; i += prime) {
    isPrime[i] = false;
  }
  return;
}

int CountPrimes(int n) {
  int count = 0;
  for (int i = 1; i <= n; i++) {
    if (isPrime[i])
      count++;
  }
  return count;
}

int main() {
  for (int i = 0; i < MAX_NUMBER; i++) {
    isPrime[i] = true;
  }
  isPrime[1] = false;

  for (int i = 1; i < MAX_NUMBER; i++) {
    if (isPrime[i]) {
      SetFalseToMultiples(i);
    }
  }
  int n;
  while (cin >> n) {
    cout << CountPrimes(n) << endl;
  }
  return 0;
}
Problem p00009 (C++)

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

const int MAX_V = 100000;
int prime[MAX_V + 1];

void init() {
  int i, k, v;
  for (i = 2; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for (i = 2; i * i <= MAX_V; i++) {
    if (prime[i]) {
      for (k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
  }
}

int isprime(int n) { return prime[n]; }

int main() {
  init();
  int num;
  while (scanf("%d", &num) != EOF) {
    int count = 0;
    for (int i = 2; i <= num; i++) {
      if (isprime(i) == 1)
        count++;
    }
    printf("%d\n", count);
  }
  return 0;
}

Fixed submission:
#include <stdio.h>

const int MAX_V = 1000000;
int prime[MAX_V + 1];

void init() {
  int i, k, v;
  for (i = 2; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for (i = 2; i * i <= MAX_V; i++) {
    if (prime[i]) {
      for (k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
  }
}

int isprime(int n) { return prime[n]; }

int main() {
  init();
  int num;
  while (scanf("%d", &num) != EOF) {
    int count = 0;
    for (int i = 2; i <= num; i++) {
      if (isprime(i) == 1)
        count++;
    }
    printf("%d\n", count);
  }
  return 0;
}
Problem p00010 (C++)

Buggy submission (status: Runtime Error):
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
typedef pair<double, double> PDD;
PDD calc(double mat[2][2], double vec[2]) {
  double a = mat[0][0], b = mat[0][1], d = mat[1][0], e = mat[1][1];
  double c = vec[0], f = vec[1];
  double det = a * e - d * b;
  return make_pair((e * c - b * f) / det, (-c * d + a * f) / det);
}
int main() {
  int Tc;
  cin >> Tc;
  for (int tc = 0; tc < Tc; ++tc) {
    double x1, y1, x2, y2, x3, y3;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    double A, B, C, D, E, F;
    A = (y1 + y3) / 2.;
    B = (x1 - x3) / (y1 - y3);
    C = (x1 + x3) / 2.;
    D = (y2 + y3) / 2.;
    E = (x2 - x3) / (y2 - y3);
    F = (x2 + x3) / 2.;
    double mat[2][2];
    mat[0][0] = B;
    mat[0][1] = 1;
    mat[1][0] = E;
    mat[1][1] = 1;
    double vec[2];
    vec[0] = A + B * C;
    vec[1] = D + E * F;
    PDD res = calc(mat, vec);
    double x = res.first, y = res.second;
    assert(x == x);
    assert(y == y);
    double r = pow((x - x1) * (x - x1) + (y - y1) * (y - y1), 0.5);
    x = (double)(round(x * 1000)) / 1000.0;
    y = (double)(round(y * 1000)) / 1000.0;
    r = (double)(round(r * 1000)) / 1000.0;
    x = (x == -0.0) ? 0.0 : x;
    y = (y == -0.0) ? 0.0 : y;
    printf("%.3f %.3f %.3f\n", x, y, r);
  }
  return 0;
}

Fixed submission:
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
typedef pair<double, double> PDD;
PDD calc(double mat[2][2], double vec[2]) {
  double a = mat[0][0], b = mat[0][1], d = mat[1][0], e = mat[1][1];
  double c = vec[0], f = vec[1];
  double det = a * e - d * b;
  return make_pair((e * c - b * f) / det, (-c * d + a * f) / det);
}
int main() {
  int Tc;
  cin >> Tc;
  for (int tc = 0; tc < Tc; ++tc) {
    double x1, y1, x2, y2, x3, y3;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    if (y1 - y3 == 0) {
      swap(y2, y3);
      swap(x2, x3);
    } else if (y2 - y3 == 0) {
      swap(y1, y3);
      swap(x1, x3);
    }
    double A, B, C, D, E, F;
    A = (y1 + y3) / 2.;
    B = (x1 - x3) / (y1 - y3);
    C = (x1 + x3) / 2.;
    D = (y2 + y3) / 2.;
    E = (x2 - x3) / (y2 - y3);
    F = (x2 + x3) / 2.;
    double mat[2][2];
    mat[0][0] = B;
    mat[0][1] = 1;
    mat[1][0] = E;
    mat[1][1] = 1;
    double vec[2];
    vec[0] = A + B * C;
    vec[1] = D + E * F;
    PDD res = calc(mat, vec);
    double x = res.first, y = res.second;
    assert(x == x);
    assert(y == y);
    double r = pow((x - x1) * (x - x1) + (y - y1) * (y - y1), 0.5);
    x = (double)(round(x * 1000)) / 1000.0;
    y = (double)(round(y * 1000)) / 1000.0;
    r = (double)(round(r * 1000)) / 1000.0;
    x = (x == -0.0) ? 0.0 : x;
    y = (y == -0.0) ? 0.0 : y;
    printf("%.3f %.3f %.3f\n", x, y, r);
  }
  return 0;
}
Problem p00010 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pb push_back

#define inOut(a, b)                                                            \
  freopen(a, "r", stdin);                                                      \
  freopen(b, "w", stdout);
#define RESET(a) memset(a, 0, sizeof(a))
#define MEMO(a) memset(a, -1, sizeof(a))
#define DEBUG puts("Debug-Has-Come-Until-Here")

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main() {
  cin.tie(NULL);

  double x1, x2, x3, y1, y2, y3;
  double a, b, c, d, e, f;
  double x, y;
  int dummy;

  scanf("%d", &dummy);
  while (scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3)) {
    a = -2 * x1 + 2 * x2;
    b = -2 * y1 + 2 * y2;
    c = (x2 * x2 - x1 * x1) + (y2 * y2 - y1 * y1);
    d = -2 * x2 + 2 * x3;
    e = -2 * y2 + 2 * y3;
    f = (x3 * x3 - x2 * x2) + (y3 * y3 - y2 * y2);

    x = (c * e - b * f) / (a * e - b * d);
    y = (c * d - a * f) / (b * d - e * a);
    printf("%.3lf %.3lf %.3lf\n", x, y,
           sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1)));
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pb push_back

#define inOut(a, b)                                                            \
  freopen(a, "r", stdin);                                                      \
  freopen(b, "w", stdout);
#define RESET(a) memset(a, 0, sizeof(a))
#define MEMO(a) memset(a, -1, sizeof(a))
#define DEBUG puts("Debug-Has-Come-Until-Here")

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main() {
  cin.tie(NULL);

  double x1, x2, x3, y1, y2, y3;
  double a, b, c, d, e, f;
  double x, y;
  int dummy;

  scanf("%d", &dummy);
  while (scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3) !=
         EOF) {
    a = -2 * x1 + 2 * x2;
    b = -2 * y1 + 2 * y2;
    c = (x2 * x2 - x1 * x1) + (y2 * y2 - y1 * y1);
    d = -2 * x2 + 2 * x3;
    e = -2 * y2 + 2 * y3;
    f = (x3 * x3 - x2 * x2) + (y3 * y3 - y2 * y2);

    x = (c * e - b * f) / (a * e - b * d);
    y = (c * d - a * f) / (b * d - e * a);
    printf("%.3lf %.3lf %.3lf\n", x, y,
           sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1)));
  }

  return 0;
}
Problem p00010 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <cstdio>
using namespace std;
int main() {
  int a;
  scanf("%d", &a);
  for (;; a--) {
    double a1, a2, b1, b2, c1, c2, x1, y1, x2, y2, x3, y3;
    double x, y, r;
    scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
    a1 = 2 * (x2 - x1), b1 = 2 * (y2 - y1);
    c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
    a2 = 2 * (x3 - x1), b2 = 2 * (y3 - y1);
    c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
    x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
    y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
    r = hypot(x - x1, y - y1);
    printf("%.3lf %.3lf %.3lf\n", x, y, r);
  }
  return 0;
}

Fixed submission:
#include <cmath>
#include <cstdio>
using namespace std;
int main() {
  int a;
  scanf("%d", &a);
  for (; a > 0; a--) {
    double a1, a2, b1, b2, c1, c2, x1, y1, x2, y2, x3, y3;
    double x, y, r;
    scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
    a1 = 2 * (x2 - x1), b1 = 2 * (y2 - y1);
    c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
    a2 = 2 * (x3 - x1), b2 = 2 * (y3 - y1);
    c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
    x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
    y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
    r = hypot(x - x1, y - y1);
    printf("%.3lf %.3lf %.3lf\n", x, y, r);
  }
  return 0;
}
Problem p00011 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdio.h>
#include <vector>
int main() {
  int w;
  std::cin >> w;
  std::vector<int> a(w);
  for (int i = 1; i <= w; i++)
    a[i] = i;
  int n;
  std::cin >> n;
  while (n > 0) {
    int b, c;
    scanf("%d,%d", &b, &c);
    // std::cin>>b>>c;
    int d = a[b];
    a[b] = a[c];
    a[c] = d;
    n--;
  }
  for (int i = 1; i <= w; i++)
    std::cout << a[i] << std::endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <stdio.h>
#include <vector>
int main() {
  int w;
  std::cin >> w;
  std::vector<int> a(w + 1);
  for (int i = 1; i <= w; i++)
    a[i] = i;
  int n;
  std::cin >> n;
  while (n > 0) {
    int b, c;
    scanf("%d,%d", &b, &c);
    // std::cin>>b>>c;
    int d = a[b];
    a[b] = a[c];
    a[c] = d;
    n--;
  }
  for (int i = 1; i <= w; i++)
    std::cout << a[i] << std::endl;
  return 0;
}
Problem p00011 (C++)

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

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  int i, temp;
  int w, n, ai, bi;

  cin >> w;
  cin >> n;

  vector<int> amida;

  // initialize
  for (i = 0; i < w; i++) {
    amida.push_back(i + 1);
  }

  for (i = 0; i < n; i++) {
    scanf("%d,%d", &ai, &bi);

    // swap
    temp = amida.at(ai - 1);
    amida.at(ai - 1) = amida.at(bi - 1);
    amida.at(bi - 1) = temp;
  }

  for (i = 0; i < w; i++) {
    cout << amida.at(i) << endl;
  }

  return 0;
}

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

int main() {
  int i, temp;
  int w, n, ai, bi;

  cin >> w;
  cin >> n;

  vector<int> amida;

  // initialize
  for (i = 0; i < w; i++) {
    amida.push_back(i + 1);
  }

  for (i = 0; i < n; i++) {
    scanf("%d,%d", &ai, &bi);

    // swap
    temp = amida.at(ai - 1);
    amida.at(ai - 1) = amida.at(bi - 1);
    amida.at(bi - 1) = temp;
  }

  for (i = 0; i < w; i++) {
    cout << amida.at(i) << endl;
  }

  return 0;
}
Problem p00011 (C++)

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

int main(void) {
  int w, n, a[30][2], i, c, no, rs[5];

  scanf("%d%d", &w, &n);
  for (i = 0; n > i; i++) {
    scanf("%d", &a[i][0]);
    getchar();
    scanf("%d", &a[i][1]);
  }

  for (i = 1; w >= i; i++) {
    no = i;
    for (c = 0; n > c; c++) {
      if (a[c][0] == no)
        no = a[c][1];
      else if (a[c][1] == no)
        no = a[c][0];
    }
    rs[no - 1] = i;
  }
  for (i = 0; w > i; i++) {
    printf("%d\n", rs[i]);
  }

  return 0;
}

Fixed submission:
#include <stdio.h>

int main(void) {
  int w, n, a[30][2], i, c, no, rs[30];

  scanf("%d%d", &w, &n);
  for (i = 0; n > i; i++) {
    scanf("%d", &a[i][0]);
    getchar();
    scanf("%d", &a[i][1]);
  }

  for (i = 1; w >= i; i++) {
    no = i;
    for (c = 0; n > c; c++) {
      if (a[c][0] == no)
        no = a[c][1];
      else if (a[c][1] == no)
        no = a[c][0];
    }
    rs[no - 1] = i;
  }
  for (i = 0; w > i; i++) {
    printf("%d\n", rs[i]);
  }

  return 0;
}
Problem p00011 (C++)

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

using namespace std;
void lots(int len, int a, int b, int array[]) {
  int buffer[5];
  for (int i = 0; i < len; i++) {
    if (i == a - 1) {
      buffer[i] = array[b - 1];
    } else if (i == b - 1) {
      buffer[i] = array[a - 1];
    } else {
      buffer[i] = array[i];
    }
  }
  for (int i = 0; i < len; i++) {
    array[i] = buffer[i];
  }
}

int main() {
  int len, duration, a, b;
  cin >> len;
  cin >> duration;
  int array[len];
  for (int i = 0; i < len; i++) {
    array[i] = i + 1;
  }
  for (int i = 0; i < duration; i++) {
    scanf("%d,%d", &a, &b);
    lots(len, a, b, array);
  }
  for (int i = 0; i < len; i++) {
    cout << array[i] << endl;
  }
}

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

using namespace std;
void lots(int len, int a, int b, int array[]) {
  int buffer[len];
  for (int i = 0; i < len; i++) {
    if (i == a - 1) {
      buffer[i] = array[b - 1];
    } else if (i == b - 1) {
      buffer[i] = array[a - 1];
    } else {
      buffer[i] = array[i];
    }
  }
  for (int i = 0; i < len; i++) {
    array[i] = buffer[i];
  }
}

int main() {
  int len, duration, a, b;
  cin >> len;
  cin >> duration;
  int array[len];
  for (int i = 0; i < len; i++) {
    array[i] = i + 1;
  }
  for (int i = 0; i < duration; i++) {
    scanf("%d,%d", &a, &b);
    lots(len, a, b, array);
  }
  for (int i = 0; i < len; i++) {
    cout << array[i] << endl;
  }
}
Problem p00011 (C++)

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

#include <cstdio>

using namespace std;

int main() {
  int W, N, A[31], B[31], C[31];

  scanf("%d", W);
  scanf("%d", N);

  for (int i = 1; i <= N; i++) {
    scanf("%d,%d", &(A[i]), &(B[i]));
  }

  for (int i = 1; i <= W; i++) {
    int t = i;

    for (int j = 1; j <= N; j++) {
      if (A[j] == t) {
        t = B[j];
      } else if (B[j] == t) {
        t = A[j];
      }
    }

    C[t] = i;
  }

  for (int i = 1; i <= W; i++) {
    printf("%d\n", C[i]);
  }

  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS 1

#include <cstdio>

using namespace std;

int main() {
  int W, N, A[31], B[31], C[31];

  scanf("%d", &W);
  scanf("%d", &N);

  for (int i = 1; i <= N; i++) {
    scanf("%d,%d", &(A[i]), &(B[i]));
  }

  for (int i = 1; i <= W; i++) {
    int t = i;

    for (int j = 1; j <= N; j++) {
      if (A[j] == t) {
        t = B[j];
      } else if (B[j] == t) {
        t = A[j];
      }
    }

    C[t] = i;
  }

  for (int i = 1; i <= W; i++) {
    printf("%d\n", C[i]);
  }

  return 0;
}
Problem p00011 (C++)

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define EPS 1.0e-8
#define MAX_N 100
typedef pair<int, int> Pii;
typedef pair<int, int> Pis;
const double PI = acos(-1);

int main() {
  int w, n;
  int stage[w];
  int a, b;
  cin >> w >> n;
  rep(i, w) stage[i] = i + 1;

  rep(i, n) {
    scanf("%d,%d", &a, &b);
    stage[a - 1] ^= stage[b - 1];
    stage[b - 1] ^= stage[a - 1];
    stage[a - 1] ^= stage[b - 1];
  }

  rep(i, w) cout << stage[i] << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define EPS 1.0e-8
#define MAX_N 100
typedef pair<int, int> Pii;
typedef pair<int, int> Pis;
const double PI = acos(-1);

int main() {
  int w, n;
  int stage[30];
  int a, b;
  cin >> w >> n;
  rep(i, w) stage[i] = i + 1;

  rep(i, n) {
    scanf("%d,%d", &a, &b);
    stage[a - 1] ^= stage[b - 1];
    stage[b - 1] ^= stage[a - 1];
    stage[a - 1] ^= stage[b - 1];
  }

  rep(i, w) cout << stage[i] << endl;
}
Problem p00012 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
double check(double xa, double ya, double xb, double yb, double xc, double yc);
int main(void) {
  for (;;) {
    double qxa, qya, qxb, qyb, qxc, qyc, qxp, qyp;
    cin >> qxa >> qya >> qxb >> qyb >> qxc >> qyc >> qxp >> qyp;
    double abc, abp, bcp, cap;
    abc = check(qxa, qya, qxb, qyb, qxc, qyc);
    abp = check(qxa, qya, qxb, qyb, qxp, qyp);
    bcp = check(qxb, qyb, qxc, qyc, qxp, qyp);
    cap = check(qxc, qyc, qxa, qya, qxp, qyp);

    double var = abc - (abp + bcp + cap);
    if (var <= 0.01 && var >= -0.01)
      var = 0.0;
    if (var == 0.0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

double check(double xa, double ya, double xb, double yb, double xc, double yc) {

  double ab, bc, ca;
  double S, s;
  ab = sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));
  bc = sqrt((xb - xc) * (xb - xc) + (yb - yc) * (yb - yc));
  ca = sqrt((xc - xa) * (xc - xa) + (yc - ya) * (yc - ya));
  s = 0.5 * (ab + bc + ca);
  S = sqrt(s * (s - ab) * (s - bc) * (s - ca));
  // cout<<S<<endl;
  return S;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
double check(double xa, double ya, double xb, double yb, double xc, double yc);
int main(void) {
  double qxa, qya, qxb, qyb, qxc, qyc, qxp, qyp;
  while (cin >> qxa) {

    cin >> qya >> qxb >> qyb >> qxc >> qyc >> qxp >> qyp;
    double abc, abp, bcp, cap;
    abc = check(qxa, qya, qxb, qyb, qxc, qyc);
    abp = check(qxa, qya, qxb, qyb, qxp, qyp);
    bcp = check(qxb, qyb, qxc, qyc, qxp, qyp);
    cap = check(qxc, qyc, qxa, qya, qxp, qyp);

    double var = abc - (abp + bcp + cap);
    if (var <= 0.01 && var >= -0.01)
      var = 0.0;
    if (var == 0.0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

double check(double xa, double ya, double xb, double yb, double xc, double yc) {

  double ab, bc, ca;
  double S, s;
  ab = sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));
  bc = sqrt((xb - xc) * (xb - xc) + (yb - yc) * (yb - yc));
  ca = sqrt((xc - xa) * (xc - xa) + (yc - ya) * (yc - ya));
  s = 0.5 * (ab + bc + ca);
  S = sqrt(s * (s - ab) * (s - bc) * (s - ca));
  // cout<<S<<endl;
  return S;
}
Problem p00012 (C++)

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

#define debug(x) cout << #x << ": " << x << endl
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;

bool isAbove(pair<double, double> p1, pair<double, double> p2,
             pair<double, double> p3) {
  if (p1.first == p2.first) {
    return p3.first > p1.first;
  } else {
    return p3.second > p1.second + (p2.second - p1.second) *
                                       (p3.first - p1.first) /
                                       (p2.first - p1.first);
  }
}

void solve() {
#ifdef _WIN32
  istream &cin = ifstream("input.txt");
#endif

  vector<pair<double, double>> vertices(4);
  while (cin >> vertices[0].first) {
    cin >> vertices[0].second;
    rep(i, 3) cin >> vertices[i + 1].first >> vertices[i + 1].second;

    bool flag = (isAbove(vertices[0], vertices[1], vertices[2]) ==
                 isAbove(vertices[0], vertices[1], vertices[3]));
    flag &= (isAbove(vertices[0], vertices[2], vertices[1]) ==
             isAbove(vertices[0], vertices[2], vertices[3]));
    flag &= (isAbove(vertices[1], vertices[2], vertices[0]) ==
             isAbove(vertices[1], vertices[2], vertices[3]));

    cout << (flag ? "YES" : "NO") << endl;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  solve();
  system("PAUSE");
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"

#define debug(x) cout << #x << ": " << x << endl
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;

bool isAbove(pair<double, double> p1, pair<double, double> p2,
             pair<double, double> p3) {
  if (p1.first == p2.first) {
    return p3.first > p1.first;
  } else {
    return p3.second > p1.second + (p2.second - p1.second) *
                                       (p3.first - p1.first) /
                                       (p2.first - p1.first);
  }
}

void solve() {
#ifdef _WIN32
  istream &cin = ifstream("input.txt");
#endif

  vector<pair<double, double>> vertices(4);
  while (cin >> vertices[0].first) {
    cin >> vertices[0].second;
    rep(i, 3) cin >> vertices[i + 1].first >> vertices[i + 1].second;

    bool flag = (isAbove(vertices[0], vertices[1], vertices[2]) ==
                 isAbove(vertices[0], vertices[1], vertices[3]));
    flag &= (isAbove(vertices[0], vertices[2], vertices[1]) ==
             isAbove(vertices[0], vertices[2], vertices[3]));
    flag &= (isAbove(vertices[1], vertices[2], vertices[0]) ==
             isAbove(vertices[1], vertices[2], vertices[3]));

    cout << (flag ? "YES" : "NO") << endl;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  solve();
  return 0;
}
Problem p00012 (C++)

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

struct Point {
  double x, y;
  Point(double x = 0, double y = 0) : x(x), y(y) {}
  Point operator*(double a) { return Point(a * x, a * y); }
  Point operator-(Point p) { return Point(x - p.x, y - p.y); }
};
struct Segment {
  Point p1, p2;
};
double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
bool isPrallel(Segment s1, Segment s2) {
  return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool isOrthogonal(Segment s1, Segment s2) {
  return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
typedef vector<Point> Polygon;
int contains(Polygon g, Point p) {
  int n = g.size();
  bool x = false;
  rep(i, n) {
    Point a = g[i] - p, b = g[(i + 1) % n] - p;
    if (abs(cross(a, b)) < EPS && dot(a, b) < EPS)
      return 1;
    if (a.y > b.y)
      swap(a, b);
    if (a.y < EPS && EPS < b.y && cross(a, b) > EPS)
      x = !x;
  }
  return x ? 2 : 0;
}
int main() {
  while (1) {
    Polygon g;
    double x, y;
    rep(i, 3) {
      if (!(cin >> x))
        break;
      cin >> y;
      g.push_back(Point(x, y));
    }
    cin >> x >> y;
    if (contains(g, Point(x, y)) == 2)
      puts("YES");
    else
      puts("NO");
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

struct Point {
  double x, y;
  Point(double x = 0, double y = 0) : x(x), y(y) {}
  Point operator*(double a) { return Point(a * x, a * y); }
  Point operator-(Point p) { return Point(x - p.x, y - p.y); }
};
struct Segment {
  Point p1, p2;
};
double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
bool isPrallel(Segment s1, Segment s2) {
  return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool isOrthogonal(Segment s1, Segment s2) {
  return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
typedef vector<Point> Polygon;
int contains(Polygon g, Point p) {
  int n = g.size();
  bool x = false;
  rep(i, n) {
    Point a = g[i] - p, b = g[(i + 1) % n] - p;
    if (abs(cross(a, b)) < EPS && dot(a, b) < EPS)
      return 1;
    if (a.y > b.y)
      swap(a, b);
    if (a.y < EPS && EPS < b.y && cross(a, b) > EPS)
      x = !x;
  }
  return x ? 2 : 0;
}
int main() {
  while (1) {
    Polygon g;
    double x, y;
    rep(i, 3) {
      if (!(cin >> x))
        return 0;
      cin >> y;
      g.push_back(Point(x, y));
    }
    cin >> x >> y;
    if (contains(g, Point(x, y)) == 2)
      puts("YES");
    else
      puts("NO");
  }
}
Problem p00012 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <complex>
#include <iostream>
using namespace std;
typedef complex<double> xy_t;
double x[4], y[4];
xy_t d[4];
double a[3];
double cross_product(xy_t a, xy_t b) { return (conj(a) * b).imag(); }
int main() {
  while (1) {
    for (int i = 0; i < 4; i++)
      cin >> x[i] >> y[i];
    for (int i = 0; i < 4; i++)
      d[i] = xy_t(x[i], y[i]);
    for (int i = 0; i < 3; i++) {
      a[i] = cross_product(d[3] - d[i], d[3] - d[(i + 1) % 3]);
    }
    if (a[0] < 0 && a[1] < 0 && a[2] < 0) {
      cout << "YES" << endl;
    } else if (a[0] > 0 && a[1] > 0 && a[2] > 0) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}

Fixed submission:
#include <complex>
#include <iostream>
using namespace std;
typedef complex<double> xy_t;
double x[4], y[4];
xy_t d[4];
double a[3];
double cross_product(xy_t a, xy_t b) { return (conj(a) * b).imag(); }
int main() {
  while (1) {
    for (int i = 0; i < 4; i++)
      cin >> x[i] >> y[i];
    if (!cin)
      break;
    for (int i = 0; i < 4; i++)
      d[i] = xy_t(x[i], y[i]);
    for (int i = 0; i < 3; i++) {
      a[i] = cross_product(d[3] - d[i], d[3] - d[(i + 1) % 3]);
    }
    if (a[0] < 0 && a[1] < 0 && a[2] < 0) {
      cout << "YES" << endl;
    } else if (a[0] > 0 && a[1] > 0 && a[2] > 0) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}
Problem p00012 (C++)

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

using namespace std;

int main() {
  double x1, y1, x2, y2, x3, y3, xp, yp;
  while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3,
               &xp, &yp)) {
    double pax = x1 - xp, pay = y1 - yp, pbx = x2 - xp, pby = y2 - yp,
           pcx = x3 - xp, pcy = y3 - yp;
    double n1 = pax * pby - pay * pbx, n2 = pbx * pcy - pby * pcx,
           n3 = pcx * pay - pcy * pax;
    if ((n1 <= 0.0 && n2 <= 0.0 && n3 <= 0.0) ||
        (n1 > 0.0 && n2 > 0.0 && n3 > 0.0)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  double x1, y1, x2, y2, x3, y3, xp, yp;
  while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3,
               &xp, &yp) == 8) {
    double pax = x1 - xp, pay = y1 - yp, pbx = x2 - xp, pby = y2 - yp,
           pcx = x3 - xp, pcy = y3 - yp;
    double n1 = pax * pby - pay * pbx, n2 = pbx * pcy - pby * pcx,
           n3 = pcx * pay - pcy * pax;
    if ((n1 <= 0.0 && n2 <= 0.0 && n3 <= 0.0) ||
        (n1 > 0.0 && n2 > 0.0 && n3 > 0.0)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
Problem p00012 (C++)

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

using namespace std;

struct Point {
  double x, y;
  Point(double x = 0.0, double y = 0.0) : x(x), y(y) {}
};

typedef Point Vector;

double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }

int main() {
  double x1, y1, x2, y2, x3, y3, xp, yp;
  while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3,
               &xp, &yp)) {
    Vector v1(x2 - x1, y2 - y1), v2(x3 - x2, y3 - y2), v3(x1 - x3, y1 - y3);
    Vector u1(xp - x1, yp - y1), u2(xp - x2, yp - y2), u3(xp - x3, yp - y3);
    if (cross(v1, u1) * cross(v2, u2) > 0 &&
        cross(v2, u2) * cross(v3, u3) > 0) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
  return 0;
}

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

using namespace std;

struct Point {
  double x, y;
  Point(double x = 0.0, double y = 0.0) : x(x), y(y) {}
};

typedef Point Vector;

double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }

int main() {
  double x1, y1, x2, y2, x3, y3, xp, yp;
  while (~scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3,
                &xp, &yp)) {
    Vector v1(x2 - x1, y2 - y1), v2(x3 - x2, y3 - y2), v3(x1 - x3, y1 - y3);
    Vector u1(xp - x1, yp - y1), u2(xp - x2, yp - y2), u3(xp - x3, yp - y3);
    if (cross(v1, u1) * cross(v2, u2) > 0 &&
        cross(v2, u2) * cross(v3, u3) > 0) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
  return 0;
}
Problem p00012 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
double root(double a1, double b1, double a2, double b2, double a3, double b3) {
  double S = a1 * b2 + a2 * b3 + a3 * b1 - b1 * a2 - b2 * a3 - b3 * a1;
  if (S < 0)
    return -S;
  else
    return S;
}
int main() {
  double x1, x2, x3, xp, y1, y2, y3, yp;
  while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3,
               &xp, &yp)) {
    double s = root(x1, y1, x2, y2, x3, y3), s1 = root(x1, y1, x2, y2, xp, yp),
           s2 = root(x1, y1, xp, yp, x3, y3), s3 = root(xp, yp, x2, y2, x3, y3);
    if (s == s1 + s2 + s3)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
double root(double a1, double b1, double a2, double b2, double a3, double b3) {
  double S = a1 * b2 + a2 * b3 + a3 * b1 - b1 * a2 - b2 * a3 - b3 * a1;
  if (S < 0)
    return -S;
  else
    return S;
}
int main() {
  double x1, x2, x3, xp, y1, y2, y3, yp;
  while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3,
               &xp, &yp) != EOF) {
    double s = root(x1, y1, x2, y2, x3, y3), s1 = root(x1, y1, x2, y2, xp, yp),
           s2 = root(x1, y1, xp, yp, x3, y3), s3 = root(xp, yp, x2, y2, x3, y3);
    if (s == s1 + s2 + s3)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
Problem p00012 (C++)

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

int main() {
  double x1, y1, x2, y2, x3, y3, xp, yp;
  double ax, ay, bx, by;
  while (1) {
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp;
    double m, n;
    ax = x2 - x1;
    ay = y2 - y1;
    bx = x3 - x1;
    by = y3 - y1;
    xp = xp - x1;
    yp = yp - y1;
    double point = ax * by - ay * bx;
    m = (by * xp - bx * yp) / point;
    n = (-ay * xp + ax * yp) / point;
    if (point == 0) {
      cout << "NO" << endl;
    } else if (m > 0 && m <= 1 && n > 0 && n <= 1 && m + n <= 1) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}

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

int main() {
  double x1, y1, x2, y2, x3, y3, xp, yp;
  double ax, ay, bx, by;
  while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) {
    double m, n;
    ax = x2 - x1;
    ay = y2 - y1;
    bx = x3 - x1;
    by = y3 - y1;
    xp = xp - x1;
    yp = yp - y1;
    double point = ax * by - ay * bx;
    m = (by * xp - bx * yp) / point;
    n = (-ay * xp + ax * yp) / point;
    if (point == 0) {
      cout << "NO" << endl;
    } else if (m > 0 && m <= 1 && n > 0 && n <= 1 && m + n <= 1) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
Problem p00013 (C++)

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

int main() {
  int data[15] = {}, i = 0, n;

  while (1) {
    cin >> n;
    if (n != 0) {
      data[i] = n;
      i++;
    } else if (n == 0) {
      cout << data[i - 1] << endl;
      i--;
    }
  }
}

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

int main() {
  int data[15] = {}, i = 0, n;

  while (scanf("%d", &n) != EOF) {
    if (n != 0) {
      data[i] = n;
      i++;
    } else if (n == 0) {
      cout << data[i - 1] << endl;
      i--;
    }
  }
}
Problem p00013 (C++)

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

using namespace std;

int main() {
  int track[10], c, num;
  while (1) {
    cin >> num;
    if (!num) {
      if (!c)
        cout << "No train" << endl;
      else
        cout << track[c--] << endl;
    } else {
      if (c == 10)
        cout << "Already Full" << endl;
      else
        track[++c] = num;
    }
  }
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int track[10], c, num;
  while (1) {
    cin >> num;
    if (!num) {
      if (!c)
        break;
      else
        cout << track[c--] << endl;
    } else {
      if (c == 10)
        cout << "Already Full" << endl;
      else
        track[++c] = num;
    }
  }
  return 0;
}
Problem p00013 (C++)

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

#define N 20
int main(void) {
  int stk[N], sp = 0;
  int n;

  while (scanf("%d", &n)) {
    if (n == 0 && sp != 0) {
      printf("%d\n", stk[--sp]);
    } else {
      stk[sp++] = n;
    }
  }
  return 0;
}

Fixed submission:
#include <stdio.h>

#define N 20
int main(void) {
  int stk[N], sp = 0;
  int n;

  while (scanf("%d", &n) != EOF) {
    if (n == 0 && sp != 0) {
      printf("%d\n", stk[--sp]);
    } else {
      stk[sp++] = n;
    }
  }
  return 0;
}
Problem p00013 (C++)

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

int main() {
  int n, count = 0;
  stack<int> get;
  while (1) {
    cin >> n;
    if (n == 0) {
      cout << get.top() << endl;
      get.pop();
      count -= 1;
    } else {
      get.push(n);
      count += 1;
    }
  }
  return 0;
}

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

int main() {
  int n, count = 0;
  stack<int> get;
  while (cin >> n) {
    if (n == 0) {
      cout << get.top() << endl;
      get.pop();
      count -= 1;
    } else {
      get.push(n);
      count += 1;
    }
  }
  return 0;
}
Problem p00013 (C++)

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

int main() {
  int n;
  vector<int> g;
  while (true) {
    cin >> n;
    if (n != 0) {
      g.push_back(n);
    } else {
      n = g.back();
      g.pop_back();
      cout << n << endl;
    }
  }
  return 0;
}

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

int main() {
  int n;
  vector<int> g;
  while (cin >> n) {
    if (n != 0) {
      g.push_back(n);
    } else {
      n = g.back();
      g.pop_back();
      cout << n << endl;
    }
  }
  return 0;
}
Problem p00013 (C++)

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

int main() {
  int a[100];
  int i = 0;

  while (1) {
    cin >> a[i];
    if (a[i] == 0) {
      int j = i;
      while (1) {
        j--;
        if (a[j] != 0) {
          cout << a[j] << endl;
          a[j] = 0;
          break;
        }
      }
    }
    i++;
  }

  return 0;
}


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

int main() {
  int a[100];
  int i = 0;
  while (cin >> a[i]) {
    if (a[i] == 0) {
      int j = i;
      while (1) {
        j--;
        if (a[j] != 0) {
          cout << a[j] << endl;
          a[j] = 0;
          break;
        }
      }
    }
    i++;
  }

  return 0;
}
Problem p00013 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <stack>
using namespace std;
int main() {
  int n;
  stack<int> car;
  while (scanf("%d", &n)) {
    if (n != 0)
      car.push(n);
    else {
      printf("%d\n", car.top());
      car.pop();
    }
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <stack>
using namespace std;
int main() {
  int n;
  stack<int> car;
  while (~scanf("%d", &n)) {
    if (n != 0)
      car.push(n);
    else {
      printf("%d\n", car.top());
      car.pop();
    }
  }
  return 0;
}
Problem p00013 (C++)

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

int main() {
  int x;
  stack<int> st;
  while (true) {
    int n;
    cin >> n;
    if (n) {
      st.push(n);
    } else {
      cout << st.top() << endl;
      st.pop();
    }
  }
  return 0;
}

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

int main() {
  int x;
  stack<int> st;
  while (cin >> x) {
    if (x) {
      st.push(x);
    } else {
      cout << st.top() << endl;
      st.pop();
    }
  }
  return 0;
}
Problem p00013 (C++)

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

using namespace std;

int main() {
  stack<int> train;
  int n;
  while (cin >> n) {
    if (n == 0) {
      cout << train.top() << endl;
      train.pop();
    } else {
      train.push(n);
    }
  }
  while (1)
    ;
  return 0;
}


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

using namespace std;

int main() {
  stack<int> train;
  int n;
  while (cin >> n) {
    if (n == 0) {
      cout << train.top() << endl;
      train.pop();
    } else {
      train.push(n);
    }
  }
  return 0;
}
Problem p00013 (C++)

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

int main() {
  int k = 0, b;
  int a[100000000];
  while (cin >> b) {
    if (b != 0) {
      a[k] = b;
      k = k + 1;
    }
    if (b == 0) {
      cout << a[k - 1] << endl;
      k = k - 1;
    }
  }
  return 0;
}

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

int main() {
  int k = 0, b;
  int a[1000000];
  while (cin >> b) {
    if (b != 0) {
      a[k] = b;
      k = k + 1;
    }
    if (b == 0) {
      cout << a[k - 1] << endl;
      k = k - 1;
    }
  }
  return 0;
}
Problem p00013 (C++)

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

using namespace std;

int main() {
  stack<int> st;
  int a, i;
  for (i = 0; i < 100; i++) {
    cin >> a;
    if (a == 0) {
      cout << st.top() << endl;
      st.pop();
    } else {
      st.push(a);
    }
  }
  return 0;
}

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

using namespace std;

int main() {
  stack<int> st;
  int a, i;
  while (cin >> a) {
    if (a == 0) {
      cout << st.top() << endl;
      st.pop();
    } else {
      st.push(a);
    }
  }
  return 0;
}
Problem p00013 (C++)

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

int main() {
  int x;
  stack<int> S;
  while (1) {
    cin >> x;
    if (x == 0) {
      cout << S.top() << endl;
      S.pop();
    } else {
      S.push(x);
    }
  }
  return 0;
}

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

int main() {
  int x;
  stack<int> S;
  while (1) {
    cin >> x;
    if (x == 0) {
      if (S.empty())
        break;
      cout << S.top() << endl;
      S.pop();
    } else {
      S.push(x);
    }
  }
  return 0;
}
Problem p00013 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stack>
using namespace std;
int main() {
  stack<int> chu;
  int i = 0;
  int input;
  int hairetu[10];
  cin >> input;
  chu.push(input);
  while (cin >> input) {
    if (input != 0) {
      chu.push(input);
    } else {
      hairetu[i] = chu.top();
      chu.pop();
      i++;
    }
  }
  for (int j = 0; j <= i - 1; j++) {
    cout << hairetu[j] << endl;
  }
}

Fixed submission:
#include <iostream>
#include <stack>
using namespace std;
int main() {
  stack<int> chu;
  int i = 0;
  int input;
  int hairetu[111];
  cin >> input;
  chu.push(input);
  while (cin >> input) {
    if (input != 0) {
      chu.push(input);
    } else {
      hairetu[i] = chu.top();
      chu.pop();
      i++;
    }
  }
  for (int j = 0; j <= i - 1; j++) {
    cout << hairetu[j] << endl;
  }
}
Problem p00013 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <deque>
#include <iostream>
#include <stack>
using namespace std;
int main() {
  int m, n;
  deque<int> deq;
  while (1) {
    cin >> n;
    if (n != 0)
      deq.push_back(n);
    else {
      if (deq.empty()) {
        continue;
      } else {
        cout << deq[(int)deq.size() - 1] << endl;
        deq.pop_back();
      }
    }
  }
  return 0;
}

Fixed submission:
#include <deque>
#include <iostream>
#include <stack>
using namespace std;
int main() {
  int m, n;
  deque<int> deq;
  while (1) {
    cin >> n;
    if (cin.eof())
      break;
    if (n != 0)
      deq.push_back(n);
    else {
      if (deq.empty()) {
        continue;
      } else {
        cout << deq[(int)deq.size() - 1] << endl;
        deq.pop_back();
      }
    }
  }
  return 0;
}
Problem p00013 (C++)

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

int main() {
  stack<int> a;
  int b;
  while (scanf("%d", &b)) {
    if (b)
      a.push(b);
    else {
      printf("%d\n", a.top());
      a.pop();
    }
  }
}

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

int main() {
  stack<int> a;
  int b;
  scanf("%d", &b);
  a.push(b);
  while (cin >> b) {
    if (b)
      a.push(b);
    else {
      printf("%d\n", a.top());
      a.pop();
    }
  }
}
Problem p00013 (C++)

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

  while (1) {
    cin >> num;
    st.push(num);
    if (num == 0) {
      st.pop(); // 0ツづーツ渉慊つュ
      cout << st.top() << endl;
      st.pop();
    }
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <stack>
using namespace std;
int main(void) {
  int num;
  stack<int> st;

  while (cin >> num) {
    st.push(num);
    if (num == 0) {
      st.pop(); // 0ツづーツ渉慊つュ
      cout << st.top() << endl;
      st.pop();
    }
  }
  return 0;
}