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 long double Pi = 2 * acos(0.0);
struct pt {
  long double first, second;
  pt() : first(0), second(0) {}
  pt(long double X, long double Y) : first(X), second(Y) {}
  long double len() { return sqrtl(len2()); }
  long double len2() { return first * first + second * second; }
};
bool eq(long double a, long double b) { return fabsl(a - b) < (1e-7); }
bool lo(long double a, long double b) { return a + (1e-7) < b; }
long double deg(long double ang) { return ang * 180 / Pi; }
long double rad(long double ang) { return ang * Pi / 180; }
pt operator+(pt a, pt b) { return pt(a.first + b.first, a.second + b.second); }
pt operator-(pt a, pt b) { return pt(a.first - b.first, a.second - b.second); }
pt operator*(pt a, long double k) { return pt(k * a.first, k * a.second); }
long double operator*(pt a, pt b) {
  return a.first * b.first + a.second * b.second;
}
long double operator^(pt a, pt b) {
  return a.first * b.second - a.second * b.first;
}
bool operator<(pt a, pt b) {
  return lo(a.first, b.first) || eq(a.first, b.first) && lo(a.second, b.second);
}
bool operator==(pt a, pt b) {
  return eq(a.first, b.first) && eq(a.second, b.second);
}
bool segmentIntersectionPoint(pt a, pt b, pt c, pt d, pt& cross) {
  long double det = (b.first - a.first) * (c.second - d.second) -
                    (c.first - d.first) * (b.second - a.second);
  if (fabsl(det) < (1e-7)) return false;
  long double t1 = ((c.first - a.first) * (c.second - d.second) -
                    (c.first - d.first) * (c.second - a.second)) /
                   det;
  long double t2 = ((b.first - a.first) * (c.second - a.second) -
                    (c.first - a.first) * (b.second - a.second)) /
                   det;
  if (t1 >= -(1e-7) && t1 <= 1 + (1e-7) && t2 >= -(1e-7) && t2 <= 1 + (1e-7)) {
    cross.first = t1 * b.first + (1 - t1) * a.first;
    cross.second = t1 * b.second + (1 - t1) * a.second;
    return true;
  }
  return false;
}
bool pointInTriangle(pt z, pt a, pt b, pt c) {
  long double st = fabsl((b - a) ^ (c - a)) / 2;
  long double s0 = fabsl((a - z) ^ (b - z)) / 2;
  long double s1 = fabsl((b - z) ^ (c - z)) / 2;
  long double s2 = fabsl((c - z) ^ (a - z)) / 2;
  return fabsl(st - s0 - s1 - s2) < (1e-7);
}
int n;
pt p[100][3];
long double calc(int k, pt a, pt b) {
  vector<pair<long double, pt> > d;
  long double length = (b - a).len();
  d.push_back(make_pair(0, a));
  d.push_back(make_pair(1, b));
  for (int i = 0, _n = (n); i < _n; ++i)
    if (i != k)
      for (int j = 0, _n = (3); j < _n; ++j) {
        pt a2 = p[i][j];
        pt b2 = p[i][(j + 1) % 3];
        pt cross;
        if (segmentIntersectionPoint(a, b, a2, b2, cross)) {
          long double clength = (cross - a).len();
          d.push_back(make_pair(clength / length, cross));
        }
      }
  sort((d).begin(), (d).end());
  long double ret = 0;
  for (int i = 0, _n = ((int)((d).size()) - 1); i < _n; ++i) {
    pt lo = d[i].second;
    pt hi = d[i + 1].second;
    long double len = (hi - lo).len();
    if (len < (1e-7)) continue;
    pt c = (lo + hi) * 0.5;
    for (int j = 0, _n = (n); j < _n; ++j)
      if (j != k && pointInTriangle(c, p[j][0], p[j][1], p[j][2])) goto nxt;
    ret += len;
  nxt:;
  }
  return ret;
}
void solution() {
  scanf("%d", &n);
  for (int i = 0, _n = (n); i < _n; ++i)
    for (int j = 0, _n = (3); j < _n; ++j) {
      double a, b;
      scanf("%lf %lf", &a, &b);
      p[i][j].first = a, p[i][j].second = b;
    }
  long double ret = 0;
  for (int i = 0, _n = (n); i < _n; ++i)
    for (int j = 0, _n = (3); j < _n; ++j)
      ret += calc(i, p[i][j], p[i][(j + 1) % 3]);
  printf("%.6lf\n", (double)ret);
}
int main() {
  solution();
  return 0;
}