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 epsilon = 1e-6;
double equal(double x, double y) {
  double delta = x - y;
  return fabs(delta) <= epsilon;
}
bool dle(double a, double b) { return a < b + epsilon; }
bool dgr(double a, double b) { return dle(b, a); }
struct point {
  double x, y;
  point() { x = y = 0; }
  point(double nx, double ny) : x(nx), y(ny) {}
  point(istream &in) { in >> x >> y; }
  double dist(point p) {
    double dx = x - p.x, dy = y - p.y;
    return sqrt(dx * dx + dy * dy);
  }
  bool operator==(point p) { return equal(x, p.x) && equal(y, p.y); }
  bool operator!=(point p) { return !operator==(p); }
  point operator+(point p) { return point(x + p.x, y + p.y); }
  point operator-() { return point(-x, -y); }
  point operator-(point p) { return point(x - p.x, y - p.y); }
  point operator*(double k) { return point(k * x, k * y); }
  double operator*(point p) { return x * p.x + y * p.y; }
  double operator^(point p) { return x * p.y - y * p.x; }
};
struct line {
  double A, B, C;
  line(point a, point b) {
    A = b.y - a.y;
    B = a.x - b.x;
    C = a.y * (b.x - a.x) - a.x * (b.y - a.y);
  }
  int side(point p) { return (A * p.x + B * p.y + C > 0) ? 1 : -1; }
  bool cross(line l, point &res) {
    double delta = A * l.B - B * l.A;
    if (equal(delta, 0)) return false;
    double deltax = -C * l.B + B * l.C;
    double deltay = -A * l.C + C * l.A;
    res = point(deltax / delta, deltay / delta);
    return true;
  }
};
struct segment {
  point a, b;
  segment(point na, point nb) : a(na), b(nb) {}
  bool cross(segment cd, point &res) {
    line abl(a, b), cdl(cd.a, cd.b);
    if (abl.side(cd.a) * abl.side(cd.b) != -1) return false;
    if (cdl.side(a) * cdl.side(b) != -1) return false;
    return abl.cross(cdl, res);
  }
  bool operator==(segment s) { return a == s.a && b == s.b; }
};
int n;
point data[110][3];
double answer;
bool compare(point a, point b) {
  return a.x + epsilon < b.x || (equal(a.x, b.x) && a.y < b.y);
}
bool inner(point p, point *tr) {
  double a = (tr[1] - tr[0]) ^ (tr[0] - p);
  double b = (tr[2] - tr[1]) ^ (tr[1] - p);
  double c = (tr[0] - tr[2]) ^ (tr[2] - p);
  if (dle(a, 0) && dle(b, 0) && dle(c, 0)) return true;
  if (dgr(a, 0) && dgr(b, 0) && dgr(c, 0)) return true;
  return false;
}
void solve(int a, int b) {
  segment seg(data[a][b], data[a][(b + 1) % 3]);
  vector<point> pts;
  pts.push_back(seg.a);
  pts.push_back(seg.b);
  for (int i = 0; i < n; i++) {
    if (i == a) continue;
    for (int j = 0; j < 3; j++) {
      segment cur(data[i][j], data[i][(j + 1) % 3]);
      if (cur == seg) continue;
      point c;
      if (seg.cross(cur, c)) pts.push_back(c);
    }
  }
  sort(pts.begin(), pts.end(), compare);
  for (int i = 0; i < (int)pts.size() - 1; i++) {
    point cur = pts[i], next = pts[i + 1], middle = (cur + next) * 0.5;
    int count = 0;
    for (int j = 0; j < n; j++) {
      if (j == a) continue;
      if (inner(middle, data[j])) count++;
    }
    if (!count) answer += cur.dist(next);
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      data[i][j] = point(cin);
    }
  }
  answer = 0.00;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      solve(i, j);
    }
  }
  cout.precision(15);
  cout << fixed << answer;
  return 0;
}