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;
inline int FSGN(double x) {
  if (x > (1e-6)) return 1;
  if (x >= -(1e-6)) return 0;
  return -1;
}
struct vec2 {
  double x, y;
  vec2() : x(0.0), y(0.0) {}
  vec2(double x, double y) : x(x), y(y) {}
  vec2 operator+(const vec2 &v) const { return vec2(x + v.x, y + v.y); }
  vec2 operator-(const vec2 &v) const { return vec2(x - v.x, y - v.y); }
  double operator*(const vec2 &v) const { return x * v.x + y * v.y; }
  vec2 operator/(const double k) const { return vec2(x / k, y / k); }
  double operator^(const vec2 &v) const { return x * v.y - y * v.x; }
  bool operator==(const vec2 &v) const {
    return fabs(x - v.x) < (1e-6) && fabs(y - v.y) < (1e-6);
  }
  double len() { return sqrt(x * x + y * y); }
  double getRatio(vec2 &a, vec2 &b) {
    if (fabs(b.x - a.x) < (1e-6)) return (y - a.y) / (b.y - a.y);
    return (x - a.x) / (b.x - a.x);
  }
};
struct Polygon2D {
  int n;
  int nr;
  vec2 *v;
  vec2 *vr;
  vec2 *buf;
  Polygon2D() {
    v = new vec2[10];
    vr = new vec2[10];
    buf = new vec2[10];
  }
  ~Polygon2D() {
    delete[] v;
    delete[] vr;
    delete[] buf;
  }
  double getArea() {
    double ret = 0;
    for (int i = 1; i < n - 1; ++i) {
      ret += (v[i] - v[0]) ^ (v[i + 1] - v[0]);
    }
    return fabs(ret) / 2;
  }
  void setOrder() {
    int i, j, di, st, dt;
    for (i = 0;
         i < n - 2 && fabs((v[i + 1] - v[i]) ^ (v[i + 2] - v[i])) < (1e-6); ++i)
      ;
    di = ((v[i + 1] - v[i]) ^ (v[i + 2] - v[i])) > (1e-6) ? 1 : -1;
    for (i = di > 0 ? 0 : n - 1, j = 0; i < n && i >= 0; i += di, j++) {
      vr[j] = v[i];
    }
    vr[nr = j] = vr[0];
  }
};
struct PolygonSet2D {
  int tot;
  Polygon2D *ps;
  pair<double, int> *buf;
  PolygonSet2D() {
    buf = new pair<double, int>[10 * 510];
    ps = new Polygon2D[510];
  }
  ~PolygonSet2D() {
    delete[] buf;
    delete[] ps;
  }
  double getCombination() {
    if (tot == 1) return ps[0].getArea();
    for (int i = 0; i < tot; ++i) {
      ps[i].setOrder();
    }
    int cnt, c1, c2;
    double s1, s2, ret = 0;
    for (int i = 0; i < tot; i++) {
      for (int ii = 0; ii < ps[i].nr; ii++) {
        cnt = 0;
        buf[cnt++] = make_pair(0.0, 0);
        buf[cnt++] = make_pair(1.0, 0);
        for (int j = 0; j < tot; j++) {
          if (i == j) continue;
          for (int jj = 0; jj < ps[j].nr; jj++) {
            c1 = FSGN((ps[i].vr[ii + 1] - ps[i].vr[ii]) ^
                      (ps[j].vr[jj] - ps[i].vr[ii]));
            c2 = FSGN((ps[i].vr[ii + 1] - ps[i].vr[ii]) ^
                      (ps[j].vr[jj + 1] - ps[i].vr[ii]));
            if (!c1 && !c2) {
              if (((ps[i].vr[ii + 1] - ps[i].vr[ii]) *
                   (ps[j].vr[jj + 1] - ps[j].vr[jj])) > 0 &&
                  i > j) {
                buf[cnt++] = make_pair(
                    ps[j].vr[jj].getRatio(ps[i].vr[ii], ps[i].vr[ii + 1]), 1);
                buf[cnt++] = make_pair(
                    ps[j].vr[jj + 1].getRatio(ps[i].vr[ii], ps[i].vr[ii + 1]),
                    -1);
              }
            } else {
              s1 = ((ps[j].vr[jj + 1] - ps[j].vr[jj]) ^
                    (ps[i].vr[ii] - ps[j].vr[jj]));
              s2 = ((ps[j].vr[jj + 1] - ps[j].vr[jj]) ^
                    (ps[i].vr[ii + 1] - ps[j].vr[jj]));
            }
            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 j = 1; j < cnt; j++) {
          now = min(max(buf[j].first, 0.0), 1.0);
          if (!cov) sum += now - pre;
          cov += buf[j].second;
          pre = now;
        }
        ret += (ps[i].vr[ii] ^ ps[i].vr[ii + 1]) * sum;
      }
    }
    return ret / 2;
  }
} ch;
int main() {
  int nt = 4;
  double ret;
  while (~scanf("%d", &ch.tot)) {
    ret = 0;
    for (int i = 0; i < ch.tot; ++i) {
      ch.ps[i].n = nt;
      for (int j = 0; j < nt; ++j) {
        scanf("%lf%lf", &ch.ps[i].v[j].x, &ch.ps[i].v[j].y);
      }
      ret += ch.ps[i].getArea();
    }
    ret /= ch.getCombination();
    printf("%.9lf\n", ret);
  }
  return 0;
}