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 ESP = 1e-6;
int dcmp(double d) { return (d > ESP) - (d < -ESP); }
double cross(complex<double> a, complex<double> b) {
  return a.real() * b.imag() - b.real() * a.imag();
}
double cross(complex<double> a, complex<double> b, complex<double> c) {
  return cross(b - a, c - a);
}
double dot(complex<double> a, complex<double> b) {
  return a.real() * b.real() + a.imag() * b.imag();
}
double dot(complex<double> a, complex<double> b, complex<double> c) {
  return dot(b - a, c - a);
}
double abs(pair<complex<double>, complex<double> > ln) {
  return abs(ln.second - ln.first);
}
complex<double> dir(pair<complex<double>, complex<double> > ln) {
  return ln.second - ln.first;
}
int n;
const int MAXN = 500;
complex<double> p[MAXN][5];
double tot1, tot2;
pair<double, int> c[MAXN * 4];
double area2(complex<double> *p) {
  double s = 0;
  for (int i = 0; i < 4; ++i) {
    s += cross(p[i], p[i + 1]);
  }
  return s;
}
void init() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int x1, y1, x2, y2, x3, y3, x4, y4;
    scanf("%d%d%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
    p[i][0] = p[i][4] = complex<double>(x1, y1);
    p[i][1] = complex<double>(x2, y2);
    p[i][2] = complex<double>(x3, y3);
    p[i][3] = complex<double>(x4, y4);
    double s = area2(p[i]);
    if (s < 0) swap(p[i][1], p[i][3]), s = -s;
    tot1 += s;
  }
}
double pos(complex<double> p, pair<complex<double>, complex<double> > ln) {
  return dcmp(ln.second.real() - ln.first.real())
             ? (p.real() - ln.first.real()) /
                   (ln.second.real() - ln.first.real())
             : (p.imag() - ln.first.imag()) /
                   (ln.second.imag() - ln.first.imag());
}
void solve() {
  for (int i = 0; i < n; ++i)
    for (int ii = 0; ii < 4; ++ii) {
      complex<double> A = p[i][ii], B = p[i][ii + 1];
      pair<complex<double>, complex<double> > AB =
          pair<complex<double>, complex<double> >(A, B);
      int m = 0;
      for (int j = 0; j < n; ++j)
        if (i != j)
          for (int jj = 0; jj < 4; ++jj) {
            complex<double> C = p[j][jj], D = p[j][jj + 1];
            pair<complex<double>, complex<double> > CD =
                pair<complex<double>, complex<double> >(C, D);
            int f1 = dcmp(cross(A, B, C));
            int f2 = dcmp(cross(A, B, D));
            if (!f1 && !f2) {
              if (i < j && dcmp(dot(dir(AB), dir(CD))) > 0) {
                c[m++] = make_pair(pos(C, AB), 1);
                c[m++] = make_pair(pos(D, AB), -1);
              }
            } else {
              double s1 = cross(C, D, A);
              double s2 = cross(C, D, B);
              double t = s1 / (s1 - s2);
              if (f1 >= 0 && f2 < 0) c[m++] = make_pair(t, 1);
              if (f1 < 0 && f2 >= 0) c[m++] = make_pair(t, -1);
            }
          }
      c[m++] = make_pair(0.0, 0);
      c[m++] = make_pair(1.0, 0);
      sort(c, c + m);
      double s = 0, z = min(max(c[0].first, 0.0), 1.0);
      for (int j = 1, k = c[0].second; j < m; ++j) {
        double w = min(max(c[j].first, 0.0), 1.0);
        if (!k) s += w - z;
        k += c[j].second;
        z = w;
      }
      tot2 += s * cross(A, B);
    }
}
int main() {
  init();
  solve();
  printf("%.10lf\n", tot1 / tot2);
}