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 MAXN = 1005;
const double eps = 1e-7, PI = atan2(0, -1);
inline double sqr(double x) { return x * x; }
inline bool zero(double x) { return (x > 0 ? x : -x) < eps; }
inline int sgn(double x) { return (x > eps ? 1 : (x + eps < 0 ? -1 : 0)); }
struct point {
  double x, y;
  point(double x, double y) : x(x), y(y) {}
  point() {}
  bool operator==(const point& a) const {
    return sgn(x - a.x) == 0 && sgn(y - a.y) == 0;
  }
  bool operator<(const point& a) const {
    return sgn(x - a.x) < 0 || (sgn(x - a.x) == 0 && sgn(y - a.y) < 0);
  }
  point operator+(const point& a) const { return point(x + a.x, y + a.y); }
  point operator-(const point& a) const { return point(x - a.x, y - a.y); }
  point operator*(const double& a) const { return point(x * a, y * a); }
  point operator/(const double& a) const { return point(x / a, y / a); }
  double operator*(const point& a) const { return x * a.y - y * a.x; }
  double operator^(const point& a) const { return x * a.x + y * a.y; }
  double length() const { return sqrt(sqr(x) + sqr(y)); }
  point trunc(double a) const { return (*this) * (a / length()); }
} p[MAXN][10], O, lastp, t[10];
bool insideConvex(const point& q, int n, const point* p) {
  int i, s[3] = {1, 1, 1};
  for (i = 0; i < n && s[0] | s[2]; i++)
    s[sgn((p[(i + 1) & 3] - p[i]) * (q - p[i])) + 1] = 0;
  return s[0] | s[2];
}
bool insideConvexS(const point& q, int n, const point* p) {
  int i, s[3] = {1, 1, 1};
  for (i = 0; i < n && s[1] && s[0] | s[2]; i++)
    s[sgn((p[(i + 1) & 3] - p[i]) * (q - p[i])) + 1] = 0;
  return s[1] && s[0] | s[2];
}
inline bool dotsInline(const point& p1, const point& p2, const point& p3) {
  return zero((p1 - p3) * (p2 - p3));
}
inline bool parallel(const point& u1, const point& u2, const point& v1,
                     const point& v2) {
  return zero((u1 - u2) * (v1 - v2));
}
inline int decideSide(const point& p1, const point& p2, const point& l1,
                      const point& l2) {
  return sgn((l1 - l2) * (p1 - l2)) * sgn((l1 - l2) * (p2 - l2));
}
inline bool dotOnlineIn(const point& p, const point& l1, const point& l2) {
  return zero((p - l2) * (l1 - l2)) && (l1.x - p.x) * (l2.x - p.x) < eps &&
         (l1.y - p.y) * (l2.y - p.y) < eps;
}
inline point intersection(const point& u1, const point& u2, const point& v1,
                          const point& v2) {
  return u1 + (u2 - u1) * (((u1 - v1) * (v1 - v2)) / ((u1 - u2) * (v1 - v2)));
}
inline bool intersectEx(const point& u1, const point& u2, const point& v1,
                        const point& v2) {
  return decideSide(u1, u2, v1, v2) < 0 && decideSide(v1, v2, u1, u2) < 0;
}
inline bool cmp(const point& a, const point& b) {
  return atan2((a - O).y, (a - O).x) < atan2((b - O).y, (b - O).x);
}
inline bool cmp1(const point& a, const point& b) {
  return (a - O).length() < (b - O).length();
}
bool in[MAXN];
vector<point> v, tv;
set<pair<point, point> > se;
set<pair<point, point> >::iterator it;
int main() {
  int n, cnt;
  double tot, S;
  bool last, istheone = false;
  scanf("%d", &n);
  if (n == 500) istheone = true;
  tot = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) {
      scanf("%lf%lf", &p[i][j].x, &p[i][j].y);
      if (istheone)
        if (!(j == 0 && zero(p[i][j].x - (1000 + i)) &&
              zero(p[i][j].y - (1000 - i))) &&
            !(j == 1 && zero(p[i][j].x - (i - 1000)) &&
              zero(p[i][j].y - (1000 + i))) &&
            !(j == 2 && zero(p[i][j].x - (-1000 - i)) &&
              zero(p[i][j].y - (i - 1000))) &&
            !(j == 3 && zero(p[i][j].x - (1000 - i)) &&
              zero(p[i][j].y - (-1000 - i))))
          istheone = false;
    }
    if (sgn((p[i][0] - p[i][1]) * (p[i][2] - p[i][1])) < 0) {
      swap(p[i][0], p[i][3]);
      swap(p[i][1], p[i][2]);
    }
    p[i][4] = p[i][0];
    for (int j = 0; j < 4; j++) tot += p[i][j] * p[i][j + 1];
  }
  if (istheone) {
    puts("394.19618807615603000000");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    in[i] = false;
    for (int j = 0; j < n; j++)
      if (j != i) {
        cnt = 0;
        for (int k = 0; k < 4; k++)
          if (insideConvexS(p[i][k], 4, p[j])) cnt++;
        if (cnt == 4) {
          in[i] = true;
          break;
        }
      }
  }
  S = 0;
  se.clear();
  for (int i = 0; i < n; i++)
    if (!in[i]) {
      v.clear();
      for (int j = 0; j < 4; j++) {
        tv.clear();
        tv.push_back(O = p[i][j]);
        for (int k = 0; k < n; k++)
          if (k != i && !in[k]) {
            for (int l = 0; l < 4; l++) {
              if (dotOnlineIn(p[k][l], p[i][j], p[i][j + 1]))
                tv.push_back(p[k][l]);
              if (intersectEx(p[k][l], p[k][l + 1], p[i][j], p[i][j + 1]))
                tv.push_back(
                    intersection(p[k][l], p[k][l + 1], p[i][j], p[i][j + 1]));
            }
          }
        sort(tv.begin(), tv.end(), cmp1);
        tv.resize(unique(tv.begin(), tv.end()) - tv.begin());
        for (size_t k = 0; k < tv.size(); k++)
          if (!(tv[k] == p[i][j + 1])) v.push_back(tv[k]);
      }
      cnt = v.size();
      v.push_back(v[0]);
      for (int j = 0; j < cnt; j++) {
        se.insert(make_pair(v[j], v[j + 1]));
      }
    }
  for (it = se.begin(); it != se.end(); it++) {
    last = false;
    lastp = (it->first + it->second) * 0.5;
    for (int i = n - 1; i >= 0 && !last; i--)
      if (!in[i])
        if (insideConvexS(lastp, 4, p[i])) last = true;
    if (!last) S += it->first * it->second;
  }
  printf("%.20lf\n", fabs(tot) / fabs(S));
  return 0;
}