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 double eps = 1e-8;
int dcmp(double x) { return (x > eps) - (x < -eps); }
struct point {
  double x, y;
  point() {}
  point(double x, double y) : x(x), y(y) {}
  point operator-(const point &b) const { return point(x - b.x, y - b.y); }
  void input() { scanf("%lf%lf", &x, &y); }
};
double cross(point a, point b) { return a.x * b.y - a.y * b.x; }
double dot(point a, point b) { return a.x * b.x + a.y * b.y; }
struct polygon {
  point p[5];
  int sz;
  void init() { p[sz] = p[0]; }
} g[505];
pair<double, int> c[100000];
double segP(point a, point b, point c) {
  if (dcmp(b.x - c.x)) return (a.x - b.x) / (c.x - b.x);
  return (a.y - b.y) / (c.y - b.y);
}
double polyUnion(int n) {
  double sum = 0;
  for (int i = 0; i < n; ++i)
    for (int ii = 0; ii < g[i].sz; ++ii) {
      int tot = 0;
      c[tot++] = make_pair(0, 0);
      c[tot++] = make_pair(1, 0);
      for (int j = 0; j < n; ++j)
        if (i != j)
          for (int jj = 0; jj < g[j].sz; ++jj) {
            int d1 = dcmp(
                cross(g[i].p[ii + 1] - g[i].p[ii], g[j].p[jj] - g[i].p[ii]));
            int d2 = dcmp(cross(g[i].p[ii + 1] - g[i].p[ii],
                                g[j].p[jj + 1] - g[i].p[ii]));
            if (!d1 && !d2) {
              point t1 = g[j].p[jj + 1] - g[j].p[jj];
              point t2 = g[i].p[ii + 1] - g[i].p[ii];
              if (dcmp(dot(t1, t2)) > 0 && j < i) {
                c[tot++] =
                    make_pair(segP(g[j].p[jj], g[i].p[ii], g[i].p[ii + 1]), 1);
                c[tot++] = make_pair(
                    segP(g[j].p[jj + 1], g[i].p[ii], g[i].p[ii + 1]), -1);
              }
            } else if (d1 >= 0 && d2 < 0 || d1 < 0 && d2 >= 0) {
              double tc =
                  cross(g[j].p[jj + 1] - g[j].p[jj], g[i].p[ii] - g[j].p[jj]);
              double td = cross(g[j].p[jj + 1] - g[j].p[jj],
                                g[i].p[ii + 1] - g[j].p[jj]);
              if (d2 < 0)
                c[tot++] = make_pair(tc / (tc - td), 1);
              else
                c[tot++] = make_pair(tc / (tc - td), -1);
            }
          }
      sort(c, c + tot);
      double cur = min(max(c[0].first, 0.0), 1.0);
      int sgn = c[0].second;
      double s = 0;
      for (int j = 1; j < tot; ++j) {
        double nxt = min(max(c[j].first, 0.0), 1.0);
        if (!sgn) s += nxt - cur;
        sgn += c[j].second;
        cur = nxt;
      }
      sum += cross(g[i].p[ii], g[i].p[ii + 1]) * s;
    }
  return sum / 2;
}
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    double sum = 0;
    for (int i = 0; i < n; ++i) {
      g[i].sz = 4;
      for (int j = 0; j < g[i].sz; ++j) g[i].p[j].input();
      g[i].init();
      double tmp = 0;
      for (int j = 1; j <= 4; ++j) tmp += cross(g[i].p[j - 1], g[i].p[j]);
      sum += fabs(tmp);
      if (tmp < 0) swap(g[i].p[1], g[i].p[3]);
    }
    printf("%.10lf\n", sum * 0.5 / polyUnion(n));
  }
  return 0;
}