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; }
};
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;
  if (dcmp(f = f1 + f2) == 0)
    return dcmp(f1) ? Pt(NAN, NAN) : Pt(INFINITY, INFINITY);
  return q1 * (f2 / f) + q2 * (f1 / f);
}
bool onseg(Pt p, Line L) {
  Pt x = L.s - p, y = L.e - p;
  return dcmp(x ^ y) == 0 && dcmp(x * y) <= 0;
}
bool inseg(Pt p, Line L) {
  Pt x = L.s - p, y = L.e - p;
  return dcmp(x ^ y) == 0 && dcmp(x * y) < 0;
}
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 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;
}
vector<Line> segs;
vector<Pt> intersects[300];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    segs.emplace_back(Pt(a, b), Pt(c, d));
    segs.emplace_back(Pt(c, d), Pt(e, f));
    segs.emplace_back(Pt(e, f), Pt(a, b));
  }
  for (int i = 0; i < segs.size(); i++) {
    for (int j = i + 1; j < segs.size(); j++) {
      auto intersect = SSIntersect(segs[i], segs[j]);
      if (!isnan(intersect.x) and !isinf(intersect.x)) {
        intersects[i].push_back(intersect);
        intersects[j].push_back(intersect);
      }
    }
  }
  for (int i = 0; i < segs.size(); i++) {
    intersects[i].push_back(segs[i].s);
    intersects[i].push_back(segs[i].e);
    sort(begin(intersects[i]), end(intersects[i]));
    intersects[i].erase(unique(begin(intersects[i]), end(intersects[i])),
                        intersects[i].end());
  }
  long double ans = 0.0;
  for (int i = 0; i < segs.size(); i++) {
    for (int j = 1; j < intersects[i].size(); ++j) {
      const auto &A = intersects[i][j - 1];
      const auto &B = intersects[i][j];
      const auto &M = (A + B) / 2;
      bool inTriangle = false;
      for (int k = 2; k < segs.size(); k += 3) {
        if (inPoly(M, {segs[k - 2].s, segs[k - 1].s, segs[k].s}) == 1) {
          inTriangle = true;
          break;
        }
      }
      if (not inTriangle) {
        ans += norm(A - B);
      }
    }
  }
  cout << fixed;
  cout.precision(20);
  cout << ans << endl;
  return 0;
}