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

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#include <iostream>
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {return os<<'(' <<p.first<<", "<<p.second<<')';}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {os<<'[';for(auto it=v.begin();it!=v.end();++it){os<<*it; if(next(it)!=v.end()){os<<", ";}}return os<<']';}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& vv) {os<<"[\n";for(auto it=vv.begin();it!=vv.end();++it){os<<"  "<<*it;if(next(it)!=vv.end()){os<<",\n";}else{os<<"\n";}}return os<<"]";}
#define dump(x) cerr << #x << " = " << (x) << '\n'
#else
#define dump(x) (void)0
#endif
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
template<class T> using pq = priority_queue<T>;
template<class T> using pq_g = priority_queue<T, vector<T>, greater<T>>;
#define out(x) cout<<x<<'\n'
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define OVERLOAD_REP(_1,_2,_3,name,...) name
#define REP1(i,n) for (auto i = std::decay_t<decltype(n)>{}; (i) < (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) < (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
template<class T> inline bool chmin(T& a, T b) {if(a > b){a = b; return true;} else {return false;}};
template<class T> inline bool chmax(T& a, T b) {if(a < b){a = b; return true;} else {return false;}};
const ll INF=(1LL<<60);
const ll mod=998244353;
using Graph = vector<vector<ll>>;
using Network = vector<vector<pair<ll,ll>>>;
using Grid = vector<string>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dx2[8] = {1, 1,  1, 0,  0, -1, -1, -1};
const int dy2[8] = {1, 0, -1, 1, -1,  1,  0, -1};

// #include "../geo.hpp"

using D = long double;
const D EPS = 1e-12L;
using P2 = complex<D>;
struct L2{P2 a, b;};
using G2 = vector<P2>;

int sgn(D x) {return (x>EPS)-(x<-EPS);}
int cmp(D a, D b){return sgn(a-b);}
int eq(D a, D b){return cmp(a, b) == 0;}
int ge(D a, D b){return cmp(a, b) >= 0;}
int lt(D a, D b){return cmp(a, b) < 0;}
D dot(P2 a, P2 b) {return real(conj(a)*b);}
D cross(P2 a, P2 b) {return imag(conj(a)*b);}
int turn(P2 a, P2 b, P2 c) {return sgn(cross(b-a,c-a));}
inline void rd(P2& p){D x, y;cin>>x>>y;p=P2(x, y);}
#define setp(n) cout<<setprecision(n)<<fixed
bool ltP2Arg(P2 a, P2 b) {
    auto up = [](P2 p) { return (imag(p) > 0 || (eq(imag(p), 0) && ge(real(p), 0))); };
    if (up(a) != up(b)) return up(a);
    if (!eq(cross(a, b), 0)) return cross(a, b) > 0;
    return lt(norm(a), norm(b));
}

D area(G2 g) {
    D s=0;
    int n=g.size();
    rep(i, n) s+=cross(g[i],g[(i+1)%n]);
    return s/2.0L;
}

P2 cpLL(L2 l, L2 m) {
    P2 a=l.b-l.a,b=m.b-m.a;
    D d=cross(a, b);
    if(eq(d, 0)) return P2(INF, INF);
    return l.a + a*cross(m.b-l.a, b)/d;
}
struct HP{
    L2 l;
    HP(){} HP(L2 _l):l(_l){}
    bool inside(P2 p){return turn(l.a, l.b, p)>=0;}
};
inline P2 dir(const HP& h){ return h.l.b - h.l.a; }
inline bool ltHPArg(const HP& a, const HP& b){
  return ltP2Arg(dir(a),dir(b));
}
vector<HP> normalizeHP(vector<HP> v) {
    sort(all(v), ltHPArg);
    vector<HP> u;u.reserve(v.size());
    for(auto &h:v) {
        if(!u.empty()&&eq(cross(dir(u.back()),dir(h)),0)){
            if(h.inside(u.back().l.a)) continue;
            u.back()=h;
        } else u.push_back(h);
    }
    return u;
}
G2 hpi(vector<HP> H) {
    H = normalizeHP(move(H));
    deque<HP> dq;
    deque<P2> I;
    auto push_hp=[&] (HP h) {
        while(!I.empty()&&!h.inside(I.back())){dq.pop_back();I.pop_back();}
        while(!I.empty()&&!h.inside(I.front())){dq.pop_front();I.pop_front();}
        if(!dq.empty()&&eq(cross(dir(dq.back()),dir(h)),0)) {
            if(h.inside(dq.back().l.a)) dq.back()=h;
            return;
        }
        if(!dq.empty()) I.push_back(cpLL(dq.back().l,h.l));
        dq.push_back(h);
    };
    for(auto h:H) push_hp(h);
    while(!I.empty()&&!dq.front().inside(I.back())){dq.pop_back();I.pop_back();}
    while(!I.empty()&&!dq.back().inside(I.front())){dq.pop_front();I.pop_front();}
    if(dq.size()<3) return{};
    G2 res;res.reserve(dq.size());
    rep(i, dq.size()) {
        res.push_back(cpLL(dq[i].l, dq[(i+1)%dq.size()].l));
    }
    return res;
}

