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:16777216")
using namespace std;
const double Pi = 2 * acos(0.0);
struct pt {
  double first, second;
  pt() : first(0), second(0) {}
  pt(double X, double Y) : first(X), second(Y) {}
  double len() { return sqrt(len2()); }
  double len2() { return first * first + second * second; }
};
bool eq(double a, double b) { return fabs(a - b) < (1e-6); }
bool lo(double a, double b) { return a + (1e-6) < b; }
double deg(double ang) { return ang * 180 / Pi; }
double rad(double ang) { return ang * Pi / 180; }
pt operator+(pt a, pt b) { return pt(a.first + b.first, a.second + b.second); }
pt operator-(pt a, pt b) { return pt(a.first - b.first, a.second - b.second); }
pt operator*(pt a, double k) { return pt(k * a.first, k * a.second); }
double operator*(pt a, pt b) { return a.first * b.first + a.second * b.second; }
double operator^(pt a, pt b) { return a.first * b.second - a.second * b.first; }
bool operator<(pt a, pt b) {
  return lo(a.first, b.first) || eq(a.first, b.first) && lo(a.second, b.second);
}
bool operator==(pt a, pt b) {
  return eq(a.first, b.first) && eq(a.second, b.second);
}
bool segmentIntersectionPoint(pt a, pt b, pt c, pt d, pt& cross) {
  double det = (b.first - a.first) * (c.second - d.second) -
               (c.first - d.first) * (b.second - a.second);
  if (fabs(det) < (1e-6)) return false;
  double t1 = ((c.first - a.first) * (c.second - d.second) -
               (c.first - d.first) * (c.second - a.second)) /
              det;
  double t2 = ((b.first - a.first) * (c.second - a.second) -
               (c.first - a.first) * (b.second - a.second)) /
              det;
  if (t1 >= -(1e-6) && t1 <= 1 + (1e-6) && t2 >= -(1e-6) && t2 <= 1 + (1e-6)) {
    cross.first = t1 * b.first + (1 - t1) * a.first;
    cross.second = t1 * b.second + (1 - t1) * a.second;
    return true;
  }
  return false;
}
bool segmentIntersectionPointMY(pt a, pt b, pt c, pt d, pt& cross) {
  double A1 = a.second - b.second, A2 = c.second - d.second;
  double B1 = b.first - a.first, B2 = d.first - c.first;
  double C1 = -(A1 * a.first + B1 * a.second),
         C2 = -(A2 * c.first + B2 * c.second);
  double d0 = A1 * B2 - A2 * B1;
  if (fabs(d0) < (1e-6)) return false;
  double d1 = -(C1 * B2 - B1 * C2);
  double d2 = -(A1 * C2 - C1 * A2);
  cross.first = d1 / d0;
  cross.second = d2 / d0;
  if (cross.first >= min(a.first, b.first) - (1e-6) &&
      cross.first <= max(a.first, b.first) + (1e-6) &&
      cross.second >= min(a.second, b.second) - (1e-6) &&
      cross.second <= max(a.second, b.second) + (1e-6) &&
      cross.first >= min(c.first, d.first) - (1e-6) &&
      cross.first <= max(c.first, d.first) + (1e-6) &&
      cross.second >= min(c.second, d.second) - (1e-6) &&
      cross.second <= max(c.second, d.second) + (1e-6)) {
    return true;
  }
  return false;
}
bool pointInTriangle(pt z, pt a, pt b, pt c) {
  double st = fabs((b - a) ^ (c - a)) / 2;
  double s0 = fabs((a - z) ^ (b - z)) / 2;
  double s1 = fabs((b - z) ^ (c - z)) / 2;
  double s2 = fabs((c - z) ^ (a - z)) / 2;
  return fabs(st - s0 - s1 - s2) < (1e-6);
}
int n;
pt p[100][3];
double calc(int k, pt a, pt b) {
  vector<pair<double, pt> > d;
  double length = (b - a).len();
  d.push_back(make_pair(0, a));
  d.push_back(make_pair(1, b));
  for (int i = 0, _n = (n); i < _n; ++i)
    if (i != k)
      for (int j = 0, _n = (3); j < _n; ++j) {
        pt a2 = p[i][j];
        pt b2 = p[i][(j + 1) % 3];
        pt cross;
        if (segmentIntersectionPoint(a, b, a2, b2, cross)) {
          double clength = (cross - a).len();
          d.push_back(make_pair(clength / length, cross));
        }
      }
  sort((d).begin(), (d).end());
  double ret = 0;
  for (int i = 0, _n = ((int)((d).size()) - 1); i < _n; ++i) {
    pt lo = d[i].second;
    pt hi = d[i + 1].second;
    double len = (hi - lo).len();
    if (len < (1e-6)) continue;
    pt c = (lo + hi) * 0.5;
    for (int j = 0, _n = (n); j < _n; ++j)
      if (j != k && pointInTriangle(c, p[j][0], p[j][1], p[j][2])) goto nxt;
    ret += len;
  nxt:;
  }
  return ret;
}
void solution() {
  scanf("%d", &n);
  for (int i = 0, _n = (n); i < _n; ++i)
    for (int j = 0, _n = (3); j < _n; ++j)
      scanf("%lf %lf", &p[i][j].first, &p[i][j].second);
  double ret = 0;
  for (int i = 0, _n = (n); i < _n; ++i)
    for (int j = 0, _n = (3); j < _n; ++j)
      ret += calc(i, p[i][j], p[i][(j + 1) % 3]);
  printf("%.6lf\n", ret);
}
int main() {
  solution();
  return 0;
}