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

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

  int a, b, c;
  int x = 0, y = 0;
  while (scanf("%d,%d,%d", &a, &b, &c)) {
    if (a * a + b * b == c * c) {
      x++;
      // cout<<a<<b<<c<<endl;
    }
    if (a == b) {
      y++;
      // cout<<a<<b<<c<<'.'<<endl;
    }
  }
  cout << x << endl << y << endl;

  return 0;
}

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

  int a, b, c;
  int x = 0, y = 0;
  while (scanf("%d,%d,%d", &a, &b, &c) != EOF) {
    if (a * a + b * b == c * c) {
      x++;
      // cout<<a<<b<<c<<endl;
    }
    if (a == b) {
      y++;
      // cout<<a<<b<<c<<'.'<<endl;
    }
  }
  cout << x << endl << y << endl;

  return 0;
}
Problem p00033 (C++)

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

#define N 10

int D, Ball[N];
int R, L;

bool solve(int i) {
  if (i == N)
    return true;
  if (R < Ball[i]) {
    R = Ball[i];
    if (solve(i + 1))
      return true;
  }
  if (L < Ball[i]) {
    L = Ball[i];
    if (solve(i + 1))
      return true;
  }
  return false;
}

int main() {
  scanf("%d", D);
  for (int i = 0; i < D; i++) {
    R = L = 0;
    for (int j = 0; j < N; j++)
      scanf("%d", &Ball[j]);
    R = Ball[0];
    if (solve(1))
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}

Fixed submission:
#include <cstdio>

#define N 10

int D, Ball[N];
int R, L;

bool solve(int i) {
  if (i == N)
    return true;
  if (R < Ball[i]) {
    R = Ball[i];
    if (solve(i + 1))
      return true;
  }
  if (L < Ball[i]) {
    L = Ball[i];
    if (solve(i + 1))
      return true;
  }
  return false;
}

int main() {
  scanf("%d", &D);
  for (int i = 0; i < D; i++) {
    R = L = 0;
    for (int j = 0; j < N; j++)
      scanf("%d", &Ball[j]);
    R = Ball[0];
    if (solve(1))
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
Problem p00034 (C++)

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

int main() {
  int l[10], v1, v2;
  int len;

  while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", l, &l[1], &l[2], &l[3],
               &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1, &v2)) {
    len = 0;
    for (int i = 0; i < 10; i++) {
      len += l[i];
    }
    double t = (double)len / (v1 + v2);
    double d = (double)v1 * t;
    len = 0;
    for (int i = 0; i < 10; i++) {
      len += l[i];
      if (d <= len) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
}

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

int main() {
  int l[10], v1, v2;
  int len;

  while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", l, &l[1], &l[2], &l[3],
               &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1, &v2) != EOF) {
    len = 0;
    for (int i = 0; i < 10; i++) {
      len += l[i];
    }
    double t = (double)len / (v1 + v2);
    double d = (double)v1 * t;
    len = 0;
    for (int i = 0; i < 10; i++) {
      len += l[i];
      if (d <= len) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
}
Problem p00034 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int inf = 1000000000;

int main(void) {

  vector<int> l(10);
  vector<int> v(2);
  while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l[0], &l[1], &l[2],
               &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v[0], &v[1])) {
    int sum = accumulate(l.begin(), l.end(), 0);
    // cerr << sum << " ";
    double tmp = sum * v[0] * 1.0 / (v[0] + v[1]);
    // cerr << tmp << endl;
    for (int i = 1; i < 10; i++)
      l[i] += l[i - 1];
    // int a = 0;
    for (int i = 1; i < 10; i++) {
      if (l[i - 1] == tmp) {
        cout << i << endl;
        break;
      } else if (l[i - 1] < tmp && tmp < l[i]) {
        // cerr << l[i-1] << " " << l[i] << endl;
        cout << i + 1 << endl;
        // break;
      }
    }
  }

  return 0;
}

// EOF

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

int main(void) {

  vector<int> l(10);
  vector<int> v(2);
  while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l[0], &l[1], &l[2],
               &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v[0],
               &v[1]) != EOF) {
    int sum = accumulate(l.begin(), l.end(), 0);
    // cerr << sum << " ";
    double tmp = sum * v[0] * 1.0 / (v[0] + v[1]);
    // cerr << tmp << endl;
    for (int i = 1; i < 10; i++)
      l[i] += l[i - 1];
    // int a = 0;
    for (int i = 1; i < 10; i++) {
      if (l[i - 1] == tmp) {
        cout << i << endl;
        break;
      } else if (l[i - 1] < tmp && tmp < l[i]) {
        // cerr << l[i-1] << " " << l[i] << endl;
        cout << i + 1 << endl;
        // break;
      }
    }
  }

  return 0;
}

// EOF
Problem p00034 (C++)

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

using namespace std;

int data[11];
int sum = 0;
bool input() {
  fill(data, data + 11, 0);
  char c;
  int x;
  for (int i = 1; i <= 10; i++) {
    cin >> x;
    cin >> c;
    data[i] = data[i - 1] + x;
  }
  return true;
}
int main() {
  while (input()) {
    int v1, v2;
    char c;
    cin >> v1 >> c >> v2;
    double t = 1. * data[10] / (v1 + v2);

    for (int i = 1; i <= 10; i++) {
      if (v1 * t <= data[i]) {
        cout << i << endl;
        break;
      }
    }
  }
}

Fixed submission:
#include <iostream>

using namespace std;

