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;
int sgn(double x) {
  if (fabs(x) < eps) return 0;
  return x < 0 ? -1 : 1;
}
int n;
struct P {
  double x, y;
} p[501][5];
P operator-(P a, P b) { return (P){a.x - b.x, a.y - b.y}; }
double crs(P a, P b) { return a.x * b.y - a.y * b.x; }
double dot(P a, P b) { return a.x * b.x + a.y * b.y; }
pair<double, int> arr[3000];
double LEN(P a, P b, P c) {
  if (sgn(a.x - b.x)) return (c.x - b.x) / (a.x - b.x);
  return (c.y - b.y) / (a.y - b.y);
}
double PolyAreaUnion() {
  double ret = 0.;
  for (int i = 0; i < n; i++)
    for (int i_ = 0; i_ < 4; i_++) {
      int top = 0;
      arr[top++] = make_pair(0., 0);
      arr[top++] = make_pair(1., 0);
      for (int j = 0; j < n; j++)
        if (j != i)
          for (int j_ = 0; j_ < 4; j_++) {
            int cl = sgn(crs(p[i][i_ + 1] - p[i][i_], p[j][j_] - p[i][i_]));
            int cr = sgn(crs(p[i][i_ + 1] - p[i][i_], p[j][j_ + 1] - p[i][i_]));
            if (!cl && !cr &&
                dot(p[j][j_ + 1] - p[j][j_], p[i][i_ + 1] - p[i][i_]) >= eps &&
                j < i) {
              arr[top++] = make_pair(LEN(p[i][i_ + 1], p[i][i_], p[j][j_]), 1);
              arr[top++] =
                  make_pair(LEN(p[i][i_ + 1], p[i][i_], p[j][j_ + 1]), -1);
            } else if (cl >= 0 && cr < 0) {
              double tl = crs(p[j][j_ + 1] - p[j][j_], p[i][i_] - p[j][j_]);
              double tr = crs(p[j][j_ + 1] - p[j][j_], p[i][i_ + 1] - p[j][j_]);
              arr[top++] = make_pair(tl / (tl - tr), 1);
            } else if (cl < 0 && cr >= 0) {
              double tl = crs(p[j][j_ + 1] - p[j][j_], p[i][i_] - p[j][j_]);
              double tr = crs(p[j][j_ + 1] - p[j][j_], p[i][i_ + 1] - p[j][j_]);
              arr[top++] = make_pair(tl / (tl - tr), -1);
            }
          }
      sort(arr, arr + top);
      double pre = min(max(arr[0].first, 0.), 1.), now, num = 0.;
      int cnt = arr[0].second;
      for (int j = 1; j < top; j++) {
        now = min(max(arr[j].first, 0.), 1.);
        if (!cnt) num += now - pre;
        cnt += arr[j].second;
        pre = now;
      }
      ret += crs(p[i][i_], p[i][i_ + 1]) * num;
    }
  return ret;
}
double sum, tmp;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int i_ = 0; i_ < 4; i_++) scanf("%lf%lf", &p[i][i_].x, &p[i][i_].y);
    p[i][4] = p[i][0];
    tmp = 0.;
    for (int i_ = 0; i_ < 4; i_++) {
      tmp += crs(p[i][i_], p[i][i_ + 1]);
    }
    sum += fabs(tmp);
    if (sgn(tmp) < 0) swap(p[i][1], p[i][3]);
  }
  printf("%.10f\n", sum / PolyAreaUnion());
  return 0;
}