Problem p00260 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

typedef complex<double> Point;
const double EPS = 1e-4;

int sign(double a) {
  if (a > EPS)
    return +1;
  if (a < -EPS)
    return -1;
  return 0;
}
double dot(Point a, Point b) { return real(conj(a) * b); }
double cross(Point a, Point b) { return imag(conj(a) * b); }
int ccw(Point a, Point b, Point c) {
  b -= a;
  c -= a;
  double len = abs(b) * abs(c); // 速さが気になるときは1にする
  if (cross(b, c) > +len * EPS)
    return +1; // 反時計回り
  if (cross(b, c) < -len * EPS)
    return -1; // 時計回り
  if (dot(b, c) < 0)
    return +2; // c--a--b の順番で一直線上
  if (norm(b) < norm(c))
    return -2; // a--b--c の順番で一直線上
  return 0;    // 点が線分ab上にある
}
struct Line : public vector<Point> {
  Line() {}
  Line(const Point &a, const Point &b) {
    push_back(a);
    push_back(b);
  }
  Point vector() const { return back() - front(); }
};
typedef vector<Point> Polygon; // 反時計回りを仮定
Point crosspointLL(Line l, Line m) {
  double A = cross(l.vector(), m.vector());
  double B = cross(l.vector(), l[1] - m[0]);
  if (sign(A) == 0 && sign(B) == 0)
    return m[0]; // 二直線が重なっている
  if (sign(A) == 0)
    assert(false); // 直線が交わらない
  return m[0] + m.vector() * B / A;
}
// 両端を含まない
bool intersectSP(Line s, Point p) {
  return ccw(s[0], s[1], p) == 0 && abs(s[0] - p) > EPS && abs(s[1] - p) > EPS;
}
bool equalLL(Line l, Line m) {
  return sign(cross(l.vector(), m[0] - l[0])) == 0;
}
bool intersectLS(Line l, Line s) {
  // 直線lについて、線分sの端点が異なる側にある
  return sign(cross(l.vector(), s[0] - l[0]) *
              cross(l.vector(), s[1] - l[0])) <= 0;
}
bool intersectSS(Line s, Line t) {
  bool f = ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
           ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
  if (!f)
    return false;
  Point cp = crosspointLL(s, t);
  return intersectSP(s, cp) && intersectSP(t, cp);
}

Point curr(const Polygon &P, int x) { return P[x]; }
Point next(const Polygon &P, int x) { return P[(x + 1) % P.size()]; }

enum { OUT, ON, IN };
int contains(const Polygon &P, const Point &p) {
  // 点pから半直線をひき、辺と交差する回数を数える
  bool in = false;
  for (int i = 0; i < P.size(); i++) {
    Point a = curr(P, i) - p;
    Point b = next(P, i) - p;
    if (a.imag() > b.imag())
      swap(a, b);
    // aからbの直線がy=0と交わり、その交点は原点の右側である
    if (a.imag() <= 0 && 0 < b.imag() && cross(a, b) < 0) {
      in = !in;
    }
    if (sign(cross(a, b)) == 0 && sign(dot(a, b)) <= 0)
      return ON;
  }
  return in ? IN : OUT;
}

bool arrivable(Point bp, Point tp, const vector<Line> &poly_line,
               const Polygon &P) {
  if (contains(P, 0.5 * (bp + tp)) == OUT)
    return false;

  Line cat(bp, tp);
  for (int k = 0; k < poly_line.size(); k++) {
    Line pol = poly_line[k];
    if (equalLL(cat, pol))
      continue;
    if (intersectSS(cat, pol))
      return false;
  }

  return true;
}

int main() {
  int N;
  while (cin >> N && N) {
    Polygon P(N);
    for (int i = 0; i < N; i++) {
      double x, y;
      cin >> x >> y;
      P[i] = Point(x, y);
    }

    vector<Line> poly_line(N);
    for (int i = 0; i < N; i++) {
      poly_line[i] = Line(P[i], P[(i + 1) % P.size()]);
      // fprintf(stderr, "line(%f, %f, %f, %f);\\n",
      // P[i].real() * 100, P[i].imag() * 100, P[(i + 1) % P.size()].real() *
      // 100, P[(i + 1) % P.size()].imag() * 100);
    }

    vector<Point> cand_point = P; // 候補点
    for (int i = 0; i < N; i++)
      for (int j = 0; j < N; j++) {
        if (i == j)
          continue;
        Point bp = P[i], ep = P[j];
        Line cat(bp, ep);

        bool is_cross = false;
        Point cross_p;
        Line cross_l;
        int cross_idx;
        for (int k = 0; k < N; k++) {
          Line pol = poly_line[k];

          if (equalLL(cat, pol))
            continue;
          if (!intersectLS(cat, pol))
            continue;

          Point cp = crosspointLL(cat, pol);

          if (!intersectSP(pol, cp))
            continue;

          if (dot(cat.vector(), cp - cat[0]) < 0)
            continue; // true??
          // if(ccw(cat[0], cat[1], cp) != -2) continue; // true???

          if (!is_cross) {
            is_cross = true;
            cross_p = cp;
            cross_l = pol;
            cross_idx = k;
          } else if (abs(cross_p - cat[0]) > abs(cp - cat[0])) {
            cross_p = cp;
            cross_l = pol;
            cross_idx = k;
          }
        }
        if (is_cross) {
          // fprintf(stderr, "o : line(p[%d] = (%.0f, %.0f), p[%d] = (%.0f,
          // %.0f)) has intersect\\n", i, bp.real(), bp.imag(), j, ep.real(),
          // ep.imag()); fprintf(stderr, "    line[%d]((%.0f, %.0f), (%.0f,
          // %.0f)) , cross (%f. %f) \\n", cross_idx, cross_l[0].real(),
          // cross_l[0].imag(), cross_l[1].real(), cross_l[1].imag(),
          // cross_p.real(), cross_p.imag());
          // fprintf(stderr, "circle(%f, %f, 5.0);\\n", cross_p.real() * 100,
          // cross_p.imag() * 100);
          cand_point.push_back(cross_p + cross_l.vector() * EPS);
          cand_point.push_back(cross_p - cross_l.vector() * EPS);
        } else {
          // fprintf(stderr, "x : line(p[%d] = (%.0f, %.0f), p[%d] = (%.0f,
          // %.0f)) has no intersect\\n", i, bp.real(), bp.imag(), j, ep.real(),
          // ep.imag());
        }
      }

    vector<vector<bool>> is_arrivable(N,
                                      vector<bool>(cand_point.size(), false));
    for (int i = 0; i < N; i++)
      for (int j = 0; j < cand_point.size(); j++) {
        Point bp = P[i], tp = cand_point[j];
        is_arrivable[i][j] = arrivable(bp, tp, poly_line, P);
        // fprintf(stderr, "%c : p[%d] -> (%f, %f)\\n", is_arrivable[i][j] ? 'o'
        // : 'x', i, cand_point[j].real(), cand_point[j].imag());
        if (i == 0 && !is_arrivable[i][j]) {
          // fprintf(stderr, "line(%f, %f, %f, %f)\\n", bp.real() * 100,
          // bp.imag() * 100, tp.real() * 100, tp.imag() * 100);
        }
      }

    int ans = N;
    for (int s = 1; s < (1 << N); s++) {
      int bits = __builtin_popcount(s);
      if (bits >= ans)
        continue;
      vector<bool> ok(cand_point.size(), false);
      for (int i = 0; i < N; i++)
        if (s >> i & 1)
          for (int j = 0; j < cand_point.size(); j++)
            ok[j] = ok[j] || is_arrivable[i][j];

      bool is_answer = true;
      for (int i = 0; i < cand_point.size(); i++)
        if (!ok[i]) {
          is_answer = false;
          break;
        }

      if (is_answer) {
        ans = bits;
      }
    }

    cout << ans << endl;
  }
  return 0;
}

