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;
const int MAX = 505;
const int N = 5;
int sgn(double x) {
  if (x > 1e-8) return 1;
  if (x < -1e-8) return -1;
  return 0;
}
struct Point {
  double x, y;
  Point() {}
  Point(double _x, double _y) : x(_x), y(_y) {}
  void read() { scanf("%lf%lf", &x, &y); }
  bool operator<(const Point &t) const {
    if (sgn(x - t.x) == 0) return sgn(y - t.y) < 0;
    return sgn(x - t.x) < 0;
  }
  bool operator==(const Point &t) const {
    return sgn(x - t.x) == 0 && sgn(y - t.y) == 0;
  }
} cuts[MAX];
double operator*(const Point &a, const Point &b) {
  return a.x * b.y - b.x * a.y;
}
Point operator*(const Point &a, const double t) {
  return Point(a.x * t, a.y * t);
}
Point operator+(const Point &a, const Point &b) {
  return Point(a.x + b.x, a.y + b.y);
}
Point operator-(const Point &a, const Point &b) {
  return Point(a.x - b.x, a.y - b.y);
}
double cross(Point a, Point b, Point c) { return (a - c) * (b - c); }
double cross(Point a, Point b) { return a.x * b.y - b.x * a.y; }
struct Poly {
  Point p[N + 2];
  int size;
  double area() {
    double res = 0;
    for (int i = 0; i < size; i++) res += cross(p[i], p[i + 1]);
    return res;
  }
} poly[MAX];
struct Line {
  Point a, b;
  double k, l;
  int idx;
  Line() {}
  Line(Point aa, Point bb) {
    a = aa;
    b = bb;
    k = (a.y - b.y) / (a.x - b.x);
    l = a.y - k * a.x;
  }
  bool operator<(const Line &t) const {
    if (sgn(k - t.k) == 0) return sgn(l - t.l) < 0;
    return sgn(k - t.k) < 0;
  }
  bool operator==(const Line &t) const {
    return sgn(t.k - k) == 0 && sgn(t.l - l) == 0;
  }
} positive[MAX * 4], negative[MAX * 4], tmp[MAX * 4];
struct E {
  double x;
  int type;
  E() {}
  E(double _x, int t) : x(_x), type(t) {}
  bool operator<(const E &t) const { return sgn(x - t.x) < 0; }
} event[MAX * 4];
int n;
Point intersection(Point a, Point b, Point c, Point d) {
  Point x = b - a, y = d - c, z = c - a;
  double t = cross(y, z) / cross(y, x);
  return a + x * t;
}
bool onSeg(Point a, Point b, Point c) {
  if (c.x < min(a.x, b.x) || c.x > max(a.x, b.x)) return false;
  if (c.y < min(a.y, b.y) || c.y > max(a.y, b.y)) return false;
  return true;
}
double polyUnion(Line lines[], int m) {
  int mm = m;
  for (int i = 0; i < mm; i++) tmp[i] = lines[i];
  sort(tmp, tmp + m);
  m = 0;
  for (int i = 0; i < mm; i++) {
    if (i == 0 || !(tmp[i] == tmp[i - 1])) {
      lines[m] = tmp[i];
      lines[m++].idx = i;
    }
  }
  double res = 0;
  for (int i = 0; i < m; i++) {
    int cnt = 0, cnt_c;
    for (int j = 0; j < n; j++) {
      bool same = false;
      cnt_c = 0;
      for (int k = 0; k < 4; k++) {
        if (lines[i] == Line(poly[j].p[k], poly[j].p[k + 1])) {
          same = true;
          break;
        }
        if (sgn(lines[i].k - Line(poly[j].p[k], poly[j].p[k + 1]).k) == 0)
          continue;
        Point t = intersection(lines[i].a, lines[i].b, poly[j].p[k],
                               poly[j].p[k + 1]);
        if (onSeg(poly[j].p[k], poly[j].p[k + 1], t)) cuts[cnt_c++] = t;
      }
      if (same) continue;
      sort(cuts, cuts + cnt_c);
      cnt_c = unique(cuts, cuts + cnt_c) - cuts;
      if (cnt_c == 2) {
        event[cnt++] = E(cuts[0].x, 0);
        event[cnt++] = E(cuts[1].x, 1);
      }
    }
    int j = lines[i].idx;
    while (j < mm && lines[i] == tmp[j]) {
      event[cnt++] = E(min(tmp[j].a.x, tmp[j].b.x), 2);
      event[cnt++] = E(max(tmp[j].a.x, tmp[j].b.x), 3);
      j++;
    }
    sort(event, event + cnt);
    int in = 0, cover = 0;
    double last = event[0].x;
    for (int j = 0; j < cnt; j++) {
      double y0 = lines[i].k * last + lines[i].l;
      double y1 = lines[i].k * event[j].x + lines[i].l;
      if (in == 0 && cover) res += (y0 + y1) * (event[j].x - last) * 0.5;
      last = event[j].x;
      int x = event[j].type;
      if (x == 0)
        in++;
      else if (x == 1)
        in--;
      else if (x == 2)
        cover++;
      else
        cover--;
    }
  }
  return res;
}
int main() {
  int i, j, k;
  while (scanf("%d", &n) != EOF) {
    double tot = 0;
    for (i = 0; i < n; i++) {
      poly[i].size = 4;
      for (j = 0; j < 4; j++) poly[i].p[j].read();
      poly[i].p[4] = poly[i].p[0];
      if (sgn(poly[i].area()) > 0) {
        reverse(poly[i].p, poly[i].p + 4);
        poly[i].p[4] = poly[i].p[0];
      }
      tot += fabs(poly[i].area());
    }
    int np = 0, nn = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < 4; j++) {
        k = sgn(poly[i].p[j].x - poly[i].p[j + 1].x);
        if (k < 0)
          positive[np++] = Line(poly[i].p[j], poly[i].p[j + 1]);
        else if (k > 0)
          negative[nn++] = Line(poly[i].p[j], poly[i].p[j + 1]);
      }
    }
    double ap = polyUnion(positive, np);
    double an = polyUnion(negative, nn);
    printf("%.11f\n", tot * 0.5 / (ap - an));
  }
  return 0;
}