int data[11];
int sum = 0;
bool input() {
  fill(data, data + 11, 0);
  char c;
  int x;
  for (int i = 1; i <= 10; i++) {
    if (!(cin >> x))
      return false;
    cin >> c;
    data[i] = data[i - 1] + x;
  }
  return true;
}
int main() {
  while (input()) {
    int v1, v2;
    char c;
    cin >> v1 >> c >> v2;
    double t = 1. * data[10] / (v1 + v2);

    for (int i = 1; i <= 10; i++) {
      if (v1 * t <= data[i]) {
        cout << i << endl;
        break;
      }
    }
  }
}
Problem p00034 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int dis[10], v1, v2;
  while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &dis[0], &dis[1], &dis[2],
               &dis[3], &dis[4], &dis[5], &dis[6], &dis[7], &dis[8], &dis[9],
               &v1, &v2)) {
    int sum = 0;
    for (int i = 0; i < 10; i++)
      sum += dis[i];
    double col = (double)sum * (double)v1 / (double)(v1 + v2);
    // cout<<"col:"<<col<<endl;
    sum = 0;
    for (int i = 0; i < 10; i++) {
      sum += dis[i];
      if ((double)sum - col >= -0.000000001) {
        sum = i;
        break;
      }
    }
    cout << sum + 1 << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int dis[10], v1, v2;
  while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &dis[0], &dis[1], &dis[2],
               &dis[3], &dis[4], &dis[5], &dis[6], &dis[7], &dis[8], &dis[9],
               &v1, &v2) != EOF) {
    int sum = 0;
    for (int i = 0; i < 10; i++)
      sum += dis[i];
    double col = (double)sum * (double)v1 / (double)(v1 + v2);
    // cout<<"col:"<<col<<endl;
    sum = 0;
    for (int i = 0; i < 10; i++) {
      sum += dis[i];
      if ((double)sum - col >= -0.000000001) {
        sum = i;
        break;
      }
    }
    cout << sum + 1 << endl;
  }
  return 0;
}
Problem p00034 (C++)

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

int pow(int a, int n) {
  if (n <= 0) {
    return 1;
  }
  return a * pow(a, n - 1);
}

int main() {
  int v1, v2;
  int a[10];
  int sum1;
  int sum2;
  int ans = 0;
  while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &a[0], &a[1], &a[2],
               &a[3], &a[4], &a[5], &a[6], &a[7], &a[8], &a[9], &v1,
               &v2) != 0) {
    sum1 = 0;
    sum2 = 0;
    for (int i = 0; i < 10; i++) {
      sum1 += a[i];
    }
    for (int i = 0; i < 10; i++) {
      sum2 += a[i];
      if (sum1 * v1 > sum2 * (v1 + v2)) {
        ans = i + 2;
      }
    }
    printf("%d\n", ans);
  }
  ///////////////////////////////////
  // Sleep(200000);///////////////////// 提出するときは必ず外す！
  ///////////////////////////////////
  return 0;
}

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

int pow(int a, int n) {
  if (n <= 0) {
    return 1;
  }
  return a * pow(a, n - 1);
}

int main() {
  int v1, v2;
  int a[10];
  int sum1;
  int sum2;
  int ans = 0;
  while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &a[0], &a[1], &a[2],
               &a[3], &a[4], &a[5], &a[6], &a[7], &a[8], &a[9], &v1,
               &v2) != EOF) {
    sum1 = 0;
    sum2 = 0;
    for (int i = 0; i < 10; i++) {
      sum1 += a[i];
    }
    for (int i = 0; i < 10; i++) {
      sum2 += a[i];
      if (sum1 * v1 > sum2 * (v1 + v2)) {
        ans = i + 2;
      }
    }
    printf("%d\n", ans);
  }
  ///////////////////////////////////
  // Sleep(200000);///////////////////// 提出するときは必ず外す！
  ///////////////////////////////////
  return 0;
}
Problem p00034 (C++)

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

using namespace std;

int main() {
  double b[10];
  double v1, v2;

  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &b[0], &b[1],
               &b[2], &b[3], &b[4], &b[5], &b[6], &b[7], &b[8], &b[9], &v1,
               &v2)) {
    double l =
        b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6] + b[7] + b[8] + b[9];
    double t = l / (v1 + v2);
    double l1 = t * v1;
    for (int i = 0; i < 10; i++) {
      l1 -= b[i];
      if (l1 <= 0) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
  return 0;
}

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

using namespace std;

int main() {
  double b[10];
  double v1, v2;

  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &b[0], &b[1],
               &b[2], &b[3], &b[4], &b[5], &b[6], &b[7], &b[8], &b[9], &v1,
               &v2) != EOF) {
    double l =
        b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6] + b[7] + b[8] + b[9];
    double t = l / (v1 + v2);
    double l1 = t * v1;
    for (int i = 0; i < 10; i++) {
      l1 -= b[i];
      if (l1 <= 0) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p00034 (C++)

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

using namespace std;

int main(void) {
  double line[10];
  double v1, v2;

  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &line[0],
               &line[1], &line[2], &line[3], &line[4], &line[5], &line[6],
               &line[7], &line[8], &line[9], &v1, &v2)) {

    double sum = 0;

    for (int i = 0; i < 10; i++) {
      sum += line[i];
    }

    double time = sum / (v1 + v2);

    double dist = time * v1;

    for (int i = 0; i < 10; i++) {
      dist -= line[i];

      if (dist <= 0) {
        cout << i + 1 << endl;
        break;
      }
    }
  }

  return 0;
}

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

using namespace std;

int main(void) {
  double line[10];
  double v1, v2;

  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &line[0],
               &line[1], &line[2], &line[3], &line[4], &line[5], &line[6],
               &line[7], &line[8], &line[9], &v1, &v2) != EOF) {

    double sum = 0;

    for (int i = 0; i < 10; i++) {
      sum += line[i];
    }

    double time = sum / (v1 + v2);

    double dist = time * v1;

    for (int i = 0; i < 10; i++) {
      dist -= line[i];

      if (dist <= 0) {
        cout << i + 1 << endl;
        break;
      }
    }
  }

  return 0;
}
Problem p00034 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <numeric>
using namespace std;
int main() {
  int l[10], v1, v2, ret;
  while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l[0], &l[1], &l[2],
               &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1, &v2)) {
    int sum = accumulate(l, l + 10, 0), k = 0;
    double ret = ((double)v1 / (v1 + v2)) * sum;
    for (int i = 0; i < 10; i++) {
      if ((k += l[i]) >= ret) {
        printf("%d\n", i + 1);
        break;
      }
    }
  }
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <numeric>
using namespace std;
int main() {
  int l[10], v1, v2, ret;
  while (~scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l[0], &l[1], &l[2],
                &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1, &v2)) {
    int sum = accumulate(l, l + 10, 0), k = 0;
    double ret = ((double)v1 / (v1 + v2)) * sum;
    for (int i = 0; i < 10; i++) {
      if ((k += l[i]) >= ret) {
        printf("%d\n", i + 1);
        break;
      }
    }
  }
}
Problem p00034 (C++)

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