Error: 0
o : line(p[0] = (0, 0), p[1] = (3, 2)) has intersect
    line[2]((6, 2), (8, 6)) , cross (7.500000. 5.000000) 
x : line(p[0] = (0, 0), p[2] = (6, 2)) has no intersect
x : line(p[0] = (0, 0), p[3] = (8, 6)) has no intersect
x : line(p[0] = (0, 0), p[4] = (6, 5)) has no intersect
x : line(p[0] = (0, 0), p[5] = (7, 7)) has no intersect
x : line(p[0] = (0, 0), p[6] = (0, 4)) has no intersect
o : line(p[0] = (0, 0), p[7] = (3, 4)) has intersect
    line[5]((7, 7), (0, 4)) , cross (4.421053. 5.894737) 
x : line(p[1] = (3, 2), p[0] = (0, 0)) has no intersect
x : line(p[1] = (3, 2), p[2] = (6, 2)) has no intersect
x : line(p[1] = (3, 2), p[3] = (8, 6)) has no intersect
x : line(p[1] = (3, 2), p[4] = (6, 5)) has no intersect
x : line(p[1] = (3, 2), p[5] = (7, 7)) has no intersect
x : line(p[1] = (3, 2), p[6] = (0, 4)) has no intersect
o : line(p[1] = (3, 2), p[7] = (3, 4)) has intersect
    line[5]((7, 7), (0, 4)) , cross (3.000000. 5.285714) 
x : line(p[2] = (6, 2), p[0] = (0, 0)) has no intersect
o : line(p[2] = (6, 2), p[1] = (3, 2)) has intersect
    line[7]((3, 4), (0, 0)) , cross (1.500000. 2.000000) 
x : line(p[2] = (6, 2), p[3] = (8, 6)) has no intersect
o : line(p[2] = (6, 2), p[4] = (6, 5)) has intersect
    line[5]((7, 7), (0, 4)) , cross (6.000000. 6.571429) 
x : line(p[2] = (6, 2), p[5] = (7, 7)) has no intersect
x : line(p[2] = (6, 2), p[6] = (0, 4)) has no intersect
o : line(p[2] = (6, 2), p[7] = (3, 4)) has intersect
    line[5]((7, 7), (0, 4)) , cross (1.826087. 4.782609) 
x : line(p[3] = (8, 6), p[0] = (0, 0)) has no intersect
x : line(p[3] = (8, 6), p[1] = (3, 2)) has no intersect
x : line(p[3] = (8, 6), p[2] = (6, 2)) has no intersect
o : line(p[3] = (8, 6), p[4] = (6, 5)) has intersect
    line[7]((3, 4), (0, 0)) , cross (2.400000. 3.200000) 
x : line(p[3] = (8, 6), p[5] = (7, 7)) has no intersect
x : line(p[3] = (8, 6), p[6] = (0, 4)) has no intersect
x : line(p[3] = (8, 6), p[7] = (3, 4)) has no intersect
x : line(p[4] = (6, 5), p[0] = (0, 0)) has no intersect
x : line(p[4] = (6, 5), p[1] = (3, 2)) has no intersect
x : line(p[4] = (6, 5), p[2] = (6, 2)) has no intersect
x : line(p[4] = (6, 5), p[3] = (8, 6)) has no intersect
x : line(p[4] = (6, 5), p[5] = (7, 7)) has no intersect
x : line(p[4] = (6, 5), p[6] = (0, 4)) has no intersect
x : line(p[4] = (6, 5), p[7] = (3, 4)) has no intersect
x : line(p[5] = (7, 7), p[0] = (0, 0)) has no intersect
x : line(p[5] = (7, 7), p[1] = (3, 2)) has no intersect
x : line(p[5] = (7, 7), p[2] = (6, 2)) has no intersect
x : line(p[5] = (7, 7), p[3] = (8, 6)) has no intersect
o : line(p[5] = (7, 7), p[4] = (6, 5)) has intersect
    line[1]((3, 2), (6, 2)) , cross (4.500000. 2.000000) 
x : line(p[5] = (7, 7), p[6] = (0, 4)) has no intersect
x : line(p[5] = (7, 7), p[7] = (3, 4)) has no intersect
x : line(p[6] = (0, 4), p[0] = (0, 0)) has no intersect
x : line(p[6] = (0, 4), p[1] = (3, 2)) has no intersect
x : line(p[6] = (0, 4), p[2] = (6, 2)) has no intersect
x : line(p[6] = (0, 4), p[3] = (8, 6)) has no intersect
o : line(p[6] = (0, 4), p[4] = (6, 5)) has intersect
    line[2]((6, 2), (8, 6)) , cross (7.636364. 5.272727) 
x : line(p[6] = (0, 4), p[5] = (7, 7)) has no intersect
o : line(p[6] = (0, 4), p[7] = (3, 4)) has intersect
    line[2]((6, 2), (8, 6)) , cross (7.000000. 4.000000) 
x : line(p[7] = (3, 4), p[0] = (0, 0)) has no intersect
x : line(p[7] = (3, 4), p[1] = (3, 2)) has no intersect
x : line(p[7] = (3, 4), p[2] = (6, 2)) has no intersect
x : line(p[7] = (3, 4), p[3] = (8, 6)) has no intersect
o : line(p[7] = (3, 4), p[4] = (6, 5)) has intersect
    line[2]((6, 2), (8, 6)) , cross (7.800000. 5.600000) 
