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>
const long double PI = acos(-1);
const long double eps = 0.000000001;
const long long INF = 0x3fffffffffffffff;
long double sqr(long double x) { return x * x; }
bool eq(long double A, long double B) {
  return fabs(A - B) / std::max(1.0l, B) <= eps;
}
struct point {
  long double x, y;
  friend point operator+(const point &A, const point &B) {
    return {A.x + B.x, A.y + B.y};
  }
  friend point operator-(const point &A, const point &B) {
    return {A.x - B.x, A.y - B.y};
  }
  point operator*(const long double &V) { return {x * V, y * V}; }
  friend bool operator<(const point &A, const point &B) {
    return eq(A.x, B.x) ? A.y < B.y : A.x < B.x;
  }
  friend bool operator==(const point &A, const point &B) {
    return eq(A.x, B.x) && eq(A.y, B.y);
  }
  friend bool operator<=(const point &A, const point &B) { return !(B < A); }
  friend long double dis(const point &A, const point &B) {
    return sqrt(sqr(A.x - B.x) + sqr(A.y - B.y));
  }
};
struct segment {
  point p[2];
};
long double cross(const point &A, const point &B) {
  return A.x * B.y - A.y * B.x;
}
struct triangle {
  point p[3];
  long double area() const {
    return fabsl(cross(p[1] - p[0], p[2] - p[0])) / 2;
  }
} a[305];
std::vector<segment> seg;
long long n;
long double ans;
bool meet(segment A, segment B) {
  return std::max(std::min(A.p[0].x, A.p[1].x), std::min(B.p[0].x, B.p[1].x)) <=
             std::min(std::max(A.p[0].x, A.p[1].x),
                      std::max(B.p[0].x, B.p[1].x)) &&
         std::max(std::min(A.p[0].y, A.p[1].y), std::min(B.p[0].y, B.p[1].y)) <=
             std::min(std::max(A.p[0].y, A.p[1].y),
                      std::max(B.p[0].y, B.p[1].y)) &&
         cross(A.p[0] - B.p[0], B.p[1] - B.p[0]) *
                 cross(A.p[1] - B.p[0], B.p[1] - B.p[0]) <=
             0 &&
         cross(B.p[0] - A.p[0], A.p[1] - A.p[0]) *
                 cross(B.p[1] - A.p[0], A.p[1] - A.p[0]) <=
             0;
}
bool on(segment A, point B) {
  return eq(cross(A.p[1] - A.p[0], B - A.p[0]), 0) &&
         std::min(A.p[0], A.p[1]) <= B && B <= std::max(A.p[0], A.p[1]);
}
point inter(segment A, segment B) {
  return A.p[0] + (A.p[1] - A.p[0]) * (cross(B.p[1] - B.p[0], A.p[0] - B.p[0]) /
                                       cross(A.p[1] - A.p[0], B.p[1] - B.p[0]));
}
bool in(triangle A, point B) {
  return eq(triangle{A.p[0], A.p[1], B}.area() +
                triangle{A.p[1], A.p[2], B}.area() +
                triangle{A.p[2], A.p[0], B}.area(),
            A.area());
}
bool check(segment x) {
  for (long long i = 0; i != n; ++i)
    if (in(a[i], x.p[0]) && in(a[i], x.p[1])) {
      bool flag = false;
      for (long long j = 0; j != 3; ++j)
        if (on({a[i].p[j], a[i].p[(j + 1) % 3]}, x.p[0]) &&
            on({a[i].p[j], a[i].p[(j + 1) % 3]}, x.p[1]))
          flag = true;
      if (!flag) return false;
    }
  return true;
}
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin >> n;
  std::cout << std::fixed << std::setprecision(20);
  for (long long i = 0; i != n; ++i) {
    for (long long j = 0; j != 3; ++j) std::cin >> a[i].p[j].x >> a[i].p[j].y;
    for (long long j = 0; j != 3; ++j)
      seg.push_back({a[i].p[j], a[i].p[(j + 1) % 3]});
  }
  for (long long i = 0; i != (long long)seg.size(); ++i) {
    std::vector<point> p;
    for (long long j = 0; j != (long long)seg.size(); ++j) {
      if (i == j) continue;
      if (meet(seg[i], seg[j])) {
        point tmp = inter(seg[i], seg[j]);
        if (tmp.x != tmp.x || tmp.y != tmp.y)
          ;
        else
          p.push_back(tmp);
      }
    }
    p.push_back(seg[i].p[0]);
    p.push_back(seg[i].p[1]);
    std::sort(p.begin(), p.end());
    p.erase(std::unique(p.begin(), p.end()), p.end());
    for (long long j = 1; j != (long long)p.size(); ++j)
      if (check({p[j - 1], p[j]})) ans += dis(p[j - 1], p[j]);
  }
  std::cout << ans << std::endl;
  return 0;
}