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;
pair<long double, long double> operator+(
    const pair<long double, long double> &p1,
    const pair<long double, long double> &p2) {
  return {p1.first + p2.first, p1.second + p2.second};
}
pair<long double, long double> operator-(
    const pair<long double, long double> &p1,
    const pair<long double, long double> &p2) {
  return {p1.first - p2.first, p1.second - p2.second};
}
pair<long double, long double> operator*(
    const long double &d, const pair<long double, long double> &p) {
  return {d * p.first, d * p.second};
}
long double operator*(const pair<long double, long double> &p1,
                      const pair<long double, long double> &p2) {
  return p1.first * p2.first + p1.second * p2.second;
}
long double operator^(const pair<long double, long double> &p1,
                      const pair<long double, long double> &p2) {
  return p1.first * p2.second - p1.second * p2.first;
}
const long double eps = 1e-8;
bool is_0(long double x) { return fabs(x) <= eps; }
int sgn(long double x) { return (x > eps) - (x < -eps); }
const int N = 100006;
pair<long double, long double> intersect(pair<long double, long double> p1,
                                         pair<long double, long double> p2,
                                         pair<long double, long double> q1,
                                         pair<long double, long double> q2) {
  return p1 + ((q1 - p1) ^ (q2 - q1)) / ((p2 - p1) ^ (q2 - q1)) * (p2 - p1);
}
bool on_seg(pair<long double, long double> p1,
            pair<long double, long double> p2,
            pair<long double, long double> q) {
  if (sgn((p1 - p2) ^ (p1 - q)) != 0) return false;
  return sgn((p1 - q) * (p2 - q)) == -1;
}
bool banana(pair<long double, long double> p1,
            pair<long double, long double> p2,
            pair<long double, long double> q1,
            pair<long double, long double> q2) {
  if (sgn((p1 - p2) ^ (q1 - q2)) == 0) {
    return false;
  }
  return sgn((p1 - q1) ^ (p2 - q1)) * sgn((p1 - q2) ^ (p2 - q2)) == -1 &&
         sgn((q1 - p1) ^ (q2 - p1)) * sgn((q1 - p2) ^ (q2 - p2)) == -1;
}
long double dis(pair<long double, long double> p) { return sqrt(p * p); }
vector<pair<long double, long double> > pts[N];
pair<pair<long double, long double>, pair<long double, long double> > line[N];
int n;
bool in_polygon(pair<long double, long double> p) {
  for (int i = 0; i < n; ++i) {
    pair<long double, long double> a = line[3 * i].first;
    pair<long double, long double> b = line[3 * i + 1].first;
    pair<long double, long double> c = line[3 * i + 2].first;
    pair<long double, long double> d = {889301, 890501};
    if (on_seg(a, b, p)) continue;
    if (on_seg(b, c, p)) continue;
    if (on_seg(a, c, p)) continue;
    int cnt = 0;
    if (banana(p, d, a, b)) ++cnt;
    if (banana(p, d, b, c)) ++cnt;
    if (banana(p, d, a, c)) ++cnt;
    if (cnt & 1) return true;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  int id = 0;
  for (int i = 1; i <= n; ++i) {
    pair<long double, long double> a, b, c;
    cin >> a.first >> a.second >> b.first >> b.second >> c.first >> c.second;
    pts[id].push_back(a);
    pts[id].push_back(b);
    line[id] = {a, b};
    ++id;
    pts[id].push_back(b);
    pts[id].push_back(c);
    line[id] = {b, c};
    ++id;
    pts[id].push_back(a);
    pts[id].push_back(c);
    line[id] = {c, a};
    ++id;
  }
  for (int i = 0; i < id; ++i) {
    for (int j = i + 1; j < id; ++j) {
      pair<long double, long double> a = line[i].first, b = line[i].second,
                                     c = line[j].first, d = line[j].second;
      if (a == c || a == d || b == c || b == d) continue;
      if (banana(a, b, c, d)) {
        pair<long double, long double> ret = intersect(a, b, c, d);
        pts[i].push_back(ret);
        pts[j].push_back(ret);
      }
    }
  }
  long double ans = 0;
  for (int i = 0; i < id; ++i) {
    sort(pts[i].begin(), pts[i].end());
    pts[i].resize(unique(pts[i].begin(), pts[i].end()) - pts[i].begin());
    for (int j = 0; j < (int)pts[i].size() - 1; ++j) {
      if (!in_polygon(0.5 * (pts[i][j] + pts[i][j + 1]))) {
        ans += dis(pts[i][j + 1] - pts[i][j]);
      }
    }
  }
  cout << fixed << setprecision(12) << ans << endl;
}