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>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const double eps = 1e-8;
const int DIM = 110;
int n;
pair<double, double> p[DIM][4];
double ch, ans;
double an[3];
vector<double> vec;
double sqr(double q) { return q * q; }
double dist(pair<double, double> A, pair<double, double> B) {
  return sqrt(sqr(A.first - B.first) + sqr(A.second - B.second));
}
double vect(pair<double, double> A, pair<double, double> B) {
  return A.first * B.second - A.second * B.first;
}
bool inter(pair<double, double> A, pair<double, double> B,
           pair<double, double> C, pair<double, double> D) {
  pair<double, double> CA = make_pair(C.first - A.first, C.second - A.second);
  pair<double, double> BA = make_pair(B.first - A.first, B.second - A.second);
  pair<double, double> DC = make_pair(D.first - C.first, D.second - C.second);
  double zn = vect(BA, DC);
  if (abs(zn) < eps) return false;
  ch = vect(CA, DC);
  ch /= zn;
  return (-eps < ch && ch < 1 + eps);
}
bool inside(pair<double, double> E, int nn) {
  for (int i = (0); i < (n); i++)
    if (i != nn) {
      for (int j = (0); j < (3); j++) {
        pair<double, double> C = p[i][j];
        pair<double, double> D = p[i][j + 1];
        pair<double, double> DC =
            make_pair(D.first - C.first, D.second - C.second);
        pair<double, double> EC =
            make_pair(E.first - C.first, E.second - C.second);
        an[j] = vect(DC, EC);
      }
      bool g1 = 1, g2 = 1;
      for (int j = (0); j < (3); j++) {
        if (an[j] < eps) g1 = 0;
        if (an[j] > -eps) g2 = 0;
      }
      if (g1 || g2) return true;
    }
  return false;
}
void cut(pair<double, double> A, pair<double, double> B, int nn) {
  for (int i = (0); i < (n); i++)
    if (i != nn) {
      for (int j = (0); j < (3); j++) {
        pair<double, double> C = p[i][j];
        pair<double, double> D = p[i][j + 1];
        if (inter(C, D, A, B) && inter(A, B, C, D)) {
          vec.push_back(ch);
        }
      }
    }
}
void solve() {
  for (int i = (0); i < (n); i++) {
    for (int j = (0); j < (3); j++) {
      pair<double, double> A = p[i][j];
      pair<double, double> B = p[i][j + 1];
      vec.clear();
      cut(A, B, i);
      vec.push_back(0.0);
      vec.push_back(1.0);
      sort(vec.begin(), vec.end());
      for (int it = (0); it < ((int)(vec.size()) - 1); it++) {
        pair<double, double> C =
            make_pair(A.first + vec[it] * (B.first - A.first),
                      A.second + vec[it] * (B.second - A.second));
        pair<double, double> D =
            make_pair(A.first + vec[it + 1] * (B.first - A.first),
                      A.second + vec[it + 1] * (B.second - A.second));
        if (dist(C, D) > eps) {
          pair<double, double> E =
              make_pair((C.first + D.first) / 2, (C.second + D.second) / 2);
          if (!inside(E, i)) {
            ans += dist(C, D);
          }
        }
      }
    }
  }
  printf("%.7lf\n", ans);
}
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n); i++) {
    for (int j = (0); j < (3); j++) {
      scanf("%lf%lf", &p[i][j].first, &p[i][j].second);
    }
    p[i][3] = p[i][0];
  }
  solve();
  return 0;
}