Problem: The night after the graduation ceremony graduate students of German University in Cairo (GUC) are playing darts. As there's no real dart board available, the photographs of members of the GUC upper management are being used.

So, n rectangular photos are placed on the wall. They can overlap arbitrary and even coincide. The photos are not necessarily placed horizontally or vertically, they could also be rotated before being pinned to the wall.

The score of one dart throw is simply the number of photos the dart went through.

Fatma has made a throw but her score was not recorded. She only remembers that she did make it into at least one photo.

Assuming that the probability distribution of the throw is equal across the whole wall, what would be the expectation of Fatma's score?

Input

The first line of input contains integer n (1 ≤ n ≤ 500) — the number of photos on the wall. Then follow n lines describing the photos, each containing 8 single-space-separated integers (coordinates of 4 vertices): x1, y1, x2, y2, x3, y3, x4, y4. Each photo is a rectangle with a nonzero area. The coordinates are integers, not exceeding 104 by absolute value. The coordinates of the rectangle are given in either clockwise or counterclockwise order.

Output

Print the expected score of the throw. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6.

Examples

Input

1
0 0 0 2 2 2 2 0


Output

1.0000000000


Input

1
-1 0 0 1 1 0 0 -1


Output

1.0000000000


Input

4
0 0 0 1 3 1 3 0
0 0 0 3 1 3 1 0
3 3 2 3 2 0 3 0
3 3 3 2 0 2 0 3


Output

1.5000000000


Input

2
-1 0 0 1 1 0 0 -1
0 0 1 1 2 0 1 -1


Output

1.1428571429

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct point {
  double x, y;
  point() {}
  point(double _x, double _y) : x(_x), y(_y) {}
  point operator+(const point &p) const { return point(x + p.x, y + p.y); }
  point operator-(const point &p) const { return point(x - p.x, y - p.y); }
  point operator*(const double &p) const { return point(x * p, y * p); }
  double operator*(const point &p) const { return x * p.x + y * p.y; }
  point operator/(const double &p) const { return point(x / p, y / p); }
  double operator^(const point &p) const { return x * p.y - y * p.x; }
  bool operator==(const point &p) const {
    return fabs(x - p.x) < 1e-8 && fabs(y - p.y) < 1e-8;
  }
  bool operator<(const point &p) const {
    if (y == p.y) return x - p.x;
    return y - p.y;
  }
  double getRatio(point &a, point &b) {
    if (fabs(b.x - a.x) < 1e-8) return (y - a.y) / (b.y - a.y);
    return (x - a.x) / (b.x - a.x);
  }
};
double xmult(point p1, point p2, point p0) {
  return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
}
double dmult(point p1, point p2, point p0) {
  return (p1.x - p0.x) * (p2.x - p0.x) + (p1.y - p0.y) * (p2.y - p0.y);
}
double distance(point p1, point p2) {
  return sqrt(((p1.x - p2.x) * (p1.x - p2.x)) +
              ((p1.y - p2.y) * (p1.y - p2.y)));
}
struct Polygon2D {
  int n, bn;
  point p[10], bag[10];
  double getArea() {
    double area = 0;
    for (int i = 2; i < bn; i++) {
      area += xmult(bag[i], bag[i - 1], bag[0]);
    }
    return fabs(area / 2.0);
  }
  void make_bag() {
    int i, j;
    sort(p, p + n);
    bag[0] = p[0];
    int len = 1;
    for (int i = 1; i < n; i++) {
      while (len >= 2 && xmult(bag[len - 2], bag[len - 1], p[i]) <= 0) len--;
      bag[len++] = p[i];
    }
    j = len + 1;
    for (i = n - 2; i >= 0; i--) {
      while (len >= j && xmult(bag[len - 2], bag[len - 1], p[i]) <= 0) len--;
      bag[len++] = p[i];
    }
    len--;
    bn = len;
  }
};
struct PolygonSet2D {
  int n;
  Polygon2D pSet[505];
  pair<double, int> buf[10 * 505];
  int FSGN(double x) {
    if (x > 1e-8) return 1;
    if (x >= -1e-8) return 0;
    return -1;
  }
  double getCombination() {
    for (int i = 0; i < n; i++) {
      pSet[i].make_bag();
    }
    if (n == 1) {
      return pSet[0].getArea();
    }
    int cnt, c1, c2;
    double s1, s2, ret = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < pSet[i].bn; j++) {
        cnt = 0;
        buf[cnt++] = pair<double, int>(0.0, 0);
        buf[cnt++] = pair<double, int>(1.0, 0);
        for (int k = 0; k < n; k++) {
          if (i == k) continue;
          for (int q = 0; q < pSet[k].bn; q++) {
            c1 = FSGN((pSet[i].bag[j + 1] - pSet[i].bag[j]) ^
                      (pSet[k].bag[q] - pSet[i].bag[j]));
            c2 = FSGN((pSet[i].bag[j + 1] - pSet[i].bag[j]) ^
                      (pSet[k].bag[q + 1] - pSet[i].bag[j]));
            if (!c1 && !c2) {
              if (((pSet[i].bag[j + 1] - pSet[i].bag[j]) *
                   (pSet[k].bag[q + 1] - pSet[k].bag[q])) > 0 &&
                  i > k) {
                buf[cnt++] = pair<double, int>(
                    pSet[k].bag[q].getRatio(pSet[i].bag[j], pSet[i].bag[j + 1]),
                    1);
                buf[cnt++] =
                    pair<double, int>(pSet[k].bag[q + 1].getRatio(
                                          pSet[i].bag[j], pSet[i].bag[j + 1]),
                                      -1);
              }
            } else {
              s1 = ((pSet[k].bag[q + 1] - pSet[k].bag[q]) ^
                    (pSet[i].bag[j] - pSet[k].bag[q]));
              s2 = ((pSet[k].bag[q + 1] - pSet[k].bag[q]) ^
                    (pSet[i].bag[j + 1] - pSet[k].bag[q]));
            }
            if (c1 >= 0 && c2 < 0)
              buf[cnt++] = make_pair(s1 / (s1 - s2), 1);
            else if (c1 < 0 && c2 >= 0)
              buf[cnt++] = make_pair(s1 / (s1 - s2), -1);
          }
        }
        sort(buf, buf + cnt);
        double pre = min(max(buf[0].first, 0.0), 1.0), now;
        double sum = 0;
        double cov = buf[0].second;
        for (int k = 1; k < cnt; k++) {
          now = min(max(buf[k].first, 0.0), 1.0);
          if (!cov) sum += now - pre;
          cov += buf[k].second;
          pre = now;
        }
        ret += (pSet[i].bag[j] ^ pSet[i].bag[j + 1]) * sum;
      }
    }
    return fabs(ret / 2.0);
  }
} ch;
int main() {
  int nt = 4;
  double ret;
  while (~scanf("%d", &ch.n)) {
    ret = 0;
    for (int i = 0; i < ch.n; ++i) {
      ch.pSet[i].n = nt;
      for (int j = 0; j < nt; ++j) {
        scanf("%lf%lf", &ch.pSet[i].p[j].x, &ch.pSet[i].p[j].y);
      }
      ch.pSet[i].make_bag();
      ret += ch.pSet[i].getArea();
    }
    ret /= ch.getCombination();
    printf("%.9lf\n", ret);
  }
  return 0;
}