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;
double prodesc(complex<double> p1, complex<double> p2) {
  return real(conj(p1) * p2);
}
double prodvec(complex<double> p1, complex<double> p2) {
  return imag(conj(p1) * p2);
}
double error = 0.0000000001;
int signo(double x) {
  if (x < -error) return -1;
  if (x > error) return 1;
  return 0;
}
pair<double, int> interseccion(complex<double> p1, complex<double> v1,
                               complex<double> p2, complex<double> v2) {
  complex<double> p = p1 + (prodvec(p2 - p1, v2) / prodvec(v1, v2)) * v1;
  return pair<double, int>(prodesc(v1, p - p1) / abs(v1),
                           signo(prodvec(v1, v2)));
}
bool hayinterseccion(complex<double> p1, complex<double> v1, complex<double> p2,
                     complex<double> v2, complex<double> p3,
                     complex<double> v3) {
  return (signo(prodvec(v1, p2 - p1)) != 0 and
          signo(prodvec(v1, p2 + v2 - p1)) != 0 and
          signo(prodvec(v1, p2 - p1)) != signo(prodvec(v1, p2 + v2 - p1))) or
         (signo(prodvec(v1, p2 - p1)) != 0 and
          signo(prodvec(v1, p2 + v2 - p1)) == 0 and
          signo(prodvec(v1, p3 + v3 - p1)) != 0 and
          signo(prodvec(v1, p2 - p1)) != signo(prodvec(v1, p3 + v3 - p1)));
}
complex<double> llegir() {
  double x, y;
  cin >> x >> y;
  return complex<double>(x, y);
}
int main() {
  cout.setf(ios::fixed);
  cout.precision(10);
  int n;
  cin >> n;
  vector<pair<complex<double>, complex<double> > > segmento;
  vector<int> next;
  for (int i = 0; i < n; i++) {
    complex<double> p1 = llegir();
    complex<double> p2 = llegir();
    complex<double> p3 = llegir();
    if (signo(prodvec(p2 - p1, p3 - p2)) == -1) swap(p2, p3);
    segmento.push_back(pair<complex<double>, complex<double> >(p1, p2 - p1));
    segmento.push_back(pair<complex<double>, complex<double> >(p2, p3 - p2));
    segmento.push_back(pair<complex<double>, complex<double> >(p3, p1 - p3));
    int pos = int(next.size());
    next.push_back(pos + 1);
    next.push_back(pos + 2);
    next.push_back(pos);
  }
  double total = 0;
  for (int i = 0; i < int(segmento.size()); i++) {
    pair<complex<double>, complex<double> > s = segmento[i];
    vector<pair<double, int> > inter;
    for (int j = 0; j < int(segmento.size()); j++) {
      if (i != j) {
        pair<complex<double>, complex<double> > ss = segmento[j];
        pair<complex<double>, complex<double> > sss = segmento[next[j]];
        if (hayinterseccion(s.first, s.second, ss.first, ss.second, sss.first,
                            sss.second)) {
          inter.push_back(interseccion(s.first, s.second, ss.first, ss.second));
        }
      }
    }
    double posini = 0;
    double posfin = abs(s.second);
    inter.push_back(pair<double, int>(posini, 0));
    inter.push_back(pair<double, int>(posfin, 0));
    sort(inter.begin(), inter.end());
    int count = 0;
    count = inter[0].second;
    for (int j = 1; j < int(inter.size()); j++) {
      if (count == 0 and inter[j].first > posini and
          inter[j].first < posfin + error and inter[j - 1].first < posfin and
          inter[j - 1].first > -error)
        total += inter[j].first - inter[j - 1].first;
      count += inter[j].second;
    }
  }
  cout << total << endl;
}