int main() {
  int dis[10], v_0 = 0, v_1 = 0;
  while (scanf("%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d", &dis[0],
               &dis[1], &dis[2], &dis[3], &dis[4], &dis[5], &dis[6], &dis[7],
               &dis[8], &dis[9], &v_0, &v_1)) {
    int dsum = 0;
    double acum[10];
    for (int x = 0; x < 10; ++x) {
      dsum += dis[x];
      acum[x] = 1.0 * dsum;
    }
    double dd = v_0 * (dsum * 1.0 / (v_0 + v_1));
    // cout<<dd<<endl;
    int index = 0;
    while (index < 10 && acum[index] < dd) {
      ++index;
    }
    --index;
    if (acum[index] == dd)
      cout << index + 1 << endl;
    else
      cout << index + 2 << endl;
  }
  return 0;
}

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

int main() {
  int dis[10], v_0 = 0, v_1 = 0;
  while (scanf("%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d", &dis[0],
               &dis[1], &dis[2], &dis[3], &dis[4], &dis[5], &dis[6], &dis[7],
               &dis[8], &dis[9], &v_0, &v_1) == 12) {
    int dsum = 0;
    double acum[10];
    for (int x = 0; x < 10; ++x) {
      dsum += dis[x];
      acum[x] = 1.0 * dsum;
    }
    double dd = v_0 * (dsum * 1.0 / (v_0 + v_1));
    // cout<<dd<<endl;
    int index = 0;
    while (index < 10 && acum[index] < dd) {
      ++index;
    }
    --index;
    if (acum[index] == dd)
      cout << index + 1 << endl;
    else
      cout << index + 2 << endl;
  }
  return 0;
}
Problem p00034 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define PI acos(-1.0)
#define ALL(A) ((A).begin(), (A).end())
#define vsort(v) sort(v.begin(), v.end())
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)

int main() {
  double v1, v2, l[10];
  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &l[0], &l[1],
               &l[2], &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1,
               &v2)) {

    double p[11];
    p[0] = 0;
    FOR(i, 1, 11) { p[i] = p[i - 1] + l[i - 1]; }
    FOR(i, 0, 10) {
      double vt = (p[10] * v1) / (v1 + v2);
      if (p[i] < vt && p[i + 1] >= vt) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define PI acos(-1.0)
#define ALL(A) ((A).begin(), (A).end())
#define vsort(v) sort(v.begin(), v.end())
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)

int main() {
  double v1, v2, l[10];
  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &l[0], &l[1],
               &l[2], &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1,
               &v2) != EOF) {

    double p[11];
    p[0] = 0;
    FOR(i, 1, 11) { p[i] = p[i - 1] + l[i - 1]; }
    FOR(i, 0, 10) {
      double vt = (p[10] * v1) / (v1 + v2);
      if (p[i] < vt && p[i + 1] >= vt) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
}
Problem p00035 (C++)

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

using namespace std;
typedef pair<double, double> P;

double Helon(P pa, P pb, P pc) {
  double a, b, c;
  a = sqrt((pb.first - pa.first) * (pb.first - pa.first) +
           (pb.second - pa.second) * (pb.second - pa.second));
  b = sqrt((pc.first - pb.first) * (pc.first - pb.first) +
           (pc.second - pb.second) * (pc.second - pb.second));
  c = sqrt((pa.first - pc.first) * (pa.first - pc.first) +
           (pa.second - pc.second) * (pa.second - pc.second));
  double s = (a + b + c) / 2;
  return (sqrt(s * (s - a) * (s - b) * (s - c)));
}

void solve() {
  vector<P> p(4);
  while (scanf("%lf,%lf", &p[0].first, &p[0].second)) {
    for (int i = 1; i < 4; ++i) {
      scanf(",%lf,%lf", &p[i].first, &p[i].second);
    }
    double S1, S2;
    S1 = Helon(p[0], p[1], p[2]);
    S1 += Helon(p[0], p[2], p[3]);

    S2 = Helon(p[0], p[1], p[3]);
    S2 += Helon(p[1], p[2], p[3]);
    if (fabs(S1 - S2) < 1e-10) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}

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

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

using namespace std;
typedef pair<double, double> P;

double Helon(P pa, P pb, P pc) {
  double a, b, c;
  a = sqrt((pb.first - pa.first) * (pb.first - pa.first) +
           (pb.second - pa.second) * (pb.second - pa.second));
  b = sqrt((pc.first - pb.first) * (pc.first - pb.first) +
           (pc.second - pb.second) * (pc.second - pb.second));
  c = sqrt((pa.first - pc.first) * (pa.first - pc.first) +
           (pa.second - pc.second) * (pa.second - pc.second));
  double s = (a + b + c) / 2;
  return (sqrt(s * (s - a) * (s - b) * (s - c)));
}

void solve() {
  vector<P> p(4);
  while (~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &p[0].first, &p[0].second,
                &p[1].first, &p[1].second, &p[2].first, &p[2].second,
                &p[3].first, &p[3].second)) {
    double S1, S2;
    S1 = Helon(p[0], p[1], p[2]);
    S1 += Helon(p[0], p[2], p[3]);

    S2 = Helon(p[0], p[1], p[3]);
    S2 += Helon(p[1], p[2], p[3]);
    if (fabs(S1 - S2) < 1e-10) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  double xa, ya, xb, yb, xc, yc, xd, yd, s1, s2, s3, s4;
  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc,
               &xd, &yd)) {
    s1 = abs((xc - xa) * (yb - ya) - (xb - xa) * (yc - ya));
    s2 = abs((xc - xa) * (yd - ya) - (xd - xa) * (yc - ya));
    s3 = abs((xb - xa) * (yd - ya) - (xd - xa) * (yb - ya));
    s4 = abs((xb - xc) * (yd - yc) - (xd - xc) * (yb - yc));
    if (s1 + s2 == s3 + s4) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  double xa, ya, xb, yb, xc, yc, xd, yd, s1, s2, s3, s4;
  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc,
               &xd, &yd) != EOF) {
    s1 = abs((xc - xa) * (yb - ya) - (xb - xa) * (yc - ya));
    s2 = abs((xc - xa) * (yd - ya) - (xd - xa) * (yc - ya));
    s3 = abs((xb - xa) * (yd - ya) - (xd - xa) * (yb - ya));
    s4 = abs((xb - xc) * (yd - yc) - (xd - xc) * (yb - yc));
    if (s1 + s2 == s3 + s4) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
Problem p00035 (C++)

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

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

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

struct vector2D {
  double x;
  double y;
};

vector2D subVector(const vector2D &t1, const vector2D &t2) {
  vector2D ret;
  ret.x = t1.x - t2.x;
  ret.y = t1.y - t2.y;
  return ret;
}

bool hittest(vector2D a, vector2D b, vector2D c, vector2D p) {
  vector2D AB = subVector(b, a);
  vector2D BP = subVector(p, b);

  vector2D BC = subVector(c, b);
  vector2D CP = subVector(p, c);

  vector2D CA = subVector(a, c);
  vector2D AP = subVector(p, a);

  double c1 = AB.x * BP.y - AB.y * BP.x;
  double c2 = BC.x * CP.y - BC.y * CP.x;
  double c3 = CA.x * AP.y - CA.y * AP.x;

  if ((c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0)) {
    return true;
  }

  return false;
}

signed main(void) {
  vector2D p1, p2, p3, p4;
  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &p1.x, &p1.y, &p2.x, &p2.y,
               &p3.x, &p3.y, &p4.x, &p4.y)) {
    if (hittest(p1, p2, p3, p4) || hittest(p1, p2, p4, p3) ||
        hittest(p1, p3, p4, p2) || hittest(p2, p3, p4, p1))
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}

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

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

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