x : line(p[7] = (3, 4), p[5] = (7, 7)) has no intersect
x : line(p[7] = (3, 4), p[6] = (0, 4)) has no intersect
o : p[0] -> (0.000000, 0.000000)
o : p[0] -> (3.000000, 2.000000)
o : p[0] -> (6.000000, 2.000000)
o : p[0] -> (8.000000, 6.000000)
o : p[0] -> (6.000000, 5.000000)
o : p[0] -> (7.000000, 7.000000)
o : p[0] -> (0.000000, 4.000000)
o : p[0] -> (3.000000, 4.000000)
o : p[0] -> (7.500002, 5.000004)
x : p[0] -> (7.499998, 4.999996)
x : p[0] -> (4.421046, 5.894734)
o : p[0] -> (4.421060, 5.894740)
x : p[0] -> (2.999993, 5.285711)
x : p[0] -> (3.000007, 5.285717)
o : p[0] -> (1.499997, 1.999996)
o : p[0] -> (1.500003, 2.000004)
o : p[0] -> (5.999993, 6.571426)
o : p[0] -> (6.000007, 6.571432)
x : p[0] -> (1.826080, 4.782606)
x : p[0] -> (1.826094, 4.782612)
o : p[0] -> (2.399997, 3.199996)
o : p[0] -> (2.400003, 3.200004)
o : p[0] -> (4.500003, 2.000000)
o : p[0] -> (4.499997, 2.000000)
o : p[0] -> (7.636366, 5.272731)
o : p[0] -> (7.636362, 5.272723)
x : p[0] -> (7.000002, 4.000004)
x : p[0] -> (6.999998, 3.999996)
o : p[0] -> (7.800002, 5.600004)
o : p[0] -> (7.799998, 5.599996)
o : p[1] -> (0.000000, 0.000000)
o : p[1] -> (3.000000, 2.000000)
o : p[1] -> (6.000000, 2.000000)
o : p[1] -> (8.000000, 6.000000)
o : p[1] -> (6.000000, 5.000000)
o : p[1] -> (7.000000, 7.000000)
x : p[1] -> (0.000000, 4.000000)
o : p[1] -> (3.000000, 4.000000)
o : p[1] -> (7.500002, 5.000004)
o : p[1] -> (7.499998, 4.999996)
o : p[1] -> (4.421046, 5.894734)
o : p[1] -> (4.421060, 5.894740)
x : p[1] -> (2.999993, 5.285711)
o : p[1] -> (3.000007, 5.285717)
o : p[1] -> (1.499997, 1.999996)
o : p[1] -> (1.500003, 2.000004)
o : p[1] -> (5.999993, 6.571426)
o : p[1] -> (6.000007, 6.571432)
x : p[1] -> (1.826080, 4.782606)
x : p[1] -> (1.826094, 4.782612)
o : p[1] -> (2.399997, 3.199996)
o : p[1] -> (2.400003, 3.200004)
o : p[1] -> (4.500003, 2.000000)
o : p[1] -> (4.499997, 2.000000)
o : p[1] -> (7.636366, 5.272731)
o : p[1] -> (7.636362, 5.272723)
o : p[1] -> (7.000002, 4.000004)
o : p[1] -> (6.999998, 3.999996)
o : p[1] -> (7.800002, 5.600004)
o : p[1] -> (7.799998, 5.599996)
o : p[2] -> (0.000000, 0.000000)
o : p[2] -> (3.000000, 2.000000)
o : p[2] -> (6.000000, 2.000000)
o : p[2] -> (8.000000, 6.000000)
o : p[2] -> (6.000000, 5.000000)
x : p[2] -> (7.000000, 7.000000)
x : p[2] -> (0.000000, 4.000000)
o : p[2] -> (3.000000, 4.000000)
o : p[2] -> (7.500002, 5.000004)
o : p[2] -> (7.499998, 4.999996)
o : p[2] -> (4.421046, 5.894734)
o : p[2] -> (4.421060, 5.894740)
o : p[2] -> (2.999993, 5.285711)
o : p[2] -> (3.000007, 5.285717)
x : p[2] -> (1.499997, 1.999996)
o : p[2] -> (1.500003, 2.000004)
o : p[2] -> (5.999993, 6.571426)
x : p[2] -> (6.000007, 6.571432)
x : p[2] -> (1.826080, 4.782606)
o : p[2] -> (1.826094, 4.782612)
o : p[2] -> (2.399997, 3.199996)
o : p[2] -> (2.400003, 3.200004)
o : p[2] -> (4.500003, 2.000000)
o : p[2] -> (4.499997, 2.000000)
o : p[2] -> (7.636366, 5.272731)
o : p[2] -> (7.636362, 5.272723)
o : p[2] -> (7.000002, 4.000004)
o : p[2] -> (6.999998, 3.999996)
o : p[2] -> (7.800002, 5.600004)
o : p[2] -> (7.799998, 5.599996)
o : p[3] -> (0.000000, 0.000000)
o : p[3] -> (3.000000, 2.000000)
o : p[3] -> (6.000000, 2.000000)
o : p[3] -> (8.000000, 6.000000)
o : p[3] -> (6.000000, 5.000000)
o : p[3] -> (7.000000, 7.000000)
x : p[3] -> (0.000000, 4.000000)
x : p[3] -> (3.000000, 4.000000)
o : p[3] -> (7.500002, 5.000004)
o : p[3] -> (7.499998, 4.999996)
x : p[3] -> (4.421046, 5.894734)
x : p[3] -> (4.421060, 5.894740)
x : p[3] -> (2.999993, 5.285711)
x : p[3] -> (3.000007, 5.285717)
o : p[3] -> (1.499997, 1.999996)
o : p[3] -> (1.500003, 2.000004)
x : p[3] -> (5.999993, 6.571426)
x : p[3] -> (6.000007, 6.571432)
x : p[3] -> (1.826080, 4.782606)
x : p[3] -> (1.826094, 4.782612)
o : p[3] -> (2.399997, 3.199996)
x : p[3] -> (2.400003, 3.200004)
o : p[3] -> (4.500003, 2.000000)
o : p[3] -> (4.499997, 2.000000)
o : p[3] -> (7.636366, 5.272731)
o : p[3] -> (7.636362, 5.272723)
o : p[3] -> (7.000002, 4.000004)
o : p[3] -> (6.999998, 3.999996)
o : p[3] -> (7.800002, 5.600004)
o : p[3] -> (7.799998, 5.599996)
o : p[4] -> (0.000000, 0.000000)
o : p[4] -> (3.000000, 2.000000)
o : p[4] -> (6.000000, 2.000000)
o : p[4] -> (8.000000, 6.000000)
o : p[4] -> (6.000000, 5.000000)
o : p[4] -> (7.000000, 7.000000)
o : p[4] -> (0.000000, 4.000000)
o : p[4] -> (3.000000, 4.000000)
o : p[4] -> (7.500002, 5.000004)
o : p[4] -> (7.499998, 4.999996)
o : p[4] -> (4.421046, 5.894734)
o : p[4] -> (4.421060, 5.894740)
o : p[4] -> (2.999993, 5.285711)
o : p[4] -> (3.000007, 5.285717)
o : p[4] -> (1.499997, 1.999996)
o : p[4] -> (1.500003, 2.000004)
o : p[4] -> (5.999993, 6.571426)
o : p[4] -> (6.000007, 6.571432)
o : p[4] -> (1.826080, 4.782606)
o : p[4] -> (1.826094, 4.782612)
o : p[4] -> (2.399997, 3.199996)
o : p[4] -> (2.400003, 3.200004)
o : p[4] -> (4.500003, 2.000000)
o : p[4] -> (4.499997, 2.000000)
o : p[4] -> (7.636366, 5.272731)
o : p[4] -> (7.636362, 5.272723)
o : p[4] -> (7.000002, 4.000004)
o : p[4] -> (6.999998, 3.999996)
o : p[4] -> (7.800002, 5.600004)
o : p[4] -> (7.799998, 5.599996)
o : p[5] -> (0.000000, 0.000000)
o : p[5] -> (3.000000, 2.000000)
x : p[5] -> (6.000000, 2.000000)
o : p[5] -> (8.000000, 6.000000)
o : p[5] -> (6.000000, 5.000000)
o : p[5] -> (7.000000, 7.000000)
o : p[5] -> (0.000000, 4.000000)
o : p[5] -> (3.000000, 4.000000)
x : p[5] -> (7.500002, 5.000004)
x : p[5] -> (7.499998, 4.999996)
o : p[5] -> (4.421046, 5.894734)
o : p[5] -> (4.421060, 5.894740)
o : p[5] -> (2.999993, 5.285711)
o : p[5] -> (3.000007, 5.285717)
o : p[5] -> (1.499997, 1.999996)
o : p[5] -> (1.500003, 2.000004)
o : p[5] -> (5.999993, 6.571426)
o : p[5] -> (6.000007, 6.571432)
o : p[5] -> (1.826080, 4.782606)
o : p[5] -> (1.826094, 4.782612)
o : p[5] -> (2.399997, 3.199996)
o : p[5] -> (2.400003, 3.200004)
x : p[5] -> (4.500003, 2.000000)
o : p[5] -> (4.499997, 2.000000)
x : p[5] -> (7.636366, 5.272731)
x : p[5] -> (7.636362, 5.272723)
x : p[5] -> (7.000002, 4.000004)
x : p[5] -> (6.999998, 3.999996)
x : p[5] -> (7.800002, 5.600004)
x : p[5] -> (7.799998, 5.599996)
o : p[6] -> (0.000000, 0.000000)
x : p[6] -> (3.000000, 2.000000)
x : p[6] -> (6.000000, 2.000000)
x : p[6] -> (8.000000, 6.000000)
o : p[6] -> (6.000000, 5.000000)
o : p[6] -> (7.000000, 7.000000)
o : p[6] -> (0.000000, 4.000000)
o : p[6] -> (3.000000, 4.000000)
o : p[6] -> (7.500002, 5.000004)
o : p[6] -> (7.499998, 4.999996)
o : p[6] -> (4.421046, 5.894734)
o : p[6] -> (4.421060, 5.894740)
o : p[6] -> (2.999993, 5.285711)
o : p[6] -> (3.000007, 5.285717)
o : p[6] -> (1.499997, 1.999996)
o : p[6] -> (1.500003, 2.000004)
o : p[6] -> (5.999993, 6.571426)
o : p[6] -> (6.000007, 6.571432)
o : p[6] -> (1.826080, 4.782606)
o : p[6] -> (1.826094, 4.782612)
o : p[6] -> (2.399997, 3.199996)
o : p[6] -> (2.400003, 3.200004)
x : p[6] -> (4.500003, 2.000000)
x : p[6] -> (4.499997, 2.000000)
x : p[6] -> (7.636366, 5.272731)
o : p[6] -> (7.636362, 5.272723)
o : p[6] -> (7.000002, 4.000004)
x : p[6] -> (6.999998, 3.999996)
x : p[6] -> (7.800002, 5.600004)
x : p[6] -> (7.799998, 5.599996)
o : p[7] -> (0.000000, 0.000000)
o : p[7] -> (3.000000, 2.000000)
o : p[7] -> (6.000000, 2.000000)
x : p[7] -> (8.000000, 6.000000)
o : p[7] -> (6.000000, 5.000000)
o : p[7] -> (7.000000, 7.000000)
o : p[7] -> (0.000000, 4.000000)
o : p[7] -> (3.000000, 4.000000)
o : p[7] -> (7.500002, 5.000004)
o : p[7] -> (7.499998, 4.999996)
o : p[7] -> (4.421046, 5.894734)
o : p[7] -> (4.421060, 5.894740)
o : p[7] -> (2.999993, 5.285711)
o : p[7] -> (3.000007, 5.285717)
o : p[7] -> (1.499997, 1.999996)
o : p[7] -> (1.500003, 2.000004)
o : p[7] -> (5.999993, 6.571426)
o : p[7] -> (6.000007, 6.571432)
o : p[7] -> (1.826080, 4.782606)
o : p[7] -> (1.826094, 4.782612)
o : p[7] -> (2.399997, 3.199996)
o : p[7] -> (2.400003, 3.200004)
o : p[7] -> (4.500003, 2.000000)
o : p[7] -> (4.499997, 2.000000)
o : p[7] -> (7.636366, 5.272731)
o : p[7] -> (7.636362, 5.272723)
o : p[7] -> (7.000002, 4.000004)
o : p[7] -> (6.999998, 3.999996)
x : p[7] -> (7.800002, 5.600004)
o : p[7] -> (7.799998, 5.599996)
o : line(p[0] = (0, 0), p[1] = (5, 3)) has intersect
    line[4]((6, 1), (8, 6)) , cross (7.368421. 4.421053) 
