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
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 9;
const double EPS = 1e-9;
struct Punkt {
  double x, y;
  Punkt() {}
  Punkt(double x, double y) : x(x), y(y) {}
  void read() { scanf("%lf%lf", &x, &y); }
  Punkt obrocony(double fi) const {
    return Punkt(x * cos(fi) - y * sin(fi), x * sin(fi) + y * cos(fi));
  }
  void obroc(double fi) { (*this) = this->obrocony(fi); }
  void operator+=(const Punkt &p) { x += p.x, y += p.y; }
  double norma() const { return sqrt(x * x + y * y); }
  double norma2() const { return x * x + y * y; }
  Punkt operator-(const Punkt &p) const { return Punkt(x - p.x, y - p.y); }
  double odlegloscDo(const Punkt &p) const { return (*this - p).norma(); }
  double odlegloscDo2(const Punkt &p) const { return (*this - p).norma2(); }
  double kat() const { return atan2(y, x); }
  void operator*=(double a) { x *= a, y *= a; }
  Punkt operator*(double a) const {
    Punkt wynik = *this;
    wynik *= a;
    return wynik;
  }
  Punkt operator+(const Punkt &p) const { return Punkt(x + p.x, y + p.y); }
  bool operator<(const Punkt &p) const {
    if (x == p.x) return y < p.y;
    return x < p.x;
  }
};
bool przecinaSie(double x1, double y1, double x2, double y2, double x3,
                 double y3, double x4, double y4) {
  double mi = (x1 - x2) * (y3 - y4) - (x3 - x4) * (y1 - y2);
  return mi != 0;
}
bool przecinaSie(const pair<Punkt, Punkt> &a, const pair<Punkt, Punkt> &b) {
  return przecinaSie(a.first.x, a.first.y, a.second.x, a.second.y, b.first.x,
                     b.first.y, b.second.x, b.second.y);
}
Punkt przeciecie(double x1, double y1, double x2, double y2, double x3,
                 double y3, double x4, double y4) {
  double mi = (x1 - x2) * (y3 - y4) - (x3 - x4) * (y1 - y2);
  double lix =
      (x1 * y2 - y1 * x2) * (x3 - x4) - ((x3 * y4 - x4 * y3) * (x1 - x2));
  double liy =
      (x1 * y2 - y1 * x2) * (y3 - y4) - ((x3 * y4 - x4 * y3) * (y1 - y2));
  return Punkt((double)lix / (double)mi, (double)liy / (double)mi);
}
Punkt przeciecie(const pair<Punkt, Punkt> &a, const pair<Punkt, Punkt> &b) {
  return przeciecie(a.first.x, a.first.y, a.second.x, a.second.y, b.first.x,
                    b.first.y, b.second.x, b.second.y);
}
bool eq(const Punkt &a, const Punkt &b) {
  return fabs(a.x - b.x) < EPS && fabs(a.y - b.y) < EPS;
}
bool eq(double a, double b) { return fabs(a - b) < EPS; }
bool lezy(const Punkt &p, const pair<Punkt, Punkt> &o) {
  return p.x >= min(o.first.x, o.second.x) &&
         p.x <= max(o.first.x, o.second.x) &&
         p.y >= min(o.first.y, o.second.y) && p.y <= max(o.first.y, o.second.y);
}
bool lezy2(const Punkt &p, const pair<Punkt, Punkt> &o) {
  return eq(o.first.odlegloscDo(o.second),
            p.odlegloscDo(o.first) + p.odlegloscDo(o.second));
}
enum Zawieranie { INSIDE, BORDER, OUTSIDE };
struct Wielokat {
  vector<Punkt> t;
  void dodaj(const Punkt &p) { t.push_back(p); }
  Zawieranie ocen(const Punkt &p) const {
    Punkt pp = p + Punkt(1, EPS * 11);
    int ile = 0;
    for (int i = 0, n = t.size(); i < n; ++i) {
      int ii = i + 1 == n ? 0 : i + 1;
      pair<Punkt, Punkt> oi(t[i], t[ii]);
      if (lezy2(p, oi)) return BORDER;
      if (przecinaSie(pair<Punkt, Punkt>(p, pp), oi)) {
        Punkt d = przeciecie(pair<Punkt, Punkt>(p, pp),
                             pair<Punkt, Punkt>(t[i], t[ii]));
        if (lezy2(d, oi) && d.x >= p.x && !eq(d, t[ii])) ++ile;
      } else if (eq(p.y, t[i].y) && t[i].x >= p.x)
        ++ile;
    }
    if (ile % 2 == 0) return OUTSIDE;
    return INSIDE;
  }
  double ileWSrodku(const pair<Punkt, Punkt> &o) {
    vector<Punkt> prz;
    prz.push_back(o.first);
    prz.push_back(o.second);
    for (int i = 0, n = t.size(); i < n; ++i) {
      int ii = i + 1 == n ? 0 : i + 1;
      pair<Punkt, Punkt> ow(t[i], t[ii]);
      if (przecinaSie(o, ow)) {
        Punkt pp = przeciecie(o, ow);
        if (lezy2(pp, o) && lezy2(pp, ow)) {
          prz.push_back(pp);
        }
      }
    }
    double wynik = 0;
    sort(prz.begin(), prz.end());
    for (int i = 0, n = prz.size(); i + 1 < n; ++i) {
      Punkt d = (prz[i] + prz[i + 1]) * 0.5;
      if (ocen(d) == INSIDE) wynik += prz[i].odlegloscDo(prz[i + 1]);
    }
    return wynik;
  }
};
vector<pair<Punkt, Punkt> > sec;
Wielokat t[103];
void inline jeden() {
  int n;
  scanf("%d", &n);
  for (int i = 0, _ = (n); i < _; ++i) {
    for (int j = 0, _ = (3); j < _; ++j) {
      Punkt p;
      p.read();
      t[i].dodaj(p);
    }
  }
  for (int i = 0, _ = (n); i < _; ++i) {
    for (int j = 0, _ = (3); j < _; ++j) {
      int jj = (j + 1) % 3;
      sec.push_back(pair<Punkt, Punkt>(t[i].t[j], t[i].t[jj]));
    }
  }
  double wynik = 0;
  for (typeof(sec.begin()) s = sec.begin(); s != sec.end(); ++s) {
    vector<Punkt> pps;
    for (typeof(sec.begin()) u = sec.begin(); u != sec.end(); ++u) {
      if (!przecinaSie(*s, *u)) {
        continue;
      }
      Punkt pp = przeciecie(*s, *u);
      if (lezy(pp, *s) && lezy(pp, *u)) {
        pps.push_back(pp);
      }
    }
    pps.push_back(s->first);
    pps.push_back(s->second);
    sort(pps.begin(), pps.end());
    for (typeof(pps.begin()) pp = pps.begin(); pp != pps.end(); ++pp) {
    }
    for (int i = 0, _ = (int((pps).size()) - 1); i < _; ++i) {
      int j = i + 1;
      Punkt d = (pps[i] + pps[j]) * .5;
      bool ok = true;
      for (int k = 0, _ = (n); k < _; ++k) {
        if (t[k].ocen(d) == INSIDE) {
          ok = false;
          break;
        }
      }
      if (ok) {
        wynik += pps[i].odlegloscDo(pps[j]);
      }
    }
  }
  printf("%.10lf\n", wynik);
}
int main() { jeden(); }
