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 int maxn = 105;
const double eps = 1e-9;
int n, m;
pair<int, int> trokut[maxn][3];
pair<int, int> lines[maxn * 3][2];
double dst(pair<int, int> a, pair<int, int> b) {
  return sqrt((a.first - b.first) * (long long)(a.first - b.first) +
              (a.second - b.second) * (long long)(a.second - b.second));
}
double dst(pair<int, int> a, pair<double, double> b) {
  return sqrt((a.first - b.first) * (a.first - b.first) +
              (a.second - b.second) * (a.second - b.second));
}
double xs(int i, pair<int, int> a, pair<int, int> b) {
  long long a1 = lines[i][1].second - lines[i][0].second;
  long long b1 = lines[i][0].first - lines[i][1].first;
  long long c1 = a1 * lines[i][0].first + b1 * lines[i][0].second;
  long long a2 = b.second - a.second;
  long long b2 = a.first - b.first;
  long long c2 = a2 * a.first + b2 * a.second;
  long long det = a1 * b2 - a2 * b1;
  if (det == 0) return -1;
  double first = (b2 * c1 - b1 * c2) / (double)det;
  double second = (a1 * c2 - a2 * c1) / (double)det;
  if (first < min(lines[i][0].first, lines[i][1].first) ||
      first > max(lines[i][0].first, lines[i][1].first))
    return -1;
  if (second < min(lines[i][0].second, lines[i][1].second) ||
      second > max(lines[i][0].second, lines[i][1].second))
    return -1;
  if (first < min(a.first, b.first) || first > max(a.first, b.first)) return -1;
  if (second < min(a.second, b.second) || second > max(a.second, b.second))
    return -1;
  return dst(lines[i][0], make_pair(first, second)) /
         dst(lines[i][0], lines[i][1]);
}
double area(pair<int, int> a, pair<int, int> b, pair<int, int> c) {
  double s1 = dst(a, b);
  double s2 = dst(a, c);
  double s3 = dst(b, c);
  double s = (s1 + s2 + s3) / 2;
  return sqrt(s * (s - s1)) * sqrt(s - s2) * sqrt(s - s3);
}
bool intri(int i, pair<int, int> a) {
  double A = area(trokut[i][0], trokut[i][1], trokut[i][2]);
  double a1 = area(trokut[i][0], trokut[i][1], a);
  double a2 = area(trokut[i][0], trokut[i][2], a);
  double a3 = area(trokut[i][1], trokut[i][2], a);
  return fabs(A - (a1 + a2 + a3)) < 0.01;
}
vector<pair<double, double> > range;
bool chk(double s, double e, double first) { return s <= first && first <= e; }
double gety(int i, double first) {
  if (lines[i][0].second == lines[i][1].second) return lines[i][0].second;
}
void print(int i) {
  cout << "[" << lines[i][0].first << " " << lines[i][0].second << " , "
       << lines[i][1].first << " " << lines[i][1].second << "]" << endl;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 3; ++j) {
      int a, b;
      scanf("%d%d", &a, &b);
      trokut[i][j] = make_pair(a, b);
      for (int k = 0; k < j; ++k)
        lines[m][0] = trokut[i][k], lines[m++][1] = trokut[i][j];
    }
  }
  double sol = 0;
  for (int i = 0; i < m; ++i) {
    range.clear();
    double x1 = lines[i][0].first, x2 = lines[i][1].first;
    for (int j = 0; j < n; ++j) {
      if (j * 3 <= i && i < j * 3 + 3) continue;
      double a = xs(i, trokut[j][0], trokut[j][1]);
      double b = xs(i, trokut[j][1], trokut[j][2]);
      double c = xs(i, trokut[j][0], trokut[j][2]);
      if (a < 0) swap(a, c);
      if (a < 0) swap(a, b);
      if (b < 0) swap(b, c);
      double s = -1, e;
      int cnt = (a + eps >= 0) + (b + eps >= 0) + (c + eps >= 0);
      if (intri(j, lines[i][0]) && intri(j, lines[i][1])) {
        s = 0, e = 1;
      } else if (cnt == 1) {
        if (intri(j, lines[i][0]))
          s = 0, e = a;
        else if (intri(j, lines[i][1]))
          s = a, e = 1;
      } else if (cnt == 2)
        s = min(a, b), e = max(a, b);
      else if (cnt == 3)
        s = min(a, min(b, c)), e = max(a, max(b, c));
      if (s + eps >= 0 && e - s > eps) range.push_back(make_pair(s, e));
    }
    sort(range.begin(), range.end());
    for (int j = 1; j < range.size(); ++j)
      if (range[j - 1].second + eps >= range[j].first) {
        range[j - 1].second = max(range[j - 1].second, range[j].second);
        range.erase(range.begin() + j);
        j--;
      }
    double coef = 1;
    for (int j = 0; j < range.size(); ++j)
      coef -= range[j].second - range[j].first;
    sol += coef * dst(lines[i][0], lines[i][1]);
  }
  printf("%.10lf\n", sol);
  return 0;
}