struct vector2D {
  double x;
  double y;
};

vector2D subVector(const vector2D &t1, const vector2D &t2) {
  vector2D ret;
  ret.x = t1.x - t2.x;
  ret.y = t1.y - t2.y;
  return ret;
}

bool hittest(vector2D a, vector2D b, vector2D c, vector2D p) {
  vector2D AB = subVector(b, a);
  vector2D BP = subVector(p, b);

  vector2D BC = subVector(c, b);
  vector2D CP = subVector(p, c);

  vector2D CA = subVector(a, c);
  vector2D AP = subVector(p, a);

  double c1 = AB.x * BP.y - AB.y * BP.x;
  double c2 = BC.x * CP.y - BC.y * CP.x;
  double c3 = CA.x * AP.y - CA.y * AP.x;

  if ((c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0)) {
    return true;
  }

  return false;
}

signed main(void) {
  vector2D p1, p2, p3, p4;
  while (~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &p1.x, &p1.y, &p2.x, &p2.y,
                &p3.x, &p3.y, &p4.x, &p4.y)) {
    if (hittest(p1, p2, p3, p4) || hittest(p1, p2, p4, p3) ||
        hittest(p1, p3, p4, p2) || hittest(p2, p3, p4, p1))
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}
Problem p00035 (C++)

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

//??´???AB????§?????????´???BC????§??????????RotType????¨????(A???B???C????????§??????)
// RotType = ????????¢1, ????????¢-1, ??´???0
int getRotType(double angle_a, double angle_b) {
  const int eps = 1e-8;
  const double PAI = 3.14159265358979;

  if (fabs(angle_a - angle_b) <= eps)
    return 0;
  if (angle_a > angle_b + PAI)
    angle_b += 2 * PAI;
  else if (angle_b > angle_a + PAI)
    angle_a += 2 * PAI;

  if (angle_b > angle_a) //?§????????¢????????????????
    return 1;
  return -1; //?§???????????°?????????????
}

int main() {
  double x[4], y[4];
  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x[0], &y[0], &x[1], &y[1],
               &x[2], &y[2], &x[3], &y[3])) {
    // A???B???C, B???C???D,
    // C???D???A?????????????????¨???????????????????????????
    double ang[4];

    for (int i = 0; i < 4; i++)
      ang[i] = atan2(y[(i + 1) % 4] - y[i % 4], x[(i + 1) % 4] - x[i % 4]);

    double angType[4];
    for (int i = 0; i < 4; i++)
      angType[i] = getRotType(ang[i], ang[(i + 1) % 4]);

    int i;
    for (i = 0; i < 3; i++) {
      if (angType[i] != angType[i + 1])
        break;
    }
    if (i == 3)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

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

//??´???AB????§?????????´???BC????§??????????RotType????¨????(A???B???C????????§??????)
// RotType = ????????¢1, ????????¢-1, ??´???0
int getRotType(double angle_a, double angle_b) {
  const int eps = 1e-8;
  const double PAI = 3.14159265358979;

  if (fabs(angle_a - angle_b) <= eps)
    return 0;
  if (angle_a > angle_b + PAI)
    angle_b += 2 * PAI;
  else if (angle_b > angle_a + PAI)
    angle_a += 2 * PAI;

  if (angle_b > angle_a) //?§????????¢????????????????
    return 1;
  return -1; //?§???????????°?????????????
}

int main() {
  double x[4], y[4];
  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x[0], &y[0], &x[1], &y[1],
               &x[2], &y[2], &x[3], &y[3]) != -1) {
    // A???B???C, B???C???D,
    // C???D???A?????????????????¨???????????????????????????
    double ang[4];

    for (int i = 0; i < 4; i++)
      ang[i] = atan2(y[(i + 1) % 4] - y[i % 4], x[(i + 1) % 4] - x[i % 4]);

    double angType[4];
    for (int i = 0; i < 4; i++)
      angType[i] = getRotType(ang[i], ang[(i + 1) % 4]);

    int i;
    for (i = 0; i < 3; i++) {
      if (angType[i] != angType[i + 1])
        break;
    }
    if (i == 3)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
Problem p00035 (C++)

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

using namespace std;

bool check(double X1, double Y1, double X2, double Y2, double X3, double Y3,
           double X4, double Y4) {
  return ((X1 - X2) * (Y3 - Y1) - (Y1 - Y2) * (X3 - X1)) *
             ((X1 - X2) * (Y4 - Y1) - (Y1 - Y2) * (X4 - X1)) >
         0.0;
}

void solve() {
  double xa, ya, xb, yb, xc, yc, xd, yd;
  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc,
               &xd, &yd))
    if (check(xa, ya, xc, yc, xb, yb, xd, yd) ||
        check(xb, yb, xd, yd, xa, ya, xc, yc)) {
      cout << "NO" << endl;
    } else {
      cout << "YES" << endl;
    }
}

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

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

