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;
const double eps = 1e-5;
int cmp(double x) {
  if (fabs(x) <= eps) return 0;
  return (x > eps) ? 1 : -1;
}
struct node {
  double x, y;
  int operator<(const node &o) const {
    return cmp(x - o.x) < 0 || cmp(x - o.x) == 0 && cmp(y - o.y) < 0;
  }
};
struct line {
  node a, b;
  vector<node> online;
};
node trian[1010][4];
line a[400];
int n, tot = 0;
void make(node x, node y) {
  a[++tot].a = x;
  a[tot].b = y;
  a[tot].online.clear();
  a[tot].online.push_back(x);
  a[tot].online.push_back(y);
}
void get(node m1, node m2, double &a1, double &b1, double &c1) {
  a1 = m1.y - m2.y;
  b1 = m2.x - m1.x;
  c1 = m1.x * m2.y - m2.x * m1.y;
}
node getcross(double a1, double b1, double c1, double a2, double b2,
              double c2) {
  node ans;
  ans.x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
  ans.y = (a1 * c2 - a2 * c1) / (b1 * a2 - b2 * a1);
  return ans;
}
int Online(node a, line v) {
  if (cmp(a.x - min(v.a.x, v.b.x)) < 0 || cmp(a.x - max(v.a.x, v.b.x)) > 0)
    return 0;
  if (cmp(a.y - min(v.a.y, v.b.y)) < 0 || cmp(a.y - max(v.a.y, v.b.y)) > 0)
    return 0;
  return 1;
}
double det(node a, node b, node c) {
  return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
}
int inside(node v, int i) {
  node a = trian[i][1], b = trian[i][2], c = trian[i][3];
  double a1 = fabs(det(v, a, b)) + fabs(det(v, b, c)) + fabs(det(v, c, a));
  double a2 = fabs(det(a, b, c));
  if (!cmp(a1 - a2))
    return 1;
  else
    return 0;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 3; j++) cin >> trian[i][j].x >> trian[i][j].y;
    make(trian[i][1], trian[i][2]);
    make(trian[i][1], trian[i][3]);
    make(trian[i][2], trian[i][3]);
  }
  for (int i = 1; i <= tot; i++)
    for (int j = i + 1; j <= tot; j++) {
      double a1, a2, b1, b2, c1, c2;
      get(a[i].a, a[i].b, a1, b1, c1);
      get(a[j].a, a[j].b, a2, b2, c2);
      if (cmp(a1 * b2 - a2 * b1)) {
        node cross = getcross(a1, b1, c1, a2, b2, c2);
        if (Online(cross, a[i]) && Online(cross, a[j]))
          a[i].online.push_back(cross), a[j].online.push_back(cross);
      }
    }
  double ans = 0.0;
  for (int i = 1; i <= tot; i++) {
    vector<node> v = a[i].online;
    sort(v.begin(), v.end());
    for (int j = 1; j < v.size(); j++) {
      int flag = 1;
      for (int k = 1; k <= n; k++) {
        if ((k - 1) * 3 < i && i <= k * 3) continue;
        if (inside(v[j], k) && inside(v[j - 1], k)) {
          flag = 0;
          break;
        }
      }
      if (flag) ans += hypot(v[j].x - v[j - 1].x, v[j].y - v[j - 1].y);
    }
  }
  printf("%.10lf\n", ans);
  return 0;
}