Problem:
Problem E. Magic Triangles

Fallen angel Yohane plans to draw a magic symbol composed of triangles on the earth. By casting some magic spell on the symbol, she will obtain magic power; this is the purpose for which she will draw a magic symbol. The magic power yielded from the magic symbol is determined only by the common area of all the triangles. Suppose the earth is a two-dimensional plane and the vertices of the triangles are points on the plane. Yohane has already had a design of the magic symbol, i.e. the positions, sizes, shapes of the triangles. However, she does not know how much magic power will be obtained from the symbol. Your task as a familiar of the fallen angel is to write a program calculating the common area of given triangles on a two-dimensional plane.

Input

The input consists of a single test case in the following format.

$N$
$x_{1,1}$ $y_{1,1}$ $x_{1,2}$ $y_{1,2}$ $x_{1,3}$ $y_{1,3}$
$...$
$x_{N,1}$ $y_{N,1}$ $x_{N,2}$ $y_{N,2}$ $x_{N,3}$ $y_{N,3}$

The first line contains an integer $N$, which is the number of triangles ($1 \leq N \leq 10^5$). The $i$-th line of the following $N$ lines contains six integers $x_{i,1}$, $y_{i,1}$, $x_{i,2}$, $y_{i,2}$, $x_{i,3}$, and $y_{i,3}$, where ($x_{i,j}, y_{i,j}$)is the coordinate of the $j$-th vertex of the $i$-th triangle ($-1,000 \leq x_{i,j}, y_{i,j} \leq 1,000$).

You can assume the followings:

Every triangle has a positive area.

The vertices of every triangle are in the counter-clockwise order.

Output

Output the common area of given triangles in a line. The output can contain an absolute or relative error no more than $10^{-6}$.

Examples

Sample Input 1

2
0 0 2 0 0 2
0 1 2 1 0 3

Output for Sample Input 1

0.5

Sample Input 2

2
0 0 100 0 50 100
50 -50 100 50 0 50

Output for Sample Input 2

3125

Sample Input 3

5
0 0 1 0 0 1
0 0 2 0 0 2
0 0 3 0 0 3
0 0 4 0 0 4
0 0 5 0 0 5

Output for Sample Input 3

0.5

Solution in C++ (judge verdict: Time Limit Exceeded)

/*  -*- coding: utf-8 -*-
 *
 * 2908.cc: Magic Triangles
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

template <typename T>
struct Pt {
  T x, y;

  Pt() {}
  Pt(T _x, T _y) : x(_x), y(_y) {}
  Pt(const Pt& pt) : x(pt.x), y(pt.y) {}

  bool operator==(const Pt pt) const { return x == pt.x && y == pt.y; }
  Pt<T> operator+(const Pt pt) const { return Pt<T>(x + pt.x, y + pt.y); }
  Pt<T> operator-() const { return Pt<T>(-x, -y); }
  Pt<T> operator-(const Pt pt) const { return Pt<T>(x - pt.x, y - pt.y); }
  Pt<T> operator*(T t) const { return Pt<T>(x * t, y * t); }
  Pt<T> operator/(T t) const { return Pt<T>(x / t, y / t); }
  T dot(Pt v) const { return x * v.x + y * v.y; }
  T cross(Pt v) const { return x * v.y - y * v.x; }
  Pt<T> mid(const Pt pt) { return Pt<T>((x + pt.x) / 2, (y + pt.y) / 2); }
  T d2() { return x * x + y * y; }
  double d() { return sqrt(d2()); }

  void read() { scanf("%lf%lf", &x, &y); }
  
  void print(string format) {
    printf(("(" + format + ", " + format + ")\n").c_str(), x, y);
  }
  void print() { print("%.6lf"); }
};

typedef Pt<double> pt;

struct CL {
  pt p;
  double t0, t1;
  CL() {}
  CL(const pt& _p, double _t0, double _t1) : p(_p), t0(_t0), t1(_t1) {}
};

/* global variables */

int cpns[2];
pt cps[2][MAX_N * 3];

/* subroutines */

bool cross_lines(const pt& ap, const pt av, const pt& bp, const pt bv, CL& cl) {
  double op01 = av.cross(bv);
  //if (op01 == 0.0) return false; /* need to handle parallel?? */

  if (op01 == 0.0) {
    pt v = bp - ap;
    if (v.cross(av) != 0.0) return false;

    pt a1 = ap + av;
    pt b1 = bp + bv;

    return
      ((bp - ap).dot(b1 - ap) <= 0.0 ||
       (bp - a1).dot(b1 - a1) <= 0.0 ||
       (ap - bp).dot(a1 - bp) <= 0.0 ||
       (ap - b1).dot(a1 - b1) <= 0.0);
  }

  pt v = bp - ap;
  double op0 = v.cross(av);
  double op1 = v.cross(bv);

  double t0 = op1 / op01;
  double t1 = op0 / op01;

  cl.p = bv * t1 + bp;
  cl.t0 = t0;
  cl.t1 = t1;

  return true;
  //return (0.0 <= cl.t0 && cl.t0 <= 1.0 && 0.0 <= cl.t1 && cl.t1 <= 1.0);
}

int convex_cut(const int n, const pt scpol[], pt dcpol[],
	       const pt& p0, const pt& p1) {
  pt pv = p1 - p0;
  int dcn = 0;

  for (int i = 0; i < n; i++) {
    const pt& cp0 = scpol[i];
    double cr0 = pv.cross(cp0 - p0);
    if (cr0 >= 0.0) dcpol[dcn++] = cp0;
    
    const pt& cp1 = scpol[(i + 1) % n];
    double cr1 = pv.cross(cp1 - p0);
    if (cr0 * cr1 < 0.0) {
      CL cl;
      cross_lines(p0, pv, cp0, cp1 - cp0, cl);
      dcpol[dcn++] = cl.p;
    }
  }

  return dcn;
}

double calc_area(const int nc, const pt cpol[]) {
  if (nc < 3) return 0.0;

  double area = 0.0;
  for (int i = 0; i < nc; i++) {
    const pt &p0 = cpol[i], &p1 = cpol[(i + 1) % nc];
    area += p0.cross(p1);
  }

  return (area / 2);
}

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < 3; i++) cps[0][i].read();
  cpns[0] = 3;

  int cur = 0, nxt = 1;
  for (int i = 1; i < n; i++) {
    pt ps[3];
    for (int j = 0; j < 3; j++) ps[j].read();

    for (int j = 0; j < 3; j++) {
      cpns[nxt] =
	convex_cut(cpns[cur], cps[cur], cps[nxt], ps[j], ps[(j + 1) % 3]);
      cur ^= 1, nxt ^= 1;
    }
  }

  printf("%.8lf\n", calc_area(cpns[cur], cps[cur]));
  return 0;
}