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 {
  long double x, y;
  point() : x(0), y(0) {}
  point(long double x, long double y) : x(x), y(y) {}
  point operator-(const point& o) { return point(x - o.x, y - o.y); }
  long double operator*(const point& o) { return x * o.y - y * o.x; }
};
struct segment {
  point a, b;
  segment() {}
  segment(point a, point b) : a(a), b(b) {}
};
struct triangle {
  point a, b, c;
  segment sides[3];
  triangle() {}
  triangle(point a, point b, point c) : a(a), b(b), c(c) {
    sides[0] = segment(a, b);
    sides[1] = segment(b, c);
    sides[2] = segment(c, a);
  }
};
int n;
triangle triangles[110];
bool straddles(segment s1, segment s2) {
  long double a = (s1.a - s1.b) * (s2.a - s1.b);
  long double b = (s1.a - s1.b) * (s2.b - s1.b);
  long double c = (s2.a - s2.b) * (s1.a - s2.b);
  long double d = (s2.a - s2.b) * (s1.b - s2.b);
  return (a < 0 && b > 0 || a > 0 && b < 0) &&
         (c < 0 && d > 0 || c > 0 && d < 0);
}
bool inside(triangle t, point p) {
  bool s[3];
  for (int i = 3; i-- > 0;) {
    s[i] = (t.sides[i].a - t.sides[i].b) * (p - t.sides[i].b) >= 0;
  }
  if (s[0] && s[1] && s[2]) return true;
  for (int i = 3; i-- > 0;) {
    s[i] = (t.sides[i].a - t.sides[i].b) * (p - t.sides[i].b) <= 0;
  }
  return s[0] && s[1] && s[2];
}
long double uncovered(long double cov[][2], int num) {
  set<pair<long double, int> > changes;
  long double left = -1;
  changes.insert(make_pair(left, 0));
  changes.insert(make_pair(2, 1));
  while (--num >= 0) {
    long double* c = cov[num];
    bool insert_left, insert_right;
    set<pair<long double, int> >::iterator x =
        changes.lower_bound(make_pair(c[0], 0));
    x--;
    insert_left = x->second == 0;
    x++;
    while (x->first <= c[1]) changes.erase(x++);
    insert_right = x->second == 1;
    if (insert_left) changes.insert(make_pair(c[0], 1));
    if (insert_right) changes.insert(make_pair(c[1], 0));
  }
  long double sum = 0;
  for (set<pair<long double, int> >::iterator i = changes.begin();
       i != changes.end(); i++) {
    if (i->second == 0) {
      sum += i->first - left;
    } else {
      left = i->first;
    }
  }
  return 1 - sum;
}
long double lambda(segment s1, segment s2) {
  return ((s2.a - s1.a) * (s2.b - s2.a)) / ((s1.b - s1.a) * (s2.b - s2.a));
}
long double length(point p) { return sqrt(p.x * p.x + p.y * p.y); }
long double length(segment s) { return length(s.a - s.b); }
long double seg_uncov(segment s, int triangle_num) {
  long double cov[110][2];
  int num = 0;
  for (int i = 0; i < n; i++) {
    if (i == triangle_num) continue;
    int t = 0;
    if (inside(triangles[i], s.a)) {
      cov[num][t++] = 0;
    }
    if (inside(triangles[i], s.b)) {
      cov[num][t++] = 1;
    }
    for (int k = 0; k < 3; k++) {
      if (straddles(s, triangles[i].sides[k])) {
        cov[num][t++] = lambda(s, triangles[i].sides[k]);
      }
    }
    if (t == 2 && cov[num][0] != cov[num][1]) {
      sort(cov[num], cov[num] + 2);
      num++;
    }
  }
  return uncovered(cov, num) * length(s);
}
long double getPeri() {
  long double sum = 0;
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < 3; k++) {
      sum += seg_uncov(triangles[i].sides[k], i);
    }
  }
  return sum;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int ax, ay, bx, by, cx, cy;
    scanf("%d%d%d%d%d%d", &ax, &ay, &bx, &by, &cx, &cy);
    triangles[i] = triangle(point(ax, ay), point(bx, by), point(cx, cy));
  }
  printf("%f", (double)getPeri());
  return 0;
}