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>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
void __never(int a) { printf("\nOPS %d", a); }
struct T {
  long long x, y;
};
long long vec(T A, T B, T C) {
  return (A.x - C.x) * (B.y - C.y) - (B.x - C.x) * (A.y - C.y);
}
double vec(T A, T B, double x, double y) {
  return ((double)A.x - x) * ((double)B.y - y) -
         ((double)B.x - x) * ((double)A.y - y);
}
double dist(double x1, double y1, double x2, double y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
struct TRI {
  T p[4];
  bool has(double x, double y) {
    double z[3];
    for (int a = (0); a <= (2); a++) z[a] = vec(p[a], p[a + 1], x, y);
    return ((z[0] < 0 && z[1] < 0 && z[2] < 0) ||
            (z[0] > 0 && z[1] > 0 && z[2] > 0));
  }
};
TRI tri[128];
bool isect(T A1, T A2, T B1, T B2) {
  long long z1 = vec(B1, A2, A1);
  long long z2 = vec(A2, B2, A1);
  long long z3 = vec(A1, B1, B2);
  long long z4 = vec(B1, A2, B2);
  if ((z1 < 0 && z2 < 0) || (z1 > 0 && z2 > 0))
    if ((z3 < 0 && z4 < 0) || (z3 > 0 && z4 > 0)) return true;
  return false;
}
pair<double, double> get_point(T A1, T A2, T B1, T B2) {
  double a11 = (double)(A2.x - A1.x);
  double a21 = (double)(A2.y - A1.y);
  double a12 = (double)(-(B2.x - B1.x));
  double a22 = (double)(-(B2.y - B1.y));
  double a13 = (double)(B1.x - A1.x);
  double a23 = (double)(B1.y - A1.y);
  double t = (a13 * a22 - a23 * a12) / (a11 * a22 - a21 * a12);
  return make_pair((double)A1.x + t * a11, (double)A1.y + t * a21);
}
int n;
void sol() {
  double ans = 0.;
  for (int a = (1); a <= (n); a++)
    for (int b = (0); b <= (2); b++) {
      vector<pair<double, double> > vec;
      vec.push_back(make_pair((double)tri[a].p[b].x, (double)tri[a].p[b].y));
      vec.push_back(
          make_pair((double)tri[a].p[b + 1].x, (double)tri[a].p[b + 1].y));
      for (int c = (1); c <= (n); c++)
        if (c != a)
          for (int d = (0); d <= (2); d++)
            if (isect(tri[a].p[b], tri[a].p[b + 1], tri[c].p[d],
                      tri[c].p[d + 1]))
              vec.push_back(get_point(tri[a].p[b], tri[a].p[b + 1], tri[c].p[d],
                                      tri[c].p[d + 1]));
      sort(vec.begin(), vec.end());
      for (int c = (0); c <= ((int)((vec).size()) - 1); c++)
        if (c != (int)((vec).size()) - 1) {
          double x = (vec[c].first + vec[c + 1].first) * 0.5;
          double y = (vec[c].second + vec[c + 1].second) * 0.5;
          bool flag = true;
          for (int d = (1); d <= (n); d++)
            if (d != a)
              if (tri[d].has(x, y)) {
                flag = false;
                break;
              }
          if (flag)
            ans += dist(vec[c].first, vec[c].second, vec[c + 1].first,
                        vec[c + 1].second);
        }
    }
  printf("%.10lf", ans);
}
int main() {
  cin >> n;
  for (int a = (1); a <= (n); a++) {
    cin >> tri[a].p[0].x >> tri[a].p[0].y >> tri[a].p[1].x >> tri[a].p[1].y >>
        tri[a].p[2].x >> tri[a].p[2].y;
    tri[a].p[3] = tri[a].p[0];
  }
  sol();
  return 0;
}