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 pi = 3.1415926535;
const double eps = 1e-5;
struct TP {
  double x, y;
} p[1100][5];
struct TL {
  double a, b, c;
};
TL ML(TP a, TP b) {
  TL c;
  c.a = b.y - a.y;
  c.b = a.x - b.x;
  c.c = -(c.a * b.x + c.b * b.y);
  return c;
}
bool across(TL a, TL b, TP &c) {
  if (fabs(a.b * b.a - b.b * a.a) < eps) return 0;
  c.y = (b.c * a.a - a.c * b.a) / (a.b * b.a - b.b * a.a);
  c.x = (b.c * a.b - a.c * b.b) / (a.a * b.b - b.a * a.b);
  return 1;
}
double det(TP a, TP b, TP c) {
  return (c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x);
}
double dot(TP a, TP b, TP c) {
  return (c.x - a.x) * (b.x - a.x) + (c.y - a.y) * (b.y - a.y);
}
bool online(TP a, TP b, TP c) {
  return fabs(det(a, b, c)) < eps && dot(c, a, b) < eps;
}
int a1, a2;
void IN(TP &a) {
  scanf("%d%d", &a1, &a2);
  a.x = a1, a.y = a2;
}
double sqr(double x) { return x * x; }
double dist(TP a, TP b) { return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)); }
int sgn(double a) {
  if (a > eps) return 1;
  if (a < -eps) return -1;
  return 0;
}
bool inside(TP a, int id) {
  int f = sgn(det(a, p[id][0], p[id][1]));
  if (f == 0) return 0;
  if (f != sgn(det(a, p[id][1], p[id][2])) ||
      f != sgn(det(a, p[id][2], p[id][0])))
    return 0;
  return 1;
}
vector<TP> all;
bool cmp(TP a, TP b) {
  if (fabs(a.x - b.x) < eps) return a.y < b.y;
  return a.x < b.x;
}
int n;
TP mid(TP a, TP b) {
  TP c;
  c.x = (a.x + b.x) / 2.;
  c.y = (a.y + b.y) / 2.;
  return c;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    IN(p[i][0]);
    IN(p[i][1]);
    IN(p[i][2]);
    p[i][3] = p[i][0];
  }
  double ans = 0;
  for (int i = 0; i < n; i++)
    for (int x = 0; x < 3; x++) {
      all.clear();
      all.push_back(p[i][x]);
      all.push_back(p[i][x + 1]);
      for (int j = 0; j < n; j++)
        if (i != j)
          for (int y = 0; y < 3; y++) {
            TL l1 = ML(p[i][x], p[i][x + 1]), l2 = ML(p[j][y], p[j][y + 1]);
            TP pp;
            if (across(l1, l2, pp) && online(p[i][x], p[i][x + 1], pp))
              all.push_back(pp);
          }
      sort(all.begin(), all.end(), cmp);
      for (int z = 1; z < all.size(); z++) {
        TP t = mid(all[z - 1], all[z]);
        bool flag = 1;
        for (int id = 0; id < n; id++)
          if (inside(t, id)) flag = 0;
        if (flag) ans += dist(all[z - 1], all[z]);
      }
    }
  printf("%.10f\n", ans);
}