alexjercan/bugnet huggingface dataset:
Problem p00012 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

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

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

Error: TLE

Fixed submission:

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

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

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

  double ab, bc, ca;
  double S, s;
  ab = sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));
  bc = sqrt((xb - xc) * (xb - xc) + (yb - yc) * (yb - yc));
  ca = sqrt((xc - xa) * (xc - xa) + (yc - ya) * (yc - ya));
  s = 0.5 * (ab + bc + ca);
  S = sqrt(s * (s - ab) * (s - bc) * (s - ca));
  // cout<<S<<endl;
  return S;
}
Problem p00012 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

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

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

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

#include <bits/stdc++.h>

using namespace std;

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

typedef Point Vector;

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

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

typedef Point Vector;

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

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

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

Error: TLE

Fixed submission:

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

#include <iostream>
using namespace std;
double x[4], y[4], px, py, ax, ay, bx, by;
int main() {
  while (true) {
    for (int i = 1; i <= 3; i++) {
      cin >> x[i];
      cin >> y[i];
    }
    if (cin.eof()) {
      break;
    }
    cin >> px;
    cin >> py;
    double m, n;
    ax = x[2] - x[1];
    ay = y[2] - y[1];
    bx = x[3] - x[1];
    by = y[3] - y[1];
    px = px - x[1];
    py = py - y[1];
    double det = ax * by - ay * bx;
    m = (by * px - bx * py) / det;
    n = (-ay * px + ax * py) / det;
    if (det == 0)
      cout << "NO" << endl;
    if (m > 0 && m <= 1 && n > 0 && n <= 1 && m + n <= 1)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int rail[11];
  int num = 0;
  while (true) {
    int now;
    cin >> now;
    if (cin.eof())
      break;
    else if (now == 0) {
      cout << rail[num] << endl;
      num--;
    } else {
      num++;
      rail[num] = now;
    }
  }
  return 0;
}
Problem p00012 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

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

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

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

Error: TLE

Fixed submission:

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

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

#include <cstdio>
using namespace std;

struct Vec2 {
  double x, y;
  Vec2(double x_, double y_) : x(x_), y(y_) {}
};

bool in_the_triangle(const Vec2 &a, const Vec2 &b, const Vec2 &c,
                     const Vec2 &p) {
  Vec2 aa(a.x - p.x, a.y - p.y);
  Vec2 bb(b.x - p.x, b.y - p.y);
  Vec2 cc(c.x - p.x, c.y - p.y);
  double k = aa.x * bb.y - bb.x * aa.y;
  double l = bb.x * cc.y - cc.x * bb.y;
  double m = cc.x * aa.y - aa.x * cc.y;
  return (k * l > 0 && k * m > 0);
}

int main() {
  double a, b, c, d, e, f, g, h;
  while (8 ==
         scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f, &g, &h)) {
    puts(in_the_triangle(Vec2(a, b), Vec2(c, d), Vec2(e, f), Vec2(g, h))
             ? "YES"
             : "NO");
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;
struct Vec2 {
  double x, y;
  Vec2(double x_, double y_) : x(x_), y(y_) {}
};

bool in_the_triangle(const Vec2 &a, const Vec2 &b, const Vec2 &c,
                     const Vec2 &p) {
  Vec2 aa(a.x - p.x, a.y - p.y);
  Vec2 bb(b.x - p.x, b.y - p.y);
  Vec2 cc(c.x - p.x, c.y - p.y);
  double k = aa.x * bb.y - bb.x * aa.y;
  double l = bb.x * cc.y - cc.x * bb.y;
  double m = cc.x * aa.y - aa.x * cc.y;
  return (k * l > 0 && k * m > 0);
}

int main() {
  double a, b, c, d, e, f, g, h;
  while (scanf("%f%f%f%f%f%f%f%f", &a, &b, &c, &d, &e, &f, &g, &h)) {
    puts(in_the_triangle(Vec2(a, b), Vec2(c, d), Vec2(e, f), Vec2(g, h))
             ? "YES"
             : "NO");
  }
  return 0;
}
Problem p00012 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#define EPS (1.0e-8)

using namespace std;

int main() {
  double x1, y1, x2, y2, x3, y3, xp, yp;
  double a[2], b[2];
  double A, B;
  while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) {
    a[0] = x2 - x1;
    a[1] = y2 - y1;
    b[0] = x3 - x1;
    b[1] = y3 - y1;
    if (fabs(a[0] * b[0] + a[1] * b[1]) != 1) {
      A = (b[1] * (xp - x1) - b[0] * (yp - y1)) / (a[0] * b[1] - b[0] * a[1]);
      B = (a[1] * (xp - x1) - (yp - y1) * a[0]) / (a[1] * b[0] - b[1] * a[0]);
      if ((A + B < 1) && (A > 0) && (B > 0)) {
        cout << "YES" << endl;
      } else {
        cout << "NO" << endl;
      }
    } else
      cout << "NO" << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

#define EPS (1e-10)

using namespace std;

double crossProduct(double px, double py, double x1, double y1, double x2,
                    double y2) {
  double v1[2] = {px - x1, py - y1};
  double v2[2] = {x2 - x1, y2 - y1};
  return v1[0] * v2[1] - v1[1] * v2[0];
}

int main() {
  double x1, x2, x3, xp, y1, y2, y3, yp;
  double t[3];
  int f;
  while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) {
    t[0] = crossProduct(xp, yp, x1, y1, x2, y2);
    t[1] = crossProduct(xp, yp, x2, y2, x3, y3);
    t[2] = crossProduct(xp, yp, x3, y3, x1, y1);
    for (int i = f = 0; i < 3; i++) {
      if (t[i] < -EPS)
        f++;
      else if (t[i] > EPS)
        f--;
      else
        return -1;
    }
    if (f == 3 || f == -3)
      cout << "YES\\n";
    else
      cout << "NO\\n";
  }
  return 0;
}
Problem p00012 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"

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

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

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

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

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

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

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

  solve();
  return 0;
}

Error: 0
sh: 1: PAUSE: not found


Fixed submission:

#include "bits/stdc++.h"

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

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

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

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

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

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

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

  solve();
  system("PAUSE");
  return 0;
}
Problem p00012 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

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

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

