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;
template <class A, class B>
A convert(B x) {
  stringstream s;
  s << x;
  A r;
  s >> r;
  return r;
}
class Point {
 public:
  double x, y;
  Point() {}
  Point(double _x, double _y) : x(_x), y(_y) {}
  void read() { scanf("%lf %lf", &x, &y); }
  double Len() { return sqrt(x * x + y * y); }
};
Point operator-(Point& a, Point& b) { return Point(a.x - b.x, a.y - b.y); }
class Tri {
 public:
  Point p1, p2, p3;
  Tri() {}
};
int n;
Tri p[1 << 8];
bool Intersect(Point p1, Point p2, Point q1, Point q2, double& tmp) {
  double A = p2.y - p1.y;
  double B = p1.x - p2.x;
  double C = -p1.x * A - p1.y * B;
  double s1 = q1.x * A + q1.y * B + C;
  int S1;
  if (abs(s1) < 1e-8)
    S1 = 0;
  else if (s1 < -1e-8)
    S1 = -1;
  else
    S1 = +1;
  double s2 = q2.x * A + q2.y * B + C;
  int S2;
  if (abs(s2) < 1e-8)
    S2 = 0;
  else if (s2 < -1e-8)
    S2 = -1;
  else
    S2 = +1;
  if (S1 * S2 > 0) return false;
  swap(p1, q1);
  swap(p2, q2);
  Point v1(p2 - p1), v2(q2 - q1);
  tmp = v1.y * v2.x - v2.y * v1.x;
  tmp = (v1.x * (q1.y - p1.y) + v1.y * (p1.x - q1.x)) / tmp;
  tmp = max(tmp, 0.);
  tmp = min(tmp, 1.);
  return true;
}
double Calc(int nom, Point a, Point b) {
  vector<pair<double, double> > v;
  for (int i = (0), _b(n); i < _b; ++i)
    if (i != nom) {
      double tmp;
      double fst = 1, snd = 0;
      if (Intersect(a, b, p[i].p1, p[i].p2, tmp)) {
        fst = min(fst, tmp);
        snd = max(snd, tmp);
      }
      if (Intersect(a, b, p[i].p2, p[i].p3, tmp)) {
        fst = min(fst, tmp);
        snd = max(snd, tmp);
      }
      if (Intersect(a, b, p[i].p3, p[i].p1, tmp)) {
        fst = min(fst, tmp);
        snd = max(snd, tmp);
      }
      if (snd - fst > 1e-8) v.push_back(make_pair(fst, snd));
    }
  sort(v.begin(), v.end());
  for (int i = 1; i < ((int)(v).size()); i++) {
    if (v[i].first <= v[i - 1].second + 1e-8) {
      v[i - 1].second = max(v[i - 1].second, v[i].second);
      v.erase(v.begin() + i);
      i--;
    }
  }
  double t = 1;
  for (int i = (0), _b(((int)(v).size())); i < _b; ++i)
    t -= v[i].second - v[i].first;
  return ((b - a).Len()) * t;
}
int main() {
  scanf("%d", &n);
  for (int i = (0), _b(n); i < _b; ++i) {
    p[i].p1.read();
    p[i].p2.read();
    p[i].p3.read();
  }
  double res = 0;
  for (int i = (0), _b(n); i < _b; ++i) {
    res += Calc(i, p[i].p1, p[i].p2);
    res += Calc(i, p[i].p2, p[i].p3);
    res += Calc(i, p[i].p3, p[i].p1);
  }
  printf("%.10lf\n", res);
  return 0;
}