using namespace std;

bool check(double X1, double Y1, double X2, double Y2, double X3, double Y3,
           double X4, double Y4) {
  return ((X1 - X2) * (Y3 - Y1) - (Y1 - Y2) * (X3 - X1)) *
             ((X1 - X2) * (Y4 - Y1) - (Y1 - Y2) * (X4 - X1)) >
         0.0;
}

void solve() {
  double xa, ya, xb, yb, xc, yc, xd, yd;
  while (~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc,
                &xd, &yd))
    if (check(xa, ya, xc, yc, xb, yb, xd, yd) ||
        check(xb, yb, xd, yd, xa, ya, xc, yc)) {
      cout << "NO" << endl;
    } else {
      cout << "YES" << endl;
    }
}

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

Buggy submission (status: Time Limit Exceeded):
#include <array>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#define _X_ 0
#define _Y_ 1
int main() {
  while (true) {
    std::vector<std::array<int, 2>> p;
    p.reserve(4);
    for (int i = 0; i < 8; i++) {
      std::string temp;
      std::cin >> temp;
      std::stringstream st(temp);
      for (int j = 0; j < 8; j++) {
        char foo;
        st >> foo;
        if (foo == '1') {
          p.push_back({j, i});
        }
      }
    }
    if (p[0][_Y_] == p[1][_Y_]) {
      if (p[0][_X_] == p[2][_X_]) {
        std::cout << 'A' << std::endl;
      } else if (p[0][_Y_] == p[2][_Y_]) {
        std::cout << 'C' << std::endl;
      } else if (p[1][_X_] == p[2][_X_]) {
        std::cout << 'E' << std::endl;
      } else if (p[0][_X_] == p[3][_X_]) {
        std::cout << 'G' << std::endl;
      }
    } else {
      if (p[0][_X_] == p[3][_X_]) {
        std::cout << 'B' << std::endl;
      } else if (p[0][_X_] > p[3][_X_]) {
        std::cout << 'D' << std::endl;
      } else {
        std::cout << 'F' << std::endl;
      }
    }
  }
  return 0;
}


Fixed submission:
#include <array>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#define _X_ 0
#define _Y_ 1
int main() {
  while (true) {
    std::vector<std::array<int, 2>> p;
    p.reserve(4);
    for (int i = 0; i < 8; i++) {
      std::string temp;
      std::cin >> temp;
      std::stringstream st(temp);
      for (int j = 0; j < 8; j++) {
        char foo;
        st >> foo;
        if (foo == '1') {
          p.push_back({j, i});
        }
      }
    }
    if (std::cin.eof()) {
      break;
    }
    if (p[0][_Y_] == p[1][_Y_]) {
      if (p[0][_X_] == p[2][_X_]) {
        std::cout << 'A' << std::endl;
      } else if (p[0][_Y_] == p[2][_Y_]) {
        std::cout << 'C' << std::endl;
      } else if (p[1][_X_] == p[2][_X_]) {
        std::cout << 'E' << std::endl;
      } else if (p[0][_X_] == p[3][_X_]) {
        std::cout << 'G' << std::endl;
      }
    } else {
      if (p[0][_X_] == p[3][_X_]) {
        std::cout << 'B' << std::endl;
      } else if (p[0][_X_] > p[3][_X_]) {
        std::cout << 'D' << std::endl;
      } else {
        std::cout << 'F' << std::endl;
      }
    }
  }
  return 0;
}
Problem p00036 (C++)

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

int main() {
  char p[7][19] = {
      "1100000011",  "10000000100000001",  "1111",     "1000000110000001",
      "11000000011", "100000001100000001", "110000011"};
  char f[65];
  char t;
  while (1 + scanf("%c", &t)) {
    while (t == 10) {
      scanf("%c", &t);
    }
    f[0] = t;
    for (int i = 1; i < 64; i++) {
      scanf("%c", &t);
      while (t == 10) {
        scanf("%c", &t);
      }
      f[i] = t;
    }
    f[64] = '\0';
    for (int i = 0; i < 7; i++) {
      if (strstr(f, p[i])) {
        printf("%c\n", i + 'A');
      }
    }
  }
  return 0;
}

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

int main() {
  char p[7][19] = {
      "1100000011",  "10000000100000001",  "1111",     "1000000110000001",
      "11000000011", "100000001100000001", "110000011"};
  char f[65];
  char t;
  while (1 + scanf("%c", &t)) {
    while (t == 10) {
      scanf("%c", &t);
    }
    f[0] = t;
    for (int i = 1; i < 64; i++) {
      scanf("%c", &t);
      while (t == 10) {
        scanf("%c", &t);
      }
      f[i] = t;
    }
    f[64] = '\0';
    for (int i = 0; i < 7; i++) {
      if (strstr(f, p[i])) {
        printf("%c\n", i + 'A');
      }
    }
    scanf("%c", &t);
  }
  return 0;
}
Problem p00036 (C++)

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

vector<string> f;

const string P[7][4] = {
    {// A
     "1100", "1100", "0000", "0000"},
    {// B
     "1000", "1000", "1000", "1000"},
    {// C
     "1111", "0000", "0000", "0000"},
    {// D
     "0100", "1100", "1000", "0000"},
    {// E
     "1100", "0110", "0000", "0000"},
    {// F
     "1000", "1100", "0100", "0000"},
    {// G
     "0110", "1100", "0000", "0000"},
};

