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 eps = 1e-7;
int cmp(long double a, long double b = 0) {
  return a + eps < b ? -1 : a - eps > b ? 1 : 0;
}
struct point {
  long double x, y;
  point(long double a = 0, long double b = 0) : x(a), y(b) {}
  bool operator<(const point& q) const {
    if (int t = cmp(x, q.x))
      return t < 0;
    else
      return cmp(y, q.y) < 0;
  }
  bool operator==(const point& q) const {
    return cmp(x, q.x) == 0 && cmp(y, q.y) == 0;
  }
  void read() { cin >> x >> y; }
};
long double dist(point& a, point& b) { return hypot(a.x - b.x, a.y - b.y); }
point mid(point& a, point& b) {
  return point((a.x + b.x) / 2, (a.y + b.y) / 2);
}
int cross(point& a, point& p, point& q) {
  long double x = (p.x - a.x) * (q.y - a.y) - (p.y - a.y) * (q.x - a.x);
  return cmp(x);
}
bool on(point& a, point& p, point& q) {
  if (cmp(p.x, q.x) == 0)
    return cmp(a.y, min(p.y, q.y)) >= 0 && cmp(a.y, max(p.y, q.y)) <= 0;
  return cmp(a.x, min(p.x, q.x)) >= 0 && cmp(a.x, max(p.x, q.x)) <= 0;
}
point tri[100][4];
int n;
bool libre(point p) {
  for (int i = 0; i < n; i++) {
    int a1 = cross(p, tri[i][0], tri[i][1]);
    int a2 = cross(p, tri[i][1], tri[i][2]);
    int a3 = cross(p, tri[i][2], tri[i][3]);
    if (a1 != 0 && a2 != 0 && a3 != 0)
      if (a1 == a2 && a2 == a3) return false;
  }
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 3; j++) tri[i][j].read();
  for (int i = 0; i < n; i++) tri[i][3] = tri[i][0];
  long double res = 0;
  point pivot;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 3; j++) {
      vector<point> inter;
      long double A1 = tri[i][j + 1].y - tri[i][j].y;
      long double B1 = tri[i][j].x - tri[i][j + 1].x;
      long double C1 = A1 * tri[i][j].x + B1 * tri[i][j].y;
      inter.push_back(tri[i][j]);
      inter.push_back(tri[i][j + 1]);
      for (int a = 0; a < n; a++)
        for (int b = 0; b < 3; b++) {
          long double A2 = tri[a][b + 1].y - tri[a][b].y;
          long double B2 = tri[a][b].x - tri[a][b + 1].x;
          long double C2 = A2 * tri[a][b].x + B2 * tri[a][b].y;
          long double det = A1 * B2 - A2 * B1;
          if (cmp(det) != 0) {
            point p((C1 * B2 - C2 * B1) / det, (A1 * C2 - A2 * C1) / det);
            if (on(p, tri[i][j], tri[i][j + 1]) &&
                on(p, tri[a][b], tri[a][b + 1]))
              inter.push_back(p);
          }
        }
      sort(inter.begin(), inter.end());
      inter.erase(unique(inter.begin(), inter.end()), inter.end());
      for (int k = 1; k < inter.size(); k++) {
        point aux = mid(inter[k], inter[k - 1]);
        if (i == 1 && j == 1 && k == 1) pivot = aux;
        if (libre(aux)) res += dist(inter[k], inter[k - 1]);
      }
    }
  cout << setprecision(10) << res << endl;
}