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;
const int moves[][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
const int maxN = 100005;
class Point {
 public:
  Point() {}
  Point(double x, double y) {
    this->x = x;
    this->y = y;
  }
  double dist(Point P) {
    double X = P.x - this->x;
    double Y = P.y - this->y;
    X *= X;
    Y *= Y;
    return sqrt(X + Y);
  }
  double x, y;
  void read() { scanf("%lf%lf", &x, &y); }
};
class Line {
 public:
  Line() {}
  Line(double A, double B, double C) {
    this->A = A;
    this->B = B;
    this->C = C;
  }
  Line(Point a, Point b) {
    double x1 = a.x, x2 = b.x;
    double y1 = a.y, y2 = b.y;
    A = y1 - y2;
    B = x2 - x1;
    C = x1 * y2 - y1 * x2;
  }
  int intersects(Line p, Point &T) {
    double det = A * p.B - B * p.A;
    if (fabs(det) < 1e-5) return 0;
    T.x = B * p.C - p.B * C;
    T.x /= det;
    T.y = p.A * C - p.C * A;
    T.y /= det;
    return 1;
  }
  double A, B, C;
};
class Segment {
 public:
  Segment() {}
  Segment(Point A, Point B) {
    this->A = A;
    this->B = B;
  }
  Point A, B;
};
double VP(Point A, Point B, Point C) {
  double x1 = B.x - A.x, y1 = B.y - A.y;
  double x2 = C.x - A.x, y2 = C.y - A.y;
  double VP = x1 * y2 - x2 * y1;
  return VP;
}
Point a[maxN][3];
vector<Segment> b[maxN][3];
long long n;
bool inTriangle(Point P, int k) {
  Point A = a[k][0], B = a[k][1], C = a[k][2];
  return fabs(fabs(VP(A, B, C)) - (fabs(VP(A, B, P)) + fabs(VP(A, C, P)) +
                                   fabs(VP(B, C, P)))) < 1e-5;
}
bool intersects(Point A, Point B, Point C, Point D, Point &T) {
  if (VP(A, B, C) * VP(A, B, D) < -1e-5 && VP(C, D, A) * VP(C, D, B) < -1e-5) {
    Line p(A, B), q(C, D);
    p.intersects(q, T);
    return true;
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    a[i][0].read();
    a[i][1].read();
    a[i][2].read();
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      int next = (j + 1) % 3;
      for (int k = 0; k < n; k++) {
        if (k == i) continue;
        vector<Point> v;
        if (inTriangle(a[i][j], k)) v.push_back(a[i][j]);
        if (inTriangle(a[i][next], k)) v.push_back(a[i][next]);
        for (int l = 0; l < 3; l++) {
          int next2 = (l + 1) % 3;
          Point T;
          if (intersects(a[i][j], a[i][next], a[k][l], a[k][next2], T)) {
            v.push_back(T);
          }
        }
        if (v.size() == 2) {
          if (v[0].dist(a[i][j]) > v[1].dist(a[i][j])) swap(v[0], v[1]);
          b[i][j].push_back(Segment(v[0], v[1]));
        }
      }
    }
  }
  double ans = 0.0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < b[i][j].size(); k++) {
        for (int l = k + 1; l < b[i][j].size(); l++) {
          if (b[i][j][k].A.dist(a[i][j]) > b[i][j][l].A.dist(a[i][j])) {
            swap(b[i][j][k], b[i][j][l]);
          }
        }
      }
      Point A = a[i][j];
      Point B = a[i][(j + 1) % 3];
      double tmp = 0.0;
      for (int k = 0; k < b[i][j].size(); k++) {
        if (a[i][j].dist(b[i][j][k].A) > a[i][j].dist(A))
          tmp += A.dist(b[i][j][k].A);
        if (A.dist(a[i][j]) < b[i][j][k].B.dist(a[i][j])) {
          A = b[i][j][k].B;
        }
      }
      tmp += A.dist(B);
      ans += tmp;
    }
  }
  printf("%.6lf\n", ans);
  return 0;
}