o : line(p[0] = (0, 0), p[2] = (5, 2)) has intersect
    line[4]((6, 1), (8, 6)) , cross (6.666667. 2.666667) 
o : line(p[0] = (0, 0), p[3] = (4, 1)) has intersect
    line[4]((6, 1), (8, 6)) , cross (6.222222. 1.555556) 
x : line(p[0] = (0, 0), p[4] = (6, 1)) has no intersect
x : line(p[0] = (0, 0), p[5] = (8, 6)) has no intersect
o : line(p[0] = (0, 0), p[6] = (6, 4)) has intersect
    line[4]((6, 1), (8, 6)) , cross (7.636364. 5.090909) 
x : line(p[0] = (0, 0), p[7] = (2, 4)) has no intersect
x : line(p[1] = (5, 3), p[0] = (0, 0)) has no intersect
o : line(p[1] = (5, 3), p[2] = (5, 2)) has intersect
    line[3]((4, 1), (6, 1)) , cross (5.000000. 1.000000) 
x : line(p[1] = (5, 3), p[3] = (4, 1)) has no intersect
x : line(p[1] = (5, 3), p[4] = (6, 1)) has no intersect
x : line(p[1] = (5, 3), p[5] = (8, 6)) has no intersect
x : line(p[1] = (5, 3), p[6] = (6, 4)) has no intersect
x : line(p[1] = (5, 3), p[7] = (2, 4)) has no intersect
x : line(p[2] = (5, 2), p[0] = (0, 0)) has no intersect
o : line(p[2] = (5, 2), p[1] = (5, 3)) has intersect
    line[6]((6, 4), (2, 4)) , cross (5.000000. 4.000000) 
