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;
const int Maxn = 300;
const long double sm = 0.0001;
int n;
pair<pair<long double, long double>, pair<long double, long double> > seg[Maxn];
set<pair<long double, long double> > dots[Maxn];
long double ans;
long double LL(const pair<pair<long double, long double>,
                          pair<long double, long double> > &p) {
  return sqrt(
      (p.first.first - p.second.first) * (p.first.first - p.second.first) +
      (p.first.second - p.second.second) * (p.first.second - p.second.second));
}
long double TP(long double a, long double b, long double c) {
  long double p = (a + b + c) / 2;
  return sqrt(p) * sqrt(p - a) * sqrt(p - b) * sqrt(p - c);
}
bool isIn(long double x, long double y, int num) {
  pair<long double, long double> p = make_pair(x, y);
  long double second =
      TP(LL(seg[3 * num]), LL(seg[3 * num + 1]), LL(seg[3 * num + 2]));
  long double s1 = TP(LL(seg[3 * num]), LL(make_pair(p, seg[3 * num].first)),
                      LL(make_pair(p, seg[3 * num].second)));
  long double s2 =
      TP(LL(seg[3 * num + 1]), LL(make_pair(p, seg[3 * num + 1].first)),
         LL(make_pair(p, seg[3 * num + 1].second)));
  long double s3 =
      TP(LL(seg[3 * num + 2]), LL(make_pair(p, seg[3 * num + 2].first)),
         LL(make_pair(p, seg[3 * num + 2].second)));
  return fabs(second - s1 - s2 - s3) < sm;
}
int main() {
  long double p[6], num, den, a, b;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) cin >> p[j];
    seg[3 * i] = make_pair(make_pair(p[0], p[1]), make_pair(p[2], p[3]));
    dots[3 * i].insert(make_pair(p[0], p[1]));
    dots[3 * i].insert(make_pair(p[2], p[3]));
    seg[3 * i + 1] = make_pair(make_pair(p[0], p[1]), make_pair(p[4], p[5]));
    dots[3 * i + 1].insert(make_pair(p[0], p[1]));
    dots[3 * i + 1].insert(make_pair(p[4], p[5]));
    seg[3 * i + 2] = make_pair(make_pair(p[2], p[3]), make_pair(p[4], p[5]));
    dots[3 * i + 2].insert(make_pair(p[2], p[3]));
    dots[3 * i + 2].insert(make_pair(p[4], p[5]));
  }
  for (int i = 0; i < 3 * n; i++)
    for (int j = 0; j < 3 * n; j++) {
      long double num, den;
      num = (seg[j].first.first - seg[i].first.first) *
                (seg[i].second.second - seg[i].first.second) -
            (seg[j].first.second - seg[i].first.second) *
                (seg[i].second.first - seg[i].first.first);
      den = (seg[i].second.first - seg[i].first.first) *
                (seg[j].second.second - seg[j].first.second) -
            (seg[i].second.second - seg[i].first.second) *
                (seg[j].second.first - seg[j].first.first);
      if (fabs(den) < sm) continue;
      b = num / den;
      if (b < 0 || b > 1) continue;
      num = seg[j].first.first - seg[i].first.first +
            (seg[j].second.first - seg[j].first.first) * b;
      den = seg[i].second.first - seg[i].first.first;
      if (fabs(den) < sm) continue;
      a = num / den;
      if (a < 0 || a > 1) continue;
      dots[i].insert(make_pair(
          seg[i].first.first + (seg[i].second.first - seg[i].first.first) * a,
          seg[i].first.second +
              (seg[i].second.second - seg[i].first.second) * a));
      dots[j].insert(make_pair(
          seg[i].first.first + (seg[i].second.first - seg[i].first.first) * a,
          seg[i].first.second +
              (seg[i].second.second - seg[i].first.second) * a));
    }
  for (int i = 0; i < 3 * n; i++) {
    set<pair<long double, long double> >::iterator lit, it;
    it = dots[i].begin();
    lit = it++;
    for (; it != dots[i].end(); lit++, it++) {
      a = (lit->first + it->first) / 2.;
      b = (lit->second + it->second) / 2.;
      int j;
      for (j = 0; j < n; j++)
        if (j != i / 3)
          if (isIn(a, b, j)) break;
      if (j == n)
        ans += sqrt((it->first - lit->first) * (it->first - lit->first) +
                    (it->second - lit->second) * (it->second - lit->second));
    }
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}