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;
long double ANS;
struct point {
  long double x, y;
  point(long double _x = 0, long double _y = 0) {
    x = _x;
    y = _y;
  }
  point operator-(point w) { return point(x - w.x, y - w.y); }
  point operator+(point w) { return point(x + w.x, y + w.y); }
  long double MOD() { return sqrt(x * x + y * y); }
  bool operator<(const point& w) const {
    return (abs(x - w.x) > 1E-9 ? x < w.x : y < w.y);
  }
  void read() {
    double _x, _y;
    scanf("%lf%lf", &_x, &_y);
    x = _x;
    y = _y;
  }
};
long double vp(point a, point b) { return (a.x * b.y - a.y * b.x); }
int ORI(point a, point b) {
  long double VP = vp(a, b);
  return (abs(VP) < 1E-6 ? 0 : (VP > 0 ? 1 : -1));
}
bool intersect(point f1, point t1, point f2, point t2) {
  if (ORI(f2 - f1, t1 - f1) * ORI(t2 - f1, t1 - f1) > 0) return false;
  if (ORI(f1 - f2, t2 - f2) * ORI(t1 - f2, t2 - f2) > 0) return false;
  return true;
}
struct prava {
  long double a, b, c;
  prava(point f = point(0, 0), point s = point(1, 1)) {
    a = s.y - f.y;
    b = f.x - s.x;
    c = s.x * f.y - f.x * s.y;
  }
  point IP(prava w) {
    point R;
    if (abs(a) < 1E-9) {
      R.y = (-c) / b;
      R.x = (-w.b * R.y - w.c) / w.a;
    } else {
      R.y = (w.a * c - a * w.c) / (a * w.b - w.a * b);
      R.x = (-b * R.y - c) / a;
    }
    return R;
  }
};
int n;
point tri[100][3];
bool inside(point w, int T) {
  if (ORI(w - tri[T][0], tri[T][1] - tri[T][0]) *
          ORI(tri[T][2] - tri[T][0], tri[T][1] - tri[T][0]) <=
      0)
    return false;
  if (ORI(w - tri[T][1], tri[T][2] - tri[T][1]) *
          ORI(tri[T][0] - tri[T][1], tri[T][2] - tri[T][1]) <=
      0)
    return false;
  if (ORI(w - tri[T][2], tri[T][0] - tri[T][2]) *
          ORI(tri[T][1] - tri[T][2], tri[T][0] - tri[T][2]) <=
      0)
    return false;
  return true;
}
void solve_side(int T, int f, int s) {
  vector<point> P;
  P.push_back(tri[T][f]);
  P.push_back(tri[T][s]);
  for (int i = 0; i < n; ++i) {
    if (i == T) continue;
    if (intersect(tri[i][0], tri[i][1], tri[T][f], tri[T][s]))
      P.push_back(prava(tri[i][0], tri[i][1]).IP(prava(tri[T][f], tri[T][s])));
    if (intersect(tri[i][1], tri[i][2], tri[T][f], tri[T][s]))
      P.push_back(prava(tri[i][1], tri[i][2]).IP(prava(tri[T][f], tri[T][s])));
    if (intersect(tri[i][2], tri[i][0], tri[T][f], tri[T][s]))
      P.push_back(prava(tri[i][2], tri[i][0]).IP(prava(tri[T][f], tri[T][s])));
  }
  sort(P.begin(), P.end());
  for (int i = 1; i < P.size(); ++i) {
    point MID((P[i - 1].x + P[i].x) / 2, (P[i - 1].y + P[i].y) / 2);
    for (int j = 0; j < n; ++j)
      if (inside(MID, j)) goto END;
    ANS += (P[i] - P[i - 1]).MOD();
  END:;
  }
}
int main() {
  int i, j, k, l;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) {
    tri[i][0].read();
    tri[i][1].read();
    tri[i][2].read();
  }
  for (i = 0; i < n; ++i) {
    solve_side(i, 0, 1);
    solve_side(i, 1, 2);
    solve_side(i, 2, 0);
  }
  printf("%.10lf\n", (double)ANS);
  return 0;
}