x : line(p[2] = (5, 2), p[3] = (4, 1)) has no intersect
x : line(p[2] = (5, 2), p[4] = (6, 1)) has no intersect
x : line(p[2] = (5, 2), p[5] = (8, 6)) has no intersect
x : line(p[2] = (5, 2), p[6] = (6, 4)) has no intersect
x : line(p[2] = (5, 2), p[7] = (2, 4)) has no intersect
x : line(p[3] = (4, 1), p[0] = (0, 0)) has no intersect
o : line(p[3] = (4, 1), p[1] = (5, 3)) has intersect
    line[6]((6, 4), (2, 4)) , cross (5.500000. 4.000000) 
o : line(p[3] = (4, 1), p[2] = (5, 2)) has intersect
    line[4]((6, 1), (8, 6)) , cross (7.333333. 4.333333) 
x : line(p[3] = (4, 1), p[4] = (6, 1)) has no intersect
x : line(p[3] = (4, 1), p[5] = (8, 6)) has no intersect
x : line(p[3] = (4, 1), p[6] = (6, 4)) has no intersect
x : line(p[3] = (4, 1), p[7] = (2, 4)) has no intersect
x : line(p[4] = (6, 1), p[0] = (0, 0)) has no intersect
o : line(p[4] = (6, 1), p[1] = (5, 3)) has intersect
    line[6]((6, 4), (2, 4)) , cross (4.500000. 4.000000) 
o : line(p[4] = (6, 1), p[2] = (5, 2)) has intersect
    line[0]((0, 0), (5, 3)) , cross (4.375000. 2.625000) 
o : line(p[4] = (6, 1), p[3] = (4, 1)) has intersect
    line[0]((0, 0), (5, 3)) , cross (1.666667. 1.000000) 
x : line(p[4] = (6, 1), p[5] = (8, 6)) has no intersect
x : line(p[4] = (6, 1), p[6] = (6, 4)) has no intersect
x : line(p[4] = (6, 1), p[7] = (2, 4)) has no intersect
x : line(p[5] = (8, 6), p[0] = (0, 0)) has no intersect
x : line(p[5] = (8, 6), p[1] = (5, 3)) has no intersect
o : line(p[5] = (8, 6), p[2] = (5, 2)) has intersect
    line[3]((4, 1), (6, 1)) , cross (4.250000. 1.000000) 
x : line(p[5] = (8, 6), p[3] = (4, 1)) has no intersect
x : line(p[5] = (8, 6), p[4] = (6, 1)) has no intersect
x : line(p[5] = (8, 6), p[6] = (6, 4)) has no intersect
x : line(p[5] = (8, 6), p[7] = (2, 4)) has no intersect
x : line(p[6] = (6, 4), p[0] = (0, 0)) has no intersect
x : line(p[6] = (6, 4), p[1] = (5, 3)) has no intersect
o : line(p[6] = (6, 4), p[2] = (5, 2)) has intersect
    line[3]((4, 1), (6, 1)) , cross (4.500000. 1.000000) 
x : line(p[6] = (6, 4), p[3] = (4, 1)) has no intersect
x : line(p[6] = (6, 4), p[4] = (6, 1)) has no intersect
x : line(p[6] = (6, 4), p[5] = (8, 6)) has no intersect
x : line(p[6] = (6, 4), p[7] = (2, 4)) has no intersect
x : line(p[7] = (2, 4), p[0] = (0, 0)) has no intersect
o : line(p[7] = (2, 4), p[1] = (5, 3)) has intersect
    line[4]((6, 1), (8, 6)) , cross (6.588235. 2.470588) 
o : line(p[7] = (2, 4), p[2] = (5, 2)) has intersect
    line[4]((6, 1), (8, 6)) , cross (6.105263. 1.263158) 
x : line(p[7] = (2, 4), p[3] = (4, 1)) has no intersect
x : line(p[7] = (2, 4), p[4] = (6, 1)) has no intersect
x : line(p[7] = (2, 4), p[5] = (8, 6)) has no intersect
o : line(p[7] = (2, 4), p[6] = (6, 4)) has intersect
    line[4]((6, 1), (8, 6)) , cross (7.200000. 4.000000) 
