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>
const int maxn = 102;
const double ee = 1e-8;
struct point {
  double x, y;
  point operator-(const point &p) const {
    point ans;
    ans.x = x - p.x;
    ans.y = y - p.y;
    return ans;
  }
  double xtimes(const point &p) const { return x * p.y - y * p.x; }
};
struct mark {
  bool outside;
  double t;
};
struct triangle {
  point p[3];
};
triangle tris[maxn];
double ts[maxn * 2];
bool cameraSolve(double a, double b, double c, double d, double e, double f,
                 double &t1, double &t2) {
  double det1, det2, det;
  det = a * d - b * c;
  if (det > -ee && det < ee) return false;
  det1 = e * d - b * f;
  det2 = a * f - e * c;
  t1 = det1 / det;
  t2 = det2 / det;
}
bool edgeCrossEdge(const point &p1, const point &p2, const point &p3,
                   const point &p4, double &t) {
  double t1, t2;
  if (!cameraSolve(p2.x - p1.x, p3.x - p4.x, p2.y - p1.y, p3.y - p4.y,
                   p3.x - p1.x, p3.y - p1.y, t1, t2))
    return false;
  if (t1 >= 0 && t1 <= 1 && t2 >= 0 && t2 <= 1) {
    t = t1;
    return true;
  }
  return false;
}
bool pointInTri(const point &p, const triangle &tri) {
  int k;
  for (k = 0; k < 3; k++) {
    const point &p0 = tri.p[k];
    const point &p1 = tri.p[(k + 1) % 3];
    const point &p2 = tri.p[(k + 2) % 3];
    point dp0, dp1, dp2;
    dp0 = p1 - p0;
    dp1 = p2 - p0;
    dp2 = p - p0;
    if (dp0.xtimes(dp1) * dp0.xtimes(dp2) < 0) return false;
  }
  return true;
}
int dblcmp(const void *a, const void *b) {
  double d = *(double *)a - *(double *)b;
  if (d > 0)
    return 1;
  else if (d < 0)
    return -1;
  else
    return 0;
}
double len(const point &p1, const point &p2) {
  double dx, dy;
  dx = p1.x - p2.x;
  dy = p1.y - p2.y;
  return sqrt(dx * dx + dy * dy);
}
double getAns(int n) {
  int i, j, k, k1, piece;
  double t;
  double total = 0;
  for (i = 0; i < n; i++) {
    for (k = 0; k < 3; k++) {
      const point &p1 = tris[i].p[k];
      const point &p2 = tris[i].p[(k + 1) % 3];
      int cnt;
      cnt = 0;
      ts[cnt++] = 0;
      for (j = 0; j < n; j++)
        if (j != i) {
          for (k1 = 0; k1 < 3; k1++) {
            const point &p3 = tris[j].p[k1];
            const point &p4 = tris[j].p[(k1 + 1) % 3];
            if (edgeCrossEdge(p1, p2, p3, p4, t)) {
              ts[cnt++] = t;
            }
          }
        }
      ts[cnt++] = 1;
      qsort(ts, cnt, sizeof(double), dblcmp);
      point pt1, pt2, pm;
      pt1.x = p1.x + (p2.x - p1.x) * ts[0];
      pt1.y = p1.y + (p2.y - p1.y) * ts[0];
      for (piece = 1; piece < cnt; piece++) {
        pt2.x = p1.x + (p2.x - p1.x) * ts[piece];
        pt2.y = p1.y + (p2.y - p1.y) * ts[piece];
        pm.x = (pt1.x + pt2.x) / 2;
        pm.y = (pt1.y + pt2.y) / 2;
        for (j = 0; j < n; j++) {
          if (j != i && pointInTri(pm, tris[j])) break;
        }
        if (j == n) {
          total += len(p1, p2) * (ts[piece] - ts[piece - 1]);
        }
        pt1 = pt2;
      }
    }
  }
  return total;
}
int main() {
  int n;
  int i, j;
  using std::cin;
  using std::cout;
  cin >> n;
  for (i = 0; i < n; i++) {
    for (j = 0; j < 3; j++) cin >> tris[i].p[j].x >> tris[i].p[j].y;
  }
  cout.precision(10);
  cout.setf(std::ios_base::fixed);
  cout << getAns(n) << '\n';
  return 0;
}