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 N = 111;
const double eps = 1e-8;
const double pi = acos(-1.0);
inline double sqr(double x) { return x * x; }
inline int sgn(double x) { return fabs(x) < eps ? 0 : x > eps ? 1 : -1; }
struct point {
  double x, y;
  point(double _x = 0, double _y = 0) : x(_x), y(_y) {}
  void input(void) { scanf("%lf%lf", &x, &y); }
  void output(void) { printf("%f %f\n", x, y); }
  bool operator==(const point &p) const {
    return sgn(x - p.x) == 0 && sgn(y - p.y) == 0;
  }
  bool operator<(const point &p) const {
    return sgn(y - p.y) < 0 || (sgn(y - p.y) == 0 && sgn(x - p.x) < 0);
  }
  point operator+(const point &p) const { return point(x + p.x, y + p.y); }
  point operator-(const point &p) const { return point(x - p.x, y - p.y); }
  point operator*(double k) { return point(x * k, y * k); }
  point operator/(double k) { return point(x / k, y / k); }
  double operator*(const point &p) const { return x * p.x + y * p.y; }
  double operator^(const point &p) const { return x * p.y - y * p.x; }
  double norm(void) { return hypot(x, y); }
  double norm2(void) { return sqr(x) + sqr(y); }
  double dist(const point &p) const { return hypot(x - p.x, y - p.y); }
  double dist2(const point &p) const { return sqr(x - p.x) + sqr(y - p.y); }
};
struct line {
  point a, b;
  line() {}
  line(point _a, point _b) : a(_a), b(_b) {}
  point cross_point(line v) {
    double a1 = (v.b - v.a) ^ (a - v.a);
    double a2 = (v.b - v.a) ^ (b - v.a);
    return point((a.x * a2 - b.x * a1) / (a2 - a1),
                 (a.y * a2 - b.y * a1) / (a2 - a1));
  }
};
struct polygon {
  int n;
  point p[N];
  void input(void) {
    for (int i = 0; i < n; i++) p[i].input();
  }
  double get_area(void) {
    double sum = 0;
    for (int i = 0; i < n; i++) sum += p[i] ^ p[(i + 1) % n];
    return fabs(sum) / 2;
  }
  bool get_dir(void) {
    double sum = 0;
    for (int i = 0; i < n; i++) sum += p[i] ^ p[(i + 1) % n];
    return sgn(sum) > 0;
  }
};
struct polygons {
  vector<polygon> p;
  vector<pair<double, int> > e;
  polygons() { p.clear(); }
  void clear(void) { p.clear(); }
  void push(polygon q) {
    if (sgn(q.get_area())) p.push_back(q);
  }
  void ins(point st, point ed, point X, int i) {
    double r = fabs(ed.x - st.x) > eps ? (X.x - st.x) / (ed.x - st.x)
                                       : (X.y - st.y) / (ed.y - st.y);
    r = min(r, 1.0);
    r = max(r, 0.0);
    e.push_back(make_pair(r, i));
  }
  double polygon_area_union(void) {
    double res = 0.0;
    int c0, c1, c2, c3, dp, k, l;
    size_t i, j;
    for (i = 0; i < p.size(); i++)
      if (!p[i].get_dir()) reverse(p[i].p, p[i].p + p[i].n);
    for (i = 0; i < p.size(); i++)
      for (k = 0; k < p[i].n; k++) {
        point &s = p[i].p[k], &t = p[i].p[(k + 1) % p[i].n];
        if (!sgn(s ^ t)) continue;
        e.clear();
        e.push_back(make_pair(0.0, 1));
        e.push_back(make_pair(1.0, -1));
        for (j = 0; j < p.size(); j++)
          if (i != j)
            for (l = 0; l < p[j].n; l++) {
              point a = p[j].p[l], b = p[j].p[(l + 1) % p[j].n],
                    c = p[j].p[(l - 1 + p[j].n) % p[j].n];
              c0 = sgn((t - s) ^ (c - s));
              c1 = sgn((t - s) ^ (a - s));
              c2 = sgn((t - s) ^ (b - s));
              if (c1 * c2 < 0)
                ins(s, t, line(s, t).cross_point(line(a, b)), -c2);
              else if (!c1 && c0 * c2 < 0)
                ins(s, t, a, -c2);
              else if (!c1 && !c2) {
                c3 = sgn((t - s) ^ (p[j].p[(l + 2) % p[j].n] - s));
                dp = sgn((t - s) * (b - a));
                if (dp && c0)
                  ins(s, t, a, dp > 0 ? c0 * ((j > i) ^ (c0 < 0)) : -(c0 < 0));
                if (dp && c3)
                  ins(s, t, b, dp > 0 ? -c3 * ((j > i) ^ (c3 < 0)) : c3 < 0);
              }
            }
        sort(e.begin(), e.end());
        int ct = 0;
        double tot = 0.0, last;
        for (j = 0; j < e.size(); j++) {
          if (ct == 1) tot += e[j].first - last;
          ct += e[j].second;
          last = e[j].first;
        }
        res += (s ^ t) * tot;
      }
    return fabs(res) * 0.5;
  }
};
int main(void) {
  polygons P;
  polygon tp;
  tp.n = 4;
  int n;
  double res = 0;
  scanf("%d", &n);
  if (n == 1) {
    puts("1");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    tp.input();
    res += tp.get_area();
    P.push(tp);
  }
  printf("%f\n", res / P.polygon_area_union());
  return 0;
}