o : p[0] -> (0.000000, 0.000000)
o : p[0] -> (5.000000, 3.000000)
o : p[0] -> (5.000000, 2.000000)
o : p[0] -> (4.000000, 1.000000)
o : p[0] -> (6.000000, 1.000000)
x : p[0] -> (8.000000, 6.000000)
o : p[0] -> (6.000000, 4.000000)
o : p[0] -> (2.000000, 4.000000)
o : p[0] -> (7.368423, 4.421058)
x : p[0] -> (7.368419, 4.421048)
x : p[0] -> (6.666669, 2.666672)
x : p[0] -> (6.666665, 2.666662)
x : p[0] -> (6.222224, 1.555561)
x : p[0] -> (6.222220, 1.555551)
x : p[0] -> (7.636366, 5.090914)
o : p[0] -> (7.636362, 5.090904)
o : p[0] -> (5.000002, 1.000000)
o : p[0] -> (4.999998, 1.000000)
o : p[0] -> (4.999996, 4.000000)
o : p[0] -> (5.000004, 4.000000)
o : p[0] -> (5.499996, 4.000000)
o : p[0] -> (5.500004, 4.000000)
x : p[0] -> (7.333335, 4.333338)
x : p[0] -> (7.333331, 4.333328)
o : p[0] -> (4.499996, 4.000000)
o : p[0] -> (4.500004, 4.000000)
o : p[0] -> (4.375005, 2.625003)
o : p[0] -> (4.374995, 2.624997)
o : p[0] -> (1.666672, 1.000003)
o : p[0] -> (1.666662, 0.999997)
o : p[0] -> (4.250002, 1.000000)
o : p[0] -> (4.249998, 1.000000)
o : p[0] -> (4.500002, 1.000000)
o : p[0] -> (4.499998, 1.000000)
x : p[0] -> (6.588237, 2.470593)
x : p[0] -> (6.588233, 2.470583)
x : p[0] -> (6.105265, 1.263163)
x : p[0] -> (6.105261, 1.263153)
x : p[0] -> (7.200002, 4.000005)
x : p[0] -> (7.199998, 3.999995)
o : p[1] -> (0.000000, 0.000000)
o : p[1] -> (5.000000, 3.000000)
o : p[1] -> (5.000000, 2.000000)
o : p[1] -> (4.000000, 1.000000)
o : p[1] -> (6.000000, 1.000000)
o : p[1] -> (8.000000, 6.000000)
o : p[1] -> (6.000000, 4.000000)
o : p[1] -> (2.000000, 4.000000)
o : p[1] -> (7.368423, 4.421058)
o : p[1] -> (7.368419, 4.421048)
o : p[1] -> (6.666669, 2.666672)
o : p[1] -> (6.666665, 2.666662)
o : p[1] -> (6.222224, 1.555561)
o : p[1] -> (6.222220, 1.555551)
o : p[1] -> (7.636366, 5.090914)
o : p[1] -> (7.636362, 5.090904)
o : p[1] -> (5.000002, 1.000000)
x : p[1] -> (4.999998, 1.000000)
o : p[1] -> (4.999996, 4.000000)
o : p[1] -> (5.000004, 4.000000)
o : p[1] -> (5.499996, 4.000000)
o : p[1] -> (5.500004, 4.000000)
o : p[1] -> (7.333335, 4.333338)
o : p[1] -> (7.333331, 4.333328)
o : p[1] -> (4.499996, 4.000000)
o : p[1] -> (4.500004, 4.000000)
o : p[1] -> (4.375005, 2.625003)
o : p[1] -> (4.374995, 2.624997)
o : p[1] -> (1.666672, 1.000003)
o : p[1] -> (1.666662, 0.999997)
x : p[1] -> (4.250002, 1.000000)
x : p[1] -> (4.249998, 1.000000)
x : p[1] -> (4.500002, 1.000000)
x : p[1] -> (4.499998, 1.000000)
o : p[1] -> (6.588237, 2.470593)
o : p[1] -> (6.588233, 2.470583)
o : p[1] -> (6.105265, 1.263163)
o : p[1] -> (6.105261, 1.263153)
o : p[1] -> (7.200002, 4.000005)
o : p[1] -> (7.199998, 3.999995)
o : p[2] -> (0.000000, 0.000000)
o : p[2] -> (5.000000, 3.000000)
o : p[2] -> (5.000000, 2.000000)
o : p[2] -> (4.000000, 1.000000)
o : p[2] -> (6.000000, 1.000000)
o : p[2] -> (8.000000, 6.000000)
o : p[2] -> (6.000000, 4.000000)
x : p[2] -> (2.000000, 4.000000)
o : p[2] -> (7.368423, 4.421058)
o : p[2] -> (7.368419, 4.421048)
o : p[2] -> (6.666669, 2.666672)
o : p[2] -> (6.666665, 2.666662)
o : p[2] -> (6.222224, 1.555561)
o : p[2] -> (6.222220, 1.555551)
o : p[2] -> (7.636366, 5.090914)
o : p[2] -> (7.636362, 5.090904)
o : p[2] -> (5.000002, 1.000000)
o : p[2] -> (4.999998, 1.000000)
x : p[2] -> (4.999996, 4.000000)
o : p[2] -> (5.000004, 4.000000)
o : p[2] -> (5.499996, 4.000000)
o : p[2] -> (5.500004, 4.000000)
o : p[2] -> (7.333335, 4.333338)
o : p[2] -> (7.333331, 4.333328)
x : p[2] -> (4.499996, 4.000000)
x : p[2] -> (4.500004, 4.000000)
o : p[2] -> (4.375005, 2.625003)
o : p[2] -> (4.374995, 2.624997)
o : p[2] -> (1.666672, 1.000003)
o : p[2] -> (1.666662, 0.999997)
o : p[2] -> (4.250002, 1.000000)
o : p[2] -> (4.249998, 1.000000)
o : p[2] -> (4.500002, 1.000000)
o : p[2] -> (4.499998, 1.000000)
o : p[2] -> (6.588237, 2.470593)
o : p[2] -> (6.588233, 2.470583)
o : p[2] -> (6.105265, 1.263163)
o : p[2] -> (6.105261, 1.263153)
o : p[2] -> (7.200002, 4.000005)
o : p[2] -> (7.199998, 3.999995)
o : p[3] -> (0.000000, 0.000000)
o : p[3] -> (5.000000, 3.000000)
o : p[3] -> (5.000000, 2.000000)
o : p[3] -> (4.000000, 1.000000)
o : p[3] -> (6.000000, 1.000000)
x : p[3] -> (8.000000, 6.000000)
x : p[3] -> (6.000000, 4.000000)
x : p[3] -> (2.000000, 4.000000)
x : p[3] -> (7.368423, 4.421058)
x : p[3] -> (7.368419, 4.421048)
o : p[3] -> (6.666669, 2.666672)
o : p[3] -> (6.666665, 2.666662)
o : p[3] -> (6.222224, 1.555561)
o : p[3] -> (6.222220, 1.555551)
x : p[3] -> (7.636366, 5.090914)
x : p[3] -> (7.636362, 5.090904)
o : p[3] -> (5.000002, 1.000000)
o : p[3] -> (4.999998, 1.000000)
x : p[3] -> (4.999996, 4.000000)
x : p[3] -> (5.000004, 4.000000)
x : p[3] -> (5.499996, 4.000000)
x : p[3] -> (5.500004, 4.000000)
o : p[3] -> (7.333335, 4.333338)
o : p[3] -> (7.333331, 4.333328)
x : p[3] -> (4.499996, 4.000000)
x : p[3] -> (4.500004, 4.000000)
o : p[3] -> (4.375005, 2.625003)
o : p[3] -> (4.374995, 2.624997)
o : p[3] -> (1.666672, 1.000003)
o : p[3] -> (1.666662, 0.999997)
o : p[3] -> (4.250002, 1.000000)
o : p[3] -> (4.249998, 1.000000)
o : p[3] -> (4.500002, 1.000000)
o : p[3] -> (4.499998, 1.000000)
o : p[3] -> (6.588237, 2.470593)
o : p[3] -> (6.588233, 2.470583)
o : p[3] -> (6.105265, 1.263163)
o : p[3] -> (6.105261, 1.263153)
o : p[3] -> (7.200002, 4.000005)
o : p[3] -> (7.199998, 3.999995)
o : p[4] -> (0.000000, 0.000000)
o : p[4] -> (5.000000, 3.000000)
o : p[4] -> (5.000000, 2.000000)
o : p[4] -> (4.000000, 1.000000)
o : p[4] -> (6.000000, 1.000000)
o : p[4] -> (8.000000, 6.000000)
o : p[4] -> (6.000000, 4.000000)
x : p[4] -> (2.000000, 4.000000)
o : p[4] -> (7.368423, 4.421058)
o : p[4] -> (7.368419, 4.421048)
o : p[4] -> (6.666669, 2.666672)
o : p[4] -> (6.666665, 2.666662)
o : p[4] -> (6.222224, 1.555561)
o : p[4] -> (6.222220, 1.555551)
o : p[4] -> (7.636366, 5.090914)
o : p[4] -> (7.636362, 5.090904)
o : p[4] -> (5.000002, 1.000000)
o : p[4] -> (4.999998, 1.000000)
o : p[4] -> (4.999996, 4.000000)
o : p[4] -> (5.000004, 4.000000)
o : p[4] -> (5.499996, 4.000000)
o : p[4] -> (5.500004, 4.000000)
o : p[4] -> (7.333335, 4.333338)
o : p[4] -> (7.333331, 4.333328)
x : p[4] -> (4.499996, 4.000000)
o : p[4] -> (4.500004, 4.000000)
x : p[4] -> (4.375005, 2.625003)
x : p[4] -> (4.374995, 2.624997)
x : p[4] -> (1.666672, 1.000003)
o : p[4] -> (1.666662, 0.999997)
o : p[4] -> (4.250002, 1.000000)
o : p[4] -> (4.249998, 1.000000)
o : p[4] -> (4.500002, 1.000000)
o : p[4] -> (4.499998, 1.000000)
o : p[4] -> (6.588237, 2.470593)
o : p[4] -> (6.588233, 2.470583)
o : p[4] -> (6.105265, 1.263163)
o : p[4] -> (6.105261, 1.263153)
o : p[4] -> (7.200002, 4.000005)
o : p[4] -> (7.199998, 3.999995)
x : p[5] -> (0.000000, 0.000000)
o : p[5] -> (5.000000, 3.000000)
o : p[5] -> (5.000000, 2.000000)
x : p[5] -> (4.000000, 1.000000)
o : p[5] -> (6.000000, 1.000000)
o : p[5] -> (8.000000, 6.000000)
o : p[5] -> (6.000000, 4.000000)
o : p[5] -> (2.000000, 4.000000)
o : p[5] -> (7.368423, 4.421058)
o : p[5] -> (7.368419, 4.421048)
o : p[5] -> (6.666669, 2.666672)
o : p[5] -> (6.666665, 2.666662)
o : p[5] -> (6.222224, 1.555561)
o : p[5] -> (6.222220, 1.555551)
o : p[5] -> (7.636366, 5.090914)
o : p[5] -> (7.636362, 5.090904)
o : p[5] -> (5.000002, 1.000000)
o : p[5] -> (4.999998, 1.000000)
o : p[5] -> (4.999996, 4.000000)
o : p[5] -> (5.000004, 4.000000)
o : p[5] -> (5.499996, 4.000000)
o : p[5] -> (5.500004, 4.000000)
o : p[5] -> (7.333335, 4.333338)
o : p[5] -> (7.333331, 4.333328)
o : p[5] -> (4.499996, 4.000000)
o : p[5] -> (4.500004, 4.000000)
x : p[5] -> (4.375005, 2.625003)
x : p[5] -> (4.374995, 2.624997)
x : p[5] -> (1.666672, 1.000003)
x : p[5] -> (1.666662, 0.999997)
o : p[5] -> (4.250002, 1.000000)
x : p[5] -> (4.249998, 1.000000)
o : p[5] -> (4.500002, 1.000000)
o : p[5] -> (4.499998, 1.000000)
o : p[5] -> (6.588237, 2.470593)
o : p[5] -> (6.588233, 2.470583)
o : p[5] -> (6.105265, 1.263163)
o : p[5] -> (6.105261, 1.263153)
o : p[5] -> (7.200002, 4.000005)
o : p[5] -> (7.199998, 3.999995)
o : p[6] -> (0.000000, 0.000000)
o : p[6] -> (5.000000, 3.000000)
o : p[6] -> (5.000000, 2.000000)
x : p[6] -> (4.000000, 1.000000)
o : p[6] -> (6.000000, 1.000000)
o : p[6] -> (8.000000, 6.000000)
o : p[6] -> (6.000000, 4.000000)
o : p[6] -> (2.000000, 4.000000)
o : p[6] -> (7.368423, 4.421058)
o : p[6] -> (7.368419, 4.421048)
o : p[6] -> (6.666669, 2.666672)
o : p[6] -> (6.666665, 2.666662)
o : p[6] -> (6.222224, 1.555561)
o : p[6] -> (6.222220, 1.555551)
o : p[6] -> (7.636366, 5.090914)
o : p[6] -> (7.636362, 5.090904)
o : p[6] -> (5.000002, 1.000000)
o : p[6] -> (4.999998, 1.000000)
o : p[6] -> (4.999996, 4.000000)
o : p[6] -> (5.000004, 4.000000)
o : p[6] -> (5.499996, 4.000000)
o : p[6] -> (5.500004, 4.000000)
o : p[6] -> (7.333335, 4.333338)
o : p[6] -> (7.333331, 4.333328)
o : p[6] -> (4.499996, 4.000000)
o : p[6] -> (4.500004, 4.000000)
o : p[6] -> (4.375005, 2.625003)
o : p[6] -> (4.374995, 2.624997)
o : p[6] -> (1.666672, 1.000003)
o : p[6] -> (1.666662, 0.999997)
x : p[6] -> (4.250002, 1.000000)
x : p[6] -> (4.249998, 1.000000)
o : p[6] -> (4.500002, 1.000000)
x : p[6] -> (4.499998, 1.000000)
o : p[6] -> (6.588237, 2.470593)
o : p[6] -> (6.588233, 2.470583)
o : p[6] -> (6.105265, 1.263163)
o : p[6] -> (6.105261, 1.263153)
o : p[6] -> (7.200002, 4.000005)
o : p[6] -> (7.199998, 3.999995)
o : p[7] -> (0.000000, 0.000000)
o : p[7] -> (5.000000, 3.000000)
x : p[7] -> (5.000000, 2.000000)
x : p[7] -> (4.000000, 1.000000)
x : p[7] -> (6.000000, 1.000000)
o : p[7] -> (8.000000, 6.000000)
o : p[7] -> (6.000000, 4.000000)
o : p[7] -> (2.000000, 4.000000)
x : p[7] -> (7.368423, 4.421058)
x : p[7] -> (7.368419, 4.421048)
o : p[7] -> (6.666669, 2.666672)
o : p[7] -> (6.666665, 2.666662)
x : p[7] -> (6.222224, 1.555561)
x : p[7] -> (6.222220, 1.555551)
x : p[7] -> (7.636366, 5.090914)
x : p[7] -> (7.636362, 5.090904)
x : p[7] -> (5.000002, 1.000000)
x : p[7] -> (4.999998, 1.000000)
o : p[7] -> (4.999996, 4.000000)
o : p[7] -> (5.000004, 4.000000)
o : p[7] -> (5.499996, 4.000000)
o : p[7] -> (5.500004, 4.000000)
x : p[7] -> (7.333335, 4.333338)
x : p[7] -> (7.333331, 4.333328)
o : p[7] -> (4.499996, 4.000000)
o : p[7] -> (4.500004, 4.000000)
o : p[7] -> (4.375005, 2.625003)
o : p[7] -> (4.374995, 2.624997)
o : p[7] -> (1.666672, 1.000003)
o : p[7] -> (1.666662, 0.999997)
x : p[7] -> (4.250002, 1.000000)
x : p[7] -> (4.249998, 1.000000)
x : p[7] -> (4.500002, 1.000000)
x : p[7] -> (4.499998, 1.000000)
o : p[7] -> (6.588237, 2.470593)
x : p[7] -> (6.588233, 2.470583)
x : p[7] -> (6.105265, 1.263163)
x : p[7] -> (6.105261, 1.263153)
x : p[7] -> (7.200002, 4.000005)
o : p[7] -> (7.199998, 3.999995)


Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

