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 xx, double yy) {
    x = xx;
    y = yy;
  }
};
struct line {
  double a, b, c;
  line() {}
  line(double aa, double bb, double cc) {
    a = aa;
    b = bb;
    c = cc;
  }
};
int n, i, j, ii, jj, xx, yy, zz, kl, sum, gr;
point p[101][5], q[1000], tt;
int kol[101][4], num[1000], who[1000];
line ll[101][4];
bool u[101];
double eps, ans;
point operator-(point p1, point p2) { return point(p1.x - p2.x, p1.y - p2.y); }
line pr2t(point p1, point p2) {
  return line(p2.y - p1.y, p1.x - p2.x,
              p1.x * (p1.y - p2.y) + p1.y * (p2.x - p1.x));
}
bool peresekpr(line l1, line l2) {
  if (fabs(l1.a * l2.b - l2.a * l1.b) < eps)
    return false;
  else
    return true;
}
point tperpr(line l1, line l2) {
  return point((l1.b * l2.c - l1.c * l2.b) / (l1.a * l2.b - l1.b * l2.a),
               (l1.a * l2.c - l1.c * l2.a) / (l1.b * l2.a - l1.a * l2.b));
}
bool eq(point p1, point p2) {
  if ((fabs(p1.x - p2.x) < eps) && (fabs(p1.y - p2.y) < eps))
    return true;
  else
    return false;
}
double skal(point p1, point p2) { return p1.x * p2.x + p1.y * p2.y; }
double vect(point p1, point p2) { return p1.x * p2.y - p1.y * p2.x; }
double len(point p) { return sqrt(p.x * p.x + p.y * p.y); }
bool printotr(point p, point p1, point p2) {
  if ((eq(p, p1)) || (eq(p, p2)))
    return false;
  else if ((fabs(vect(p2 - p1, p - p1)) < eps) && (skal(p1 - p, p2 - p) < 0))
    return true;
  else
    return false;
}
bool men(int i, int j) {
  double zz = q[i].x - q[j].x;
  if (zz < -eps)
    return true;
  else if (zz > eps)
    return false;
  else
    return (q[i].y - q[j].y < -eps);
}
int main() {
  scanf("%d", &n);
  eps = 1e-4;
  for (i = 1; i <= n; i++) {
    for (ii = 1; ii <= 3; ii++) {
      scanf("%d%d", &xx, &yy);
      p[i][ii] = point(xx, yy);
    }
    p[i][4] = p[i][1];
    for (ii = 1; ii <= 3; ii++) {
      ll[i][ii] = pr2t(p[i][ii], p[i][ii + 1]);
      zz = ii + 2;
      if (zz > 3) zz -= 3;
    }
  }
  for (i = 1; i <= n; i++) {
    for (ii = 1; ii <= 3; ii++) {
      kl = 2;
      q[1] = p[i][ii];
      q[2] = p[i][ii + 1];
      num[1] = 1;
      num[2] = 2;
      for (j = 1; j <= n; j++) {
        if (i == j) continue;
        zz = 0;
        for (jj = 1; jj <= 3; jj++) {
          if (!peresekpr(ll[i][ii], ll[j][jj])) continue;
          tt = tperpr(ll[i][ii], ll[j][jj]);
          if (printotr(tt, p[j][jj], p[j][jj + 1])) {
            kl++;
            q[kl] = tt;
            num[kl] = kl;
            who[kl] = j;
            zz++;
          }
        }
        if (zz == 1) {
          for (jj = 1; jj <= 3; jj++) {
            if (!peresekpr(ll[i][ii], ll[j][jj])) continue;
            tt = tperpr(ll[i][ii], ll[j][jj]);
            if ((eq(tt, p[j][jj])) || (eq(tt, p[j][jj + 1]))) {
              kl++;
              q[kl] = tt;
              num[kl] = kl;
              who[kl] = j;
              break;
            }
          }
        }
      }
      sort(num + 1, num + kl + 1, men);
      for (j = 1; j <= n; j++) u[j] = 0;
      sum = 0;
      gr = 0;
      for (j = 1; j <= kl; j++) {
        jj = num[j];
        if ((jj == 1) || (jj == 2)) {
          gr++;
          if (gr == 2) {
            if (sum == 0) ans += len(q[jj] - q[num[j - 1]]);
            break;
          }
          if (gr == 1) continue;
        }
        if (u[who[jj]]) {
          sum--;
        } else {
          sum++;
          u[who[jj]] = true;
          if ((gr > 0) && (j > 1) && (sum == 1))
            ans += len(q[jj] - q[num[j - 1]]);
        }
      }
    }
  }
  cout.precision(30);
  cout << ans;
  return 0;
}