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 double EPS = 1e-6;
struct pt {
  double x, y;
  pt() {}
  pt(double _x, double _y) : x(_x), y(_y) {}
};
inline bool operator<(pt a, pt b) {
  return make_pair(a.x, a.y) < make_pair(b.x, b.y);
}
struct line {
  double a, b, c;
  line(double _a, double _b, double _c) : a(_a), b(_b), c(_c) {}
};
struct vecd {
  double x, y;
  vecd(double _x, double _y) : x(_x), y(_y) {}
  double norm() { return sqrt(x * x + y * y); }
};
inline vecd operator/(vecd w, double x) { return vecd(w.x / x, w.y / x); }
inline pt operator-(pt a, vecd w) { return pt(a.x - w.x, a.y - w.y); }
inline pt operator+(pt a, vecd w) { return pt(a.x + w.x, a.y + w.y); }
inline pt operator+(pt a, pt b) { return pt(a.x + b.x, a.y + b.y); }
inline pt operator/(pt a, double x) { return pt(a.x / x, a.y / x); }
struct seg {
  pt a, b;
  line toLine() { return line(a.y - b.y, b.x - a.x, a.x * b.y - b.x * a.y); }
  vecd toVec() { return vecd(a.y - b.y, b.x - a.x); }
  seg(pt _a, pt _b) : a(_a), b(_b) {}
  bool isin(pt w) {
    return (min(a.x, b.x) - EPS < w.x && w.x < max(a.x, b.x) + EPS) ||
           (min(a.y, b.y) - EPS < w.y && w.y < max(a.y, b.y) + EPS);
  }
};
double det(double a, double b, double c, double d) { return a * d - b * c; }
inline bool intersect(line m, line n, pt& res) {
  double zn = det(m.a, m.b, n.a, n.b);
  if (abs(zn) < EPS) return false;
  res.x = -det(m.c, m.b, n.c, n.b) / zn;
  res.y = -det(m.a, m.c, n.a, n.c) / zn;
  return true;
}
inline bool iseg(seg a, seg b, pt& res) {
  if (!intersect(a.toLine(), b.toLine(), res)) return false;
  if (a.isin(res) && b.isin(res)) return true;
  return false;
}
inline double S(pt a, pt b) { return (a.x - b.x) * (a.y + b.y) / 2.0; }
inline double S(pt a, pt b, pt c) { return S(a, b) + S(b, c) + S(c, a); }
struct triangle {
  pt a[3];
  vector<pt> div[3];
  bool isin(pt w) {
    double e, r, t;
    e = S(a[0], a[1], w), r = S(a[1], a[2], w), t = S(a[2], a[0], w);
    if (e > -EPS && r > -EPS && t > -EPS) return true;
    if (e < EPS && r < EPS && t < EPS) return true;
    return false;
  }
};
vector<triangle> t;
inline bool col(pt a) {
  bool c = false;
  for (int _n(((int)((t).end() - (t).begin())) - 1), i(0); i <= _n; i++)
    c |= t[i].isin(a);
  return c;
}
int main() {
  int n;
  scanf("%d", &n);
  t.resize(n);
  for (int _n((n)-1), i(0); i <= _n; i++) {
    int x1, y1, x2, y2, x3, y3;
    scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3);
    t[i].a[0].x = x1;
    t[i].a[0].y = y1;
    t[i].a[1].x = x2;
    t[i].a[1].y = y2;
    t[i].a[2].x = x3;
    t[i].a[2].y = y3;
  }
  for (int _n((n)-1), i(0); i <= _n; i++)
    for (int _n((n)-1), j(0); j <= _n; j++) {
      pt ir;
      for (int _n((3) - 1), k(0); k <= _n; k++)
        for (int _n((3) - 1), u(0); u <= _n; u++) {
          if (iseg(seg(t[i].a[k], t[i].a[(k + 1) % 3]),
                   seg(t[j].a[u], t[j].a[(u + 1) % 3]), ir)) {
            t[i].div[k].push_back(ir);
            t[j].div[u].push_back(ir);
          }
        }
    }
  double res = 0;
  for (int _n((n)-1), i(0); i <= _n; i++)
    for (int _n((3) - 1), k(0); k <= _n; k++)
      t[i].div[k].push_back(t[i].a[k]),
          t[i].div[k].push_back(t[i].a[(k + 1) % 3]);
  for (int _n((n)-1), i(0); i <= _n; i++)
    for (int _n((3) - 1), k(0); k <= _n; k++)
      sort((t[i].div[k]).begin(), (t[i].div[k]).end());
  for (int _n((n)-1), i(0); i <= _n; i++)
    for (int _n((3) - 1), k(0); k <= _n; k++)
      for (int _n(((int)((t[i].div[k]).end() - (t[i].div[k]).begin()) - 1) - 1),
           j(0);
           j <= _n; j++) {
        pt md = (t[i].div[k][j] + t[i].div[k][j + 1]) / 2.0;
        seg s = seg(t[i].div[k][j], t[i].div[k][j + 1]);
        vecd v = s.toVec();
        v = v / (v.norm() * 100.0);
        double l = sqrt((s.a.x - s.b.x) * (s.a.x - s.b.x) +
                        (s.a.y - s.b.y) * (s.a.y - s.b.y));
        if (l < EPS) continue;
        if (col(md + v) ^ col(md - v)) res += l;
      }
  printf("%.9lf\n", res);
  return 0;
}