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;
template <class T>
int size(const T &a) {
  return int(a.size());
}
template <class T>
T sqr(const T &a) {
  return a * a;
}
struct Point {
  double x, y;
  Point() {}
  Point(double x, double y) : x(x), y(y) {}
  void scan() { scanf("%lf %lf", &x, &y); }
  Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); }
  double operator*(const Point &p) const { return x * p.y - y * p.x; }
  double operator&(const Point &p) const { return x * p.x + y * p.y; }
  Point rot() const { return Point(y, -x); }
};
const double eps = 1e-9;
const double eps2 = 1e-4;
struct Triangle {
  Point p[3];
  Point a[3];
  double c[3];
  void scan() {
    for (int i = 0; i < 3; i++) p[i].scan();
    if (p[0] * p[1] + p[1] * p[2] + p[2] * p[0] < 0) {
      swap(p[1], p[2]);
    }
    for (int i = 0; i < 3; i++) {
      a[i] = (p[(i + 1) % 3] - p[i]).rot();
      c[i] = a[i] & p[i];
    }
  }
  bool inside(const Point &p) const {
    for (int i = 0; i < 3; i++) {
      if ((a[i] & p) - c[i] > -eps) {
        return false;
      }
    }
    return true;
  }
} a[100];
double t[50000];
int sgn(double x) {
  if (x > eps2) return 1;
  if (x < -eps2) return -1;
  return 0;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    a[i].scan();
  }
  double res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      Point d = a[i].p[(j + 1) % 3] - a[i].p[j], p0 = a[i].p[j], al = d.rot();
      if (fabs(d.y) < eps2) {
        if (fabs(p0.y) < eps2 || fabs(p0.y - 1e5) < eps2) continue;
      }
      if (fabs(d.x) < eps2) {
        if (fabs(p0.x) < eps2 || fabs(p0.x - 1e5) < eps2) continue;
      }
      double cl = al & a[i].p[j];
      int u = 0;
      for (int k = 0; k < n; k++) {
        for (int z = 0; z < 3; z++) {
          Point &p1 = a[k].p[z];
          Point &p2 = a[k].p[(z + 1) % 3];
          if (sgn((al & p1) - cl) * sgn((al & p2) - cl) > 0) continue;
          Point A = a[k].a[z];
          double C = a[k].c[z];
          C -= A & p0;
          double kk = A & d;
          if (fabs(kk) < eps2) continue;
          double ct = C / kk;
          if (ct > -eps && ct < 1 + eps) {
            t[u++] = C / kk;
          }
        }
      }
      sort(t, t + u);
      double cr = 0;
      for (int i = 1; i < u; i++) {
        if (t[i] - t[i - 1] > eps) {
          double ct = (t[i] + t[i - 1]) * 0.5;
          Point p(d.x * ct + p0.x, d.y * ct + p0.y);
          bool good = 1;
          for (int k = 0; k < n; k++) {
            if (a[k].inside(p)) {
              good = 0;
              break;
            }
          }
          if (good) {
            cr += t[i] - t[i - 1];
          }
        }
      }
      res += cr * sqrt(d & d);
    }
  }
  printf("%.15lf\n", res);
  return 0;
}