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;
struct Point {
  long double x, y;
  Point(long double x = 0.0, long double y = 0.0) : x(x), y(y) {}
};
const long double eps = 1e-9;
const long double inf = 1e30;
const long double pi = acos(-1.0);
bool operator<(const Point &a, const Point &b) { return a.x < b.x; }
inline bool eq(long double x, long double y) { return fabs(x - y) <= eps; }
inline bool le(long double x, long double y) { return x <= y || eq(x, y); }
inline bool lt(long double x, long double y) { return x < y && !eq(x, y); }
inline bool ge(long double x, long double y) { return x >= y || eq(x, y); }
inline bool gt(long double x, long double y) { return x > y && !eq(x, y); }
inline Point operator+(Point a, Point b) { return Point(a.x + b.x, a.y + b.y); }
inline Point operator-(Point a, Point b) { return Point(a.x - b.x, a.y - b.y); }
inline Point operator*(Point a, long double b) {
  return Point(a.x * b, a.y * b);
}
inline Point normal(Point p) { return Point(p.y, -p.x); }
inline long double vect(Point a, Point b) { return a.x * b.y - a.y * b.x; }
inline long double scal(Point a, Point b) { return a.x * b.x + a.y * b.y; }
inline long double sqr(long double x) { return x * x; }
inline long double dist(Point a) { return sqrt(sqr(a.x) + sqr(a.y)); }
inline int sgn(long double x) { return eq(x, 0.0) ? 0 : (x > 0 ? 1 : -1); }
long double ans = 0.0;
int N;
Point P[1000][3];
bool inside(Point *p, Point q) {
  int g1 = 0, l1 = 0;
  for (int i = 0; i < 3; ++i) {
    int j = (i + 1) % 3;
    int s = sgn(vect(p[j] - p[i], q - p[i]));
    if (s > 0) g1++;
    if (s < 0) l1++;
  }
  return g1 == 3 || l1 == 3;
}
bool check(Point p1, Point p2) {
  Point q = (p1 + p2) * 0.5;
  for (int i = 0; i < N; ++i) {
    if (inside(P[i], q)) return false;
  }
  return true;
}
bool crossSegments(Point p1, Point p2, Point p3, Point p4) {
  return le(min(p1.x, p2.x), max(p3.x, p4.x)) &&
         le(min(p3.x, p4.x), max(p1.x, p2.x)) &&
         le(min(p1.y, p2.y), max(p3.y, p4.y)) &&
         le(min(p3.y, p4.y), max(p1.y, p2.y)) &&
         sgn(vect(p2 - p1, p3 - p1)) * sgn(vect(p2 - p1, p4 - p1)) <= 0 &&
         sgn(vect(p4 - p3, p1 - p3)) * sgn(vect(p4 - p3, p2 - p3)) <= 0;
}
Point crossLines(Point p1, Point p2, Point p3, Point p4) {
  long double t = vect(p2 - p1, p4 - p3);
  return p1 + (p2 - p1) * (vect(p4 - p3, p1 - p3) / t);
}
void process(int skipI, Point p1, Point p2) {
  vector<pair<long double, Point> > v;
  v.push_back(make_pair(0, p1));
  for (int i = 0; i < N; ++i) {
    if (skipI == i) continue;
    for (int j = 0; j < 3; ++j) {
      int k = (j + 1) % 3;
      if (!crossSegments(p1, p2, P[i][j], P[i][k])) continue;
      Point q = crossLines(p1, p2, P[i][j], P[i][k]);
      long double d = dist(q - p1);
      v.push_back(make_pair(d, q));
    }
  }
  sort((v).begin(), (v).end());
  v.push_back(make_pair(0, p2));
  for (int i = 0; i + 1 < ((int)(v.size())); ++i) {
    if (check(v[i].second, v[i + 1].second)) {
      ans += dist(v[i].second - v[i + 1].second);
    }
  }
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> P[i][j].x >> P[i][j].y;
    }
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 3; ++j) {
      int k = (j + 1) % 3;
      process(i, P[i][j], P[i][k]);
    }
  }
  double out = (double)ans;
  printf("%0.12lf\n", out);
  return 0;
}