bool check(int x, int y, int k) {
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      int nx = x + j;
      int ny = y + i;
      if (P[k][i][j] == '1') {
        if (nx < 0 || nx > 8 || ny < 0 || ny > 8) {
          return false;
        }
        if (P[k][i][j] != f[ny][nx])
          return false;
      }
    }
  }
  return true;
}

int main(void) {
  while (cin.eof() == false) {
    f = vector<string>(8);
    string line;
    for (int i = 0; i < 8; i++) {
      getline(cin, line);
      f[i] = line;
      if (cin.eof())
        break;
    }
    if (cin.eof())
      break;
    getline(cin, line);

    char answer = 'A';
    bool not_found = true;
    for (int i = 0; not_found && i < 8; i++) {
      for (int j = 0; not_found && j < 8; j++) {
        for (int k = 0; not_found && k < 7; k++) {
          if (check(j, i, k)) {
            answer += k;
            not_found = false;
          }
        }
      }
    }

    cout << answer << endl;
  }
  return 0;
}

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

vector<string> f;

const string P[7][4] = {
    {// A
     "1100", "1100", "0000", "0000"},
    {// B
     "1000", "1000", "1000", "1000"},
    {// C
     "1111", "0000", "0000", "0000"},
    {// D
     "0100", "1100", "1000", "0000"},
    {// E
     "1100", "0110", "0000", "0000"},
    {// F
     "1000", "1100", "0100", "0000"},
    {// G
     "0110", "1100", "0000", "0000"},
};

bool check(int x, int y, int k) {
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      int nx = x + j;
      int ny = y + i;
      if (P[k][i][j] == '1') {
        if (nx < 0 || nx >= 8 || ny < 0 || ny >= 8) {
          return false;
        }
        if (P[k][i][j] != f[ny][nx])
          return false;
      }
    }
  }
  return true;
}

int main(void) {
  while (cin.eof() == false) {
    f = vector<string>(8);
    string line;
    for (int i = 0; i < 8; i++) {
      getline(cin, line);
      f[i] = line;
      if (cin.eof())
        break;
    }
    if (cin.eof())
      break;
    getline(cin, line);

    char answer = 'A';
    bool not_found = true;
    for (int i = 0; not_found && i < 8; i++) {
      for (int j = 0; not_found && j < 8; j++) {
        for (int k = 0; not_found && k < 7; k++) {
          if (check(j, i, k)) {
            answer += k;
            not_found = false;
          }
        }
      }
    }

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long int lli;
using namespace std;

int dx[7][4] = {{0, 0, 1, 1}, {0, 0, 0, 0}, {0, 1, 2, 3}, {0, 0, -1, -1},
                {0, 1, 1, 2}, {0, 0, 1, 1}, {0, -1, 0, 1}};
int dy[7][4] = {{0, 1, 1, 0}, {0, 1, 2, 3}, {0, 0, 0, 0}, {0, 1, 1, 2},
                {0, 0, 1, 1}, {0, 1, 1, 2}, {0, 1, 1, 0}};
string MAP[8];
string ans = "ABCDEFG";

int main() {
  while (1) {
    for (int i = 0; i < 8; ++i) {
      for (int j = 0; j < 8; ++j) {
        cin >> MAP[i][j];
      }
    }
    for (int i = 0; i < 8; ++i) {
      for (int j = 0; j < 8; ++j) {
        if (MAP[i][j] == '1') {
          for (int k = 0; k < 7; ++k) {
            bool ok = true;
            for (int l = 0; l < 4; ++l) {
              int nx = j + dx[k][l];
              int ny = i + dy[k][l];
              if ((0 <= nx && nx < 8 && 0 <= ny && ny < 8 &&
                   MAP[ny][nx] != '1') ||
                  (nx < 0 || 8 <= nx || ny < 0 || 8 <= ny)) {
                ok = false;
                break;
              }
            }
            if (ok) {
              cout << ans[k] << "\n";
              break;
            }
          }
        }
      }
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long int lli;
using namespace std;

int dx[7][4] = {{0, 0, 1, 1}, {0, 0, 0, 0}, {0, 1, 2, 3}, {0, 0, -1, -1},
                {0, 1, 1, 2}, {0, 0, 1, 1}, {0, -1, 0, 1}};
int dy[7][4] = {{0, 1, 1, 0}, {0, 1, 2, 3}, {0, 0, 0, 0}, {0, 1, 1, 2},
                {0, 0, 1, 1}, {0, 1, 1, 2}, {0, 1, 1, 0}};
string MAP[8];
string ans = "ABCDEFG";

int main() {
  while (1) {
    for (int i = 0; i < 8; ++i) {
      if (!(cin >> MAP[i])) {
        return 0;
      }
    }
    for (int i = 0; i < 8; ++i) {
      for (int j = 0; j < 8; ++j) {
        if (MAP[i][j] == '1') {
          for (int k = 0; k < 7; ++k) {
            bool ok = true;
            for (int l = 0; l < 4; ++l) {
              int nx = j + dx[k][l];
              int ny = i + dy[k][l];
              if ((0 <= nx && nx < 8 && 0 <= ny && ny < 8 &&
                   MAP[ny][nx] != '1') ||
                  (nx < 0 || 8 <= nx || ny < 0 || 8 <= ny)) {
                ok = false;
                break;
              }
            }
            if (ok) {
              cout << ans[k] << "\n";
              break;
            }
          }
        }
      }
    }
  }
  return 0;
}
Problem p00036 (C++)

Buggy submission (status: Runtime Error):
// A Figure on Surface

#include <iostream>
#include <string>
using namespace std;

int main(void) {
  const int N = 8;
  while (1) {
    string a[N];
    int i, j;
    for (i = 0; i < N; i++) {
      cin >> a[i];
    }
    if (!cin)
      break;

    // ¶ã©çÌÀWð²×é
    for (i = 0; i < N; i++) {
      for (j = 0; j < N; j++) {
        if (a[i][j] == '1')
          goto DISCOVER;
      }
    }
  DISCOVER:
    // ÔÈñÄÇ¤ÅàÇ¢©çÀSÉs«Üµå¤
    if ((a[i][j] == a[i + 1][j]) && (a[i][j] == a[i][j + 1]) &&
        (a[i][j] == a[i + 1][j + 1]))
      cout << 'A' << endl;
    else if ((i < N - 3) && (a[i][j] == a[i + 3][j]))
      cout << 'B' << endl;
    else if ((j < N - 3) && (a[i][j] == a[i][j + 3]))
      cout << 'C' << endl;
    else if ((i < N - 2) && (j > 0) && (a[i][j] == a[i + 2][j - 1]))
      cout << 'D' << endl;
    else if ((j < N - 2) && (a[i][j] == a[i + 1][j + 2]))
      cout << 'E' << endl;
    else if ((i < N - 2) && (a[i][j] == a[i + 2][j + 1]))
      cout << 'F' << endl;
    else
      cout << 'G' << endl;
  }
  return 0;
}

Fixed submission:
// A Figure on Surface

#include <iostream>
#include <string>
using namespace std;

int main(void) {
  const int N = 8;
  while (1) {
    string a[N];
    int i, j;
    for (i = 0; i < N; i++) {
      cin >> a[i];
    }
    if (!cin)
      break;

    // ¶ã©çÌÀWð²×é
    for (i = 0; i < N; i++) {
      for (j = 0; j < N; j++) {
        if (a[i][j] == '1')
          goto DISCOVER;
      }
    }
  DISCOVER:
    // ÔÈñÄÇ¤ÅàÇ¢©çÀSÉs«Üµå¤
    if ((i < N - 1) && (j < N - 1) && (a[i][j] == a[i + 1][j]) &&
        (a[i][j] == a[i][j + 1]) && (a[i][j] == a[i + 1][j + 1]))
      cout << 'A' << endl;
    else if ((i < N - 3) && (a[i][j] == a[i + 3][j]))
      cout << 'B' << endl;
    else if ((j < N - 3) && (a[i][j] == a[i][j + 3]))
      cout << 'C' << endl;
    else if ((i < N - 2) && (j > 0) && (a[i][j] == a[i + 2][j - 1]))
      cout << 'D' << endl;
    else if ((j < N - 2) && (a[i][j] == a[i + 1][j + 2]))
      cout << 'E' << endl;
    else if ((i < N - 2) && (a[i][j] == a[i + 2][j + 1]))
      cout << 'F' << endl;
    else
      cout << 'G' << endl;
  }
  return 0;
}
Problem p00036 (C++)

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

char m[8][8];
void figure(int, int);

int main() {

  while (1) {
    bool f = true;
    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 8; j++) {
        cin >> m[i][j];
      }
    }
    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 8; j++) {
        if (m[i][j] == '1') {
          figure(i, j);
          f = false;
          break;
        }
      }
      if (!f) {
        break;
      }
    }
  }
}

void figure(int i, int j) {
  char s;
  if (m[i][j + 1] == '1' && m[i + 1][j + 1] == '1' && m[i + 1][j] == '1') {
    s = 'A';
  } else if (m[i + 1][j] == '1' && m[i + 2][j] == '1') {
    s = 'B';
  } else if (m[i][j + 1] == '1' && m[i][j + 2] == '1') {
    s = 'C';
  } else if (m[i][j + 1] == '1' && m[i + 1][j + 1] == '1') {
    s = 'E';
  } else if (m[i][j + 1] == '1') {
    s = 'G';
  } else if (m[i + 1][j + 1] == '1') {
    s = 'F';
  } else {
    s = 'D';
  }
  cout << s << endl;
}

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

char m[8][8];
void figure(int, int);

int main() {

  while (1) {
    bool f = true;
    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 8; j++) {
        cin >> m[i][j];
        if (cin.eof()) {
          return 0;
        }
      }
    }
    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 8; j++) {
        if (m[i][j] == '1') {
          figure(i, j);
          f = false;
          break;
        }
      }
      if (!f) {
        break;
      }
    }
  }
}

