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

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

struct edge {
  int u, v, cost;
};

bool comp(const edge &e1, const edge &e2) { return e1.cost < e2.cost; }

const int MAX_N = 101;
const int MAX_E = 150;
int par[MAX_N];
int r[MAX_N];

void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    r[i] = 0;
  }
}

int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y)
    return;

  if (r[x] < r[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}

bool same(int x, int y) { return find(x) == find(y); }

edge es[MAX_E];
int V, E;

int kruskal() {
  sort(es, es + E, comp);
  init(V);
  int res = 0;
  for (int i = 0; i < E; i++) {
    edge e = es[i];
    if (!same(e.u, e.v)) {
      unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}

int main() {
  while (cin >> V >> E, V) {

    for (int i = 0; i < E; i++) {
      char ch;
      cin >> es[i].u >> ch >> es[i].v >> ch >> es[i].cost;
    }

    int ans = kruskal();
    cout << ((ans / 100) - (V - 1)) << endl;
  }
  return 0;
}

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

struct edge {
  int u, v, cost;
};

bool comp(const edge &e1, const edge &e2) { return e1.cost < e2.cost; }

const int MAX_N = 101;
const int MAX_E = 10000;
int par[MAX_N];
int r[MAX_N];

void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    r[i] = 0;
  }
}

int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y)
    return;

  if (r[x] < r[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}

bool same(int x, int y) { return find(x) == find(y); }

edge es[MAX_E];
int V, E;

int kruskal() {
  sort(es, es + E, comp);
  init(V);
  int res = 0;
  for (int i = 0; i < E; i++) {
    edge e = es[i];
    if (!same(e.u, e.v)) {
      unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}

int main() {
  while (cin >> V >> E, V) {

    for (int i = 0; i < E; i++) {
      char ch;
      cin >> es[i].u >> ch >> es[i].v >> ch >> es[i].cost;
    }

    int ans = kruskal();
    cout << ((ans / 100) - (V - 1)) << endl;
  }
  return 0;
}
Problem p00072 (C++)

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

constexpr int MAX_N = 100;

struct edge {
  int from_, to_, cost_;
  edge() = default;
  edge(int from, int to, int cost) : from_(from), to_(to), cost_(cost) {}
  bool operator<(const edge &rhs) const {
    return (cost_ == rhs.cost_) ? to_ < rhs.to_ : cost_ < rhs.cost_;
  }
};

int n, m;
std::vector<edge> edges;

class Union {
  int par[MAX_N], rank[MAX_N];

public:
  Union() {
    for (int i = 0; i < n; ++i) {
      par[i] = i;
      rank[i] = 0;
    }
  }
  int find(int x) {
    if (x == par[x])
      return x;
    par[x] = find(par[x]);
  }
  bool same(int x, int y) { return find(x) == find(y); }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (rank[x] < rank[y])
      std::swap(x, y);
    par[y] = x;
    rank[x] += rank[y];
  }
};

int main() {
  while (1) {
    std::cin >> n;
    if (!n)
      break;
    std::cin >> m;
    Union uni;
    edges.clear();
    int a, b, d;
    char ch;
    for (int i = 0; i < m; ++i) {
      std::cin >> a >> ch >> b >> ch >> d;
      d /= 100;
      --d;
      edges.push_back(edge(a, b, d));
    }

    std::sort(edges.begin(), edges.end());

    long long int ans = 0;
    for (int i = 0; i < edges.size(); ++i) {
      if (!uni.same(edges[i].from_, edges[i].to_)) {
        uni.unite(edges[i].from_, edges[i].to_);
        ans += edges[i].cost_;
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

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

constexpr int MAX_N = 100;

struct edge {
  int from_, to_, cost_;
  edge() = default;
  edge(int from, int to, int cost) : from_(from), to_(to), cost_(cost) {}
  bool operator<(const edge &rhs) const {
    return (cost_ == rhs.cost_) ? to_ < rhs.to_ : cost_ < rhs.cost_;
  }
};

int n, m;
std::vector<edge> edges;

class Union {
  int par[MAX_N], rank[MAX_N];

public:
  Union() {
    for (int i = 0; i < n; ++i) {
      par[i] = i;
      rank[i] = 0;
    }
  }
  int find(int x) {
    if (x == par[x])
      return x;
    return par[x] = find(par[x]);
  }
  bool same(int x, int y) { return find(x) == find(y); }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (rank[x] < rank[y])
      std::swap(x, y);
    par[y] = x;
    rank[x] += rank[y];
  }
};

int main() {
  while (1) {
    std::cin >> n;
    if (!n)
      break;
    std::cin >> m;
    Union uni;
    edges.clear();
    int a, b, d;
    char ch;
    for (int i = 0; i < m; ++i) {
      std::cin >> a >> ch >> b >> ch >> d;
      d /= 100;
      --d;
      edges.push_back(edge(a, b, d));
    }

    std::sort(edges.begin(), edges.end());

    long long int ans = 0;
    for (int i = 0; i < edges.size(); ++i) {
      if (!uni.same(edges[i].from_, edges[i].to_)) {
        uni.unite(edges[i].from_, edges[i].to_);
        ans += edges[i].cost_;
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}
Problem p00072 (C++)

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

using namespace std;

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

typedef vector<int> vi;
typedef pair<int, int> pii;

struct Edge {
  int src, dst, cost;
  Edge(int s, int d, int c) : src(s), dst(d), cost(c) {}
  Edge() {}
  bool operator<(const Edge &e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

Edges prim(const Graph &g) {
  Edges T;
  vector<int> visited(g.size(), 0);
  visited[0] = 1;

  priority_queue<Edge> Q;
  rep(i, g[0].size()) Q.push(g[0][i]);

  while (!Q.empty()) {
    Edge e = Q.top();
    Q.pop();
    if (visited[e.dst])
      continue;
    T.push_back(e);
    visited[e.dst] = 1;
    rep(i, g[e.dst].size()) {
      if (!visited[g[e.dst][i].dst])
        Q.push(g[e.dst][i]);
    }
  }
  return T;
}

int main() {
  int n, m;
  while (scanf("%d", &n), n) {
    scanf("%d", &m);
    Graph g(n);
    rep(i, n) {
      int a, b, d;
      scanf("%d,%d,%d", &a, &b, &d);
      g[a].push_back(Edge(a, b, d));
      g[b].push_back(Edge(b, a, d));
    }
    Edges t = prim(g);
    int ans = 0;
    rep(i, t.size()) ans += t[i].cost / 100 - 1;
    printf("%d\n", ans);
  }

  return 0;
}

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

using namespace std;

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

typedef vector<int> vi;
typedef pair<int, int> pii;

struct Edge {
  int src, dst, cost;
  Edge(int s, int d, int c) : src(s), dst(d), cost(c) {}
  Edge() {}
  bool operator<(const Edge &e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

Edges prim(const Graph &g) {
  Edges T;
  vector<int> visited(g.size(), 0);
  visited[0] = 1;

  priority_queue<Edge> Q;
  rep(i, g[0].size()) Q.push(g[0][i]);

  while (!Q.empty()) {
    Edge e = Q.top();
    Q.pop();
    if (visited[e.dst])
      continue;
    T.push_back(e);
    visited[e.dst] = 1;
    rep(i, g[e.dst].size()) {
      if (!visited[g[e.dst][i].dst])
        Q.push(g[e.dst][i]);
    }
  }
  return T;
}

int main() {
  int n, m;
  while (scanf("%d", &n), n) {
    scanf("%d", &m);
    Graph g(n);
    rep(i, m) {
      int a, b, d;
      scanf("%d,%d,%d", &a, &b, &d);
      g[a].push_back(Edge(a, b, d));
      g[b].push_back(Edge(b, a, d));
    }
    Edges t = prim(g);
    int ans = 0;
    rep(i, t.size()) ans += t[i].cost / 100 - 1;
    printf("%d\n", ans);
  }

  return 0;
}
Problem p00075 (C++)

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

int main() {
  int n;
  double kg, m;

  while (scanf("%d, %lf,%lf", &n, &kg, &m)) {
    if (kg / (m * m) >= 25) {
      cout << n << endl;
    }
  }
}

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

int main() {
  int n;
  double kg, m;

  while (scanf("%d, %lf,%lf", &n, &kg, &m) != EOF) {
    if (kg / (m * m) >= 25) {
      cout << n << endl;
    }
  }
}
Problem p00075 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define r(i, a, n) for (int i = a; i < n; i++)
using namespace std;
int main() {
  int a;
  double b, c;
  while (scanf("%d,%lf,%lf", &a, &b, &c)) {
    if (25 <= (b / (c * c)))
      cout << a << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define r(i, a, n) for (int i = a; i < n; i++)
using namespace std;
int main() {
  int a;
  double b, c;
  while (scanf("%d,%lf,%lf", &a, &b, &c) != EOF) {
    if (25 <= (b / (c * c)))
      cout << a << endl;
  }
}
Problem p00075 (C++)

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

using namespace std;

int main(void) {
  int a;
  double b, c;

  while (scanf("%d,%lf,%lf", &a, &b, &c)) {
    int d = 0;
    d = b / (c * c);
    if (d >= 25.00) {
      cout << a << endl;
    }
  }

  return (0);
}

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

using namespace std;

int main(void) {
  int a;
  double b, c;

  while (scanf("%d,%lf,%lf", &a, &b, &c) != EOF) {
    int d = 0;
    d = b / (c * c);
    if (d >= 25.00) {
      cout << a << endl;
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
int main(void) {
  int ban;
  double tai, sin, BMI;
  while (scanf("%d %lf %lf", &ban, &tai, &sin) != EOF) {
    BMI = tai / (sin * sin);
    if (BMI >= 25.0) {
      printf("%d\n", ban);
    }
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
int main(void) {
  int ban;
  double tai, sin, BMI;
  while (scanf("%d,%lf,%lf", &ban, &tai, &sin) != EOF) {
    BMI = tai / (sin * sin);
    if (BMI >= 25.0) {
      printf("%d\n", ban);
    }
  }
  return 0;
}
Problem p00075 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int a = 0;
  double b, c;
  while (scanf("%d,%lf,%lf", &a, &b, &c)) {
    if (b / (c * c) >= 25)
      cout << a << endl;
  }
}

Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int a = 0;
  double b, c;
  while (~scanf("%d,%lf,%lf", &a, &b, &c)) {
    if (b / (c * c) >= 25)
      cout << a << endl;
  }
}
Problem p00075 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <stdio.h>
using namespace std;
double BMI(double Kg, double m) {
  double bmi;
  bmi = Kg / (m * m);
  return bmi;
}

int main() {
  double Kg, m;
  int student;
  while (scanf("%d,%lf,%lf", &student, &Kg, &m)) {
    if (BMI(Kg, m) >= 25) {
      cout << student << endl;
    }
  }
}

Fixed submission:
#include <iostream>
#include <stdio.h>
using namespace std;
double BMI(double Kg, double m) {
  double bmi;
  bmi = Kg / (m * m);
  return bmi;
}

int main() {
  double Kg, m;
  int student;
  while (scanf("%d,%lf,%lf", &student, &Kg, &m) != EOF) {
    if (BMI(Kg, m) >= 25) {
      cout << student << endl;
    }
  }
}
Problem p00075 (C++)

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

int main() {
  int l, i = 0;
  double m, n;
  while (scanf("%d,%lf,%lf", &l, &m, &n) != NULL) {
    if (25.0 <= m / (n * n)) {
      printf("%d\n", l);
      i++;
    }
  }
  if (i == 0)
    printf("????????????\n");
  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  int l, i = 0;
  double m, n;
  while (scanf("%d,%lf,%lf", &l, &m, &n) != EOF) {
    if (25.0 <= m / (n * n)) {
      printf("%d\n", l);
      i++;
    }
  }
  if (i == 0)
    printf("????????????\n");
  return 0;
}
Problem p00075 (C++)

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

struct data {
  int number;
  double weight;
  double tall;
};

int main() {
  data dt;
  while (1) {
    scanf("%d,%lf,%lf", &dt.number, &dt.weight, &dt.tall);
    if (!dt.number)
      break;
    if (dt.weight / pow(dt.tall, 2) >= 25)
      cout << dt.number << endl;
  }
  return 0;
}

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

struct data {
  int number;
  double weight;
  double tall;
};

int main() {
  data dt;
  while (scanf("%d,%lf,%lf", &dt.number, &dt.weight, &dt.tall) != EOF) {
    if (dt.weight / pow(dt.tall, 2) >= 25)
      cout << dt.number << endl;
  }
  return 0;
}
Problem p00075 (C++)

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

int main() {
  int id;
  double h, w;
  while (scanf("%d,%lf,%lf", &id, &w, &h)) {
    double b = (double)w / (h * h);
    if (b >= 25.0)
      cout << id << endl;
  }

  return 0;
}

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

int main() {
  int id;
  double h, w;
  while (scanf("%d,%lf,%lf", &id, &w, &h) != EOF) {
    double b = (double)w / (h * h);
    if (b >= 25.0)
      cout << id << endl;
  }

  return 0;
}
Problem p00075 (C++)

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

int main() {
  int id;
  double w, h;
  while (scanf("%d,%lf,%lf", &id, &w, &h), id) {
    double bmi = w / (h * h);
    if (bmi >= 25.0) {
      cout << id << endl;
    }
  }
  return 0;
}

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

int main() {
  int id;
  double w, h;
  while (scanf("%d,%lf,%lf", &id, &w, &h) != EOF) {
    double bmi = w / (h * h);
    if (bmi >= 25.0) {
      cout << id << endl;
    }
  }
  return 0;
}
Problem p00075 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int num;
  double tai, sint;
  char d;
  while (scanf("%d,%lf,%lf", &num, &tai, &sint) != '\0') {
    // cout<<tai/sint*sint<<endl;
    if (tai / (sint * sint) >= 25)
      cout << num << endl;
  }
}

Fixed submission:
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int num;
  double tai, sint;
  char d;
  while (scanf("%d,%lf,%lf", &num, &tai, &sint) != EOF) {
    // cout<<tai/sint*sint<<endl;
    if (tai / (sint * sint) >= 25)
      cout << num << endl;
  }
}
Problem p00076 (C++)

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

int main() {
  int n;
  while (std::cin >> n) {
    double x = 1.0, y = 0.0;

    for (int i = 0; i != n - 1; ++i) {
      double t = sqrt(x * x + y * y);
      double vx = -y / t, vy = x / t;
      x += vx;
      y += vy;
    }

    std::cout << std::fixed << std::setprecision(2);
    std::cout << x << std::endl;
    std::cout << y << std::endl;
  }

  return 0;
}

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

int main() {
  int n;
  while (std::cin >> n, n != -1) {
    double x = 1.0, y = 0.0;

    for (int i = 0; i != n - 1; ++i) {
      double t = sqrt(x * x + y * y);
      double vx = -y / t, vy = x / t;
      x += vx;
      y += vy;
    }

    std::cout << std::fixed << std::setprecision(2);
    std::cout << x << std::endl;
    std::cout << y << std::endl;
  }

  return 0;
}
Problem p00077 (C++)

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

int main() {
  char a;
  while (scanf("%c", &a)) {
    if (a == '@') {
      int s;
      cin >> a;
      s = a - '0';
      cin >> a;
      for (int i = 0; i < s; i++) {
        cout << a;
      }
    } else if (a == '\n')
      cout << endl;
    else
      cout << a;
  }
}

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

int main() {
  char a;
  while (scanf("%c", &a) != EOF) {
    if (a == '@') {
      int s;
      cin >> a;
      s = a - '0';
      cin >> a;
      for (int i = 0; i < s; i++) {
        cout << a;
      }
    } else if (a == '\n')
      cout << endl;
    else
      cout << a;
  }
}
Problem p00077 (C++)

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

using namespace std;

int main() {
  std::ios_base::sync_with_stdio(false);

  string inp, mozi;
  int kai;

  while (1) {
    cin >> inp;
    for (int i = 0; i < inp.length(); i++) {
      if (inp[i] == '@') {
        kai = inp[i + 1] - '0';
        mozi = inp[i + 2];
        for (int j = 0; j < kai; j++) {
          cout << mozi;
        }
        i += 2;
      } else
        cout << inp[i];
    }
    cout << endl;
  }

  return 0;
}

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

using namespace std;

int main() {
  std::ios_base::sync_with_stdio(false);

  string inp, mozi;
  int kai;

  while (cin >> inp) {
    for (int i = 0; i < inp.length(); i++) {
      if (inp[i] == '@') {
        kai = inp[i + 1] - '0';
        mozi = inp[i + 2];
        for (int j = 0; j < kai; j++) {
          cout << mozi;
        }
        i += 2;
      } else
        cout << inp[i];
    }
    cout << endl;
  }

  return 0;
}
Problem p00077 (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 <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int main() {
  string s;
  while (1) {
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '@') {
        for (int j = 0; j < (s[i + 1] - '0'); j++) {
          cout << s[i + 2];
        }
        i += 2;
      } else {
        cout << s[i];
      }
    }
    cout << endl;
  }
  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 <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int main() {
  string s;
  while (cin >> s) {
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '@') {
        for (int j = 0; j < (s[i + 1] - '0'); j++) {
          cout << s[i + 2];
        }
        i += 2;
      } else {
        cout << s[i];
      }
    }
    cout << endl;
  }
  return 0;
}
Problem p00077 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  while (cin >> s) {
    while (s.find("@") != 0) {
      int x = s.find("@");
      string buf;
      for (int i = 0; i < s[x + 1] - '0'; i++)
        buf += s[x + 2];
      s.replace(x, 3, buf);
    }
    cout << s << endl;
  }
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  while (cin >> s) {
    while (s.find("@") != -1) {
      int x = s.find("@");
      string buf;
      for (int i = 0; i < s[x + 1] - '0'; i++)
        buf += s[x + 2];
      s.replace(x, 3, buf);
    }
    cout << s << endl;
  }
}
Problem p00079 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
using namespace std;
#pragma warning(disable : 4996)
struct Point {
  long double px, py;
};
struct Segment {
  Point p1, p2;
};
Point X[200000];
Point Minus(Point a, Point b) {
  Point G;
  G.px = a.px - b.px;
  G.py = a.py - b.py;
  return G;
}
long double Abs(Point a) { return sqrt(a.px * a.px + a.py * a.py); }
long double dot(const Point &a, const Point &b) {
  return a.px * b.px + a.py * b.py;
}
long double crs(const Point &a, const Point &b) {
  return a.px * b.py - a.py * b.px;
}
long double dst(const Segment &a, const Point &b) {
  return abs(crs(Minus(a.p2, a.p1), Minus(b, a.p1)) / Abs(Minus(a.p2, a.p1)));
}
int main() {
  int N = 0;
  while (scanf("%Lf,%Lf", &X[N].px, &X[N].py)) {
    N++;
  }
  long double SUM = 0.0l;
  for (int i = 1; i < N - 1; i++) {
    Segment A;
    A.p1 = X[i];
    A.p2 = X[i + 1];
    long double DST = dst(A, X[0]);
    Point H;
    H.px = X[i].px - X[i + 1].px;
    H.py = X[i].py - X[i + 1].py;
    long double LEN = Abs(H);
    SUM += DST * LEN / 2;
  }
  cout << fixed << setprecision(1919) << SUM << endl;
  return 0;
}

Fixed submission:
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
using namespace std;
#pragma warning(disable : 4996)
struct Point {
  long double px, py;
};
struct Segment {
  Point p1, p2;
};
Point X[200000];
Point Minus(Point a, Point b) {
  Point G;
  G.px = a.px - b.px;
  G.py = a.py - b.py;
  return G;
}
long double Abs(Point a) { return sqrt(a.px * a.px + a.py * a.py); }
long double dot(const Point &a, const Point &b) {
  return a.px * b.px + a.py * b.py;
}
long double crs(const Point &a, const Point &b) {
  return a.px * b.py - a.py * b.px;
}
long double dst(const Segment &a, const Point &b) {
  return abs(crs(Minus(a.p2, a.p1), Minus(b, a.p1)) / Abs(Minus(a.p2, a.p1)));
}
int main() {
  int N = 0;
  while (scanf("%Lf,%Lf", &X[N].px, &X[N].py) != EOF) {
    N++;
  }
  long double SUM = 0.0l;
  for (int i = 1; i < N - 1; i++) {
    Segment A;
    A.p1 = X[i];
    A.p2 = X[i + 1];
    long double DST = dst(A, X[0]);
    Point H;
    H.px = X[i].px - X[i + 1].px;
    H.py = X[i].py - X[i + 1].py;
    long double LEN = Abs(H);
    SUM += DST * LEN / 2;
  }
  cout << fixed << setprecision(1919) << SUM << endl;
  return 0;
}
Problem p00079 (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 <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int main() {
  double num[21][2];
  int r = 1;
  while (scanf("%lf %lf", &num[r][0], &num[r][1]) != EOF) {
    r++;
  }
  double ans = 0.0;
  for (int i = 2; i < r - 1; i++) {
    double a, b, c;
    a = sqrt((num[i][0] - num[1][0]) * (num[i][0] - num[1][0]) +
             (num[i][1] - num[1][1]) * (num[i][1] - num[1][1]));
    b = sqrt((num[i + 1][0] - num[1][0]) * (num[i + 1][0] - num[1][0]) +
             (num[i + 1][1] - num[1][1]) * (num[i + 1][1] - num[1][1]));
    c = sqrt((num[i][0] - num[i + 1][0]) * (num[i][0] - num[i + 1][0]) +
             (num[i][1] - num[i + 1][1]) * (num[i][1] - num[i + 1][1]));
    double y = (a + b + c) / 2.0;
    ans += sqrt(y * (y - a) * (y - b) * (y - c));
  }
  printf("%f\n", ans);
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int main() {
  double num[21][2];
  int r = 1;
  while (scanf("%lf,%lf", &num[r][0], &num[r][1]) != EOF) {
    r++;
  }
  double ans = 0.0;
  for (int i = 2; i < r - 1; i++) {
    double a, b, c;
    a = sqrt((num[i][0] - num[1][0]) * (num[i][0] - num[1][0]) +
             (num[i][1] - num[1][1]) * (num[i][1] - num[1][1]));
    b = sqrt((num[i + 1][0] - num[1][0]) * (num[i + 1][0] - num[1][0]) +
             (num[i + 1][1] - num[1][1]) * (num[i + 1][1] - num[1][1]));
    c = sqrt((num[i][0] - num[i + 1][0]) * (num[i][0] - num[i + 1][0]) +
             (num[i][1] - num[i + 1][1]) * (num[i][1] - num[i + 1][1]));
    double y = (a + b + c) / 2.0;
    ans += sqrt(y * (y - a) * (y - b) * (y - c));
  }
  printf("%f\n", ans);
}
Problem p00079 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
using namespace std;
typedef complex<double> xy_t;
int main() {
  xy_t P[110];
  int N = 0;
  double x, y;
  while (scanf("%lf,%lf", &x, &y)) {
    P[N++] = xy_t(x, y);
  }
  double sum = 0.0;
  for (int i = 0; i + 2 < N; ++i) {
    xy_t a = P[0], b = P[i + 1], c = P[i + 2];
    sum += (conj(b - a) * (c - a)).imag();
  }
  sum /= 2;
  printf("%.6f\n", abs(sum));
  return 0;
}

Fixed submission:
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
using namespace std;
typedef complex<double> xy_t;
int main() {
  xy_t P[110];
  int N = 0;
  double x, y;
  while (~scanf("%lf,%lf", &x, &y)) {
    P[N++] = xy_t(x, y);
  }
  double sum = 0.0;
  for (int i = 0; i + 2 < N; ++i) {
    xy_t a = P[0], b = P[i + 1], c = P[i + 2];
    sum += (conj(b - a) * (c - a)).imag();
  }
  sum /= 2;
  printf("%.6f\n", abs(sum));
  return 0;
}
Problem p00079 (C++)

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

using namespace std;

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

#define X real()
#define Y imag()
typedef complex<double> P;

double cross(P a, P b) { return a.X * b.Y - a.Y * b.X; }
int main() {

  double a, b;
  vector<P> p;
  while (scanf("%lf,%lf", &a, &b)) {
    p.push_back(P(a, b));
  }

  double sum = 0;
  reps(i, 1, p.size() - 1) { sum += cross(p[i] - p[0], p[i + 1] - p[0]) / 2; }

  printf("%.9lf\n", fabs(sum));
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

#define X real()
#define Y imag()
typedef complex<double> P;

double cross(P a, P b) { return a.X * b.Y - a.Y * b.X; }
int main() {

  double a, b;
  vector<P> p;
  while (scanf("%lf,%lf", &a, &b) != EOF) {
    p.push_back(P(a, b));
  }

  double sum = 0;
  reps(i, 1, p.size() - 1) { sum += cross(p[i] - p[0], p[i + 1] - p[0]) / 2; }

  printf("%.9lf\n", fabs(sum));
}
Problem p00080 (C++)

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

#define EPS 1e-5

int main() {

  double q;
  while (cin >> q, q >= 0) {
    double x = q / 2;
    while (fabs(x * x * x) > EPS * q) {
      x = x - (x * x * x - q) / (3 * x * x);
    }
    printf("%f\n", x);
  }

  return 0;
}

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

#define EPS 1e-5

int main() {

  double q;
  while (cin >> q, q >= 0) {
    double x = q / 2;
    while (fabs(x * x * x - q) >= EPS * q) {
      x = x - (x * x * x - q) / (3 * x * x);
    }
    printf("%f\n", x);
  }

  return 0;
}
Problem p00080 (C++)

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

int main() {
  int in;
  double q, x;
  while (cin >> in && in) {
    q = in;
    x = q / 2;
    while (fabs(x * x * x - q) >= q * 1e-5) {
      x = x - (x * x * x - q) / (3 * x * x);
    }
    printf("%.5f\n", x);
  }
  return 0;
}

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

int main() {
  int in;
  double q, x;
  while (cin >> in && in != -1) {
    q = in;
    x = q / 2;
    while (fabs(x * x * x - q) >= q * 1e-5) {
      x = x - (x * x * x - q) / (3 * x * x);
    }
    printf("%.5f\n", x);
  }
  return 0;
}
Problem p00080 (C++)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define REPR(i, n) for (ll i = 1; i < n; ++i)
#define FOR(i, a, b) for (ll i = a; i < b; ++i)

#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG_VEC(v)                                                           \
  cout << #v << ":";                                                           \
  REP(i, v.size()) cout << " " << v[i];                                        \
  cout << endl
#define ALL(a) (a).begin(), (a).end()

#define MOD (ll)(1e9 + 7)
#define ADD(a, b) a = ((a) + (b)) % MOD
#define FIX(a) ((a) % MOD + MOD) % MOD

#define INF 1000000000

typedef double Real;
#define EPS 1e-11
#define EQ(x) (-EPS < x && x < EPS)
typedef complex<Real> P;
Real dot(P a, P b) { return real(conj(a) * b); }
Real cross(P a, P b) { return imag(conj(a) * b); }

int main() {
  cout.precision(12);
  while (true) {
    Real x;
    cin >> x;
    if (x == -1)
      break;
    Real a = x / 2;
    while (abs(a * a * a - x) > 1e-7) {
      a = a - (a * a * a - x) / (3 * a * a);
    }
    cout << fixed << a << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define REPR(i, n) for (ll i = 1; i < n; ++i)
#define FOR(i, a, b) for (ll i = a; i < b; ++i)

#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG_VEC(v)                                                           \
  cout << #v << ":";                                                           \
  REP(i, v.size()) cout << " " << v[i];                                        \
  cout << endl
#define ALL(a) (a).begin(), (a).end()

#define MOD (ll)(1e9 + 7)
#define ADD(a, b) a = ((a) + (b)) % MOD
#define FIX(a) ((a) % MOD + MOD) % MOD

#define INF 1000000000

typedef double Real;
#define EPS 1e-11
#define EQ(x) (-EPS < x && x < EPS)
typedef complex<Real> P;
Real dot(P a, P b) { return real(conj(a) * b); }
Real cross(P a, P b) { return imag(conj(a) * b); }

int main() {
  cout.precision(12);
  while (true) {
    Real x;
    cin >> x;
    if (x == -1)
      break;
    Real a = x / 2.0;
    while (abs(a * a * a - x) >= 0.00001 * x) {
      a = a - (a * a * a - x) / (3.0 * a * a);
    }
    cout << fixed << a << endl;
  }
  return 0;
}
Problem p00080 (C++)

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

using namespace std;

int main(void) {

  int q;
  while (cin >> q) {
    if (q == -1)
      break;

    double x = q / 2;
    while (1) {
      if (abs(x * x * x - q) < 0.00001 * q)
        break;
      x = x - (x * x * x - q) / (3 * x * x);
    }
    printf("%.6f", x);
    cout << endl;
  }
  return 0;
}

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

using namespace std;

int main(void) {

  int q;
  while (cin >> q) {
    if (q == -1)
      break;
    if (q == 1) {
      printf("1.000000");
      cout << endl;
      continue;
    }
    double x = q / 2;
    while (1) {
      if (abs(x * x * x - q) < 0.00001 * q)
        break;
      x = x - (x * x * x - q) / (3 * x * x);
    }
    printf("%.6f", x);
    cout << endl;
  }
  return 0;
}
Problem p00080 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
  double q;
  while (cin >> q && q != -1) {
    double x = q / 2;
    while (true) {
      if (fabs(x * x * x * q) < 0.00001 * q)
        break;
      x -= (x * x * x - q) / (x * x * 3);
    }
    cout << fixed << setprecision(7) << x << endl;
  }
}

Fixed submission:
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
  double q;
  while (cin >> q && q != -1) {
    double x = q / 2;
    while (true) {
      if (fabs(x * x * x - q) < 0.00001 * q)
        break;
      x -= (x * x * x - q) / (x * x * 3);
    }
    cout << fixed << setprecision(7) << x << endl;
  }
}
Problem p00080 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <cstdio>
int main() {
  int q;
  float x;
  for (; scanf("%d", &q), ~q; printf("%f\n", x))
    for (x = q / 2.; fabs(x * x * x - q) > 1e-5 * q; x -= x / 3 - q / 3 / x / x)
      ;
}

Fixed submission:
#include <cmath>
#include <cstdio>
int main() {
  int q;
  float x;
  for (; scanf("%d", &q), ~q; printf("%f\n", x))
    for (x = q / 2.; fabs(x * x * x - q) > 1e-5 * q;
         x -= (x * x * x - q) / (3 * x * x))
      ;
}
Problem p00080 (C++)

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

int main() {
  double tmp[20][2];
  int cnt = 0;
  int n;
  for (;;) {
    scanf("%d", &n);
    if (n == -1)
      break;
    double ans = 1.0 * n / 2.0;
    while (abs(ans * ans * ans - n) >= 1e-10)
      ans -= (ans * ans * ans - n) / (3 * ans * ans);
    printf("%.8lf\n", ans);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <list>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

int main() {
  double tmp[20][2];
  int cnt = 0;
  int n;
  for (;;) {
    scanf("%d", &n);
    if (n == -1)
      break;
    double ans = 1.0 * n / 2.0;
    while (abs(ans * ans * ans - n) >= 0.00001 * n)
      ans -= (ans * ans * ans - n) / (3 * ans * ans);
    printf("%.8lf\n", ans);
  }
  return 0;
}
Problem p00081 (C++)

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

#define rep(i, j) for (int i = 0; i < j; i++)

// note: theta[rad]
void rotate(double &x, double &y, const double &theta) {
  double nx, ny;
  nx = x * cos(theta) - y * sin(theta);
  ny = x * sin(theta) + y * cos(theta);
  x = nx;
  y = ny;
}

int main() {
  double p[2][2], q[2];
  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf", &p[0][0], &p[0][1], &p[1][0],
               &p[1][1], &q[0], &q[1])) {
    double bias[2] = {p[0][0], p[0][1]};
    p[0][0] -= bias[0];
    p[0][1] -= bias[1];
    p[1][0] -= bias[0];
    p[1][1] -= bias[1];
    q[0] -= bias[0];
    q[1] -= bias[1];
    double theta = atan2(p[1][1] - p[0][1], p[1][0] - p[0][0]);
    rotate(q[0], q[1], -theta);
    double r[2] = {q[0], -q[1]};
    rotate(r[0], r[1], theta);
    r[0] += bias[0];
    r[1] += bias[1];
    printf("%lf %lf\n", r[0], r[1]);
  }
  return 0;
}

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

#define rep(i, j) for (int i = 0; i < j; i++)

// note: theta[rad]
void rotate(double &x, double &y, const double &theta) {
  double nx, ny;
  nx = x * cos(theta) - y * sin(theta);
  ny = x * sin(theta) + y * cos(theta);
  x = nx;
  y = ny;
}

int main() {
  double p[2][2], q[2];
  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf", &p[0][0], &p[0][1], &p[1][0],
               &p[1][1], &q[0], &q[1]) == 6) {
    double bias[2] = {p[0][0], p[0][1]};
    p[0][0] -= bias[0];
    p[0][1] -= bias[1];
    p[1][0] -= bias[0];
    p[1][1] -= bias[1];
    q[0] -= bias[0];
    q[1] -= bias[1];
    double theta = atan2(p[1][1] - p[0][1], p[1][0] - p[0][0]);
    rotate(q[0], q[1], -theta);
    double r[2] = {q[0], -q[1]};
    rotate(r[0], r[1], theta);
    r[0] += bias[0];
    r[1] += bias[1];
    printf("%lf %lf\n", r[0], r[1]);
  }
  return 0;
}
Problem p00081 (C++)

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

typedef long double ld;

const ld EPS = 1e-9;
const ld INF = 1e10;
const ld PI = M_PI;

struct Point {
  ld x, y;
  Point(ld x, ld y) : x(x), y(y) {}
  Point() {}
};

Point operator+(const Point &a, const Point &b) {
  return Point(a.x + b.x, a.y + b.y);
}
Point operator-(const Point &a, const Point &b) {
  return Point(a.x - b.x, a.y - b.y);
}
Point operator*(const Point &a, const ld b) { return Point(a.x * b, a.y * b); }
Point operator*(const Point &a, const Point &b) {
  return Point(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
}
Point operator/(const Point &a, const ld b) { return Point(a.x / b, a.y / b); }

ld dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; }
ld norm(const Point &a) { return dot(a, a); }

struct Line : vector<Point> {
  Line(Point a = Point(0, 0), Point b = Point(0, 0)) {
    this->push_back(a);
    this->push_back(b);
  }
};

// 写像
Point projection(const Line &l, const Point &p) {
  ld t = dot(p - l[0], l[1] - l[0]) / norm(l[0] - l[1]);
  return l[0] + (l[1] - l[0]) * t;
}

// 反射
Point reflection(const Line &l, const Point &p) {
  return p + (projection(l, p) - p) * 2;
}

int main() {
  double x1, y1, x2, y2, xq, yq;
  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf", &x1, &y1, &x2, &y2, &xq, &yq)) {
    Line l = Line(Point(x1, y1), Point(x2, y2));
    Point p = Point(xq, yq);

    Point ans = reflection(l, p);
    printf("%.6Lf %.6Lf\n", ans.x, ans.y);
  }
  return 0;
}

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

typedef long double ld;

const ld EPS = 1e-9;
const ld INF = 1e10;
const ld PI = M_PI;

struct Point {
  ld x, y;
  Point(ld x, ld y) : x(x), y(y) {}
  Point() {}
};

Point operator+(const Point &a, const Point &b) {
  return Point(a.x + b.x, a.y + b.y);
}
Point operator-(const Point &a, const Point &b) {
  return Point(a.x - b.x, a.y - b.y);
}
Point operator*(const Point &a, const ld b) { return Point(a.x * b, a.y * b); }
Point operator*(const Point &a, const Point &b) {
  return Point(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
}
Point operator/(const Point &a, const ld b) { return Point(a.x / b, a.y / b); }

ld dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; }
ld norm(const Point &a) { return dot(a, a); }

struct Line : vector<Point> {
  Line(Point a = Point(0, 0), Point b = Point(0, 0)) {
    this->push_back(a);
    this->push_back(b);
  }
};

// 写像
Point projection(const Line &l, const Point &p) {
  ld t = dot(p - l[0], l[1] - l[0]) / norm(l[0] - l[1]);
  return l[0] + (l[1] - l[0]) * t;
}

// 反射
Point reflection(const Line &l, const Point &p) {
  return p + (projection(l, p) - p) * 2;
}

int main() {
  double x1, y1, x2, y2, xq, yq;
  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf", &x1, &y1, &x2, &y2, &xq, &yq) !=
         EOF) {
    Line l = Line(Point(x1, y1), Point(x2, y2));
    Point p = Point(xq, yq);

    Point ans = reflection(l, p);
    printf("%.6Lf %.6Lf\n", ans.x, ans.y);
  }
  return 0;
}
Problem p00083 (C++)

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

int main(void) {
  int x, y, z, sum;
  while (true) {
    scanf("%d%d%d", &x, &y, &z);
    sum = 10000 * x + 100 * y + z;
    if (sum < 18680908) {
      printf("pre-meiji\n");
    } else if (sum < 19120730) {
      printf("meiji %d %d %d\n", x - 1867, y, z);
    } else if (sum < 19261225) {
      printf("taisho %d %d %d\n", x - 1911, y, z);
    } else if (sum < 19890108) {
      printf("showa %d %d %d\n", x - 1925, y, z);
    } else {
      printf("heisei %d %d %d\n", x - 1988, y, z);
    }
  }
  return 0;
}

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

int main(void) {
  int x, y, z, sum;
  while (scanf("%d%d%d", &x, &y, &z) != EOF) {
    sum = 10000 * x + 100 * y + z;
    if (sum < 18680908) {
      printf("pre-meiji\n");
    } else if (sum < 19120730) {
      printf("meiji %d %d %d\n", x - 1867, y, z);
    } else if (sum < 19261225) {
      printf("taisho %d %d %d\n", x - 1911, y, z);
    } else if (sum < 19890108) {
      printf("showa %d %d %d\n", x - 1925, y, z);
    } else {
      printf("heisei %d %d %d\n", x - 1988, y, z);
    }
  }
  return 0;
}
Problem p00085 (C++)

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

int main() {
  int total, step;
  vector<int> person;
  vector<int>::iterator it;
  int i, m;

  while (1) {
    // get input
    cin >> total >> step;

    // finish condition
    if (total == 0 && step == 0)
      break;

    // init
    for (i = 1; i <= total; i++) {
      person.push_back(i);
    }
    it = person.begin();

    while (1) {
      // answer
      if (person.size() == 1) {
        cout << person[0] << endl;
        person.clear();
        break;
      }

      // step forward
      for (m = 0; m < (step - 1); m++) {
        it++;
        if (it == person.end()) {
          it = person.begin();
        }
      }

      // delete
      person.erase(it);
      if (it == person.end()) {
        it = person.begin();
      }

      for (int k = 0; k < person.size(); k++) {
        cout << *it << "is erased " << person[k] << endl;
      }
    }
  }

  return 0;
}

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

int main() {
  int total, step;
  vector<int> person;
  vector<int>::iterator it;
  int i, m;

  while (1) {
    // get input
    cin >> total >> step;

    // finish condition
    if (total == 0 && step == 0)
      break;

    // init
    for (i = 1; i <= total; i++) {
      person.push_back(i);
    }
    it = person.begin();

    while (1) {
      // answer
      if (person.size() == 1) {
        cout << person[0] << endl;
        person.clear();
        break;
      }

      // step forward
      for (m = 0; m < (step - 1); m++) {
        it++;
        if (it == person.end()) {
          it = person.begin();
        }
      }

      // delete
      person.erase(it);
      if (it == person.end()) {
        it = person.begin();
      }

      //            for(int k = 0; k < person.size(); k++){
      //                cout << *it <<"is erased " << person[k] << endl;
      //            }
    }
  }

  return 0;
}
Problem p00085 (C++)

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

int main() {
  int n, m;
  queue<int> qu;
  while (1) {
    cin >> n >> m;
    if (!n && !m)
      break;
    for (int i = 1; i <= n; i++)
      qu.push(i);
    int cnt = 0;
    while (qu.front() != qu.back()) {
      int buf = qu.front();
      qu.pop();
      qu.push(buf);
      cnt++;
      if (cnt % (m - 1) == 0) {
        qu.pop();
      }
    }
    cout << qu.back() << endl;
    qu.pop();
  }
  return 0;
}

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

int main() {
  int n, m;
  queue<int> qu;
  while (1) {
    cin >> n >> m;
    if (!n && !m)
      break;
    for (int i = 1; i <= n; i++)
      qu.push(i);
    int cnt = 0;
    while (qu.front() != qu.back()) {
      int buf = qu.front();
      qu.pop();
      if (++cnt % m != 0)
        qu.push(buf);
    }
    cout << qu.back() << endl;
    qu.pop();
  }
  return 0;
}
Problem p00085 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int n, m, pc, count;
  while (cin >> n >> m) {
    if (n == 0 && m == 0)
      break;
    int p[n + 1];
    p[0] = 0;
    pc = n;
    count = 0;
    for (int i = 1; i <= n; i++)
      p[i] = 1;
    while (pc != 1) {
      for (int i = 1; i <= n; i++) {
        if (p[i] == 1)
          count++;
        if (count == m) {
          p[i] = 0;
          pc--;
          if (pc == -1)
            break;
          count = 0;
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      if (p[i] == 1)
        cout << i << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, m, pc, count;
  while (cin >> n >> m) {
    if (n == 0 && m == 0)
      break;
    int p[n + 1];
    p[0] = 0;
    pc = n;
    count = 0;
    for (int i = 1; i <= n; i++)
      p[i] = 1;
    while (pc != 1) {
      for (int i = 1; i <= n; i++) {
        if (p[i] == 1)
          count++;
        if (count == m) {
          p[i] = 0;
          pc--;
          if (pc == 1)
            break;
          count = 0;
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      if (p[i] == 1)
        cout << i << endl;
    }
  }
  return 0;
}
Problem p00085 (C++)

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

using namespace std;

int main() {

  int hito[1000];
  int m, n;
  int a;
  int counter = 0;
  int counter2 = 0;
  int k = 0;

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

    if (n == 0 && m == 0) {
      break;
    }

    for (int i = 0; i < n; i++) {
      hito[i] = 1;
    }

    while (1) {
      if (hito[k] == 1) {
        counter++;
      }

      if (counter == m) {
        hito[k] = 0;
        counter = 0;
        counter2++;
      }

      if (counter2 == n) {
        cout << k << endl;
      }

      k++;

      if (k >= n) {
        k = 0;
      }
    }
  }

  return 0;
}

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

using namespace std;

int main() {

  int hito[1000];
  int m, n;
  int a;
  int counter = 0;
  int counter2 = 0;
  int k = 0;

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

    if (n == 0 && m == 0) {
      break;
    }

    for (int i = 0; i < n; i++) {
      hito[i] = 1;
    }

    while (1) {
      if (hito[k] == 1) {
        counter++;
      }

      if (counter == m) {
        hito[k] = 0;
        counter = 0;
        counter2++;
      }

      if (counter2 == n) {
        cout << k + 1 << endl;
        counter = 0;
        counter2 = 0;
        k = 0;
        break;
      }

      k++;

      if (k >= n) {
        k = 0;
      }
    }
  }

  return 0;
}
Problem p00086 (C++)

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

int list[100];

int main(void) {
  int a, b;
  bool flag = false;
  while (scanf("%d %d", &a, &b)) {
    memset(list, 0, 100);
    list[a - 1]++;
    list[b - 1]++;
    while (true) {
      scanf("%d %d", &a, &b);
      if (!a && !b)
        break;
      list[a - 1]++;
      list[b - 1]++;
    }
    flag = false;
    if (!(list[0] & 1) || !(list[1] & 1))
      flag = true;
    for (int i = 2; i < 100; i++) {
      if (list[i] & 1)
        flag = true;
    }
    if (!flag)
      printf("OK\n");
    else
      printf("NG\n");
  }
  return 0;
}

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

int list[100];

int main(void) {
  int a, b;
  bool flag = false;
  while (scanf("%d %d", &a, &b) != EOF) {
    memset(list, 0, 100);
    list[a - 1]++;
    list[b - 1]++;
    while (true) {
      scanf("%d %d", &a, &b);
      if (!a && !b)
        break;
      list[a - 1]++;
      list[b - 1]++;
    }
    flag = false;
    if (!(list[0] & 1) || !(list[1] & 1))
      flag = true;
    for (int i = 2; i < 100; i++) {
      if (list[i] & 1)
        flag = true;
    }
    if (!flag)
      printf("OK\n");
    else
      printf("NG\n");
  }
  return 0;
}