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:136777216")
using namespace std;
int bits(int x) { return x == 0 ? 0 : 1 + bits(x & (x - 1)); }
const long double PI = 3.14159265358979323846;
const long double eps = 1e-12;
struct pt {
  long double x, y;
  pt() {}
  pt(long double xx, long double yy) { x = xx, y = yy; }
};
struct triangle {
  pt A, B, C;
  triangle() {}
  triangle(pt AA, pt BB, pt CC) { A = AA, B = BB, C = CC; }
};
struct line {
  double A, B, C;
};
struct segment {
  pt A, B;
  segment() {}
  segment(pt AA, pt BB) { A = AA, B = BB; }
};
long double det(long double a, long double b, long double c, long double d) {
  return a * d - b * c;
}
line get_line(pt A, pt B) {
  line ans;
  ans.A = A.y - B.y;
  ans.B = B.x - A.x;
  ans.C = -ans.A * A.x - ans.B * A.y;
  return ans;
}
bool in(long double a, long double b, double c) {
  return min(a, b) <= c + eps && c - eps <= max(a, b);
}
pt intersect(pt A, pt B, pt C, pt D) {
  line l1 = get_line(A, B);
  line l2 = get_line(C, D);
  long double check = det(l1.A, l1.B, l2.A, l2.B);
  if (check) {
    long double x = -det(l1.C, l1.B, l2.C, l2.B) * 1. / check;
    long double y = -det(l1.A, l1.C, l2.A, l2.C) * 1. / check;
    if (in(A.x, B.x, x) && in(C.x, D.x, x) && in(A.y, B.y, y) &&
        in(C.y, D.y, y))
      return pt(x, y);
  }
  return pt(PI, PI);
}
vector<triangle> tr;
bool compare_pt(pt A, pt B) { return (A.x < B.x) || (A.x == B.x && A.y < B.y); }
bool left(pt A, line CUR) {
  long double tmp = CUR.A * A.x + CUR.B * A.y + CUR.C;
  return (tmp < 0);
}
bool in_triangle(pt A, pt B, triangle X) {
  pt CUR = pt((A.x + B.x) / 2, (A.y + B.y) / 2);
  line l1 = get_line(X.A, X.B);
  line l2 = get_line(X.B, X.C);
  line l3 = get_line(X.C, X.A);
  if (left(CUR, l1) && left(CUR, l2) && left(CUR, l3)) return true;
  if (!left(CUR, l1) && !left(CUR, l2) && !left(CUR, l3)) return true;
  return false;
}
long double dist(pt A, pt B) {
  long double dx = A.x - B.x;
  long double dy = A.y - B.y;
  return sqrt(dx * dx + dy * dy);
}
long double result = 0.;
void add_result(pt X, pt Y, int ind) {
  vector<pt> cur;
  cur.push_back(X);
  for (int(i) = 0; (i) < ((int)(tr).size()); (i)++) {
    if (i == ind) continue;
    pt A = intersect(X, Y, tr[i].A, tr[i].B);
    pt B = intersect(X, Y, tr[i].B, tr[i].C);
    pt C = intersect(X, Y, tr[i].C, tr[i].A);
    if (A.x != PI && A.y != PI) cur.push_back(A);
    if (B.x != PI && B.y != PI) cur.push_back(B);
    if (C.x != PI && C.y != PI) cur.push_back(C);
  }
  cur.push_back(Y);
  sort((cur).begin(), (cur).end(), compare_pt);
  for (int(i) = 0; (i) < ((int)(cur).size() - 1); (i)++) {
    bool in = false;
    for (int(j) = 0; (j) < ((int)(tr).size()); (j)++) {
      if (j == ind) continue;
      if (in_triangle(cur[i], cur[i + 1], tr[j])) in = true;
    }
    if (!in) result += dist(cur[i], cur[i + 1]);
  }
}
void check_segm() {
  for (int(i) = 0; (i) < ((int)(tr).size()); (i)++) {
    add_result(tr[i].A, tr[i].B, i);
    add_result(tr[i].B, tr[i].C, i);
    add_result(tr[i].C, tr[i].A, i);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int(i) = 0; (i) < (n); (i)++) {
    pt A, B, C;
    cin >> A.x >> A.y >> B.x >> B.y >> C.x >> C.y;
    tr.push_back(triangle(A, B, C));
  }
  check_segm();
  cout.precision(100);
  cout << result << "\n";
  return 0;
}