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-8;
double sqr(double x) { return x * x; }
int sgn(double x) {
  if (x < -eps) return -1;
  if (x > eps) return 1;
  return 0;
}
struct point {
  double x, y;
  point(double _x = 0, double _y = 0) { x = _x, y = _y; }
  point operator+(const point &a) { return point(x + a.x, y + a.y); }
  point operator*(const double &a) { return point(x * a, y * a); }
  friend bool operator<(const point &a, const point &b) {
    if (a.x == b.x) return a.y < b.y;
    return a.x < b.x;
  }
  void input() { scanf("%lf%lf", &x, &y); }
} p[105][8], e[800];
double dist(point a, point b) { return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)); }
int mult(point a, point b, point c) {
  return sgn((a.x - c.x) * (b.y - c.y) - (a.y - c.y) * (b.x - c.x));
}
bool inter(point a, point b, point c, point d) {
  if (min(a.x, b.x) > max(c.x, d.x) || min(a.y, b.y) > max(c.y, d.y) ||
      min(c.x, d.x) > max(a.x, b.x) || min(c.y, d.y) > max(a.y, b.y))
    return 0;
  double h, i, j, k;
  h = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
  i = (b.x - a.x) * (d.y - a.y) - (b.y - a.y) * (d.x - a.x);
  j = (d.x - c.x) * (a.y - c.y) - (d.y - c.y) * (a.x - c.x);
  k = (d.x - c.x) * (b.y - c.y) - (d.y - c.y) * (b.x - c.x);
  return h * i <= eps && j * k <= eps;
}
point intersection(point u1, point u2, point v1, point v2) {
  point ret = u1;
  double t = ((u1.x - v1.x) * (v1.y - v2.y) - (u1.y - v1.y) * (v1.x - v2.x)) /
             ((u1.x - u2.x) * (v1.y - v2.y) - (u1.y - u2.y) * (v1.x - v2.x));
  ret.x += (u2.x - u1.x) * t;
  ret.y += (u2.y - u1.y) * t;
  return ret;
}
int parallel(point u1, point u2, point v1, point v2) {
  double d = (u1.y - u2.y) * (v1.x - v2.x) - (v1.y - v2.y) * (u1.x - u2.x);
  return sgn(d) == 0;
}
bool isin(point t, int n, point p[]) {
  for (int i = 0; i < n; i++) {
    if (mult(t, p[i + 1], p[i]) * mult(t, p[i + 2], p[i + 1]) < 0) return 0;
  }
  return 1;
}
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 3; j++) p[i][j].input();
      p[i][3] = p[i][0];
      p[i][4] = p[i][1];
    }
    double ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 3; j++) {
        int m = 0;
        e[m++] = p[i][j];
        e[m++] = p[i][j + 1];
        for (int k = 0; k < n; k++) {
          if (k == i) continue;
          for (int l = 0; l < 3; l++) {
            if (!inter(p[i][j], p[i][j + 1], p[k][l], p[k][l + 1]) ||
                parallel(p[i][j], p[i][j + 1], p[k][l], p[k][l + 1]))
              continue;
            e[m++] = intersection(p[i][j], p[i][j + 1], p[k][l], p[k][l + 1]);
          }
        }
        sort(e, e + m);
        for (int k = 0; k < m - 1; k++) {
          point t = (e[k] + e[k + 1]) * 0.5;
          bool f = 1;
          for (int l = 0; l < n; l++) {
            if (l == i) continue;
            if (isin(t, 3, p[l])) f = 0;
          }
          if (f) ans += dist(e[k], e[k + 1]);
        }
      }
    }
    printf("%.10f\n", ans);
  }
}