typedef complex<double> Point;
const double EPS = 1e-6;

int sign(double a) {
  if (a > EPS)
    return +1;
  if (a < -EPS)
    return -1;
  return 0;
}
double dot(Point a, Point b) { return real(conj(a) * b); }
double cross(Point a, Point b) { return imag(conj(a) * b); }
int ccw(Point a, Point b, Point c) {
  b -= a;
  c -= a;
  double len = abs(b) * abs(c); // 速さが気になるときは1にする
  if (cross(b, c) > +len * EPS)
    return +1; // 反時計回り
  if (cross(b, c) < -len * EPS)
    return -1; // 時計回り
  if (dot(b, c) < 0)
    return +2; // c--a--b の順番で一直線上
  if (norm(b) < norm(c))
    return -2; // a--b--c の順番で一直線上
  return 0;    // 点が線分ab上にある
}
struct Line : public vector<Point> {
  Line() {}
  Line(const Point &a, const Point &b) {
    push_back(a);
    push_back(b);
  }
  Point vector() const { return back() - front(); }
};
typedef vector<Point> Polygon; // 反時計回りを仮定
Point crosspointLL(Line l, Line m) {
  double A = cross(l.vector(), m.vector());
  double B = cross(l.vector(), l[1] - m[0]);
  if (sign(A) == 0 && sign(B) == 0)
    return m[0]; // 二直線が重なっている
  if (sign(A) == 0)
    assert(false); // 直線が交わらない
  return m[0] + m.vector() * B / A;
}
// 両端を含まない
bool intersectSP(Line s, Point p) {
  return ccw(s[0], s[1], p) == 0 && abs(s[0] - p) > EPS && abs(s[1] - p) > EPS;
}
bool equalLL(Line l, Line m) {
  return sign(cross(l.vector(), m[0] - l[0])) == 0;
}
bool intersectLS(Line l, Line s) {
  // 直線lについて、線分sの端点が異なる側にある
  return sign(cross(l.vector(), s[0] - l[0]) *
              cross(l.vector(), s[1] - l[0])) <= 0;
}
bool intersectSS(Line s, Line t) {
  bool f = ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
           ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
  if (!f)
    return false;
  Point cp = crosspointLL(s, t);
  return intersectSP(s, cp) && intersectSP(t, cp);
}

