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 INF = int(1e9) + 7;
const long double EPS = 1e-9;
const long double PI = acos(-1.0);
template <class first>
first sqr(first a) {
  return a * a;
}
template <class first>
first abs(first a) {
  return (a < 0) ? (-a) : (a);
}
inline pair<long double, long double> operator-(
    const pair<long double, long double>& a,
    const pair<long double, long double>& b) {
  return pair<long double, long double>(a.first - b.first, a.second - b.second);
}
inline long double dist(const pair<long double, long double>& a,
                        const pair<long double, long double>& b) {
  return sqrtl(sqr(a.first - b.first) + sqr(a.second - b.second));
}
inline long double det(const long double& a, const long double& b,
                       const long double& c, const long double& d) {
  return a * d - b * c;
}
inline bool mid(const pair<long double, long double>& a,
                const pair<long double, long double>& b,
                const pair<long double, long double>& c) {
  return min(a.first, b.first) <= c.first + EPS &&
         c.first <= max(a.first, b.first) &&
         min(a.second, b.second) <= c.second + EPS &&
         c.second <= max(a.second, b.second);
}
inline void makeLine(const pair<long double, long double>& a,
                     const pair<long double, long double>& b, long double& A,
                     long double& B, long double& C) {
  A = b.second - a.second;
  B = a.first - b.first;
  C = -A * a.first - B * a.second;
}
inline bool intersect(const pair<long double, long double>& a1,
                      const pair<long double, long double>& b1,
                      const long double& A2, const long double& B2,
                      const long double& C2,
                      pair<long double, long double>& res) {
  long double A1, B1, C1;
  makeLine(a1, b1, A1, B1, C1);
  long double dt = det(A1, B1, A2, B2);
  if (abs(dt) < EPS) return false;
  long double dx = det(C1, B1, C2, B2);
  long double dy = det(A1, C1, A2, C2);
  res = pair<long double, long double>(-dx / dt, -dy / dt);
  return mid(a1, b1, res);
}
inline bool cmpEps(const long double& a, const long double& b) {
  if (abs(a - b) < EPS) return false;
  return a < b;
}
inline bool eq(const pair<long double, long double>& a,
               const pair<long double, long double>& b) {
  return abs(a.first - b.first) < EPS && abs(a.second - b.second) < EPS;
}
inline int vmulS(const pair<long double, long double>& a,
                 const pair<long double, long double>& b) {
  long double res = a.first * b.second - a.second * b.first;
  if (abs(res) < EPS) return 0;
  return (res < 0) ? -1 : 1;
}
inline bool clockwise(const pair<long double, long double>& a,
                      const pair<long double, long double>& b,
                      const pair<long double, long double>& c) {
  return vmulS(b - a, c - b) <= 0;
}
int n;
pair<long double, long double> a[1000][4];
bool used[1000][4];
struct event {
  pair<long double, long double> p;
  int t, a;
  event(const pair<long double, long double>& cp =
            pair<long double, long double>(0, 0),
        int ct = 0, int ca = 0)
      : p(cp), t(ct), a(ca) {}
  bool operator<(const event& c) const {
    if (abs(p.first - c.p.first) > EPS) return p.first < c.p.first;
    if (abs(p.second - c.p.second) > EPS) return p.second < c.p.second;
    if (a != c.a) return a > c.a;
    return t < c.t;
  }
};
long double ta;
long double ua;
int main() {
  cin >> n;
  for (int i = 0; i < int(n); ++i) {
    for (int j = 0; j < int(4); ++j) {
      int x, y;
      scanf("%d %d", &x, &y);
      a[i][j] = pair<long double, long double>(x, y);
    }
    if (!clockwise(a[i][0], a[i][1], a[i][2])) reverse(a[i], a[i] + 4);
    long double s = 0;
    for (int j = 0; j < int(4); ++j) {
      int k = j + 1;
      if (k == 4) k = 0;
      s += (a[i][k].first - a[i][j].first) *
           (a[i][j].second + a[i][k].second + 30000);
    }
    if (s < 0) throw;
    ta += s;
  }
  ua = 0;
  for (int i = 0; i < int(n); ++i)
    for (int j1 = 0; j1 < int(4); ++j1) {
      if (used[i][j1]) continue;
      int j2 = j1 + 1;
      if (j2 == 4) j2 = 0;
      int cc = j1 + 2;
      if (cc >= 4) cc -= 4;
      long double A, B, C;
      makeLine(a[i][j1], a[i][j2], A, B, C);
      bool dir = a[i][j1] < a[i][j2];
      if (abs(B) < EPS) continue;
      vector<event> evs;
      for (int k = 0; k < int(n); ++k) {
        bool online = false;
        for (int q1 = 0; q1 < int(4); ++q1) {
          int q2 = q1 + 1;
          if (q2 == 4) q2 = 0;
          if (abs(A * a[k][q1].first + B * a[k][q1].second + C) < EPS &&
              abs(A * a[k][q2].first + B * a[k][q2].second + C) < EPS) {
            online = true;
            used[k][q1] = true;
            int type = (a[k][q1] < a[k][q2]) == dir;
            evs.push_back(event(min(a[k][q1], a[k][q2]), type, 1));
            evs.push_back(event(max(a[k][q1], a[k][q2]), type, -1));
            break;
          }
        }
        if (!online) {
          pair<long double, long double> st[5];
          int cnt = 0;
          for (int q1 = 0; q1 < int(4); ++q1) {
            int q2 = q1 + 1;
            if (q2 == 4) q2 = 0;
            pair<long double, long double> res;
            if (intersect(a[k][q1], a[k][q2], A, B, C, res)) {
              st[cnt++] = res;
            }
          }
          if (cnt > 0) {
            sort(st, st + cnt);
            cnt = unique(st, st + cnt, eq) - st;
            evs.push_back(event(st[0], 2, 1));
            evs.push_back(event(st[1], 2, -1));
          }
        }
      }
      sort((evs).begin(), (evs).end());
      int cnt[3], ocnt[3];
      int prev[3];
      memset(cnt, 0, sizeof(cnt));
      for (int i = 0; i < int(int((evs).size())); ++i) {
        memcpy(ocnt, cnt, sizeof(ocnt));
        cnt[evs[i].t] += evs[i].a;
        for (int j = 0; j < int(2); ++j) {
          if ((cnt[j] != 0 && cnt[1 - j] == 0 && cnt[2] == 0) &&
              !(ocnt[j] != 0 && ocnt[1 - j] == 0 && ocnt[2] == 0)) {
            prev[j] = i;
          }
          if ((ocnt[j] != 0 && ocnt[1 - j] == 0 && ocnt[2] == 0) &&
              !(cnt[j] != 0 && cnt[1 - j] == 0 && cnt[2] == 0)) {
            ua += ((evs[i].p.first - evs[prev[j]].p.first) *
                   (evs[i].p.second + evs[prev[j]].p.second + 30000)) *
                  ((j == dir) ? 1 : -1);
          }
        }
      }
    }
  cout.precision(10);
  cout << fixed << ta / ua << endl;
  return 0;
}