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 long long MAXN = 300 * 1000 + 7;
const long long MOD = 998244353;
const double PI = 2 * acos(0.0);
struct line {
  double x, y, xx, yy;
};
long long n;
line N[MAXN];
double ans = 0, del = 0.0000001;
long long ccw(double a, double aa, double b, double bb, double c, double cc) {
  double m1 = (bb - aa) * (c - b);
  double m2 = (cc - bb) * (b - a);
  if (abs(m2 - m1) < del) return 0;
  if (m2 > m1) return 1;
  return -1;
}
pair<double, double> cross(line a, line b) {
  double a1 = a.yy - a.y;
  double b1 = a.x - a.xx;
  double c1 = a1 * (a.x) + b1 * (a.y);
  double a2 = b.yy - b.y;
  double b2 = b.x - b.xx;
  double c2 = a2 * (b.x) + b2 * (b.y);
  double determinant = a1 * b2 - a2 * b1;
  double X = (b2 * c1 - b1 * c2) / determinant;
  double Y = (a1 * c2 - a2 * c1) / determinant;
  return make_pair(X, Y);
}
int main(void) {
  cin >> n;
  for (long long i0 = 0; i0 < n; i0++) {
    double i, j;
    cin >> i >> j;
    N[(3 * i0)].x = i;
    N[(3 * i0)].y = j;
    N[(3 * i0) + 1].x = i;
    N[(3 * i0) + 1].y = j;
    cin >> i >> j;
    N[(3 * i0)].xx = i;
    N[(3 * i0)].yy = j;
    N[(3 * i0) + 2].x = i;
    N[(3 * i0) + 2].y = j;
    cin >> i >> j;
    N[(3 * i0) + 1].xx = i;
    N[(3 * i0) + 1].yy = j;
    N[(3 * i0) + 2].xx = i;
    N[(3 * i0) + 2].yy = j;
  }
  for (long long i0 = 0; i0 < 3 * n; i0++) {
    double i = N[i0].x, j = N[i0].y, ii = N[i0].xx, jj = N[i0].yy;
    vector<pair<double, double> > kobe;
    kobe.push_back({i, j});
    kobe.push_back({ii, jj});
    for (long long j0 = 0; j0 < 3 * n; j0++) {
      if (i0 == j0) continue;
      long long q = ccw(i, j, ii, jj, N[j0].x, N[j0].y);
      long long w = ccw(i, j, ii, jj, N[j0].xx, N[j0].yy);
      long long e = ccw(N[j0].x, N[j0].y, N[j0].xx, N[j0].yy, i, j);
      long long r = ccw(N[j0].x, N[j0].y, N[j0].xx, N[j0].yy, ii, jj);
      if (!(q == 0 || w == 0 || e == 0 || r == 0) && (q + w == 0) &&
          (e + r == 0)) {
        kobe.push_back(cross(N[i0], N[j0]));
      }
    }
    sort(kobe.begin(), kobe.end());
    long long SIZE = kobe.size();
    for (long long j0 = 0; j0 < SIZE - 1; j0++) {
      i = kobe[j0].first;
      j = kobe[j0].second;
      ii = kobe[j0 + 1].first;
      jj = kobe[j0 + 1].second;
      if (abs(j - i) < del && abs(jj - ii) < del) continue;
      pair<double, double> mid;
      mid.first = i + (ii - i) / 2;
      mid.second = j + (jj - j) / 2;
      bool ok = true;
      for (long long k = 0; k < n; k++) {
        if (k == (i0 / 3)) continue;
        double m, l, mm, ll, mmm, lll;
        m = N[3 * k].x, l = N[3 * k].y;
        mm = N[3 * k].xx, ll = N[3 * k].yy;
        mmm = N[(3 * k) + 1].xx, lll = N[(3 * k) + 1].yy;
        long long q = ccw(m, l, mm, ll, mid.first, mid.second);
        long long w = ccw(mm, ll, mmm, lll, mid.first, mid.second);
        long long e = ccw(mmm, lll, m, l, mid.first, mid.second);
        if (!(q == 0 || w == 0 || e == 0) && (q == w) && (w == e)) {
          ok = false;
          break;
        }
      }
      if (ok) ans += sqrt((ii - i) * (ii - i) + (jj - j) * (jj - j));
    }
  }
  cout << setprecision(10) << fixed << ans << endl;
  return 0;
}