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>
double sq(double first) { return first * first; }
struct P {
  double first, second;
  P() {}
  P(double first, double second) : first(first), second(second) {}
  void eat() { scanf("%lf%lf", &first, &second); }
  P operator+(const P &p) const {
    return P(first + p.first, second + p.second);
  }
  P operator-(const P &p) const {
    return P(first - p.first, second - p.second);
  }
  P operator*(double k) { return P(first * k, second * k); }
  double operator*(P p) { return first * p.first + second * p.second; }
  double operator^(P p) { return first * p.second - second * p.first; }
  double mag2() { return first * first + second * second; }
  double mag() { return sqrt(mag2()); }
  double ang() { return atan2(second, first); }
  bool operator<(const P &p) const {
    if ((fabs((first) - (p.first)) < 1e-9))
      return ((second) < (p.second) - 1e-9);
    return ((first) < (p.first) - 1e-9);
  }
  bool operator==(const P &p) const {
    return (fabs((first) - (p.first)) < 1e-9) &&
           (fabs((second) - (p.second)) < 1e-9);
  }
  P rot() { return P(-second, first); }
  P rot(double the) {
    return P(first * cos(the) - second * sin(the),
             first * sin(the) + second * cos(the));
  }
  P nor() {
    if ((fabs((mag()) - (0)) < 1e-9)) return *this;
    return *this * (1. / mag());
  }
  P ref(P n) {
    n = n.nor();
    return n * (n * (*this)) * 2 - *this;
  }
  void out() { printf("(%f,%f)\n", first, second); }
};
bool ssi(P a, P b, P c, P d, double &s) {
  P cd = d - c, ab = b - a;
  if ((fabs((cd ^ ab) - (0)) < 1e-9)) return 0;
  double t = ((a ^ ab) - (c ^ ab)) / (cd ^ ab);
  s = ((c ^ cd) - (a ^ cd)) / (ab ^ cd);
  if (((t) < (0) - 1e-9) || ((1) < (t)-1e-9)) return 0;
  if (((s) < (0) - 1e-9) || ((1) < (s)-1e-9)) return 0;
  return 1;
}
bool Ccw(P a, P b, P c) { return ((0) < ((b - a) ^ (c - a)) - 1e-9); }
bool Btw(P a, P b, P c) {
  return (fabs(((a - c).mag()) - ((b - a).mag() + (c - b).mag())) < 1e-9);
}
bool inTri(P tri[3], P q, bool degen = 1) {
  if (degen)
    for (int j = (0); j < (3); ++j)
      if (Btw(tri[j], q, tri[(j + 1) % 3])) return 1;
  bool pos = 0, neg = 0;
  for (int j = (0); j < (3); ++j) {
    if (Ccw(tri[j], tri[(j + 1) % 3], q))
      pos = 1;
    else
      neg = 1;
  }
  return pos ^ neg;
}
using namespace std;
int main(int argc, char **argv) {
  int N;
  cin >> N;
  P fur[N][3];
  for (int i = (0); i < (N); ++i) {
    for (int j = (0); j < (3); ++j) fur[i][j].eat();
    if (!Ccw(fur[i][0], fur[i][1], fur[i][2])) reverse(fur[i], fur[i] + 3);
  }
  double t, res = 0;
  for (int i = (0); i < (N); ++i)
    for (int p = (0); p < (3); ++p) {
      vector<double> tmp;
      tmp.push_back(0);
      for (int j = (0); j < (N); ++j)
        if (i != j)
          for (int q = (0); q < (3); ++q)
            if (ssi(fur[i][p], fur[i][(p + 1) % 3], fur[j][q],
                    fur[j][(q + 1) % 3], t))
              if (!(fabs((tmp.back()) - (t)) < 1e-9)) tmp.push_back(t);
      sort(tmp.begin(), tmp.end());
      if (!(fabs((tmp.back()) - (1)) < 1e-9)) tmp.push_back(1);
      P v = fur[i][(p + 1) % 3] - fur[i][p];
      for (int j = (0); j < ((int)(tmp.size()) - 1); ++j) {
        P vec = fur[i][p] + (v * ((tmp[j + 1] + tmp[j]) * 0.5));
        bool ok = 1;
        for (int k = (0); k < (N) && (ok); ++k)
          if (k != i) ok = !inTri(fur[k], vec);
        if (ok) res += v.mag() * (tmp[j + 1] - tmp[j]);
      }
    }
  printf("%.10f\n", res);
  return 0;
}