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;
inline double det(double a, double b, double c, double d) {
  return a * d - b * c;
}
int n;
struct line {
  double a, b, c;
  line() {}
  line(complex<double> p, complex<double> q) {
    a = q.imag() - p.imag();
    b = p.real() - q.real();
    c = p.real() * a + p.imag() * b;
  }
};
vector<line> L;
vector<double> H;
void cross(const line &p, const line &q) {
  double d = det(p.a, p.b, q.a, q.b);
  if (fabs(d) < 1e-9) return;
  H.push_back(det(p.a, p.c, q.a, q.c) / d);
}
struct event {
  double x0, x1;
  int id;
};
bool operator<(const event &p, const event &q) {
  return p.x0 + p.x1 < q.x0 + q.x1;
}
const double eps = 1e-9;
double first(const complex<double> &p, const complex<double> &q, double y) {
  return p.real() +
         (q.real() - p.real()) * (y - p.imag()) / (q.imag() - p.imag());
}
struct triangle {
  complex<double> p[3];
  void read() {
    for (int i(0); i < 3; ++i) {
      double x, y;
      cin >> x >> y;
      p[i] = complex<double>(x, y) * polar(1.0, 0.123456789);
      H.push_back(p[i].imag());
    }
    for (int i(0); i < 3; ++i) {
      int j = (i + 1) % 3;
      L.push_back(line(p[i], p[j]));
    }
  }
  void f(double y0, double y1, vector<event> &e, int id) {
    for (int i(0); i < 3; ++i) {
      complex<double> P = p[i], Q = p[(i + 1) % 3];
      if (P.imag() > Q.imag()) swap(P, Q);
      if (P.imag() <= y0 + eps && Q.imag() >= y1 - eps) {
        event q;
        q.id = id;
        q.x0 = first(P, Q, y0);
        q.x1 = first(P, Q, y1);
        e.push_back(q);
      }
    }
  }
} t[111];
double d2(double x, double y) { return sqrt(x * x + y * y); }
int main() {
  cin >> n;
  for (int i(0); i < n; ++i) t[i].read();
  for (int j(0); j < int((L).size()); ++j)
    for (int i(0); i < j; ++i) cross(L[i], L[j]);
  sort((H).begin(), (H).end()),
      (H).erase(unique((H).begin(), (H).end()), (H).end());
  double res = 0;
  for (int i(1); i < int((H).size()); ++i) {
    double y0 = H[i - 1], y1 = H[i];
    if (y1 - y0 > 1e-9) {
      vector<event> e;
      for (int j(0); j < n; ++j) t[j].f(y0, y1, e, j);
      sort((e).begin(), (e).end());
      int k = 0;
      vector<bool> u(n);
      for (vector<event>::iterator j = e.begin(); j != e.end(); ++j) {
        if (u[j->id]) {
          if (--k == 0) res += d2(j->x0 - j->x1, y1 - y0);
        } else {
          u[j->id] = true;
          if (k++ == 0) res += d2(j->x0 - j->x1, y1 - y0);
        }
      }
    }
  }
  printf("%.12lf\n", res);
  return 0;
}