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 MAX_N = 505;
const int MAX_S = 10;
inline int sgn(double a) { return a > EPS ? 1 : (a < -EPS ? -1 : 0); }
struct Point {
  double x, y;
  Point() { x = y = 0; }
  Point(double _x, double _y) : x(_x), y(_y) {}
  Point operator+(const Point &a) const { return Point(x + a.x, y + a.y); }
  Point operator-(const Point &a) const { return Point(x - a.x, y - a.y); }
  Point operator*(const double &k) const { return Point(x * k, y * k); }
  Point operator/(const double &k) const { return Point(x / k, y / k); }
  Point &operator=(const Point &a) {
    x = a.x, y = a.y;
    return *this;
  }
  bool operator<(const Point &a) const {
    return sgn(x - a.x) < 0 || (!sgn(x - a.x) && sgn(y - a.y) < 0);
  }
  bool operator==(const Point &a) const {
    return !sgn(x - a.x) && !sgn(y - a.y);
  }
  bool operator!=(const Point &a) const { return sgn(x - a.x) || sgn(y - a.y); }
  Point normal() const { return Point(-y, x); }
  void read() { scanf("%lf %lf", &x, &y); }
  void print() { printf("%.6f %.6f\n", x, y); }
};
inline double dot(const Point &a, const Point &b, const Point &c) {
  return (b.x - a.x) * (c.x - a.x) + (b.y - a.y) * (c.y - a.y);
}
inline double det(const Point &a, const Point &b, const Point &c) {
  return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
}
inline double dot(const Point &a, const Point &b) {
  return a.x * b.x + a.y * b.y;
}
inline double det(const Point &a, const Point &b) {
  return a.x * b.y - a.y * b.x;
}
int n;
Point poly[MAX_N][MAX_S];
int size[MAX_N];
pair<double, int> event[MAX_N * 8];
inline double getProp(const Point &a, const Point &b, const Point &c) {
  if (sgn(a.x - b.x) == 0) {
    return (c.y - a.y) / (b.y - a.y);
  }
  return (c.x - a.x) / (b.x - a.x);
}
double polygonUnion(Point poly[MAX_N][MAX_S], int n) {
  double ret = 0;
  for (int i = 0; i < n; i++) {
    for (int x = 0; x < size[i]; x++) {
      int cntEvent = 0;
      event[cntEvent++] = make_pair(0.0, 0);
      event[cntEvent++] = make_pair(1.0, 0);
      for (int j = 0; j < n; j++) {
        if (j != i) {
          for (int y = 0; y < size[j]; y++) {
            int tag1 = sgn(det(poly[i][x], poly[i][x + 1], poly[j][y]));
            int tag2 = sgn(det(poly[i][x], poly[i][x + 1], poly[j][y + 1]));
            if (!tag1 && !tag2) {
              if (sgn(dot(poly[i][x + 1] - poly[i][x],
                          poly[j][y + 1] - poly[j][y])) > 0 &&
                  j < i) {
                event[cntEvent++] = make_pair(
                    getProp(poly[i][x], poly[i][x + 1], poly[j][y]), 1);
                event[cntEvent++] = make_pair(
                    getProp(poly[i][x], poly[i][x + 1], poly[j][y + 1]), -1);
              }
            }
            if (tag1 >= 0 && tag2 < 0) {
              double area1 = det(poly[j][y], poly[j][y + 1], poly[i][x]);
              double area2 = det(poly[j][y], poly[j][y + 1], poly[i][x + 1]);
              event[cntEvent++] = make_pair(area1 / (area1 - area2), 1);
            }
            if (tag1 < 0 && tag2 >= 0) {
              double area1 = det(poly[j][y], poly[j][y + 1], poly[i][x]);
              double area2 = det(poly[j][y], poly[j][y + 1], poly[i][x + 1]);
              event[cntEvent++] = make_pair(area1 / (area1 - area2), -1);
            }
          }
        }
      }
      sort(event, event + cntEvent);
      double last = min(max(0.0, event[0].first), 1.0);
      int cnt = event[0].second;
      double sum = 0;
      for (int j = 1; j < cntEvent; j++) {
        double cur = min(max(0.0, event[j].first), 1.0);
        if (!cnt) {
          sum += cur - last;
        }
        cnt += event[j].second;
        last = cur;
      }
      ret += det(poly[i][x], poly[i][x + 1]) * sum;
    }
  }
  return 0.5 * ret;
}
int main() {
  scanf("%d", &n);
  double areaSum = 0;
  double areaUnion = 0;
  for (int i = 0; i < n; i++) {
    size[i] = 4;
    for (int j = 0; j < 4; j++) {
      poly[i][j].read();
    }
    poly[i][4] = poly[i][0];
    double area = 0;
    for (int j = 0; j < 4; j++) {
      area += 0.5 * det(poly[i][j], poly[i][j + 1]);
    }
    if (sgn(area) < 0) {
      swap(poly[i][0], poly[i][3]);
      swap(poly[i][1], poly[i][2]);
    }
    poly[i][4] = poly[i][0];
    areaSum += fabs(area);
  }
  areaUnion = polygonUnion(poly, n);
  printf("%.10f\n", areaSum / areaUnion);
  return 0;
}