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 pt {
  double x, y;
  pt() {}
  pt(double _x, double _y) : x(_x), y(_y) {}
  pt operator-(const pt p1) { return pt(x - p1.x, y - p1.y); }
  void read() { scanf("%lf%lf", &x, &y); }
};
double cpr(const pt &a, const pt &b, const pt &c) {
  return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
}
double cpr(const pt &a, const pt &b) { return a.x * b.y - a.y * b.x; }
double dpr(const pt &a, const pt &b) { return a.x * b.x + a.y * b.y; }
pt its(const pt &a, const pt &b, const pt &c, const pt &d) {
  pt ret = a;
  double t = ((c.x - a.x) * (d.y - c.y) - (c.y - a.y) * (d.x - c.x)) /
             ((b.x - a.x) * (d.y - c.y) - (b.y - a.y) * (d.x - c.x));
  ret.x += (b.x - a.x) * t;
  ret.y += (b.y - a.y) * t;
  return ret;
}
const int maxn = 1000;
int n[maxn];
pt p[maxn][1010];
int m;
pair<double, int> e[1010];
int cnt;
inline void insert(pt &s, pt &t, pt X, int inc) {
  double ratio = ((t.x - s.x) > 1e-8 ? 1 : ((t.x - s.x) > -1e-8 ? 0 : -1))
                     ? (X.x - s.x) / (t.x - s.x)
                     : (X.y - s.y) / (t.y - s.y);
  if (ratio > 1.0) ratio = 1.0;
  if (ratio < 0.0) ratio = 0.0;
  e[cnt++] = make_pair(ratio, inc);
}
double solve() {
  double ans = 0.0;
  int cp0, cp1, cp2, cp3;
  for (int i = 0; i < m; i++) {
    for (int k = 0; k < n[i]; k++) {
      pt &s = p[i][k], &t = p[i][k == n[i] - 1 ? 0 : k + 1];
      if (fabs(cpr(s, t)) < 1e-8) continue;
      cnt = 0;
      e[cnt++] = make_pair(0.0, 1);
      e[cnt++] = make_pair(1.0, -1);
      for (int j = 0; j < m; j++)
        if (i != j) {
          for (int l = 0; l < n[j]; l++) {
            cp0 = ((cpr(s, t, p[j][l == 0 ? n[j] - 1 : l - 1])) > 1e-8
                       ? 1
                       : ((cpr(s, t, p[j][l == 0 ? n[j] - 1 : l - 1])) > -1e-8
                              ? 0
                              : -1));
            cp1 = ((cpr(s, t, p[j][l])) > 1e-8
                       ? 1
                       : ((cpr(s, t, p[j][l])) > -1e-8 ? 0 : -1));
            cp2 = ((cpr(s, t, p[j][l == n[j] - 1 ? 0 : l + 1])) > 1e-8
                       ? 1
                       : ((cpr(s, t, p[j][l == n[j] - 1 ? 0 : l + 1])) > -1e-8
                              ? 0
                              : -1));
            if (cp1 * cp2 < 0)
              insert(s, t, its(s, t, p[j][l], p[j][l == n[j] - 1 ? 0 : l + 1]),
                     -cp2);
            else if (!cp1 && cp0 * cp2 < 0)
              insert(s, t, p[j][l], -cp2);
            else if (!cp1 && !cp2) {
              cp3 =
                  ((cpr(s, t, p[j][(l + 2) % n[j]])) > 1e-8
                       ? 1
                       : ((cpr(s, t, p[j][(l + 2) % n[j]])) > -1e-8 ? 0 : -1));
              double dp = dpr(t - s, p[j][l == n[j] - 1 ? 0 : l + 1] - p[j][l]);
              if (dp > 1e-8) {
                if (((cp0) > 1e-8 ? 1 : ((cp0) > -1e-8 ? 0 : -1)))
                  insert(s, t, p[j][l], 1 * ((j > i) ^ (cp0 < 0)));
                if (((cp3) > 1e-8 ? 1 : ((cp3) > -1e-8 ? 0 : -1)))
                  insert(s, t, p[j][l == n[j] - 1 ? 0 : l + 1],
                         -1 * ((j > i) ^ (cp3 < 0)));
              } else if (dp < -1e-8) {
                if (((cp0) > 1e-8 ? 1 : ((cp0) > -1e-8 ? 0 : -1)))
                  insert(s, t, p[j][l], 1 * (cp0 > 0));
                if (((cp3) > 1e-8 ? 1 : ((cp3) > -1e-8 ? 0 : -1)))
                  insert(s, t, p[j][l == n[j] - 1 ? 0 : l + 1], -1 * (cp3 > 0));
              }
            }
          }
        }
      sort(e, e + cnt);
      int acc = 0;
      double total = 0.0, last;
      for (int j = 0; j < cnt; j++) {
        if (acc == 1) total += e[j].first - last;
        acc += e[j].second;
        last = e[j].first;
      }
      ans += cpr(s, t) * total;
    }
  }
  return fabs(ans) * 0.5;
}
double dis(pt p1, pt p2) {
  p1.x -= p2.x;
  p1.y -= p2.y;
  return p1.x * p1.x + p1.y * p1.y;
}
void pre(pt p[], int n) {
  double sum = 0;
  p[n] = p[0];
  for (int i = 0; i < n; i++) sum += p[i].x * p[i + 1].y - p[i + 1].x * p[i].y;
  pt tp[maxn];
  if (sum < 0) {
    for (int i = 0; i < n; i++) tp[i] = p[n - 1 - i];
    for (int i = 0; i < n; i++) p[i] = tp[i];
  }
}
int main() {
  while (scanf("%d", &m) != EOF) {
    for (int i = 0; i < m; i++) n[i] = 4;
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < 4; j++) p[i][j].read();
      pre(p[i], 4);
    }
    double ans = solve();
    double area = 0;
    for (int i = 0; i < m; i++) {
      double l1 = dis(p[i][0], p[i][1]);
      double l2 = dis(p[i][1], p[i][2]);
      double tmp = sqrt(l1 * l2);
      area += tmp;
    }
    double p = area / ans;
    printf("%.10lf\n", p);
  }
  return 0;
}