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;
struct point {
  double x, y;
  point() {}
  point(double x1, double y1) {
    x = x1;
    y = y1;
  }
  inline double operator%(const point &a) const { return x * a.y - y * a.x; }
  inline double operator*(const point &a) const { return x * a.x + y * a.y; }
  inline point operator+(const point &a) const {
    return point(x + a.x, y + a.y);
  }
  inline point operator-(const point &a) const {
    return point(x - a.x, y - a.y);
  }
  inline point operator*(double k) const { return point(x * k, y * k); }
  inline point operator/(double k) const { return point(x / k, y / k); }
  inline double dis() { return sqrt(x * x + y * y); }
};
double ans, sum;
int n, m, r;
struct PT {
  point v[6];
  point &operator[](const int i) { return v[i]; }
} a[508];
struct arr {
  double x;
  int y;
  arr() {}
  arr(double x1, int y1) {
    x = x1;
    y = y1;
  }
  inline bool operator<(const arr &i) const { return x < i.x; }
} c[2008];
inline double Area(PT &a) {
  double sum = 0;
  for (int i = 1; i <= m; i++) sum += a[i] % a[i + 1];
  return sum;
}
inline void Init() {
  scanf("%d", &n);
  m = 4;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) scanf("%lf%lf", &a[i][j].x, &a[i][j].y);
    a[i][5] = a[i][1];
    double s = Area(a[i]);
    if (s < 0) {
      swap(a[i][2], a[i][4]);
      s = -s;
    }
    sum += s;
  }
}
inline double Cross(point &a, point &b, point &c) { return (b - a) % (c - a); }
inline int Sg(double x) {
  if (fabs(x) < 1e-6) return 0;
  return x > 0 ? 1 : -1;
}
inline double Seg(point &a, point &b, point &c) {
  double t;
  if (fabs(a.x - b.x) > 1e-6)
    t = (c.x - a.x) / (b.x - a.x);
  else
    t = (c.y - a.y) / (b.y - a.y);
  t = ((t < 1.0 ? t : 1.0) > 0.0 ? (t < 1.0 ? t : 1.0) : 0.0);
  return t;
}
inline void Work() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      r = 0;
      for (int k = 1; k <= n; k++)
        if (k != i)
          for (int l = 1; l <= m; l++) {
            int t1 = Sg(Cross(a[i][j], a[i][j + 1], a[k][l]));
            int t2 = Sg(Cross(a[i][j], a[i][j + 1], a[k][l + 1]));
            if (t1 == 0 && t2 == 0) {
              if (k < i &&
                  (a[k][l + 1] - a[k][l]) * (a[i][j + 1] - a[i][j]) >= 0) {
                double d1 = Seg(a[i][j], a[i][j + 1], a[k][l]);
                double d2 = Seg(a[i][j], a[i][j + 1], a[k][l + 1]);
                c[++r] = arr(d1, 1);
                c[++r] = arr(d2, -1);
              }
            } else if (t1 >= 0 && t2 < 0 || t1 < 0 && t2 >= 0) {
              double d1 = Cross(a[k][l], a[k][l + 1], a[i][j]);
              double d2 = Cross(a[k][l], a[k][l + 1], a[i][j + 1]);
              int t = 1;
              if (t2 >= 0) t = -1;
              c[++r] = arr(((d1 / (d1 - d2) < 1.0 ? d1 / (d1 - d2) : 1.0) > 0.0
                                ? (d1 / (d1 - d2) < 1.0 ? d1 / (d1 - d2) : 1.0)
                                : 0.0),
                           t);
            }
          }
      sort(c + 1, c + r + 1);
      int cnt = 0;
      double s = 0, tmp = 0;
      bool f = 1;
      for (int i = 1; i <= r; i++) {
        cnt += c[i].y;
        if (!cnt && !f) tmp = c[i].x, f = 1;
        if (cnt && f) s += c[i].x - tmp, f = 0;
      }
      s += 1.0 - tmp;
      ans += (a[i][j] % a[i][j + 1]) * s;
    }
  printf("%.9lf\n", sum / ans);
}
int main() {
  Init();
  Work();
  return 0;
}