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;
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
  os << "{" << p.first << ", " << p.second << "}";
  return os;
}
const long double eps = 10E-8l;
struct Po {
  long double x, y;
  Po(long double _x = 0, long double _y = 0) : x(_x), y(_y) {}
};
Po operator+(const Po& a, const Po& b) { return Po(a.x + b.x, a.y + b.y); }
Po operator-(const Po& a, const Po& b) { return Po(a.x - b.x, a.y - b.y); }
Po operator*(const long double a, const Po& b) { return Po(a * b.x, a * b.y); }
Po operator/(const Po& b, const long double a) { return Po(b.x / a, b.y / a); }
bool operator<(const Po& a, const Po& b) {
  if (fabs(b.x - a.x) > eps) return a.x < b.x;
  return a.y < b.y;
}
long double norm(const Po& p) { return sqrt(p.x * p.x + p.y * p.y); }
ostream& operator<<(ostream& os, const Po& p) {
  os << make_pair(p.x, p.y);
  return os;
}
int n;
Po tr[128][3];
Po otr[512][2];
Po in[512];
long double cross(const Po& a, const Po& b) { return (a.x * b.y - a.y * b.x); }
bool inTriangle(const Po tr[3], const Po& p) {
  long double cr[3];
  for (int i = 0; i < 3; ++i)
    cr[i] = cross(tr[i] - tr[(i + 1) % 3], p - tr[(i + 1) % 3]);
  return ((cr[0] > eps && cr[1] > eps && cr[2] > eps) ||
          (cr[0] < -eps && cr[1] < -eps && cr[2] < -eps));
}
Po normal(const Po& p) { return p / norm(p); }
bool in_seg(const Po a[2], const Po& p) {
  return ((a[0].x < p.x && p.x < a[1].x) || (a[1].x < p.x && p.x < a[0].x)) ||
         (a[0].y < p.y && p.y < a[1].y) || (a[1].y < p.y && p.y < a[0].y);
}
bool intersect(const Po a[2], const Po b[2], Po& p, bool first = true) {
  Po da = a[1] - a[0];
  Po db = b[1] - b[0];
  if (norm(normal(da) - normal(db)) < eps ||
      norm(normal((-1) * da) - normal(db)) < eps)
    return false;
  if (da.x == 0.0l) {
    if (!first) {
      cout << make_pair(a[0], a[1]) << make_pair(b[0], b[1]) << endl;
      cout << make_pair(da, db) << endl;
      exit(0);
    }
    return intersect(b, a, p, false);
  }
  Po c = b[0] - a[0];
  Po aa = da;
  Po bb = (-1.0l) * db;
  long double u, t;
  u = (c.y - (aa.y * c.x) / aa.x) / (bb.y - (aa.y * bb.x) / aa.x);
  p = b[0] + u * db;
  return (in_seg(a, p) && in_seg(b, p));
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 3; ++j) {
      long double xx, yy;
      cin >> xx >> yy;
      tr[i][j] = Po(xx, yy);
    }
    for (int j = 0; j < 3; ++j)
      for (int k = 0; k < 2; ++k) otr[3 * i + j][k] = tr[i][(j + k) % 3];
  }
  long double len = 0.0l;
  for (int i = 0; i < 3 * n; ++i) {
    int cnt = 0;
    for (int k = 0; k < 2; ++k) in[cnt++] = otr[i][k];
    for (int j = 0; j < 3 * n; ++j) {
      if (i == j) continue;
      Po inter;
      if (intersect(otr[i], otr[j], inter)) {
        in[cnt++] = inter;
      }
    }
    sort(in, in + cnt);
    for (int j = 1; j < cnt; ++j) {
      Po p = (in[j - 1] + in[j]) / 2.0l;
      bool inTr = false;
      for (int k = 0; k < n; ++k) {
        if (inTriangle(tr[k], p)) {
          inTr = true;
          break;
        }
      }
      if (!inTr) len += norm(in[j - 1] - in[j]);
    }
  }
  cout.precision(10);
  cout << fixed << len << endl;
  return 0;
}