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 double EPS = 1e-9;
int sgn(double x) {
  if (fabs(x) < EPS) return 0;
  return x > 0 ? 1 : -1;
}
struct point {
  double x, y;
  point() : x(0), y(0) {}
  point(double a, double b) : x(a), y(b) {}
  point operator-(const point &b) const { return point(x - b.x, y - b.y); }
  point operator+(const point &b) const { return point(x + b.x, y + b.y); }
  double operator*(const point &b) const { return x * b.y - y * b.x; }
  double dis(const point &b) const {
    return sqrt((x - b.x) * (x - b.x) + (y - b.y) * (y - b.y));
  }
};
struct hplane {
  point s, t;
  point cross(const hplane &b) const {
    double s1 = (b.t - s) * (b.s - s);
    double s2 = (b.s - t) * (b.t - t);
    return point((s.x * s2 + t.x * s1) / (s2 + s1),
                 (s.y * s2 + t.y * s1) / (s2 + s1));
  }
};
bool cross(hplane l1, hplane l2) {
  double s1 = (l2.t - l1.s) * (l2.s - l1.s);
  double s2 = (l2.s - l1.t) * (l2.t - l1.t);
  if (sgn(s1 + s2) == 0) return false;
  double num1 = (l2.s - l1.s) * (l2.t - l1.s);
  double num2 = (l2.s - l1.t) * (l2.t - l1.t);
  if (sgn(num1 * num2) > 0) return false;
  num1 = (l1.s - l2.s) * (l1.t - l2.s);
  num2 = (l1.s - l2.t) * (l1.t - l2.t);
  if (sgn(num1 * num2) > 0) return false;
  return true;
}
point p[110][10], num[100010];
point POINT;
bool cmp(const point &a, const point &b) { return a.dis(POINT) < b.dis(POINT); }
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 3; j++) scanf("%lf%lf", &p[i][j].x, &p[i][j].y);
      p[i][3] = p[i][0];
    }
    double ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 3; j++) {
        int cnt = 0;
        num[cnt++] = p[i][j];
        num[cnt++] = p[i][j + 1];
        for (int k = 0; k < n; k++) {
          if (k == i) continue;
          for (int l = 0; l < 3; l++) {
            hplane l1, l2;
            l1.s = p[i][j];
            l1.t = p[i][j + 1];
            l2.s = p[k][l];
            l2.t = p[k][l + 1];
            if (cross(l1, l2)) num[cnt++] = l1.cross(l2);
          }
        }
        POINT = p[i][j];
        sort(num, num + cnt, cmp);
        for (int k = 0; k < cnt - 1; k++) {
          point p1 = num[k] + num[k + 1];
          p1.x /= 2;
          p1.y /= 2;
          bool ok = true;
          for (int l = 0; l < n; l++) {
            if (l == i) continue;
            double tnum[5];
            for (int m = 0; m < 3; m++)
              tnum[m] = (p[l][m] - p1) * (p[l][m + 1] - p1);
            tnum[3] = tnum[0];
            ok = false;
            for (int m = 0; m < 3; m++)
              if (sgn(tnum[m] * tnum[m + 1]) <= 0) ok = true;
            if (!ok) break;
          }
          if (ok) ans += num[k].dis(num[k + 1]);
        }
      }
    }
    printf("%.15f\n", ans);
  }
  return 0;
}