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 long double EPS = 1e-9;
inline long double absl(long double a) {
  if (a < 0) return -a;
  return a;
}
bool operator<(const pair<long double, long double>& a,
               const pair<long double, long double>& b) {
  if (absl(a.first - b.first) > EPS) return a.first < b.first;
  return a.second < b.second;
}
bool operator==(const pair<long double, long double>& a,
                const pair<long double, long double>& b) {
  return absl(a.first - b.first) < EPS && absl(a.second - b.second) < EPS;
}
const int NMAX = 100000;
const int INF = 1000000000;
int n;
pair<pair<long double, long double>, pair<long double, long double> > t[NMAX];
inline void makeLine(
    pair<pair<long double, long double>, pair<long double, long double> > a,
    long double& A, long double& B, long double& C) {
  A = a.first.second - a.second.second;
  B = a.second.first - a.first.first;
  C = -A * a.first.first - B * a.first.second;
}
inline bool mid(long double a, long double b, long double c) {
  return min(a, b) <= c + EPS && c <= max(a, b) + EPS;
}
inline bool mid(
    pair<pair<long double, long double>, pair<long double, long double> > a,
    pair<long double, long double> res) {
  return mid(a.first.first, a.second.first, res.first) &&
         mid(a.first.second, a.second.second, res.second);
}
vector<pair<long double, long double> > c;
inline long double dist(pair<long double, long double> a,
                        pair<long double, long double> b) {
  return sqrtl((a.first - b.first) * (a.first - b.first) +
               (a.second - b.second) * (a.second - b.second));
}
inline long double S(pair<long double, long double> a,
                     pair<long double, long double> b,
                     pair<long double, long double> c) {
  long double res = absl((a.first - b.first) * (c.second - b.second) -
                         (c.first - b.first) * (a.second - b.second));
  return res;
}
inline bool good(pair<long double, long double> a) {
  for (int i = 0; i < int(n); i++) {
    long double A, B, C;
    makeLine(t[i], A, B, C);
    if (absl(A * a.first + B * a.second + C) < EPS) {
      i += 2;
      continue;
    }
    makeLine(t[i + 1], A, B, C);
    if (absl(A * a.first + B * a.second + C) < EPS) {
      i += 2;
      continue;
    }
    makeLine(t[i + 2], A, B, C);
    if (absl(A * a.first + B * a.second + C) < EPS) {
      i += 2;
      continue;
    }
    if (absl(S(t[i].first, t[i].second, t[i + 1].second) -
             (S(t[i].first, t[i].second, a) +
              S(t[i].first, t[i + 1].second, a) +
              S(t[i].second, t[i + 1].second, a))) < EPS)
      return false;
    i += 2;
  }
  return true;
}
int main() {
  cin >> n;
  for (int i = 0; i < int(n); i++) {
    int aX, aY, bX, bY, cX, cY;
    scanf("%d %d %d %d %d %d", &aX, &aY, &bX, &bY, &cX, &cY);
    t[3 * i] = make_pair(pair<long double, long double>(aX, aY),
                         pair<long double, long double>(bX, bY));
    t[3 * i + 1] = make_pair(pair<long double, long double>(bX, bY),
                             pair<long double, long double>(cX, cY));
    t[3 * i + 2] = make_pair(pair<long double, long double>(aX, aY),
                             pair<long double, long double>(cX, cY));
  }
  n *= 3;
  for (int i = 0; i < int(n); i++)
    for (int j = 0; j < int(i); j++) {
      pair<long double, long double> res;
      long double A, B, C, A1, B1, C1;
      makeLine(t[i], A, B, C);
      makeLine(t[j], A1, B1, C1);
      if (absl(B1 * A - A1 * B) < EPS) continue;
      res.second = (A1 * C - C1 * A) / (B1 * A - A1 * B);
      res.first = (B * C1 - B1 * C) / (B1 * A - A1 * B);
      if (mid(t[i], res) && mid(t[j], res)) {
        c.push_back(res);
      }
    }
  sort((c).begin(), (c).end());
  long double res = 0;
  for (int i = 0; i < int(n); i++) {
    long double A, B, C;
    makeLine(t[i], A, B, C);
    vector<pair<long double, long double> > nc;
    for (int j = 0; j < int((int)(c).size()); j++) {
      if (absl(A * c[j].first + B * c[j].second + C) < EPS && mid(t[i], c[j]))
        nc.push_back(c[j]);
    }
    sort((nc).begin(), (nc).end());
    for (int j = 0; j < int((int)(nc).size() - 1); j++) {
      if (dist(nc[j], nc[j + 1]) > EPS &&
          good(pair<long double, long double>(
              (nc[j].first + nc[j + 1].first) / 2.0,
              (nc[j].second + nc[j + 1].second) / 2.0))) {
        res += dist(nc[j], nc[j + 1]);
      }
    }
  }
  cout.precision(10);
  cout << fixed << res << endl;
  return 0;
}