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;
int Sig(double a) {
  if (a < -1e-5)
    return -1;
  else if (a > 1e-5)
    return 1;
  else
    return 0;
}
struct Point {
  double x, y;
  Point() {}
  Point(double x0, double y0) : x(x0), y(y0) {}
  void in() { scanf("%lf%lf", &x, &y); }
  Point operator*(double t) { return Point(t * x, t * y); }
  double operator*(Point pt) { return x * pt.y - y * pt.x; }
  double operator^(Point pt) { return pt.x * x + pt.y * y; }
  Point operator+(Point pt) { return Point(x + pt.x, y + pt.y); }
  Point operator-(Point pt) { return Point(x - pt.x, y - pt.y); }
  bool operator==(Point pt) {
    if (fabs(x - pt.x) < 1e-5 && fabs(y - pt.y) < 1e-5)
      return true;
    else
      return false;
  }
};
struct Triangle {
  Point p[4];
  void in() {
    for (int i = 0; i < 3; i++) p[i].in();
    if ((p[1] - p[0]) * (p[2] - p[0]) < 0) swap(p[0], p[1]);
    p[3] = p[0];
  }
} T[110];
double dis(Point a, Point b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
struct Line {
  Point p, q;
  Line() {}
  Line(Point p0, Point q0) : p(p0), q(q0) {}
};
Point Intersect(Line u, Line v) {
  Point ret = u.p;
  double t =
      ((u.p.x - v.p.x) * (v.p.y - v.q.y) - (u.p.y - v.p.y) * (v.p.x - v.q.x)) /
      ((u.p.x - u.q.x) * (v.p.y - v.q.y) - (u.p.y - u.q.y) * (v.p.x - v.q.x));
  ret.x += (u.q.x - u.p.x) * t;
  ret.y += (u.q.y - u.p.y) * t;
  return ret;
}
bool Is_InLine(Point o, Line l) {
  double x1 = min(l.p.x, l.q.x);
  double x2 = max(l.p.x, l.q.x);
  double y1 = min(l.p.y, l.q.y);
  double y2 = max(l.p.y, l.q.y);
  if (Sig(o.x - x1) >= 0 && Sig(x2 - o.x) >= 0 && Sig(o.y - y1) >= 0 &&
      Sig(y2 - o.y) >= 0)
    return true;
  else
    return false;
}
bool Is_Parallel(Line u, Line v) {
  Point p = u.p - u.q;
  Point q = v.p - v.q;
  return fabs(p.x * q.y - q.x * p.y) < 1e-5;
}
bool Is_Same(Line u, Line v) {
  Point p = u.p - u.q;
  Point q = v.p - u.q;
  return Is_Parallel(u, v) && fabs(p * q) < 1e-5;
}
Point pp[1000010];
int qq;
bool cmp(Point a, Point b) {
  if (Sig(a.x - b.x) == 0) return a.y < b.y;
  return a.x < b.x;
}
int n;
bool InAny(Point o) {
  for (int i = 0; i < n; i++) {
    bool flag = true;
    for (int a = 0; a < 3; a++) {
      if (Sig((T[i].p[a + 1] - T[i].p[a]) * (o - T[i].p[a])) <= 0) flag = false;
    }
    if (flag) return true;
  }
  return false;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) T[i].in();
  double ans = 0;
  for (int i = 0; i < n; i++)
    for (int a = 0; a < 3; a++) {
      Line l = Line(T[i].p[a], T[i].p[a + 1]);
      qq = 0;
      pp[qq++] = l.p;
      pp[qq++] = l.q;
      for (int j = 0; j < n; j++) {
        if (i == j) continue;
        for (int b = 0; b < 3; b++) {
          Line g = Line(T[j].p[b], T[j].p[b + 1]);
          if (Is_Parallel(l, g)) {
            if (Is_Same(l, g)) {
              if (l.p == g.p || l.p == g.q) pp[qq++] = l.p;
              if (l.q == g.p || l.q == g.q) pp[qq++] = l.q;
            }
          } else {
            Point o = Intersect(l, g);
            if (Is_InLine(o, l) && Is_InLine(o, g)) pp[qq++] = o;
          }
        }
      }
      sort(pp, pp + qq, cmp);
      for (int i = 1; i < qq; i++) {
        Point o = (pp[i - 1] + pp[i]) * 0.5;
        if (!InAny(o)) ans += dis(pp[i - 1], pp[i]);
      }
    }
  printf("%.10f\n", ans);
  return 0;
}