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;
  void input() { scanf("%lf%lf", &x, &y); }
  point(double _x = 0, double _y = 0) : x(_x), y(_y){};
  point operator+(point a) { return point(x + a.x, y + a.y); }
  point operator-(point a) { return point(x - a.x, y - a.y); }
  point operator*(double p) { return point(x * p, y * p); }
  point operator/(double p) { return point(x / p, y / p); }
};
double dmult(point a, point b) { return a.x * b.x + a.y * b.y; }
double xmult(point a, point b) { return a.x * b.y - a.y * b.x; }
struct Event {
  double pos;
  int kind;
  Event(double _p = -1, int _k = -1) {
    pos = _p;
    kind = _k;
  }
  bool operator<(const Event &t) const {
    if (((pos - t.pos) < (-1.0e-9) ? -1 : ((pos - t.pos) > 1.0e-9)) != 0)
      return ((pos - t.pos) < (-1.0e-9) ? -1 : ((pos - t.pos) > 1.0e-9)) < 0;
    else
      return kind < t.kind;
  }
} t[5005];
double GetPolyUnionArea(int n, point p[505][5]) {
  double s = 0;
  for (int i = 0; i < n; ++i) {
    for (int x = 0; x < 4; ++x) {
      int m = 2;
      t[0] = Event(0.0, 0);
      t[1] = Event(1.0, 0);
      point v = p[i][x + 1] - p[i][x];
      double d = dmult(v, v);
      for (int j = 0; j < n; ++j) {
        if (i == j) continue;
        for (int y = 0; y < 4; ++y) {
          int ta = ((xmult(v, p[j][y] - p[i][x])) < (-1.0e-9)
                        ? -1
                        : ((xmult(v, p[j][y] - p[i][x])) > 1.0e-9));
          int tb = ((xmult(v, p[j][y + 1] - p[i][x])) < (-1.0e-9)
                        ? -1
                        : ((xmult(v, p[j][y + 1] - p[i][x])) > 1.0e-9));
          if (ta == 0 && tb == 0) {
            if (((dmult(p[j][y + 1] - p[j][y], v)) < (-1.0e-9)
                     ? -1
                     : ((dmult(p[j][y + 1] - p[j][y], v)) > 1.0e-9)) > 0 &&
                j < i) {
              t[m++] = Event(dmult(p[j][y] - p[i][x], v) / d, 1);
              t[m++] = Event(dmult(p[j][y + 1] - p[i][x], v) / d, -1);
            }
          } else if (ta >= 0 && tb < 0) {
            double tc = xmult(p[j][y + 1] - p[j][y], p[i][x] - p[j][y]);
            double td = xmult(p[j][y + 1] - p[j][y], p[i][x + 1] - p[j][y]);
            t[m++] = Event(tc / (tc - td), 1);
          } else if (ta < 0 && tb >= 0) {
            double tc = xmult(p[j][y + 1] - p[j][y], p[i][x] - p[j][y]);
            double td = xmult(p[j][y + 1] - p[j][y], p[i][x + 1] - p[j][y]);
            t[m++] = Event(tc / (tc - td), -1);
          }
        }
      }
      sort(t, t + m);
      double cur = t[0].pos;
      if (((cur) < (-1.0e-9) ? -1 : ((cur) > 1.0e-9)) < 0)
        cur = 0;
      else if (((cur - 1) < (-1.0e-9) ? -1 : ((cur - 1) > 1.0e-9)) > 0)
        cur = 1;
      int num = t[0].kind;
      double tp = 0;
      for (int j = 1; j < m; ++j) {
        double w = t[j].pos;
        if (((w) < (-1.0e-9) ? -1 : ((w) > 1.0e-9)) < 0)
          w = 0;
        else if (((w - 1) < (-1.0e-9) ? -1 : ((w - 1) > 1.0e-9)) > 0)
          w = 1;
        if (num == 0) tp += w - cur;
        num += t[j].kind;
        cur = w;
      }
      s += xmult(p[i][x], p[i][x + 1]) * tp;
    }
  }
  return s * 0.5;
}
int main() {
  int n;
  point p[505][5];
  scanf("%d", &n);
  double s = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) p[i][j].input();
    double tp = xmult(p[i][3], p[i][0]);
    for (int j = 0; j < 3; ++j) tp += xmult(p[i][j], p[i][j + 1]);
    if (((tp) < (-1.0e-9) ? -1 : ((tp) > 1.0e-9)) < 0) {
      swap(p[i][0], p[i][3]);
      swap(p[i][1], p[i][2]);
      tp = -tp;
    }
    s += tp;
    p[i][4] = p[i][0];
  }
  s *= 0.5;
  s /= GetPolyUnionArea(n, p);
  printf("%.10f\n", s);
  return 0;
}