bool arrivable(Point bp, Point tp, const vector<Line> &poly_line) {
  Line cat(bp, tp);
  for (int k = 0; k < poly_line.size(); k++) {
    Line pol = poly_line[k];
    if (equalLL(cat, pol))
      continue;
    if (intersectSS(cat, pol))
      return false;
  }
  return true;
}

int main() {
  int N;
  while (cin >> N && N) {
    Polygon P(N);
    for (int i = 0; i < N; i++) {
      double x, y;
      cin >> x >> y;
      P[i] = Point(x, y);
    }

    vector<Line> poly_line(N);
    for (int i = 0; i < N; i++) {
      poly_line[i] = Line(P[i], P[(i + 1) % P.size()]);
    }

    vector<Point> cand_point = P; // 候補点
    for (int i = 0; i < N; i++)
      for (int j = 0; j < N; j++) {
        if (i == j)
          continue;
        Point bp = P[i], ep = P[j];
        Line cat(bp, ep);

        bool is_cross = false;
        Point cross_p;
        Line cross_l;
        int cross_idx;
        for (int k = 0; k < N; k++) {
          Line pol = poly_line[k];

          if (equalLL(cat, pol))
            continue;
          if (!intersectLS(cat, pol))
            continue;

          Point cp = crosspointLL(cat, pol);

          if (!intersectSP(pol, cp))
            continue;
          if (ccw(cat[0], cat[1], cp) != -2)
            continue; // true???

          if (!is_cross) {
            is_cross = true;
            cross_p = cp;
            cross_l = pol;
            cross_idx = k;
          } else if (abs(cross_p - cat[0]) > abs(cp - cat[0])) {
            cross_p = cp;
            cross_l = pol;
            cross_idx = k;
          }
        }
        if (is_cross) {
          fprintf(stderr,
                  "o : line(p[%d] = (%.0f, %.0f), p[%d] = (%.0f, %.0f)) has "
                  "intersect\\n",
                  i, bp.real(), bp.imag(), j, ep.real(), ep.imag());
          fprintf(
              stderr,
              "    line[%d]((%.0f, %.0f), (%.0f, %.0f)) , cross (%f. %f) \\n",
              cross_idx, cross_l[0].real(), cross_l[0].imag(),
              cross_l[1].real(), cross_l[1].imag(), cross_p.real(),
              cross_p.imag());
          cand_point.push_back(cross_p + cross_l.vector() * EPS);
          cand_point.push_back(cross_p - cross_l.vector() * EPS);
        } else {
          fprintf(stderr,
                  "x : line(p[%d] = (%.0f, %.0f), p[%d] = (%.0f, %.0f)) has no "
                  "intersect\\n",
                  i, bp.real(), bp.imag(), j, ep.real(), ep.imag());
        }
      }

    vector<vector<bool>> is_arrivable(N,
                                      vector<bool>(cand_point.size(), false));
    for (int i = 0; i < N; i++)
      for (int j = 0; j < cand_point.size(); j++) {
        Point bp = P[i], tp = cand_point[j];
        is_arrivable[i][j] = arrivable(bp, tp, poly_line);
        fprintf(stderr, "%c : p[%d] -> (%f, %f)\\n",
                is_arrivable[i][j] ? 'o' : 'x', i, cand_point[j].real(),
                cand_point[j].imag());
      }

    int ans = N;
    for (int s = 1; s < (1 << N); s++) {
      int bits = __builtin_popcount(s);
      if (bits >= ans)
        continue;
      vector<bool> ok(cand_point.size(), false);
      for (int i = 0; i < N; i++)
        if (s >> i & 1)
          for (int j = 0; j < cand_point.size(); j++)
            ok[j] = ok[j] || is_arrivable[i][j];

      bool is_answer = true;
      for (int i = 0; i < cand_point.size(); i++)
        if (!ok[i]) {
          is_answer = false;
          break;
        }

      if (is_answer) {
        ans = bits;
      }
    }

    cout << ans << endl;
  }
  return 0;
}