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
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
struct Point {
  long double x, y;
};
int n;
Point p[105][4];
long double dist(Point& p1, Point& p2) {
  return sqrtl((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}
long double det(long double x1, long double y1, long double x2,
                long double y2) {
  return x1 * y2 - x2 * y1;
}
long double sq(Point& p1, Point& p2, Point& p3) {
  return fabsl(det(p1.x - p3.x, p1.y - p3.y, p2.x - p3.x, p2.y - p3.y));
}
bool on_segm(Point& q, Point& p1, Point& p2) {
  return sq(p1, p2, q) < 1e-9 &&
         (p1.x - q.x) * (p2.x - q.x) + (p1.y - q.y) * (p2.y - q.y) < 1e-9;
}
bool inside_triangle(Point& q) {
  for (int i = 0; i < int(n); i++) {
    bool ok = true;
    for (int j = 0; j < int(3); j++) {
      if (on_segm(q, p[i][j], p[i][j + 1])) {
        ok = false;
        break;
      }
    }
    if (ok) {
      long double s1 = 0, s2 = 0;
      for (int j = 0; j < int(3); j++) {
        s1 += sq(p[i][j], p[i][j + 1], p[i][0]);
        s2 += sq(p[i][j], p[i][j + 1], q);
      }
      if (fabsl(s1 - s2) < 1e-9) return true;
    }
  }
  return false;
}
bool intersect(Point& p1, Point& p2, Point& q1, Point& q2, long double& t) {
  long double d = det(p2.x - p1.x, q2.x - q1.x, p2.y - p1.y, q2.y - q1.y);
  if (abs(d) < 1e-9) {
    return false;
  }
  long double t1 = det(q1.x - p1.x, q2.x - q1.x, q1.y - p1.y, q2.y - q1.y) / d;
  long double t2 = det(p2.x - p1.x, p1.x - q1.x, p2.y - p1.y, p1.y - q1.y) / d;
  if (t1 < 1e-9 || t1 > 1 - 1e-9 || t2 < 1e-9 || t2 > 1 - 1e-9) {
    return false;
  }
  t = t1;
  return true;
}
int main() {
  cin >> n;
  for (int i = 0; i < int(n); i++) {
    for (int j = 0; j < int(3); j++) {
      cin >> p[i][j].x >> p[i][j].y;
    }
    p[i][3] = p[i][0];
  }
  long double ans = 0;
  for (int i = 0; i < int(n); i++) {
    for (int j = 0; j < int(3); j++) {
      vector<long double> v;
      v.push_back(0.0);
      v.push_back(1.0);
      for (int i1 = 0; i1 < int(n); i1++) {
        for (int j1 = 0; j1 < int(3); j1++) {
          long double t;
          if (intersect(p[i][j], p[i][j + 1], p[i1][j1], p[i1][j1 + 1], t)) {
            v.push_back(t);
          }
        }
      }
      sort(v.begin(), v.end());
      long double len = dist(p[i][j], p[i][j + 1]);
      for (int k = 0; k < int((int)v.size() - 1); k++) {
        if (fabsl(v[k] - v[k + 1]) < 1e-9) continue;
        Point q;
        long double mid = (v[k] + v[k + 1]) / 2;
        q.x = p[i][j].x + mid * (p[i][j + 1].x - p[i][j].x);
        q.y = p[i][j].y + mid * (p[i][j + 1].y - p[i][j].y);
        if (!inside_triangle(q)) ans += (v[k + 1] - v[k]) * len;
      }
    }
  }
  cout.precision(10);
  cout << fixed;
  cout << ans << endl;
  return 0;
}