#include <cmath>
#include <cstdio>

using namespace std;

int main(void) {
  double x[3], y[3], cx, cy;
  double p[3];

  while (scanf("%lf%lf", &x[0], &y[0]) > 0) {
    scanf("%lf%lf%lf%lf%lf%lf", &x[1], &y[1], &x[2], &y[2], &cx, &cy);
    for (int i = 0; i < 3; i++) {
      int j = (i + 1) % 3;
      p[i] = (x[i] - cx) * (y[j] - cy) - (x[j] - cx) * (y[i] - cy);
    }
    puts(p[0] * p[1] < 0 || p[1] * p[2] < 0 || p[2] * p[0] < 0 ? "NO" : "YES");
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>

using namespace std;

int main(void) {
  double x[3], y[3], cx, cy;
  double p[3];

  while (scanf("%lf%lf", &x[0], &y[0])) {
    scanf("%lf%lf%lf%lf%lf%lf", &x[1], &y[1], &x[2], &y[2], &cx, &cy);
    for (int i = 0; i < 3; i++) {
      int j = (i + 1) % 3;
      p[i] = (x[i] - cx) * (y[j] - cy) - (x[j] - cx) * (y[i] - cy);
      printf("%lf\\n", p[i]);
    }
    puts(p[0] * p[1] < 0 || p[1] * p[2] < 0 || p[2] * p[0] < 0 ? "NO" : "YES");
  }
  return 0;
}
Problem p00012 (C++) — buggy submission, verdict: Runtime Error

/*problem C*/

#include <iostream>
using namespace std;

typedef struct {
  double x, y;
} point_obj;

int isClossLine(double x1, double y1, double x2, double y2, double x3,
                double y3, double x4, double y4) {
  return ((x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3)) *
         ((x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4));
}

int main() {
  point_obj p[5];
  int i, j;
  p[3].x = 0;
  p[3].y = 0;

  while (cin >> p[0].x) {
    cin >> p[0].y;

    p[3].x = p[0].x;
    p[3].y = p[0].y;

    for (int i = 1; i < 3; i++) {
      cin >> p[i].x, cin >> p[i].y;

      p[3].x += p[i].x;
      p[3].y += p[i].y;
    }
    cin >> p[4].x;
    cin >> p[4].y;
    p[3].x /= 3.0;
    p[3].y /= 3.0;

    if (isClossLine(p[0].x, p[0].y, p[1].x, p[1].y, p[3].x, p[3].y, p[4].x,
                    p[4].y) > 0 &&
        isClossLine(p[1].x, p[1].y, p[2].x, p[2].y, p[3].x, p[3].y, p[4].x,
                    p[4].y) > 0 &&
        isClossLine(p[0].x, p[0].y, p[2].x, p[2].y, p[3].x, p[3].y, p[4].x,
                    p[4].y) > 0) {
      cout << "YES" << endl;
    }

    else {
      cout << "NO" << endl;
    }
  }

  return 0;
}

Error: -11

Fixed submission:

/*problem C*/

#include <stdio.h>

typedef struct {
  double x, y;
} point_obj;

int isClossLine(double x1, double y1, double x2, double y2, double x3,
                double y3, double x4, double y4) {
  return ((x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3)) *
         ((x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4));
}

int main() {
  point_obj p[5];
  int i, j;
  p[3].x = 0;
  p[3].y = 0;

  while (scanf("%lf %lf %lf %lf %lf %lf", p[0].x, p[0].y, p[1].x, p[1].y,
               p[2].x, p[2].y, p[4].x, p[4].y)) {

    p[3].x += p[0].x;
    p[3].y += p[0].y;

    p[3].x /= 3.0;
    p[3].y /= 3.0;

    if (isClossLine(p[0].x, p[0].y, p[1].x, p[1].y, p[3].x, p[3].y, p[4].x,
                    p[4].y) > 0 &&
        isClossLine(p[1].x, p[1].y, p[2].x, p[2].y, p[3].x, p[3].y, p[4].x,
                    p[4].y) > 0 &&
        isClossLine(p[0].x, p[0].y, p[2].x, p[2].y, p[3].x, p[3].y, p[4].x,
                    p[4].y) > 0) {

      printf("YES");
    }

    else {
      printf("NO");
    }
  }

  return 0;
}