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;
template <class T, class IT>
inline void PRINT(IT i1, IT i2) {
  cout << '[';
  copy(i1, i2, ostream_iterator<T>(cout, ", "));
  cout << "]\n";
}
template <typename T>
struct point2d {
  T x, y;
  point2d(const T& _x, const T& _y) : x(_x), y(_y) {}
  point2d() {}
  double norm2() const { return sqrt(x * x + y * y); }
  point2d<T> operator*(T v) const { return point2d<T>(x * v, y * v); }
  point2d<T> operator-(const point2d<T>& rhs) const {
    return point2d<T>(x - rhs.x, y - rhs.y);
  }
  point2d<T> operator+(const point2d<T>& rhs) const {
    return point2d<T>(x + rhs.x, y + rhs.y);
  }
};
point2d<double> inner(const point2d<long long>& a, const point2d<long long>& b,
                      double t) {
  point2d<double> result(a.x + t * (b.x - a.x), a.y + t * (b.y - a.y));
  return result;
}
template <typename T>
struct segment2d {
  T a;
  T b;
  segment2d(const T& _a, const T& _b) : a(_a), b(_b) {}
  segment2d() {}
};
point2d<double> D(const point2d<long long>& p) {
  return point2d<double>(1.0 * p.x, 1.0 * p.y);
}
inline bool ZERO(long long a) { return a == 0; }
inline bool ZERO(double a) { return fabs(a) < (1e-9); }
template <typename PointT1, typename PointT2>
double vmul(const PointT1& a, const PointT2& b) {
  return a.x * b.y - b.x * a.y;
}
bool intersect(const segment2d<point2d<long long> >& a,
               const segment2d<point2d<long long> >& b, double& t) {
  double f = vmul(b.b - a.a, b.a - a.a);
  double s = vmul(b.b - a.b, b.a - a.b);
  if ((f > 0 && s < 0) || (f < 0 && s > 0)) {
    t = f / (f - s);
    return true;
  } else {
    return false;
  }
}
bool inside(const point2d<long long>& a, const point2d<long long>& b,
            const point2d<long long>& c, const point2d<double>& p) {
  double s1 = abs(vmul(D(a) - p, D(b) - p)) + abs(vmul(D(b) - p, D(c) - p)) +
              abs(vmul(D(c) - p, D(a) - p));
  double s2 = abs(vmul(b - a, c - a));
  return ZERO(s1 - s2);
}
point2d<long long> triangle[111][3];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < (int)(n); ++i) {
    cin >> triangle[i][0].x >> triangle[i][0].y >> triangle[i][1].x >>
        triangle[i][1].y >> triangle[i][2].x >> triangle[i][2].y;
  }
  double result = 0.0;
  for (int i = 0; i < (int)(n); ++i)
    for (int k = 0; k < (int)(3); ++k) {
      segment2d<point2d<long long> > current(triangle[i][k],
                                             triangle[i][(k + 1) % 3]);
      vector<double> intersection;
      intersection.push_back(0);
      intersection.push_back(1);
      for (int j = 0; j < (int)(n); ++j)
        if (i != j)
          for (int l = 0; l < (int)(3); ++l) {
            segment2d<point2d<long long> > test(triangle[j][l],
                                                triangle[j][(l + 1) % 3]);
            double t;
            if (intersect(current, test, t)) {
              if (t != t) {
                cout << current.a.x << " " << current.a.y << " " << current.b.x
                     << " " << current.b.y << " vs. " << test.a.x << " "
                     << test.a.y << " " << test.b.x << " " << test.b.y << " : "
                     << t << endl;
              }
              intersection.push_back(t);
            }
          }
      sort(intersection.begin(), intersection.end());
      for (int j = 0; j < (int)(intersection.size() - 1); ++j) {
        double t = (intersection[j] + intersection[j + 1]) / 2;
        bool black = false;
        for (int l = 0; l < (int)(n); ++l)
          if (l != i) {
            if (inside(triangle[l][0], triangle[l][1], triangle[l][2],
                       inner(current.a, current.b, t))) {
              black = true;
            }
          }
        double qqq = (current.b - current.a).norm2() *
                     (intersection[j + 1] - intersection[j]);
        if (qqq != qqq) {
        }
        if (!black)
          result += (current.b - current.a).norm2() *
                    (intersection[j + 1] - intersection[j]);
      }
    }
  cout << setprecision(10) << result;
  return 0;
}