void solve() {
    ll n;cin>>n;
    vector<HP> hps;
    rep(i, n) {
        vector<P2> ps(3);
        rep(j, 3) rd(ps[j]);
        rep(j, 3) hps.push_back(L2{ps[j], ps[(j+1)%3]});
    }
    setp(15);
    out(area(hpi(hps)));
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int t = 1;
    while (t--) {
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 320
memory_kb: 61188
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#include <iostream>
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {return os<<'(' <<p.first<<", "<<p.second<<')';}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {os<<'[';for(auto it=v.begin();it!=v.end();++it){os<<*it; if(next(it)!=v.end()){os<<", ";}}return os<<']';}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& vv) {os<<"[\n";for(auto it=vv.begin();it!=vv.end();++it){os<<"  "<<*it;if(next(it)!=vv.end()){os<<",\n";}else{os<<"\n";}}return os<<"]";}
#define dump(x) cerr << #x << " = " << (x) << '\n'
#else
#define dump(x) (void)0
#endif
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
template<class T> using pq = priority_queue<T>;
template<class T> using pq_g = priority_queue<T, vector<T>, greater<T>>;
#define out(x) cout<<x<<'\n'
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define OVERLOAD_REP(_1,_2,_3,name,...) name
#define REP1(i,n) for (auto i = std::decay_t<decltype(n)>{}; (i) < (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) < (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
template<class T> inline bool chmin(T& a, T b) {if(a > b){a = b; return true;} else {return false;}};
template<class T> inline bool chmax(T& a, T b) {if(a < b){a = b; return true;} else {return false;}};
const ll INF=(1LL<<60);
const ll mod=998244353;
using Graph = vector<vector<ll>>;
using Network = vector<vector<pair<ll,ll>>>;
using Grid = vector<string>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dx2[8] = {1, 1,  1, 0,  0, -1, -1, -1};
const int dy2[8] = {1, 0, -1, 1, -1,  1,  0, -1};

// #include "../geo.hpp"

using D = long double;
const D EPS = 1e-12L;
using P2 = complex<D>;
struct L2{P2 a, b;};
using G2 = vector<P2>;

int sgn(D x) {return (x>EPS)-(x<-EPS);}
int cmp(D a, D b){return sgn(a-b);}
int eq(D a, D b){return cmp(a, b) == 0;}
D dot(P2 a, P2 b) {return real(conj(a)*b);}
D cross(P2 a, P2 b) {return imag(conj(a)*b);}
int turn(P2 a, P2 b, P2 c) {return sgn(cross(b-a,c-a));}
inline void rd(P2& p){D x, y;cin>>x>>y;p=P2(x, y);}
#define setp(n) cout<<setprecision(n)<<fixed

D area(G2 g) {
    D s=0;
    int n=g.size();
    rep(i, n) s+=cross(g[i],g[(i+1)%n]);
    return s/2.0L;
}

P2 cpLL(L2 l, L2 m) {
    P2 a=l.b-l.a,b=m.b-m.a;
    D d=cross(a, b);
    if(eq(d, 0)) return P2(INF, INF);
    return l.a + a*cross(m.b-l.a, b)/d;
}
struct HP{
    L2 l;
    HP(){} HP(L2 _l):l(_l){}
    bool inside(P2 p){return turn(l.a, l.b, p)>=0;}
};
P2 dir(HP h) {return h.l.b-h.l.a;}
int half(P2 v) {
    if (v.imag()>0)return 0;
    if(eq(v.imag(), 0) && v.real()>=0) return 0;
    return 1;
}
bool angLessHP(HP a, HP b) {
    P2 u=dir(a), v=dir(b);
    int ha=half(u), hb=half(v);
    if(ha!=hb) return ha<hb;
    D cr=cross(u,v);
    if(!eq(cr,0)) return cr>0;
    return false;
}
vector<HP> normalizeHP(vector<HP> v) {
    sort(all(v), angLessHP);
    vector<HP> u;u.reserve(v.size());
    for(auto &h:v) {
        if(!u.empty()&&eq(cross(dir(u.back()),dir(h)),0)){
            if(h.inside(u.back().l.a)) continue;
            u.back()=h;
        } else u.push_back(h);
    }
    return u;
}
G2 hpi(vector<HP> H) {
    H = normalizeHP(move(H));
    deque<HP> dq;
    deque<P2> I;
    auto push_hp=[&] (HP h) {
        while(!I.empty()&&!h.inside(I.back())){dq.pop_back();I.pop_back();}
        while(!I.empty()&&!h.inside(I.front())){dq.pop_front();I.pop_front();}
        if(!dq.empty()&&eq(cross(dir(dq.back()),dir(h)),0)) {
            if(h.inside(dq.back().l.a)) dq.back()=h;
            return;
        }
        if(!dq.empty()) I.push_back(cpLL(dq.back().l,h.l));
        dq.push_back(h);
    };
    for(auto h:H) push_hp(h);
    while(!I.empty()&&!dq.front().inside(I.back())){dq.pop_back();I.pop_back();}
    while(!I.empty()&&!dq.back().inside(I.front())){dq.pop_front();I.pop_front();}
    if(dq.size()<3) return{};
    G2 res;res.reserve(dq.size());
    rep(i, dq.size()) {
        res.push_back(cpLL(dq[i].l, dq[(i+1)%dq.size()].l));
    }
    return res;
}

void solve() {
    ll n;cin>>n;
    vector<HP> hps;
    rep(i, n) {
        vector<P2> ps(3);
        rep(j, 3) rd(ps[j]);
        rep(j, 3) hps.push_back(L2{ps[j], ps[(j+1)%3]});
    }
    setp(15);
    out(area(hpi(hps)));
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int t = 1;
    while (t--) {
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 290
memory_kb: 60772
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#include <iostream>
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {return os<<'(' <<p.first<<", "<<p.second<<')';}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {os<<'[';for(auto it=v.begin();it!=v.end();++it){os<<*it; if(next(it)!=v.end()){os<<", ";}}return os<<']';}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& vv) {os<<"[\n";for(auto it=vv.begin();it!=vv.end();++it){os<<"  "<<*it;if(next(it)!=vv.end()){os<<",\n";}else{os<<"\n";}}return os<<"]";}
#define dump(x) cerr << #x << " = " << (x) << '\n'
#else
#define dump(x) (void)0
#endif
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
template<class T> using pq = priority_queue<T>;
template<class T> using pq_g = priority_queue<T, vector<T>, greater<T>>;
#define out(x) cout<<x<<'\n'
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define OVERLOAD_REP(_1,_2,_3,name,...) name
#define REP1(i,n) for (auto i = std::decay_t<decltype(n)>{}; (i) < (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) < (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
template<class T> inline bool chmin(T& a, T b) {if(a > b){a = b; return true;} else {return false;}};
template<class T> inline bool chmax(T& a, T b) {if(a < b){a = b; return true;} else {return false;}};
const ll INF=(1LL<<60);
const ll mod=998244353;
using Graph = vector<vector<ll>>;
using Network = vector<vector<pair<ll,ll>>>;
using Grid = vector<string>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dx2[8] = {1, 1,  1, 0,  0, -1, -1, -1};
const int dy2[8] = {1, 0, -1, 1, -1,  1,  0, -1};

// #include "../geo.hpp"

using D = long double;
const D EPS = 1e-12L;
using P2 = complex<D>;
struct L2{P2 a, b;};
using G2 = vector<P2>;

int sgn(D x) {return (x>EPS)-(x<-EPS);}
int cmp(D a, D b){return sgn(a-b);}
int eq(D a, D b){return cmp(a, b) == 0;}
D dot(P2 a, P2 b) {return real(conj(a)*b);}
D cross(P2 a, P2 b) {return imag(conj(a)*b);}
int turn(P2 a, P2 b, P2 c) {return sgn(cross(b-a,c-a));}
inline void rd(P2& p){D x, y;cin>>x>>y;p=P2(x, y);}
#define setp(n) cout<<setprecision(n)<<fixed

D area(G2 g) {
    D s=0;
    int n=g.size();
    rep(i, n) s+=cross(g[i],g[(i+1)%n]);
    return s/2.0L;
}

P2 cpLL(L2 l, L2 m) {
    P2 a=l.b-l.a,b=m.b-m.a;
    D d=cross(a, b);
    if(eq(d, 0)) return P2(INF, INF);
    return l.a + a*cross(m.b-l.a, b)/d;
}
struct HP{
    L2 l;
    HP(){} HP(L2 _l):l(_l){}
    bool inside(P2 p){return turn(l.a, l.b, p)>=0;}
};
P2 dir(HP h) {return h.l.b-h.l.a;}
int half(P2 v) {
    if (v.imag()>0)return 0;
    if(eq(v.imag(), 0) && v.real()>=0) return 0;
    return 1;
}
bool angLessHP(HP a, HP b) {
    P2 u=dir(a), v=dir(b);
    int ha=half(u), hb=half(v);
    if(ha!=hb) return ha<hb;
    D cr=cross(u,v);
    if(!eq(cr,0)) return cr>0;
    return false;
}
vector<HP> normalizeHP(vector<HP> v) {
    sort(all(v), angLessHP);
    vector<HP> u;u.reserve(v.size());
    for(auto &h:v) {
        if(!u.empty()&&eq(cross(dir(u.back()),dir(h)),0)){
            if(h.inside(u.back().l.a)) continue;
            u.back()=h;
        } else u.push_back(h);
    }
    return u;
}
G2 hpi(vector<HP> H) {
    H = normalizeHP(move(H));
    deque<HP> dq;
    deque<P2> I;
    auto push_hp=[&] (HP h) {
        while(!I.empty()&&!h.inside(I.back())){dq.pop_back();I.pop_back();}
        while(!I.empty()&&!h.inside(I.front())){dq.pop_front();I.pop_front();}
        if(!dq.empty()&&eq(cross(dir(dq.back()),dir(h)),0)) {
            if(h.inside(dq.back().l.a)) dq.back()=h;
            return;
        }
        if(!dq.empty()) I.push_back(cpLL(dq.back().l,h.l));
        dq.push_back(h);
    };
    for(auto h:H) push_hp(h);
    while(!I.empty()&&!dq.front().inside(I.back())){dq.pop_back();I.pop_back();}
    while(!I.empty()&&!dq.back().inside(I.front())){dq.pop_front();I.pop_front();}
    if(dq.size()<3) return{};
    G2 res;res.reserve(dq.size());
    rep(i, dq.size()) {
        res.push_back(cpLL(dq[i].l, dq[(i+1)%dq.size()].l));
    }
    return res;
}

void solve() {
    ll n;cin>>n;
    vector<HP> hps;
    rep(i, n) {
        vector<P2> ps(3);
        rep(j, 3) rd(ps[j]);
        rep(j, 3) {
            hps.push_back(L2{ps[j], ps[(j+1)%3]});
        }
    }
    auto g = hpi(hps);
    // for(auto p:g) {
    //     cout << "(" << p.real() << ", " << p.imag() << ")"<< endl;
    // }
    setp(15);
    out(area(g));
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int t = 1;
    while (t--) {
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 290
memory_kb: 60784
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1ll << 60;
#define REP(i, n) for(ll i=0; i <ll(n); i++)
template <class T> using V = vector<T>;
template <class A, class B>
bool chmax(A &a, B b) { return a < b && (a=b, true); }
template <class A, class B>
bool chmin(A &a, B b) { return b < a && (a=b, true); }

using D = double;
const D PI = acos(D(-1)), EPS = 1e-10;
int sgn(D a) {
  return (a < -EPS) ? -1 : (a > EPS);
}
int sgn(D a, D b) {
  return sgn(a - b);
}
struct P {
  D x, y;
  P(D x = D(), D y = D()) : x(x), y(y) {
  }
  P operator+(P r) const {
    return {x + r.x, y + r.y};
  }
  P operator-(P r) const {
    return {x - r.x, y - r.y};
  }
  P operator*(P r) const {
    return {x * r.x - y * r.y, x * r.y + y * r.x};
  }
  P operator*(D r) const {
    return {x * r, y * r};
  }
  P operator/(D r) const {
    return {x / r, y / r};
  }
  P& operator+=(P r) {
    return *this = *this + r;
  }
  P& operator-=(P r) {
    return *this = *this - r;
  }
  P& operator*=(P r) {
    return *this = *this * r;
  }
  P& operator*=(D r) {
    return *this = *this * r;
  }
  P& operator/=(D r) {
    return *this = *this / r;
  }
  P operator-() const {
    return {-x, -y};
  }
  bool operator<(P r) const {
    return 2 * sgn(x, r.x) + sgn(y, r.y) < 0;
  }
  bool operator==(P r) const {
    return sgn((*this - r).rabs()) == 0;
  }
  bool operator!=(P r) const {
    return !(*this == r);
  }
  D norm() const {
    return x * x + y * y;
  }
  D abs() const {
    return sqrt(norm());
  }
  D rabs() const {
    return max(std ::abs(x), std ::abs(y));
  }
  D arg() const {
    return atan2(y, x);
  }
  pair<D, D> to_pair() const {
    return {x, y};
  }
  static P polar(D le, D th) {
    return {le * cos(th), le * sin(th)};
  }
};
ostream& operator<<(ostream& os, const P& p) {
  return os << "P(" << p.x << ", " << p.y << ")";
}
struct L {
  P s, t;
  L(P s = P(), P t = P()) : s(s), t(t) {
  }
  P vec() const {
    return t - s;
  }
  D abs() const {
    return vec().abs();
  }
  D arg() const {
    return vec().arg();
  }
};
ostream& operator<<(ostream& os, const L& l) {
  return os << "L(" << l.s << ", " << l.t << ")";
}
D crs(P a, P b) {
  return a.x * b.y - a.y * b.x;
}
D dot(P a, P b) {
  return a.x * b.x + a.y * b.y;
}
int sgncrs(P a, P b) {
  D cr = crs(a, b);
  if (abs(cr) <= (a.rabs() + b.rabs()) * EPS) return 0;
  return (cr < 0) ? -1 : 1;
}
int ccw(P b, P c) {
  int s = sgncrs(b, c);
  if (s) return s;
  if (!sgn(c.rabs()) || !sgn((c - b).rabs())) return 0;
  if (dot(b, c) < 0) return 2;
  if (dot(-b, c - b) < 0) return -2;
  return 0;
}
int ccw(P a, P b, P c) {
  return ccw(b - a, c - a);
}
int ccw(L l, P p) {
  return ccw(l.s, l.t, p);
}


int argcmp(P l, P r) {
    auto psgn = [&](P p) {
        if (int u = sgn(p.y)) return u;
        if (sgn(p.x) == -1) return 2;
        return 0;
    };
    int lsgn = psgn(l), rsgn = psgn(r);
    if (lsgn < rsgn) return -1;
    if (lsgn > rsgn) return 1;
    return sgncrs(r, l);
}
V<L> halfplane_intersection(V<L> lines) {
    sort(lines.begin(), lines.end(), [&](L a, L b) {
        if (int u = argcmp(a.vec(), b.vec())) return u == -1;
        return sgncrs(a.vec(), b.s - a.s) < 0;
    });
    lines.erase(unique(lines.begin(), lines.end(), [&](L a, L b) { return argcmp(a.vec(), b.vec()) == 0; }), lines.end());
    deque<L> st;
    for (auto l : lines) {
        bool err = false;
        auto is_need = [&](L a, L b, L c) {
            D ab_dw = crs(a.vec(), b.vec()), ab_up = crs(a.vec(), a.t - b.s);
            D bc_dw = crs(b.vec(), c.vec()), bc_up = crs(c.t - b.s, c.vec());
            if (ab_dw <= 0 || bc_dw <= 0) return true;
            bool f = bc_up * ab_dw > bc_dw * ab_up;
            if (!f && crs(a.vec(), c.vec()) < 0) err = true;
            return f;
        };
        while (st.size() >= 2 && !is_need(l, st[0], st[1])) st.pop_front();
        while (st.size() >= 2 &&
                !is_need(st[st.size() - 2], st[st.size() - 1], l))
            st.pop_back();
        if (st.size() < 2 || is_need(st.back(), l, st.front())) st.push_back(l);
        if (err) return {};
    }
    if (st.size() == 2 && !sgncrs(st[0].vec(), st[1].vec()) &&
        sgncrs(st[0].vec(), st[1].s - st[0].s) <= 0)
        return {};
    return V<L>(st.begin(), st.end());
}
int crossLL(L l, L m, P& r) {
  D cr1 = crs(l.vec(), m.vec()), cr2 = crs(l.vec(), l.t - m.s);
  if (sgncrs(l.vec(), m.vec()) == 0) {
    r = l.s;
    return sgncrs(l.vec(), l.t - m.s) ? 0 : -1;
  }
  r = m.s + m.vec() * cr2 / cr1;
  return 1;
}

void testcase(){
  int N; cin >> N;
  V<V<ll>> A(N, V<ll>(6));
  REP(i,N) REP(j,6) cin >> A[i][j];
  V<L> lns;
  for(auto& a : A){
    lns.push_back({ {(D)a[0], (D)a[1]}, {(D)a[2], (D)a[3]} });
    lns.push_back({ {(D)a[2], (D)a[3]}, {(D)a[4], (D)a[5]} });
    lns.push_back({ {(D)a[4], (D)a[5]}, {(D)a[0], (D)a[1]} });
  }
  auto pol_ln = halfplane_intersection(lns);
  if(pol_ln.empty()){
    cout << "0\n"; return;
  }
  V<P> pol(pol_ln.size());
  REP(i,pol.size()){
    P p;
    if(crossLL(pol_ln[i], pol_ln[(i+1)%pol.size()], p)) pol[i] = p;
  }
  D ans = 0;
  for(ll i=2; i<ll(pol.size()); i++){
    ans += crs(pol[i - 1] - pol[0], pol[i] - pol[0]);
  }
  ans /= 2.0;
  cout.precision(20);
  cout << fixed;
  cout << ans << "\n";
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  testcase();
  return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 32412
final_rank: 1

code_snippet: ////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
//#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}
const double EPS = 1e-15;

struct point{
	double x,y;
	point() {x=y=0.0;}
	point(double _x,double _y):x(_x),y(_y) {}
	bool operator < (point other) const {
		if (fabs(x-other.x) > EPS) return x<other.x;
		return y<other.y; 
	}
	bool operator == (point other) const {
		return (fabs(x-other.x) < EPS && fabs(y-other.y) < EPS);
	}

};

inline point lineIntersectSeg(point p, point q, point A, point B) {
	double a = B.y - A.y;
	double b = A.x - B.x;
	double c = B.x * A.y - A.x * B.y;
	double u = fabs(a * p.x + b * p.y + c);
	double v = fabs(a * q.x + b * q.y + c);
	return point((p.x * v + q.x * u) / (u + v),(p.y * v + q.y * u) / (u + v)); 
}

struct vec {
	double x,y;
	vec() {x=y=0.0;}
	vec(double _x,double _y):x(_x),y(_y) {}
};
inline vec toVec(point p1,point p2) {
	return vec(p2.x-p1.x,p2.y-p1.y);
}
inline double cross(vec a,vec b) {
	return a.x*b.y - a.y*b.x;
}

vector<point> P;

vector<point> triangle, polygon;

vector<vector<point> > triangles;

inline void cutPolygon(point a, point b) {
	P.clear();
	for (int i=0;i<(int)polygon.size();i++) {
		double left1 = cross(toVec(a,b),toVec(a,polygon[i]));
		double left2 = 0;
		if (i!=(int)polygon.size()-1) left2 = cross(toVec(a,b),toVec(a,polygon[i+1]));
		if (left1 > -EPS) P.push_back(polygon[i]);
		if (left1*left2 < -EPS) {
			P.push_back(lineIntersectSeg(polygon[i],polygon[i+1],a,b));
		}
	}
	if (!P.empty() && !(P.back()==P.front())) {
		P.push_back(P.front());
	}
	polygon = P;
	return ;
}

double shoelace(point A,point B) {
	return A.x * B.y - A.y * B.x;
}

int main(){

	srand(time(NULL));
	int n;
	scanf("%d",&n);
		point tmp;
	for(int i = 0;i < n;i++) {
		triangle.clear();
		for(int j = 0;j < 3;j++) {
			scanf("%lf%lf",&tmp.x,&tmp.y);
			triangle.PB(tmp);
		}
		triangles.PB(triangle);
	}
	random_shuffle(triangles.begin(),triangles.end());
	for(int i = 0;i < n;i++) {
		triangle = triangles[i];
		if(i == 0) {
			for(int j = 0;j < 4;j++) polygon.PB(triangle[j % 3]);
			continue;
		}
		for(int j = 0;j < 3;j++) {
			cutPolygon(triangle[j], triangle[(j + 1) % 3]);
			if(polygon.size() == 0) break;
		}
	}
	double tot = 0;
	int sz = polygon.size();
	for(int i = 0;i < sz;i++) {
		tot += shoelace(polygon[i], polygon[(i + 1) % sz]);
	}
	tot = fabs(tot) / 2.0;
	printf("%.10lf\n",tot);
	return 0;
}
accuracy: 1
time_ms: 1390
memory_kb: 12512
final_rank: 2

code_snippet: //#define HOHOHO
#pragma GCC Optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define FI first
#define SE second
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;
typedef pair < ll , ll > pll;
typedef vector < pll > vll;

const ll MOD = 1e9 + 7;
const double eps = 1e-9;
const int INF = 1e9;

ll addMod(ll a, ll b){
	if(a + b >= MOD) return a + b - MOD;
	return a + b;
}

ll mulMod(ll a, ll b){
	return (a*b)%MOD;
}

ll fast(ll a, ll b){
	if(b == 0) return 1;
	ll tmp = fast(a,b/2);
	tmp = mulMod(tmp,tmp);
	if(b & 1) tmp = mulMod(tmp,a);
	return tmp;
}

ll GCD(ll a, ll b){
	if(a > b) return GCD(b,a);
	if(a == 0) return b;
	return GCD(b%a,a);
}

#ifdef HOHOHO
	#define avm getchar
#else
	#define avm getchar_unlocked
#endif
char getnum_temp;
int getnum(){
	int sgn = 1;
	do{
		getnum_temp = avm();
		if('0' <= getnum_temp && getnum_temp <= '9'){
			break;
		}
		if(getnum_temp == '-') sgn = -1;
	}while(1);
	int res = 0;
	do{
		res = 10*res + (getnum_temp-'0');
		getnum_temp = avm();
		if(getnum_temp < '0' || '9' < getnum_temp){
			break;
		}
	} while(1);
	// return
	return sgn*res;
}

//////////////////////////////////////////////

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front

struct point{
	double x,y;
	point(){}
	point(double _x, double _y) : x(_x), y(_y){}
}p[4];

int n;
vector < point > pol;

struct line{
	point st, en;
	line(){}
	line(point a, point b) : st(a), en(b){
		if(st.x > en.x || (st.x ==en.x && st.y > en.y)){
			swap(st, en);
		}
	}
}li;

inline double cross(point a, point b, point c){
	return (b.x-a.x)*(c.y-b.y) - (b.y-a.y)*(c.x-b.x);
}

inline bool isAbove(point a, point b, point c){
	return (cross(a,b,c) >= 0.0);
}

inline int nxt(int a){
	return (a+1)%pol.size();
}

inline point getIntersect(line a, line b){
	point ret;
	double denom=(a.st.x-a.en.x)*(b.st.y-b.en.y) - (a.st.y-a.en.y)*(b.st.x-b.en.x);
	ret.x=((a.st.x*a.en.y-a.st.y*a.en.x)*(b.st.x-b.en.x) - (a.st.x-a.en.x)*(b.st.x*b.en.y-b.st.y*b.en.x))/denom;
	ret.y=((a.st.x*a.en.y-a.st.y*a.en.x)*(b.st.y-b.en.y) - (a.st.y-a.en.y)*(b.st.x*b.en.y-b.st.y*b.en.x))/denom;
	if(fabs(ret.x)<=eps) ret.x=fabs(ret.x);
	if(fabs(ret.y)<=eps) ret.y=fabs(ret.y);
//	printf("	%lf %lf\n",ret.x,ret.y);
	return ret;
}

inline double cross2(point a, point b){
	return a.x*b.y - a.y*b.x;
}

inline double getArea(){
	double area = 0.0;
	FOR(i,pol.size()){
		area += cross2(pol[i],pol[nxt(i)]);
	}
	return abs(area)/2.0;
}

inline bool isSame(point a, point b){
	return (fabs(a.x-b.x) <= eps && fabs(a.y-b.y) <= eps);
}

inline void cutPolygon(point a, point b, vector<point>& Q) {
	deque<point> dq; while(!dq.empty()) dq.pof();
	int idx = 0, idx2 = 0;
	int sz = (int)Q.size();
	for(; idx+5 > idx2 && idx2 < sz; idx2++) dq.pb(Q[idx2]);
	while(!dq.empty()){
		for(; idx+5 > idx2 && idx2 < sz; idx2++) dq.pb(Q[idx2]);
		//
		point curr = dq.front(); dq.pof();
		//
		double left1 = cross(a,b,curr), left2 = 0;
		if (!dq.empty()){
			left2 = cross(a, b, dq.front());
		}
		if (left1 > -eps){
			if(idx == (int)Q.size()) Q.PB(curr), idx++;
			else Q[idx++] = curr; 
		}
		if (left1 * left2 < -eps){
			point temp = getIntersect(line(curr, dq.front()), line(a, b));
			if(idx == (int)Q.size()) Q.PB(temp), idx++;
			Q[idx++] = temp;
		}
		for(; idx+5 > idx2 && idx2 < sz; idx2++) dq.pb(Q[idx2]);
	}
	while(idx < (int)Q.size()) Q.pob();
	//
	if (!Q.empty() && !isSame(Q[0],Q[(int)Q.size()-1])) Q.PB(Q[0]); 
	
//	pol.clear();
//	FOR(i,Q.size()){
//		double left1 = cross(a,b,Q[i]), left2 = 0;
//		if (i != (int) Q.size() - 1) left2 = cross(a, b, Q[i+1]);
//		if (left1 > -eps) pol.PB(Q[i]); 
//		if (left1 * left2 < -eps) pol.PB(getIntersect(line(Q[i], Q[i + 1]), line(a, b)));
//	}
//	if (!pol.empty() && !isSame(pol[0],pol[(int)pol.size()-1])) pol.PB(pol[0]); 
}

int main(){
	point pp;
	n = getnum();
	FOR(i,n){
		FOR(j,3){
			p[j].x = getnum();
			p[j].y = getnum();
//			printf("     << %lf %lf\n", p[j].x, p[j].y);
//			scanf("%lf %lf",&p[j].x,&p[j].y);
		}
		if(i == 0){
			FORD(j,3){
				pol.PB(p[j]);
			}
			pol.PB(p[2]);
		}
		else{
			if((int)pol.size() == 0) continue;
			FORD(j,3){
				pp = p[j];
				li.en = p[j];
				li.st = p[(j+2)%3];
				if(isAbove(li.st,li.en, pp)) cutPolygon(li.st, li.en, pol);
				else cutPolygon(li.en, li.st, pol);
			}
		}
	}
	printf("%.7lf\n",getArea());
	return 0;
}
accuracy: 0.44
time_ms: 30
memory_kb: 3220
final_rank: 6

code_snippet: //#define HOHOHO
#pragma GCC Optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define FI first
#define SE second
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;
typedef pair < ll , ll > pll;
typedef vector < pll > vll;

const ll MOD = 1e9 + 7;
const double eps = 1e-9;
const int INF = 1e9;

ll addMod(ll a, ll b){
	if(a + b >= MOD) return a + b - MOD;
	return a + b;
}

ll mulMod(ll a, ll b){
	return (a*b)%MOD;
}

ll fast(ll a, ll b){
	if(b == 0) return 1;
	ll tmp = fast(a,b/2);
	tmp = mulMod(tmp,tmp);
	if(b & 1) tmp = mulMod(tmp,a);
	return tmp;
}

ll GCD(ll a, ll b){
	if(a > b) return GCD(b,a);
	if(a == 0) return b;
	return GCD(b%a,a);
}

#ifdef HOHOHO
	#define avm getchar
#else
	#define avm getchar_unlocked
#endif
char getnum_temp;
int getnum(){
	int sgn = 1;
	do{
		getnum_temp = avm();
		if('0' <= getnum_temp && getnum_temp <= '9'){
			break;
		}
		if(getnum_temp == '-') sgn = -1;
	}while(1);
	int res = 0;
	do{
		res = 10*res + (getnum_temp-'0');
		getnum_temp = avm();
		if(getnum_temp < '0' || '9' < getnum_temp){
			break;
		}
	} while(1);
	// return
	return sgn*res;
}

//////////////////////////////////////////////

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front

struct point{
	double x,y;
	point(){}
	point(double _x, double _y) : x(_x), y(_y){}
}p[4];

int n;
vector < point > pol;

struct line{
	point st, en;
	line(){}
	line(point a, point b) : st(a), en(b){
		if(st.x > en.x || (st.x ==en.x && st.y > en.y)){
			swap(st, en);
		}
	}
}li;

inline double cross(point a, point b, point c){
	return (b.x-a.x)*(c.y-b.y) - (b.y-a.y)*(c.x-b.x);
}

inline bool isAbove(point a, point b, point c){
	return (cross(a,b,c) >= 0.0);
}

inline int nxt(int a){
	return (a+1)%pol.size();
}

inline point getIntersect(line a, line b){
	point ret;
	double denom=(a.st.x-a.en.x)*(b.st.y-b.en.y) - (a.st.y-a.en.y)*(b.st.x-b.en.x);
	ret.x=((a.st.x*a.en.y-a.st.y*a.en.x)*(b.st.x-b.en.x) - (a.st.x-a.en.x)*(b.st.x*b.en.y-b.st.y*b.en.x))/denom;
	ret.y=((a.st.x*a.en.y-a.st.y*a.en.x)*(b.st.y-b.en.y) - (a.st.y-a.en.y)*(b.st.x*b.en.y-b.st.y*b.en.x))/denom;
	if(fabs(ret.x)<=eps) ret.x=fabs(ret.x);
	if(fabs(ret.y)<=eps) ret.y=fabs(ret.y);
//	printf("	%lf %lf\n",ret.x,ret.y);
	return ret;
}

inline double cross2(point a, point b){
	return a.x*b.y - a.y*b.x;
}

inline double getArea(){
	double area = 0.0;
	FOR(i,pol.size()){
		area += cross2(pol[i],pol[nxt(i)]);
	}
	return abs(area)/2.0;
}

inline bool isSame(point a, point b){
	return (fabs(a.x-b.x) <= eps && fabs(a.y-b.y) <= eps);
}

inline void cutPolygon(point a, point b, vector<point>& Q) {
	deque<point> dq; while(!dq.empty()) dq.pof();
	int idx = 0, idx2 = 0;
	int sz = (int)Q.size();
	for(; idx+5 > idx2 && idx2 < sz; idx2++) dq.pb(Q[idx2]);
	while(!dq.empty()){
		for(; idx+5 > idx2 && idx2 < sz; idx2++) dq.pb(Q[idx2]);
		//
		point curr = dq.front(); dq.pof();
		//
		double left1 = cross(a,b,curr), left2 = 0;
		if (!dq.empty()){
			left2 = cross(a, b, dq.front());
		}
		if (left1 > -eps){
			if(idx == (int)Q.size()) Q.PB(curr), idx++;
			else Q[idx++] = curr; 
		}
		if (left1 * left2 < -eps){
			point temp = getIntersect(line(curr, dq.front()), line(a, b));
			if(idx == (int)Q.size()) Q.PB(temp), idx++;
			Q[idx++] = temp;
		}
	}
	while(idx < (int)Q.size()) Q.pob();
	//
	if (!Q.empty() && !isSame(Q[0],Q[(int)Q.size()-1])) Q.PB(Q[0]); 
	
//	pol.clear();
//	FOR(i,Q.size()){
//		double left1 = cross(a,b,Q[i]), left2 = 0;
//		if (i != (int) Q.size() - 1) left2 = cross(a, b, Q[i+1]);
//		if (left1 > -eps) pol.PB(Q[i]); 
//		if (left1 * left2 < -eps) pol.PB(getIntersect(line(Q[i], Q[i + 1]), line(a, b)));
//	}
//	if (!pol.empty() && !isSame(pol[0],pol[(int)pol.size()-1])) pol.PB(pol[0]); 
}

int main(){
	point pp;
	n = getnum();
	FOR(i,n){
		FOR(j,3){
			p[j].x = getnum();
			p[j].y = getnum();
//			printf("     << %lf %lf\n", p[j].x, p[j].y);
//			scanf("%lf %lf",&p[j].x,&p[j].y);
		}
		if(i == 0){
			FORD(j,3){
				pol.PB(p[j]);
			}
			pol.PB(p[2]);
		}
		else{
			if((int)pol.size() == 0) continue;
			FORD(j,3){
				pp = p[j];
				li.en = p[j];
				li.st = p[(j+2)%3];
				if(isAbove(li.st,li.en, pp)) cutPolygon(li.st, li.en, pol);
				else cutPolygon(li.en, li.st, pol);
			}
		}
	}
	printf("%.7lf\n",getArea());
	return 0;
}
accuracy: 0.44
time_ms: 30
memory_kb: 3220
final_rank: 6