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>
const double kEPS = 1e-6;
const int kMaxN = 100;
std::complex<long long> tri[kMaxN][3];
std::complex<long long> p[3 * kMaxN + 2];
double list[3 * kMaxN + 2];
int lsize;
int n;
inline int Sign(double x, double y = 0.0) {
  if (fabs(x - y) < kEPS) return 0;
  return x < y ? -1 : 1;
}
inline long long Cross(const std::complex<long long> &a,
                       const std::complex<long long> &b) {
  return a.real() * b.imag() - a.imag() * b.real();
}
inline double Cross(const std::complex<long long> &a,
                    const std::complex<long long> &b, double x, double y) {
  return (b.real() - a.real()) * (y - a.imag()) -
         (b.imag() - a.imag()) * (x - a.real());
}
inline bool DoubleCmp(double a, double b) { return Sign(a - b) == 0; }
void ReadIn() {
  int x, y;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 3; ++j) {
      scanf("%d%d", &x, &y);
      tri[i][j] = std::complex<long long>(x, y);
    }
    if (Cross(tri[i][1] - tri[i][0], tri[i][2] - tri[i][0]) < 0)
      std::swap(tri[i][1], tri[i][2]);
  }
}
inline double CrossPoint(const std::complex<long long> &a,
                         const std::complex<long long> &at,
                         const std::complex<long long> &b,
                         const std::complex<long long> &bt) {
  std::complex<long long> va = at - a, vb = bt - b;
  long long q = Cross(va, vb);
  long long pa = Cross(b - a, vb), pb = Cross(b - a, va);
  if (q == 0) return -1.0;
  if (q < 0) {
    pa = -pa;
    pb = -pb;
    q = -q;
  }
  if (pa <= 0 || pa > q || pb < 0 || pb > q) return -1.0;
  return (double)pa / (double)q;
}
inline bool IsInside(double x, double y) {
  for (int i = 0; i < n; ++i)
    if (Sign(Cross(tri[i][0], tri[i][1], x, y)) > 0 &&
        Sign(Cross(tri[i][1], tri[i][2], x, y)) > 0 &&
        Sign(Cross(tri[i][2], tri[i][0], x, y)) > 0)
      return true;
  return false;
}
void Solve() {
  double result = 0.0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 3; ++j) {
      lsize = 2;
      list[0] = 0.0;
      list[1] = 1.0;
      for (int k = 0; k < n; ++k)
        if (i != k)
          for (int l = 0; l < 3; ++l) {
            double t = CrossPoint(tri[i][j], tri[i][(j + 1) % 3], tri[k][l],
                                  tri[k][(l + 1) % 3]);
            if (Sign(t) >= 0) list[lsize++] = t;
          }
      std::sort(list, list + lsize);
      lsize = std::unique(list, list + lsize, DoubleCmp) - list;
      std::complex<long long> v = tri[i][(j + 1) % 3] - tri[i][j];
      for (int k = 0; k < lsize - 1; ++k)
        if (!IsInside(
                tri[i][j].real() + v.real() * (list[k] + list[k + 1]) / 2.0,
                tri[i][j].imag() + v.imag() * (list[k] + list[k + 1]) / 2.0))
          result += sqrt(v.real() * v.real() + v.imag() * v.imag()) *
                    (list[k + 1] - list[k]);
    }
  printf("%lf\n", result);
}
int main() {
  ReadIn();
  Solve();
  return 0;
}