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;
long double cross(complex<long double> p, complex<long double> q) {
  return imag(conj(p) * q);
}
int dir(complex<long double> a, complex<long double> b,
        complex<long double> c) {
  complex<long double> u = b - a;
  complex<long double> v = c - a;
  long double x = cross(u, v);
  return (((x) > 0) - ((x) < 0));
}
bool inside(complex<long double> a, complex<long double> b,
            complex<long double> c, complex<long double> x) {
  int u = dir(a, b, x);
  int v = dir(b, c, x);
  int w = dir(c, a, x);
  return u * v >= 0 && u * w >= 0 && v * w >= 0;
}
bool lineline(complex<long double> a1, complex<long double> a2,
              complex<long double> b1, complex<long double> b2,
              complex<long double> &isect, long double *at = 0,
              long double *bt = 0) {
  long double d = cross(a2 - a1, b2 - b1);
  if (d == 0) return false;
  long double t = cross(b2 - b1, a1 - b1) / d;
  long double s = cross(a2 - a1, a1 - b1) / d;
  if (t < 0 || t > 1) return false;
  if (s < 0 || s > 1) return false;
  isect = a1 + (a2 - a1) * t;
  if (at) *at = t;
  if (bt) *bt = s;
  return true;
}
complex<long double> P[120][3];
long double solve(complex<long double> a, complex<long double> b, int me,
                  int N) {
  vector<pair<long double, long double> > I;
  for (int i = 0; i < (N); ++i) {
    if (i == me) continue;
    if (inside(P[i][0], P[i][1], P[i][2], a) &&
        inside(P[i][0], P[i][1], P[i][2], b))
      return 0;
    int d1 = dir(a, b, P[i][0]);
    int d2 = dir(a, b, P[i][1]);
    int d3 = dir(a, b, P[i][2]);
    if (d1 * d2 >= 0 && d2 * d3 >= 0 && d1 * d3 >= 0) continue;
    for (int j = 0; j < (3); ++j) {
    }
    vector<long double> found;
    long double t, s;
    complex<long double> tmp;
    for (int j = 0; j < (3); ++j) {
      complex<long double> u = P[i][j];
      complex<long double> v = P[i][(j + 1) % 3];
      if (lineline(a, b, u, v, tmp, &t, &s)) {
        found.push_back(t);
      }
    }
    if (found.empty()) continue;
    assert(found.size() <= 3);
    sort(found.begin(), found.end());
    if (found.size() >= 2 && abs(found[0] - found[1]) <= 1e-6) {
      swap(found[1], found.back());
      found.pop_back();
    }
    if (found.size() >= 3 && abs(found[1] - found[2]) <= 1e-6) {
      found.pop_back();
    }
    assert(!found.empty());
    assert(found.size() <= 2);
    if (found.size() == 2) {
      I.push_back(make_pair(found[0], found[1]));
    } else if (inside(P[i][0], P[i][1], P[i][2], a)) {
      I.push_back(make_pair(0, found[0]));
    } else if (inside(P[i][0], P[i][1], P[i][2], b)) {
      I.push_back(make_pair(found[0], 1));
    } else {
      assert(false);
    }
  }
  I.push_back(make_pair(1e9, 1e9));
  sort(I.begin(), I.end());
  long double ans = 0;
  long double L = 0;
  long double R = 0;
  int M = I.size();
  for (int x = 0; x < (M); ++x) {
    assert(I[x].first <= I[x].second);
    if (I[x].first <= R)
      R = max(R, I[x].second);
    else {
      assert(R >= L);
      ans += R - L;
      L = I[x].first;
      R = I[x].second;
    }
    assert(ans <= 1 + 1e-6);
  }
  return (1 - ans) * abs(b - a);
}
int main() {
  int N, a, b, c, d, e, f;
  scanf("%d", &N);
  for (int i = 0; i < (N); ++i) {
    scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f);
    P[i][0] = complex<long double>(a, b);
    P[i][1] = complex<long double>(c, d);
    P[i][2] = complex<long double>(e, f);
  }
  long double ans = 0;
  for (int i = 0; i < (N); ++i)
    for (int j = 0; j < (3); ++j)
      ans += solve(P[i][j], P[i][(j + 1) % 3], i, N);
  cout << fixed << setprecision(12) << ans << endl;
}