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;
double TriangleArea(pair<double, double> t1, pair<double, double> t2,
                    pair<double, double> t3) {
  return (double)0.5 * abs(t1.first * t2.second + t2.first * t3.second +
                           t3.first * t1.second - t1.first * t3.second -
                           t3.first * t2.second - t2.first * t1.second);
}
bool IsInsideTriangle(pair<double, double> point, pair<double, double> t1,
                      pair<double, double> t2, pair<double, double> t3) {
  return (abs(TriangleArea(point, t1, t2) + TriangleArea(point, t1, t3) +
              TriangleArea(point, t3, t2) - TriangleArea(t1, t2, t3)) <= 1e-8);
}
bool PointEquals(pair<double, double> p1, pair<double, double> p2) {
  return abs(p1.first - p2.first) <= 1e-8 && abs(p1.second - p2.second) <= 1e-8;
}
bool IsIntersecting(pair<pair<double, double>, pair<double, double> > segment1,
                    pair<pair<double, double>, pair<double, double> > segment2,
                    int* parallel = NULL,
                    pair<double, double>* intersection_point = NULL) {
  int dummy_parallel;
  pair<double, double> dummy_intersection_point;
  if (parallel == NULL) parallel = &dummy_parallel;
  if (intersection_point == NULL)
    intersection_point = &dummy_intersection_point;
  double xx1 = segment1.first.first;
  double yy1 = segment1.first.second;
  double xx2 = segment1.second.first;
  double yy2 = segment1.second.second;
  double xx3 = segment2.first.first;
  double yy3 = segment2.first.second;
  double xx4 = segment2.second.first;
  double yy4 = segment2.second.second;
  double ua, ub;
  *parallel = 0;
  if (fabs((yy4 - yy3) * (xx2 - xx1) - (xx4 - xx3) * (yy2 - yy1)) <= 1e-8) {
    *parallel = 1;
    if (PointEquals(segment1.first, segment2.first) ||
        PointEquals(segment1.first, segment2.second)) {
      *intersection_point = segment1.first;
      return true;
    } else if (PointEquals(segment1.second, segment2.first) ||
               PointEquals(segment1.second, segment2.second)) {
      *intersection_point = segment1.second;
      return true;
    }
    return false;
  }
  ua = ((xx4 - xx3) * (yy1 - yy3) - (yy4 - yy3) * (xx1 - xx3)) /
       ((yy4 - yy3) * (xx2 - xx1) - (xx4 - xx3) * (yy2 - yy1));
  ub = ((xx2 - xx1) * (yy1 - yy3) - (yy2 - yy1) * (xx1 - xx3)) /
       ((yy4 - yy3) * (xx2 - xx1) - (xx4 - xx3) * (yy2 - yy1));
  double& xi = (*intersection_point).first;
  double& yi = (*intersection_point).second;
  xi = xx1 + ua * (xx2 - xx1);
  yi = yy1 + ua * (yy2 - yy1);
  return ((xi + 1e-8 >= fmin(xx1, xx2)) && (xi - 1e-8 <= fmax(xx1, xx2)) &&
          (yi + 1e-8 >= fmin(yy1, yy2)) && (yi - 1e-8 <= fmax(yy1, yy2)) &&
          (xi + 1e-8 >= fmin(xx3, xx4)) && (xi - 1e-8 <= fmax(xx3, xx4)) &&
          (yi + 1e-8 >= fmin(yy3, yy4)) && (yi - 1e-8 <= fmax(yy3, yy4)));
}
bool PointLess(pair<double, double> p1, pair<double, double> p2) {
  return p2.second + 1e-8 < p1.second ||
         (fabs(p1.second - p2.second) <= 1e-8 && p1.first + 1e-8 < p2.first);
}
struct CmpPointLess {
  bool operator()(pair<double, double> p1, pair<double, double> p2) {
    return PointLess(p1, p2);
  }
};
vector<pair<double, double> > triangles[150];
pair<double, double> MidPoint(pair<double, double> p1,
                              pair<double, double> p2) {
  return make_pair(0.5 * (p1.first + p2.first), 0.5 * (p1.second + p2.second));
}
double SegmentLength(pair<pair<double, double>, pair<double, double> > seg) {
  return sqrt((seg.first.first - seg.second.first) *
                  (seg.first.first - seg.second.first) +
              (seg.first.second - seg.second.second) *
                  (seg.first.second - seg.second.second));
}
int main() {
  int n;
  cin >> n;
  for (int(i) = 0; (i) < (n); ++(i)) {
    for (int(j) = 0; (j) < (3); ++(j)) {
      int x, y;
      cin >> x >> y;
      triangles[i].push_back(make_pair((double)x, (double)y));
    }
  }
  double ret = 0.0;
  for (int(i) = 0; (i) < (n); ++(i))
    for (int(j) = 0; (j) < (3); ++(j)) {
      vector<pair<double, double> > intersections;
      pair<double, double> awal = triangles[i][j];
      pair<double, double> akhir = triangles[i][(j + 1) % 3];
      intersections.push_back(awal);
      intersections.push_back(akhir);
      for (int(k) = 0; (k) < (n); ++(k))
        if (k != i)
          for (int(l) = 0; (l) < (3); ++(l)) {
            pair<double, double> p;
            if (IsIntersecting(
                    make_pair(awal, akhir),
                    make_pair(triangles[k][l], triangles[k][(l + 1) % 3]), NULL,
                    &p)) {
              intersections.push_back(p);
            }
          }
      sort(intersections.begin(), intersections.end(), CmpPointLess());
      for (int(k) = 0; (k) < (((int)intersections.size()) - 1); ++(k)) {
        pair<double, double> p1 = intersections[k];
        pair<double, double> p2 = intersections[k + 1];
        if (PointEquals(p1, p2)) continue;
        pair<double, double> mid = MidPoint(p1, p2);
        int contained = 0;
        for (int(l) = 0; (l) < (n); ++(l))
          if (l != i) {
            if (IsInsideTriangle(mid, triangles[l][0], triangles[l][1],
                                 triangles[l][2])) {
              contained = 1;
              break;
            }
          }
        if (!contained) ret += SegmentLength(make_pair(p1, p2));
      }
    }
  printf("%.9lf\n", ret);
  return 0;
}