Problem: In Medieval times existed the tradition of burning witches at steaks together with their pets, black cats. By the end of the 15-th century the population of black cats ceased to exist. The difficulty of the situation led to creating the EIC - the Emergency Inquisitory Commission.

The resolution #666 says that a white cat is considered black when and only when the perimeter of its black spots exceeds the acceptable norm. But what does the acceptable norm equal to? Every inquisitor will choose it himself depending on the situation. And your task is to find the perimeter of black spots on the cat's fur.

The very same resolution says that the cat's fur is a white square with the length of 105. During the measurement of spots it is customary to put the lower left corner of the fur into the origin of axes (0;0) and the upper right one — to the point with coordinates (105;105). The cats' spots are nondegenerate triangles. The spots can intersect and overlap with each other, but it is guaranteed that each pair of the triangular spots' sides have no more than one common point.

We'll regard the perimeter in this problem as the total length of the boarders where a cat's fur changes color.

Input

The first input line contains a single integer n (0 ≤ n ≤ 100). It is the number of spots on the cat's fur. The i-th of the last n lines contains 6 integers: x1i, y1i, x2i, y2i, x3i, y3i. They are the coordinates of the i-th triangular spot (0 < xji, yji < 105).

Output

Print a single number, the answer to the problem, perimeter of the union of triangles. Your answer should differ from the correct one in no more than 10 - 6.

Examples

Input

1
1 1 2 1 1 2


Output

3.4142135624


Input

3
3 3 10 3 3 10
1 1 9 4 5 6
2 2 11 7 6 11


Output

37.7044021497

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-8;
int dcmp(long double x) {
  if (abs(x) < eps)
    return 0;
  else
    return x < 0 ? -1 : 1;
}
struct Pt {
  long double x, y;
  Pt(long double _x = 0, long double _y = 0) : x(_x), y(_y) {}
  Pt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); }
  Pt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); }
  Pt operator*(const long double &a) const { return Pt(x * a, y * a); }
  Pt operator/(const long double &a) const { return Pt(x / a, y / a); }
  long double operator*(const Pt &a) const { return x * a.x + y * a.y; }
  long double operator^(const Pt &a) const { return x * a.y - y * a.x; }
  bool operator<(const Pt &a) const { return x < a.x || (x == a.x && y < a.y); }
  bool operator==(const Pt &a) const {
    return dcmp(x - a.x) == 0 && dcmp(y - a.y) == 0;
  }
};
long double norm2(const Pt &a) { return a * a; }
long double norm(const Pt &a) { return sqrt(norm2(a)); }
Pt perp(const Pt &a) { return Pt(-a.y, a.x); }
Pt rotate(const Pt &a, long double ang) {
  return Pt(a.x * cos(ang) - a.y * sin(ang), a.x * sin(ang) + a.y * cos(ang));
}
struct Line {
  Pt s, e, v;
  long double ang;
  Line(Pt _s = Pt(0, 0), Pt _e = Pt(0, 0)) : s(_s), e(_e) {
    v = e - s;
    ang = atan2(v.y, v.x);
  }
  bool operator<(const Line &L) const { return ang < L.ang; }
};
struct Circle {
  Pt o;
  long double r;
  Circle(Pt _o = Pt(0, 0), long double _r = 0) : o(_o), r(_r) {}
};
bool onseg(Pt p, Line L) {
  Pt x = L.s - p, y = L.e - p;
  return dcmp(x ^ y) == 0 && dcmp(x * y) <= 0;
}
int inPoly(Pt p, vector<Pt> &v) {
  int n = v.size(), wn = 0;
  for (int i = 0; i < n; ++i) {
    if (onseg(p, Line(v[i], v[(i + 1) % n]))) return -1;
    int k = dcmp((v[(i + 1) % n] - v[i]) ^ (p - v[i]));
    int d1 = dcmp(v[i].y - p.y), d2 = dcmp(v[(i + 1) % n].y - p.y);
    if (k > 0 && d1 <= 0 && d2 > 0) ++wn;
    if (k < 0 && d2 <= 0 && d1 > 0) --wn;
  }
  if (wn != 0) return 1;
  return 0;
}
Pt LLIntersect(Line a, Line b) {
  Pt p1 = a.s, p2 = a.e, q1 = b.s, q2 = b.e;
  double f1 = (p2 - p1) ^ (q1 - p1), f2 = (p2 - p1) ^ (p1 - q2), f = f1 + f2;
  if (dcmp(f) == 0) return dcmp(f1) ? Pt(NAN, NAN) : Pt(INFINITY, INFINITY);
  return q1 * (f2 / f) + q2 * (f1 / f);
}
Pt SSIntersect(Line a, Line b) {
  Pt p = LLIntersect(a, b);
  if (isinf(p.x) &&
      (onseg(a.s, b) || onseg(a.e, b) || onseg(b.s, a) || onseg(b.e, a)))
    return p;
  if (isfinite(p.x) && onseg(p, a) && onseg(p, b)) return p;
  return {NAN, NAN};
}
int n;
vector<vector<Pt> > v;
vector<Line> seg, seg2;
vector<Pt> inter[100000];
long double check(int id) {
  Pt mid = (seg2[id].s + seg2[id].e) / 2;
  for (int i = 0; i < n; ++i)
    if (inPoly(mid, v[i]) == 1) return 0.0;
  return norm(seg2[id].v);
}
void init() {
  cin >> n;
  v.resize(n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 3; ++j) {
      Pt p;
      cin >> p.x >> p.y;
      v[i].push_back(p);
    }
  }
}
void solve() {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 3; ++j) {
      seg.push_back(Line(v[i][j], v[i][(j + 1) % 3]));
    }
  }
  for (int i = 0; i < 3 * n; ++i) {
    inter[i].push_back(seg[i].s);
    inter[i].push_back(seg[i].e);
    for (int j = i + 1; j < 3 * n; ++j)
      if (i / 3 != j / 3) {
        Pt p = SSIntersect(seg[i], seg[j]);
        if (!isnan(p.x) && !isinf(p.x)) {
          inter[i].push_back(p);
          inter[j].push_back(p);
        }
      }
    sort(inter[i].begin(), inter[i].end());
    for (int j = 0; j < (int)inter[i].size() - 1; ++j) {
      seg2.push_back(Line(inter[i][j], inter[i][j + 1]));
    }
  }
  long double ans = 0;
  for (int i = 0; i < (int)seg2.size(); ++i) {
    ans += check(i);
  }
  cout << fixed << setprecision(10) << ans << '\n';
}
int main() {
  init();
  solve();
}