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
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
template <typename first>
inline first abs(const first& a) {
  return a < 0 ? -a : a;
}
template <typename first>
inline first sqr(const first& a) {
  return a * a;
}
const long double PI = 3.1415926535897932384626433832795;
const int INF = 1000 * 1000 * 1000;
const long double EPS = 1e-9;
struct pt {
  long double x, y;
  pt(long double x = 0.0, long double y = 0.0) : x(x), y(y) {}
};
struct seg {
  pt a, b;
  int idx;
  seg(pt a, pt b, int idx = -1) : a(a), b(b), idx(idx) {}
};
inline bool goodBox(const pt& a, const seg& s) {
  if (a.x + EPS < min(s.a.x, s.b.x) || a.x > max(s.a.x, s.b.x) + EPS)
    return false;
  if (a.y + EPS < min(s.a.y, s.b.y) || a.y > max(s.a.y, s.b.y) + EPS)
    return false;
  return true;
}
inline long double det(const long double& ax, const long double& ay,
                       const long double& bx, const long double& by) {
  return ax * by - ay * bx;
}
inline bool intersect(const seg& s1, const seg& s2, pt& p) {
  long double A1 = s1.b.y - s1.a.y, B1 = s1.a.x - s1.b.x,
              C1 = -(A1 * s1.a.x + B1 * s1.a.y);
  long double A2 = s2.b.y - s2.a.y, B2 = s2.a.x - s2.b.x,
              C2 = -(A2 * s2.a.x + B2 * s2.a.y);
  long double d = det(A1, B1, A2, B2);
  if (abs(d) < EPS) return false;
  long double x = det(-C1, B1, -C2, B2) / d;
  long double y = det(A1, -C1, A2, -C2) / d;
  p = pt(x, y);
  if (!goodBox(p, s1) || !goodBox(p, s2)) return false;
  return true;
}
inline long double dist(const pt& a, const pt& b) {
  return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
}
inline long double leng(const seg& s) { return dist(s.a, s.b); }
inline bool cmpLess(const long double& a, const long double& b) {
  return a + EPS < b;
}
inline bool cmpEq(const long double& a, const long double& b) {
  return abs(a - b) < EPS;
}
inline bool cmpY(const seg& s1, const seg& s2) {
  long double mid1 = (s1.a.y + s1.b.y) / 2.0;
  long double mid2 = (s2.a.y + s2.b.y) / 2.0;
  return mid1 + EPS < mid2;
}
inline bool cmpYs(const pair<long double, int>& a,
                  const pair<long double, int>& b) {
  return a.first + EPS < b.first;
}
const int N = 300 + 13;
int n;
vector<long double> xs;
vector<seg> s;
int opened[N];
int main() {
  cin >> n;
  long double alp = 1.23478362834823;
  long double cosa = cos(alp);
  long double sina = sin(alp);
  for (int i = 0; i < int(n); i++) {
    pt p[3];
    for (int j = 0; j < int(3); j++) {
      int ax, ay;
      scanf("%d%d", &ax, &ay);
      p[j] = pt(ax, ay);
      p[j] = pt(p[j].x * cosa + p[j].y * sina, -p[j].x * sina + p[j].y * cosa);
    }
    for (int j = 0; j < int(3); j++) s.push_back(seg(p[j], p[(j + 1) % 3], i));
  }
  for (int i = 0; i < int(int((s).size())); i++) {
    xs.push_back(s[i].a.x);
    xs.push_back(s[i].b.x);
    for (int j = 0; j < int(i); j++) {
      pt p;
      if (!intersect(s[j], s[i], p)) continue;
      xs.push_back(p.x);
    }
  }
  sort((xs).begin(), (xs).end(), cmpLess);
  xs.erase(unique((xs).begin(), (xs).end(), cmpEq), xs.end());
  long double ans = 0.0;
  for (int i = 0; i < int(int((xs).size()) - 1); i++) {
    long double x1 = xs[i], x2 = xs[i + 1];
    seg s1 = seg(pt(x1, -1e6), pt(x1, 1e6));
    seg s2 = seg(pt(x2, -1e6), pt(x2, 1e6));
    vector<seg> ys;
    for (int j = 0; j < int(int((s).size())); j++) {
      seg& cur = s[j];
      if (max(cur.a.x, cur.b.x) < x1 + EPS || min(cur.a.x, cur.b.x) + EPS > x2)
        continue;
      pt p1, p2;
      assert(intersect(s1, cur, p1));
      assert(intersect(s2, cur, p2));
      ys.push_back(seg(p1, p2, s[j].idx));
    }
    sort((ys).begin(), (ys).end(), cmpY);
    int cntOp = 0;
    for (int j = 0; j < int(int((ys).size())); j++) {
      int idx = ys[j].idx;
      if (opened[idx]) {
        cntOp--;
        assert(cntOp >= 0);
        if (cntOp == 0) ans += leng(ys[j]);
      } else {
        assert(cntOp >= 0);
        if (cntOp == 0) ans += leng(ys[j]);
        cntOp++;
      }
      opened[idx] = 1 - opened[idx];
    }
    for (int j = 0; j < int(n); j++) assert(!opened[j]);
  }
  cout << setprecision(10) << fixed;
  cout << ans << endl;
  return 0;
}
