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 = 110;
const double EPS = 1E-10;
struct TTriangle {
  double x[3], y[3];
} a[MaxN];
struct TSeg {
  double x[2], y[2];
} Seg[MaxN * 3];
int n, Total;
double Ans;
pair<double, int> s[MaxN * 3 * 2];
inline double Cross(const double x1, const double y1, const double x2,
                    const double y2) {
  return x1 * y2 - x2 * y1;
}
inline bool Equal(const TTriangle &a, const TTriangle &b) {
  return a.x[0] == b.x[0] && a.y[0] == b.y[0] && a.x[1] == b.x[1] &&
             a.y[1] == b.y[1] && a.x[2] == b.x[2] && a.y[2] == b.y[2] ||
         a.x[0] == b.x[1] && a.y[0] == b.y[1] && a.x[1] == b.x[2] &&
             a.y[1] == b.y[2] && a.x[2] == b.x[0] && a.y[2] == b.y[0] ||
         a.x[0] == b.x[2] && a.y[0] == b.y[2] && a.x[1] == b.x[0] &&
             a.y[1] == b.y[0] && a.x[2] == b.x[1] && a.y[2] == b.y[1];
}
void Init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lf%lf%lf%lf%lf%lf", &a[i].x[0], &a[i].y[0], &a[i].x[1], &a[i].y[1],
          &a[i].x[2], &a[i].y[2]);
    if (Cross(a[i].x[1] - a[i].x[0], a[i].y[1] - a[i].y[0],
              a[i].x[2] - a[i].x[0], a[i].y[2] - a[i].y[0]) < -EPS) {
      swap(a[i].x[1], a[i].x[2]);
      swap(a[i].y[1], a[i].y[2]);
    }
    for (int j = 1; j < i; ++j)
      if (Equal(a[i], a[j])) {
        --i, --n;
        break;
      }
  }
  for (int i = 1; i <= n; ++i) {
    Seg[i * 3 - 2].x[0] = a[i].x[0], Seg[i * 3 - 2].y[0] = a[i].y[0],
                Seg[i * 3 - 2].x[1] = a[i].x[1],
                Seg[i * 3 - 2].y[1] = a[i].y[1];
    Seg[i * 3 - 1].x[0] = a[i].x[1], Seg[i * 3 - 1].y[0] = a[i].y[1],
                Seg[i * 3 - 1].x[1] = a[i].x[2],
                Seg[i * 3 - 1].y[1] = a[i].y[2];
    Seg[i * 3].x[0] = a[i].x[2], Seg[i * 3].y[0] = a[i].y[2],
            Seg[i * 3].x[1] = a[i].x[0], Seg[i * 3].y[1] = a[i].y[0];
  }
}
inline bool Check(const TSeg &a, const TSeg &b) {
  return Cross(b.x[0] - a.x[0], b.y[0] - a.y[0], b.x[1] - a.x[0],
               b.y[1] - a.y[0]) *
             Cross(b.x[0] - a.x[1], b.y[0] - a.y[1], b.x[1] - a.x[1],
                   b.y[1] - a.y[1]) <
         EPS;
}
inline double GetRatio(const TSeg &a, const TSeg &b) {
  const double u = Cross(a.x[1] - a.x[0], a.y[1] - a.y[0], b.x[0] - a.x[0],
                         b.y[0] - a.y[0]),
               v = u + Cross(b.x[1] - a.x[0], b.y[1] - a.y[0], a.x[1] - a.x[0],
                             a.y[1] - a.y[0]);
  return u / v;
}
inline void Calc(const TSeg &a, const TSeg &b, const TSeg &c) {
  if (Check(a, c) && Check(b, c)) {
    double l = GetRatio(a, c), r = GetRatio(b, c);
    if (l > r) swap(l, r);
    l = (l > (double)0 ? l : (double)0);
    l = (l < (double)1 ? l : (double)1);
    r = (r > (double)0 ? r : (double)0);
    r = (r < (double)1 ? r : (double)1);
    if (fabs(l - r) < EPS) return;
    s[++Total] = make_pair(l, -1);
    s[++Total] = make_pair(r, 1);
  }
}
inline pair<double, double> RatioToVertex(const TSeg &a, const double &k) {
  return make_pair(a.x[0] + (a.x[1] - a.x[0]) * k,
                   a.y[0] + (a.y[1] - a.y[0]) * k);
}
int main() {
  Init();
  double l;
  pair<double, double> p1, p2;
  for (int i = 1, j, k; i <= n * 3; ++i) {
    for (j = 1, Total = 0; j <= n; ++j)
      if ((i - 1) / 3 + 1 != j) {
        Calc(Seg[j * 3 - 2], Seg[j * 3 - 1], Seg[i]);
        Calc(Seg[j * 3 - 1], Seg[j * 3], Seg[i]);
        Calc(Seg[j * 3], Seg[j * 3 - 2], Seg[i]);
      }
    sort(s + 1, s + Total + 1);
    s[++Total] = make_pair((double)1, 0);
    for (j = 1, k = 0; j <= Total; ++j) {
      if (!k) {
        p1 = RatioToVertex(Seg[i], s[j - 1].first);
        p2 = RatioToVertex(Seg[i], s[j].first);
        Ans += sqrt(((p1.first - p2.first) * (p1.first - p2.first)) +
                    ((p1.second - p2.second) * (p1.second - p2.second)));
      }
      k -= s[j].second;
    }
  }
  cout << setprecision(10) << fixed << Ans << endl;
  return 0;
}