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 int MaxN = 1200;
const double eps = 1e-8;
int sgn(double x) { return x < -eps ? -1 : x > eps; }
struct Point {
  double x, y;
  int st;
  Point() {}
  Point(double x, double y) : x(x), y(y) {}
  Point operator+(const Point& p) const { return Point(x + p.x, y + p.y); }
  Point operator-(const Point& p) const { return Point(x - p.x, y - p.y); }
  double operator*(const Point& p) const { return x * p.y - y * p.x; }
  Point operator*(const double& d) const { return Point(x * d, y * d); }
  Point operator/(const double& d) const { return Point(x / d, y / d); }
  bool operator==(const Point& p) const {
    return sgn(x - p.x) == 0 && sgn(y - p.y) == 0;
  }
  double norm() const { return hypot(x, y); }
  bool operator<(const Point& p) const {
    if (sgn(x - p.x))
      return x < p.x;
    else if (sgn(y - p.y))
      return y < p.y;
    else
      return st < p.st;
  }
  void init() { scanf("%lf%lf", &x, &y); }
};
struct Line {
  Point a, b;
  Line() {}
  Line(const Point& a, const Point& b) : a(a), b(b) {}
} l[MaxN];
int n, ln;
bool ins(const Line& lhs, const Line& rhs) {
  return sgn((rhs.a - lhs.a) * (lhs.b - lhs.a)) *
             sgn((rhs.b - lhs.a) * (lhs.b - lhs.a)) <=
         0;
}
Point ins_point(const Line& lhs, const Line& rhs) {
  double u = (lhs.b - lhs.a) * (rhs.a - lhs.a);
  double v = (lhs.a - lhs.b) * (rhs.b - lhs.b);
  return (rhs.a * v + rhs.b * u) / (u + v);
}
int main() {
  Point t[MaxN];
  int tn, cnt;
  double ret;
  while (scanf("%d", &n) == 1) {
    ln = 0;
    ret = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 3; j++) t[j].init();
      if (sgn((t[1] - t[0]) * (t[2] - t[0])) < 0) swap(t[1], t[2]);
      for (int j = 0; j < 3; j++) l[ln++] = Line(t[j], t[(j + 1) % 3]);
    }
    for (int i = 0; i < ln; i++) {
      vector<Point> v;
      if (l[i].b < l[i].a) swap(l[i].a, l[i].b);
      l[i].a.st = -1;
      l[i].b.st = 1;
      v.push_back(l[i].a);
      v.push_back(l[i].b);
      for (int j = 0; j < ln; j += 3) {
        if (i / 3 == j / 3) continue;
        tn = 0;
        for (int k = 0; k < 3; k++) {
          if (ins(l[i], l[j + k])) t[tn++] = ins_point(l[i], l[j + k]);
        }
        if (tn > 1) {
          sort(t, t + tn);
          if (t[0] == t[tn - 1]) continue;
          t[0].st = 1;
          t[tn - 1].st = -1;
          v.push_back(t[0]);
          v.push_back(t[tn - 1]);
        }
      }
      cnt = 1;
      sort(v.begin(), v.end());
      for (vector<Point>::iterator it = v.begin(); it != v.end(); it++) {
        if (it->st == 1) {
          if (cnt == 0) {
            ret += (*it - t[0]).norm();
          }
          cnt++;
        } else
          cnt--;
        t[0] = *it;
      }
    }
    printf("%.10f\n", ret);
  }
  return 0;
}