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;
struct Point {
  double x, y;
  Point() {}
  Point(double a, double b) {
    x = a;
    y = b;
  }
  double mod2() { return x * x + y * y; }
  double mod() { return sqrt(x * x + y * y); }
  double arg() { return atan2(y, x); }
  Point ort() { return Point(-y, x); }
  Point unit() {
    double k = mod();
    return Point(x / k, y / k);
  }
};
Point operator+(const Point &a, const Point &b) {
  return Point(a.x + b.x, a.y + b.y);
}
Point operator-(const Point &a, const Point &b) {
  return Point(a.x - b.x, a.y - b.y);
}
Point operator/(const Point &a, double k) { return Point(a.x / k, a.y / k); }
Point operator*(const Point &a, double k) { return Point(a.x * k, a.y * k); }
bool operator==(const Point &a, const Point &b) {
  return fabs(a.x - b.x) < 1e-8 && fabs(a.y - b.y) < 1e-8;
}
bool operator!=(const Point &a, const Point &b) { return !(a == b); }
bool operator<(const Point &a, const Point &b) {
  if (a.x != b.x) return a.x < b.x;
  return a.y < b.y;
}
double dist(const Point &A, const Point &B) {
  return hypot(A.x - B.x, A.y - B.y);
}
double cross(const Point &A, const Point &B) { return A.x * B.y - A.y * B.x; }
double dot(const Point &A, const Point &B) { return A.x * B.x + A.y * B.y; }
double area(const Point &A, const Point &B, const Point &C) {
  return cross(B - A, C - A);
}
bool isParallel(Point P1, Point P2, Point P3, Point P4) {
  return cross(P2 - P1, P4 - P3) == 0;
}
bool onSegment(Point A, Point B, Point P) {
  return abs(area(A, B, P)) < 1e-8 && P.x >= min(A.x, B.x) &&
         P.x <= max(A.x, B.x) && P.y >= min(A.y, B.y) && P.y <= max(A.y, B.y);
}
bool intersects(Point P1, Point P2, Point P3, Point P4) {
  double A1 = area(P3, P4, P1);
  double A2 = area(P3, P4, P2);
  double A3 = area(P1, P2, P3);
  double A4 = area(P1, P2, P4);
  if (((A1 > 0 && A2 < 0) || (A1 < 0 && A2 > 0)) &&
      ((A3 > 0 && A4 < 0) || (A3 < 0 && A4 > 0)))
    return true;
  else if (A1 == 0 && onSegment(P3, P4, P1))
    return true;
  else if (A2 == 0 && onSegment(P3, P4, P2))
    return true;
  else if (A3 == 0 && onSegment(P1, P2, P3))
    return true;
  else if (A4 == 0 && onSegment(P1, P2, P4))
    return true;
  else
    return false;
}
double distToIntersection(Point P1, Point P2, Point P3, Point P4) {
  double a1 = P1.x, a2 = P1.y, b1 = P2.x, b2 = P2.y;
  double m1 = P3.x, m2 = P3.y, n1 = P4.x, n2 = P4.y;
  return ((m1 - a1) * (n2 - m2) - (m2 - a2) * (n1 - m1)) /
         ((b1 - a1) * (n2 - m2) - (b2 - a2) * (n1 - m1));
}
int n;
Point P[105][3];
bool inside(int ind, Point M) {
  double A1 = area(P[ind][0], P[ind][1], M);
  double A2 = area(P[ind][1], P[ind][2], M);
  double A3 = area(P[ind][2], P[ind][0], M);
  double A4 = area(P[ind][0], P[ind][1], P[ind][2]);
  return abs(abs(A1) + abs(A2) + abs(A3) - abs(A4)) < 1e-8;
}
bool valid(Point M, int ind) {
  for (int i = 0; i < n; i++)
    if (i != ind && inside(i, M)) return 0;
  return 1;
}
int main() {
  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 3; j++) {
        int x, y;
        cin >> x >> y;
        P[i][j] = Point(x, y);
      }
    }
    vector<double> Q[n][3];
    for (int i1 = 0; i1 < n; i1++) {
      for (int j1 = 0; j1 < 3; j1++) {
        Point P1 = P[i1][j1], P2 = P[i1][(j1 + 1) % 3];
        for (int i2 = 0; i2 < n; i2++) {
          if (i1 == i2) continue;
          for (int j2 = 0; j2 < 3; j2++) {
            Point P3 = P[i2][j2], P4 = P[i2][(j2 + 1) % 3];
            if (!isParallel(P1, P2, P3, P4) && intersects(P1, P2, P3, P4))
              Q[i1][j1].push_back(distToIntersection(P1, P2, P3, P4));
          }
        }
      }
    }
    double ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 3; j++) {
        Q[i][j].push_back(0);
        Q[i][j].push_back(1);
        sort(Q[i][j].begin(), Q[i][j].end());
        for (int k = 0; k + 1 < Q[i][j].size(); k++) {
          Point M = P[i][j] + (P[i][(j + 1) % 3] - P[i][j]) *
                                  (Q[i][j][k] + Q[i][j][k + 1]) / 2.0;
          if (valid(M, i))
            ans += (Q[i][j][k + 1] - Q[i][j][k]) *
                   (P[i][(j + 1) % 3] - P[i][j]).mod();
        }
      }
    }
    printf("%.10lf\n", ans);
  }
  return 0;
}