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-9;
const int maxn = 5000 + 2;
struct Point {
  double x, y;
  Point(double a = 0, double b = 0) : x(a), y(b) {}
};
Point operator-(Point a, Point b) { return Point(a.x - b.x, a.y - b.y); }
Point operator+(Point a, Point b) { return Point(a.x + b.x, a.y + b.y); }
Point operator*(Point a, double r) { return Point(a.x * r, a.y * r); }
Point operator/(Point a, double r) { return Point(a.x / r, a.y / r); }
int sig(double rt) { return (rt > eps) - (rt < -eps); };
double det(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 Rect {
  Point d[5];
  void read() {
    for (int i = 0; i < 4; i++) scanf("%lf%lf", &d[i].x, &d[i].y);
    d[4] = d[0];
  }
  Point operator[](const int &n) { return d[n]; }
} r[maxn];
int n;
pair<double, short> res[maxn];
double getLoc(Point a, Point b, Point p) {
  if (sig(b.x - a.x)) return (p.x - a.x) / (b.x - a.x);
  return (p.y - a.y) / (b.y - a.y);
}
double work() {
  double rt = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 4; j++) {
      int size = 0;
      res[size++] = pair<double, short>(0, 0);
      res[size++] = pair<double, short>(1, 0);
      for (int t = 0; t < n; t++) {
        if (t == i) continue;
        for (int g = 0; g < 4; g++) {
          int da = sig(det(r[i][j + 1] - r[i][j], r[t][g] - r[i][j]));
          int db = sig(det(r[i][j + 1] - r[i][j], r[t][g + 1] - r[i][j]));
          if (!da && !db) {
            if (sig(dot(r[i][j + 1] - r[i][j], r[t][g + 1] - r[t][g])) < 0 ||
                i < t) {
              res[size++] =
                  pair<double, short>(getLoc(r[i][j], r[i][j + 1], r[t][g]), 1);
              res[size++] = pair<double, short>(
                  getLoc(r[i][j], r[i][j + 1], r[t][g + 1]), -1);
            }
          } else {
            double s1 = det(r[i][j] - r[t][g], r[t][g + 1] - r[t][g]);
            double s2 = det(r[t][g + 1] - r[t][g], r[i][j + 1] - r[t][g]);
            if (da >= 0 && db < 0)
              res[size++] = pair<double, short>(s1 / (s1 + s2), 1);
            else if (da < 0 && db >= 0)
              res[size++] = pair<double, short>(s1 / (s1 + s2), -1);
          }
        }
      }
      sort(res, res + size);
      int cnt = 0;
      size--;
      double tmp = rt;
      for (int t = 0; t < size; t++) {
        cnt += res[t].second;
        if (cnt == 0 && sig(res[t].first - res[t + 1].first)) {
          double a = res[t].first;
          if (a < 0) a = 0;
          if (a > 1) break;
          double b = res[t + 1].first;
          if (b < 0) continue;
          if (b > 1) b = 1;
          rt += det((r[i][j + 1] - r[i][j]) * a + r[i][j],
                    (r[i][j + 1] - r[i][j]) * b + r[i][j]);
        }
      }
    }
  return rt / 2;
}
int main() {
  double cur = 0, rt = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cur = 0;
    r[i].read();
    for (int j = 0; j < 4; j++) cur += det(r[i].d[j], r[i].d[j + 1]);
    if (cur < 0) {
      swap(r[i].d[0], r[i].d[3]);
      swap(r[i].d[1], r[i].d[2]);
      r[i].d[4] = r[i].d[0];
      cur = -cur;
    }
    rt += cur / 2;
  }
  printf("%.10lf\n", rt / work());
  return 0;
}