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>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
template <class T>
T abs(const T& a) {
  return a > 0 ? a : -a;
}
template <class T>
int sgn(const T& a) {
  return a > 0 ? 1 : (a < 0 ? -1 : 0);
}
const double PI = 2.0 * acos(1.0);
struct point {
  double x, y;
};
point operator-(point a, point b) {
  a.x -= b.x;
  a.y -= b.y;
  return a;
}
point operator+(point a, point b) {
  a.x += b.x;
  a.y += b.y;
  return a;
}
double operator*(point a, point b) { return a.x * b.x + a.y * b.y; }
double operator^(point a, point b) { return a.x * b.y - a.y * b.x; }
point operator*(point a, double b) {
  a.x *= b;
  a.y *= b;
  return a;
}
int n;
point p[500][4];
bool inside(point a, int k) {
  for (int i = 0; i < 4; i++) {
    point A = p[k][i];
    point B = p[k][(i + 1) % 4];
    if (abs((A - a) ^ (B - a)) < 1e-9) {
      return ((A - a) * (B - a) <= 0.0);
    }
    if (((A - a) ^ (B - a)) < 0.0) return false;
  }
  return true;
}
int main() {
  cin >> n;
  double S = 0.0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) cin >> p[i][j].x >> p[i][j].y;
    if (((p[i][1] - p[i][0]) ^ (p[i][3] - p[i][0])) < 0) {
      reverse(p[i], p[i] + 4);
    }
    S += (p[i][1] - p[i][0]) ^ (p[i][3] - p[i][0]);
  }
  double SS = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) {
      point A = p[i][j], B = p[i][(j + 1) % 4];
      vector<pair<double, int> > t;
      t.push_back(make_pair(1.0, -1.0));
      for (int k = 0; k < n; k++)
        if (k != i) {
          vector<pair<double, int> > q;
          bool onborder = false;
          for (int l = 0; l < 4; l++) {
            point C = p[k][l], D = p[k][(l + 1) % 4];
            if (abs((A - B) ^ (C - D)) < 1e-9) {
              if (abs((C - A) ^ (B - A)) > 1e-9) continue;
              if ((B - A) * (D - C) < 0) continue;
              onborder = true;
              if (i < k) continue;
              point v = (B - A);
              double ta = (A - A) * v;
              double tb = (B - A) * v;
              double tc = (C - A) * v;
              double td = (D - A) * v;
              double l = max(ta, tc);
              double r = min(tb, td);
              if (l >= r) continue;
              q.clear();
              q.push_back(make_pair(l / ((v) * (v)), 1));
              q.push_back(make_pair(r / ((v) * (v)), -1));
              break;
            }
            double t = ((C - A) ^ (D - C)) / ((B - A) ^ (D - C));
            double s = ((A - C) ^ (B - A)) / ((D - C) ^ (B - A));
            if (0 < t && t < 1 && 0 < s && s < 1) {
              point N = D - C;
              swap(N.x, N.y);
              N.x = -N.x;
              q.push_back(make_pair(t, sgn((B - A) * N)));
            }
          }
          if (q.size() == 1) {
            if (q[0].second < 0)
              q.push_back(make_pair(0, 1));
            else
              q.push_back(make_pair(1.0, -1));
          }
          if (q.size() == 0 && !onborder) {
            if (inside(A, k) && inside(B, k)) {
              q.push_back(make_pair(0.0, 1.0));
              q.push_back(make_pair(1.0, -1.0));
            }
          }
          if (q.size() > 2) {
            while (1)
              ;
          }
          while (q.size()) {
            t.push_back(q.back());
            q.pop_back();
          }
        }
      sort(t.begin(), t.end());
      point last = A;
      int c = 0;
      for (int k = 0; k < (int)t.size(); k++) {
        point cur = A + (B - A) * t[k].first;
        if (c <= 0) {
          SS += last ^ cur;
        }
        c += t[k].second;
        last = cur;
      }
    }
  }
  SS = abs(SS / 2.0);
  printf("%.10lf\n", S / SS);
  return 0;
}