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-(pair<long double, long double> a,
                                         pair<long double, long double> b) {
  return pair<long double, long double>(a.first - b.first, a.second - b.second);
}
long double cros(pair<long double, long double> a,
                 pair<long double, long double> b) {
  return a.first * b.second - a.second * b.first;
}
long long int sign(long double x) {
  if (x > 0)
    return 1;
  else if (x < 0)
    return -1;
  else
    return 0;
}
long double gm(pair<long double, long double> a,
               pair<long double, long double> b) {
  return (b.second - a.second) / (b.first - a.first);
}
pair<long double, long double> itp(pair<long double, long double> a,
                                   pair<long double, long double> b,
                                   pair<long double, long double> c,
                                   pair<long double, long double> d) {
  if (a.first == b.first)
    return pair<long double, long double>(
        a.first, gm(c, d) * (a.first - c.first) + c.second);
  else if (c.first == d.first)
    return pair<long double, long double>(
        c.first, gm(a, b) * (c.first - a.first) + a.second);
  else {
    long double m1 = gm(a, b), m2 = gm(c, d);
    long double p =
        (c.second - a.second + m2 * a.first - m2 * c.first) / (m1 - m2);
    return pair<long double, long double>(a.first + p, a.second + p * m1);
  }
}
bool inter(pair<long double, long double> a, pair<long double, long double> b,
           pair<long double, long double> c, pair<long double, long double> d) {
  if (sign(cros(c - a, b - a)) * sign(cros(d - a, b - a)) < 0 &&
      sign(cros(a - c, d - c)) * sign(cros(b - c, d - c)) < 0)
    return 1;
  else
    return 0;
}
long double len(pair<long double, long double> a,
                pair<long double, long double> b) {
  pair<long double, long double> d = a - b;
  return sqrt(d.first * d.first + d.second * d.second);
}
pair<long double, long double> mid(pair<long double, long double> a,
                                   pair<long double, long double> b) {
  return pair<long double, long double>((a.first + b.first) / 2,
                                        (a.second + b.second) / 2);
}
const long double eps = 1e-9;
bool inbt(pair<long double, long double> a, pair<long double, long double> b,
          pair<long double, long double> c, pair<long double, long double> d) {
  return cros(a - b, d - b) * cros(c - b, d - b) < eps;
}
bool in(pair<long double, long double> p, pair<long double, long double> a,
        pair<long double, long double> b, pair<long double, long double> c) {
  return inbt(a, b, c, p) && inbt(b, c, a, p) && inbt(c, a, b, p);
}
long double per(pair<long double, long double> &a,
                pair<long double, long double> &b,
                vector<pair<long double, long double>> t[], int n, int id) {
  vector<pair<long double, long double>> intP;
  intP.push_back(a);
  intP.push_back(b);
  for (int i = 0; i < n; i++) {
    if (i != id) {
      for (int j = 0; j < 3; j++) {
        if (inter(a, b, t[i][j], t[i][(j + 1) % 3])) {
          intP.push_back(itp(a, b, t[i][j], t[i][(j + 1) % 3]));
        }
      }
    }
  }
  sort(intP.begin(), intP.end());
  intP.resize(unique(intP.begin(), intP.end()) - intP.begin());
  long double sum = 0;
  for (int i = 0; i < intP.size() - 1; i++) {
    pair<long double, long double> md = mid(intP[i], intP[i + 1]);
    bool fg = 1;
    for (int j = 0; j < n; j++) {
      if (j != id && in(md, t[j][0], t[j][1], t[j][2])) fg = 0;
    }
    if (fg) sum += len(intP[i], intP[i + 1]);
  }
  return sum;
}
int main() {
  int n;
  cin >> n;
  cout << fixed << setprecision(12);
  vector<pair<long double, long double>> t[n];
  for (int i = 0; i < n; i++) {
    t[i].resize(3);
    cin >> t[i][0].first >> t[i][0].second >> t[i][1].first >> t[i][1].second >>
        t[i][2].first >> t[i][2].second;
  }
  long double ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      ans += per(t[i][j], t[i][(j + 1) % 3], t, n, i);
    }
  }
  cout << ans << endl;
}