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;
double fRand(double fMin, double fMax) {
  double f = (double)rand() / RAND_MAX;
  return fMin + f * (fMax - fMin);
}
template <class T>
T min(T a, T b, T c) {
  return min(a, min(b, c));
}
template <class T>
T max(T a, T b, T c) {
  return max(a, max(b, c));
}
const double PI = acos(-1.0);
const double EPS = 1e-9;
struct pt {
  double x, y;
  pt operator+(pt p) { return {x + p.x, y + p.y}; }
  pt operator-(pt p) { return {x - p.x, y - p.y}; }
  pt operator*(double k) { return {x * k, y * k}; }
  pt operator/(double k) { return {x / k, y / k}; }
  double operator*(pt p) { return x * p.y - y * p.x; }
  double operator%(pt p) { return x * p.x + y * p.y; }
  friend istream &operator>>(istream &is, pt &p) {
    is >> p.x >> p.y;
    return is;
  }
  friend ostream &operator<<(ostream &os, pt &p) {
    os << "(" << p.x << ", " << p.y << ")";
    return os;
  }
};
int sign(double x) { return (x > EPS) - (x < -EPS); }
struct line {
  pt v;
  double c;
  line(pt p, pt q) : v(q - p), c(v * p) {}
  double side(pt p) { return v * p - c; }
  bool contain(pt p) { return sign(side(p)) == 0; }
};
double area(pt po[], int n) {
  double res = 0;
  for (int i = (0); i <= (n - 1); ++i) res += po[i] * po[(i + 1) % n];
  return abs(res) / 2;
}
const int MAXN = 505;
int n;
pt rect[MAXN][4];
enum MarkerType {
  AREA_ABOVE_START,
  AREA_ABOVE_END,
  AREA_BELOW_START,
  AREA_BELOW_END
};
pt inter(line l1, line l2) {
  return (l2.v * l1.c - l1.v * l2.c) / (l1.v * l2.v);
}
vector<pt> inter(pt po[], int n, line l) {
  vector<pt> res;
  for (int i = (0); i <= (n - 1); ++i) {
    pt a = po[i], b = po[(i + 1) % n];
    if (l.contain(a))
      res.push_back(a);
    else if (sign(l.side(a)) * sign(l.side(b)) < 0)
      res.push_back(inter(l, line(a, b)));
  }
  return res;
}
struct Marker {
  pt p;
  MarkerType type;
  bool operator<(const Marker &rhs) const { return p.x < rhs.p.x; }
};
double trapezoidArea(pt p, pt q) { return (q.x - p.x) * (p.y + q.y) / 2; }
double solve(line l) {
  vector<Marker> mark;
  for (int i = (0); i <= (n - 1); ++i) {
    bool onBorder = false;
    for (int j = (0); j <= (3); ++j) {
      pt a = rect[i][j], b = rect[i][(j + 1) % 4];
      if (a.x > b.x) swap(a, b);
      if (l.contain(a) && l.contain(b)) {
        onBorder = true;
        if (sign(l.side(rect[i][(j + 2) % 4])) > 0) {
          mark.push_back({a, AREA_ABOVE_START});
          mark.push_back({b, AREA_ABOVE_END});
        } else {
          mark.push_back({a, AREA_BELOW_START});
          mark.push_back({b, AREA_BELOW_END});
        }
      }
    }
    if (onBorder) continue;
    vector<pt> p = inter(rect[i], 4, l);
    if ((int)p.size() > 1) {
      if (p[0].x > p[1].x) swap(p[0], p[1]);
      mark.push_back({p[0], AREA_ABOVE_START});
      mark.push_back({p[0], AREA_BELOW_START});
      mark.push_back({p[1], AREA_ABOVE_END});
      mark.push_back({p[1], AREA_BELOW_END});
    }
  }
  sort(mark.begin(), mark.end());
  double ans = 0;
  int j = 0, cntAbove = 0, cntBelow = 0;
  for (int i = (1); i <= ((int)mark.size() - 1); ++i) {
    while (j < (int)mark.size() && mark[j].p.x < mark[i].p.x) {
      switch (mark[j].type) {
        case AREA_ABOVE_START:
          ++cntAbove;
          break;
        case AREA_ABOVE_END:
          --cntAbove;
          break;
        case AREA_BELOW_START:
          ++cntBelow;
          break;
        case AREA_BELOW_END:
          --cntBelow;
          break;
      }
      ++j;
    }
    int sgn = (cntBelow > 0) - (cntAbove > 0);
    ans += trapezoidArea(mark[i - 1].p, mark[i].p) * sgn;
  }
  return ans;
}
int main() {
  cin >> n;
  for (int i = (0); i <= (n - 1); ++i)
    for (int j = (0); j <= (3); ++j) cin >> rect[i][j];
  vector<pair<pt, pt> > done;
  double unionArea = 0;
  for (int i = (0); i <= (n - 1); ++i) {
    for (int j = (0); j <= (3); ++j) {
      pt s = rect[i][j], t = rect[i][(j + 1) % 4];
      if (s.x == t.x) continue;
      if (s.x > t.x) swap(s, t);
      line l(s, t);
      bool solved = false;
      for (auto p : done) {
        if (l.contain(p.first) && l.contain(p.second)) {
          solved = true;
          break;
        }
      }
      if (solved) continue;
      unionArea += solve(l);
      done.push_back(make_pair(s, t));
    }
  }
  double totalArea = 0;
  for (int i = (0); i <= (n - 1); ++i) totalArea += area(rect[i], 4);
  double ans = totalArea / unionArea;
  cout << setprecision(50) << ans;
  return 0;
}