void figure(int i, int j) {
  char s;
  if (m[i][j + 1] == '1' && m[i + 1][j + 1] == '1' && m[i + 1][j] == '1') {
    s = 'A';
  } else if (m[i + 1][j] == '1' && m[i + 2][j] == '1') {
    s = 'B';
  } else if (m[i][j + 1] == '1' && m[i][j + 2] == '1') {
    s = 'C';
  } else if (m[i][j + 1] == '1' && m[i + 1][j + 1] == '1') {
    s = 'E';
  } else if (m[i][j + 1] == '1') {
    s = 'G';
  } else if (m[i + 1][j + 1] == '1') {
    s = 'F';
  } else {
    s = 'D';
  }
  cout << s << endl;
}
Problem p00037 (C++)

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

class Dot {
public:
  bool d[4];
  Dot() { d[0] = d[1] = d[2] = d[3] = false; }
};

int main() {
  Dot data[5][5];
  for (int i = 0; i < 9; i++) {
    string str;
    getline(cin, str);
    int y = i / 2;
    if (i % 2 == 0) {
      for (int j = 0; j < 4; j++) {
        if (str[j] == '1') {
          data[y][j].d[0] = data[y][j + 1].d[2] = true;
        }
      }
    } else {
      for (int j = 0; j < 5; j++) {
        if (str[j] == '1') {
          data[y][j].d[1] = data[y + 1][j].d[3] = true;
        }
      }
    }
  }

  int d[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
  int x = 0;
  int y = 0;
  int dir = 0;
  while (1) {
    for (int i = 0; i < 3; i++) {
      int t = (dir + i + 3) % 4;
      if (data[y][x].d[t]) {
        dir = t;
        x += d[t][0];
        y += d[t][1];
        switch (t) {
        case 0:
          cout << 'R';
          break;
        case 1:
          cout << 'D';
          break;
        case 2:
          cout << 'L';
          break;
        case 3:
          cout << 'U';
          break;
        }
        break;
      }
    }
    if (x == 0 && y == 0) {
      cout << endl;
      break;
    }
  }
  return 0;
}

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

class Dot {
public:
  bool d[4];
  Dot() { d[0] = d[1] = d[2] = d[3] = false; }
};

int main() {
  Dot data[5][5];
  for (int i = 0; i < 9; i++) {
    string str;
    getline(cin, str);
    int y = i / 2;
    if (i % 2 == 0) {
      for (int j = 0; j < 4; j++) {
        if (str[j] == '1') {
          data[y][j].d[0] = data[y][j + 1].d[2] = true;
        }
      }
    } else {
      for (int j = 0; j < 5; j++) {
        if (str[j] == '1') {
          data[y][j].d[1] = data[y + 1][j].d[3] = true;
        }
      }
    }
  }

  int d[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
  int x = 0;
  int y = 0;
  int dir = 0;
  while (1) {
    for (int i = 0; i < 4; i++) {
      int t = (dir + i + 3) % 4;
      if (data[y][x].d[t]) {
        dir = t;
        x += d[t][0];
        y += d[t][1];
        switch (t) {
        case 0:
          cout << 'R';
          break;
        case 1:
          cout << 'D';
          break;
        case 2:
          cout << 'L';
          break;
        case 3:
          cout << 'U';
          break;
        }
        break;
      }
    }
    if (x == 0 && y == 0) {
      cout << endl;
      break;
    }
  }
  return 0;
}
Problem p00037 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
vector<string> strs;
int H, W;
bool isroad(int fx, int fy, int tx, int ty) {
  int fromx, fromy, tox, toy;
  fromx = min(fx, tx);
  fromy = min(fy, ty);
  tox = max(fx, tx);
  toy = max(fy, ty);
  if (fromx < 1 || tox < 1 || tox > W || fromx > W || fromy < 1 || toy < 1 ||
      fromy > H || toy > H)
    return false;
  if (fromx == tox) {
    if (strs[(fromy - 1) * 2 + 1][fromx - 1] == '1')
      return true;
    else {
      return false;
    }
  } else {
    if (strs[(fromy - 1) * 2][fromx - 1] == '1')
      return true;
    else {
      return false;
    }
  }
}
int vx[] = {1, 0, -1, 0}, vy[] = {0, -1, 0, 1};
int main() {
  string ins;
  while (cin >> ins) {
    strs.push_back(ins);
  }
  W = strs[0].size() + 1;
  H = strs.size() / 2 + 1;
  int nx = 2, ny = 1, v = 0;
  string outs = "R";
  while (nx != 1 || ny != 1) {
    for (int i = 5; i >= 3; i--) {
      bool r = isroad(nx, ny, nx + vx[(v + i) % 4], ny + vy[(v + i) % 4]);
      if (r) {
        v = (v + i) % 4;
        nx += vx[v];
        ny += vy[v];
        if (v == 0)
          outs += 'R';
        else if (v == 1)
          outs += 'U';
        else if (v == 2)
          outs += 'L';
        else
          outs += 'D';
        break;
      }
    }
  }
  cout << outs << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
vector<string> strs;
int H, W;
bool isroad(int fx, int fy, int tx, int ty) {
  int fromx, fromy, tox, toy;
  fromx = min(fx, tx);
  fromy = min(fy, ty);
  tox = max(fx, tx);
  toy = max(fy, ty);
  if (fromx < 1 || tox < 1 || tox > W || fromx > W || fromy < 1 || toy < 1 ||
      fromy > H || toy > H)
    return false;
  if (fromx == tox) {
    if (strs[(fromy - 1) * 2 + 1][fromx - 1] == '1')
      return true;
    else {
      return false;
    }
  } else {
    if (strs[(fromy - 1) * 2][fromx - 1] == '1')
      return true;
    else {
      return false;
    }
  }
}
int vx[] = {1, 0, -1, 0}, vy[] = {0, -1, 0, 1};
int main() {
  string ins;
  while (cin >> ins) {
    strs.push_back(ins);
  }
  W = strs[0].size() + 1;
  H = strs.size() / 2 + 1;
  int nx = 2, ny = 1, v = 0;
  string outs = "R";
  while (nx != 1 || ny != 1) {
    for (int i = 5; i >= 2; i--) {
      bool r = isroad(nx, ny, nx + vx[(v + i) % 4], ny + vy[(v + i) % 4]);
      if (r) {
        v = (v + i) % 4;
        nx += vx[v];
        ny += vy[v];
        if (v == 0)
          outs += 'R';
        else if (v == 1)
          outs += 'U';
        else if (v == 2)
          outs += 'L';
        else
          outs += 'D';
        break;
      }
    }
  }
  cout << outs << endl;
}
Problem p00037 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int f[5][5], i, j, a, y, x, p;
int main() {
  for (; i < 9; ++i) {
    char s[6];
    scanf("%s", s);
    for (j = 0; j < 4 + i % 2; ++j) {
      a = s[j] - 48;
      f[i / 2][j] |= a << (1 + i % 2);
      f[i / 2 + i % 2][j + !(i % 2)] |= a << 3 - i % 2 * 3;
    }
  }
  do {
    do
      p = (p + 1) % 4;
    while (!((f[y][x] >> p) & 1));
    putchar("URDL"[p]);
    x += p ? 2 - p : 0;
    y += p == 3 ? 0 : p - 1;
    p = (p + 2) % 4;
  } while (y != 0 || x != 0 || f[0][0] == 6 && p == 3);
  return puts("");
}

Fixed submission:
#include <stdio.h>
int f[5][5], i, j, a, y, x, p;
int main() {
  for (; i < 9; ++i) {
    char s[6];
    scanf("%s", s);
    for (j = 0; j < 4 + i % 2; ++j) {
      a = s[j] - 48;
      f[i / 2][j] |= a << (1 + i % 2);
      f[i / 2 + i % 2][j + !(i % 2)] |= a << 3 - i % 2 * 3;
    }
  }
  do {
    do
      p = (p + 1) % 4;
    while (!((f[y][x] >> p) & 1));
    putchar("URDL"[p]);
    x += p ? 2 - p : 0;
    y += p == 3 ? 0 : p - 1;
    p = (p + 2) % 4;
  } while (y != 0 || x != 0 || f[0][0] == 6 && p == 3);
  return !puts("");
}