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 INF = (int)1e9;
const int MXN = (int)2e5 + 7;
const int mod = (int)1e9 + 7;
pair<long double, long double> operator+(pair<long double, long double> p1,
                                         pair<long double, long double> p2) {
  return {p1.first + p2.first, p1.second + p2.second};
}
pair<long double, long double> operator-(pair<long double, long double> p1,
                                         pair<long double, long double> p2) {
  return {p1.first - p2.first, p1.second - p2.second};
}
pair<long double, long double> operator*(pair<long double, long double> p1,
                                         long double d) {
  return {p1.first * d, p1.second * d};
}
pair<long double, long double> operator/(pair<long double, long double> p1,
                                         long double d) {
  return {p1.first / d, p1.second / d};
}
long double operator^(pair<long double, long double> p1,
                      pair<long double, long double> p2) {
  return p1.first * p2.second - p1.second * p2.first;
}
long double operator*(pair<long double, long double> p1,
                      pair<long double, long double> p2) {
  return p1.first * p2.first + p1.second * p2.second;
}
long double norm2(pair<long double, long double> p1) { return p1 * p1; }
long double norm(pair<long double, long double> p1) { return sqrt(p1 * p1); }
pair<long double, long double> pt[MXN][3];
const long double eps = 1e-7;
int n;
int ori(const pair<long double, long double> &o,
        const pair<long double, long double> &a,
        const pair<long double, long double> &b) {
  long double ret = (a - o) ^ (b - o);
  return (ret > eps) - (ret < -eps);
}
bool banana(const pair<long double, long double> &p1,
            const pair<long double, long double> &p2,
            const pair<long double, long double> q1,
            const pair<long double, long double> q2) {
  if (((p2 - p1) ^ (q2 - q1)) == 0) {
    return false;
  }
  return (ori(p1, p2, q1) * ori(p1, p2, q2) <= 0) &&
         (ori(q1, q2, p1) * ori(q1, q2, p2) <= 0);
}
pair<long double, long double> Inter(pair<long double, long double> p1,
                                     pair<long double, long double> p2,
                                     pair<long double, long double> q1,
                                     pair<long double, long double> q2) {
  long double v1 = (p2 - p1) ^ (q1 - p1);
  long double v2 = (p2 - p1) ^ (p1 - q2);
  long double v3 = (v1 + v2);
  return q1 * (v2 / v3) + q2 * (v1 / v3);
}
bool inn(pair<long double, long double> p) {
  for (int i = 1; i <= n; i++) {
    bool ok = true;
    for (int j = 0; j < 3; j++) {
      if (ori(pt[i][j], pt[i][(j + 1) % 3], p) <= 0) {
        ok = false;
      }
    }
    if (ok) return true;
  }
  return false;
}
int main() {
  scanf("%d", &n);
  long double ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 3; j++)
      scanf("%Lf %Lf", &pt[i][j].first, &pt[i][j].second);
    if (ori(pt[i][0], pt[i][1], pt[i][2]) == -1) swap(pt[i][1], pt[i][2]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 3; j++) {
      pair<pair<long double, long double>, pair<long double, long double> >
          line1 = {pt[i][j], pt[i][(j + 1) % 3]};
      vector<pair<long double, long double> > seg;
      for (int k = 1; k <= n; k++) {
        if (i == k) continue;
        for (int l = 0; l < 3; l++) {
          pair<pair<long double, long double>, pair<long double, long double> >
              line2 = {pt[k][l], pt[k][(l + 1) % 3]};
          if (!banana(line1.first, line1.second, line2.first, line2.second))
            continue;
          pair<long double, long double> md =
              Inter(line1.first, line1.second, line2.first, line2.second);
          seg.push_back(md);
        }
      }
      seg.push_back(pt[i][j]);
      seg.push_back(pt[i][(j + 1) % 3]);
      sort(begin(seg), end(seg));
      for (int k = 0; k < ((int)(seg).size()) - 1; k++) {
        if (inn((seg[k] + seg[k + 1]) / 2))
          continue;
        else
          ans += norm(seg[k] - seg[k + 1]);
      }
    }
  }
  printf("%.7Lf\n", ans);
  return 0;
}