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;
struct pkt {
  double x, y;
  int nr;
};
bool por(pkt a, pkt b) {
  if (a.x < b.x) return true;
  if (a.x > b.x) return false;
  if (a.y < b.y) return true;
  if (a.y > b.y) return false;
  return (a.nr < b.nr);
}
double Odl(pkt a, pkt b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
double Wek(pkt a, pkt b, pkt c) {
  pkt w1 = {b.x - a.x, b.y - a.y};
  pkt w2 = {c.x - a.x, c.y - a.y};
  return w1.x * w2.y - w2.x * w1.y;
}
bool NaOdc(pkt a, pkt b, pkt s) {
  if (a.x == b.x) {
    if (a.y > b.y) swap(a, b);
    return (s.x == a.x && s.y >= a.y && s.y <= b.y);
  }
  if (a.y == b.y) {
    if (a.x > b.x) swap(a, b);
    return (s.y == a.y && s.x >= a.x && s.x <= b.x);
  }
  if (a.x > b.x) swap(a, b);
  return (Wek(a, b, s) == 0 && s.x >= a.x && s.x <= b.x);
}
bool WTrojkacie(vector<pkt>& tr, pkt sr) {
  int dod = 0, uj = 0;
  for (int i = 0; i < 3; ++i) {
    double wek = Wek(tr[i], tr[(i + 1) % 3], sr);
    if (wek > 0.0) ++dod;
    if (wek < 0.0) ++uj;
  }
  return (dod == 3 || uj == 3);
}
pkt PrzeOdc(pkt a, pkt b, pkt c, pkt d) {
  if (a.x == b.x) {
    double a1 = (d.y - c.y) / (d.x - c.x);
    double b1 = c.y - a1 * c.x;
    return {a.x, a1 * a.x + b1};
  }
  if (c.x == d.x) {
    double a1 = (b.y - a.y) / (b.x - a.x);
    double b1 = a.y - a1 * a.x;
    return {c.x, a1 * c.x + b1};
  }
  double a1 = (b.y - a.y) / (b.x - a.x);
  double b1 = a.y - a1 * a.x;
  double a2 = (d.y - c.y) / (d.x - c.x);
  double b2 = c.y - a2 * c.x;
  double X = (b2 - b1) / (a1 - a2);
  double Y = a2 * X + b2;
  return {X, Y, 0};
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<vector<pkt> > p(n, vector<pkt>(3));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 3; ++j) cin >> p[i][j].x >> p[i][j].y;
  double odp = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 3; ++j) odp += Odl(p[i][j], p[i][(j + 1) % 3]);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 3; ++j) {
      pkt a = p[i][j], b = p[i][(j + 1) % 3];
      vector<pkt> przec;
      przec.push_back(a);
      przec.push_back(b);
      for (int k = 0; k < n; ++k) {
        if (k == i) continue;
        for (int l = 0; l < 3; ++l) {
          pkt c = p[k][l], d = p[k][(l + 1) % 3];
          int ile = 0;
          if (NaOdc(a, b, c)) {
            ++ile;
            przec.push_back(c);
          }
          if (NaOdc(a, b, d)) {
            ++ile;
            przec.push_back(d);
          }
          if (ile != 0) continue;
          int dod = 0, uj = 0;
          if (Wek(a, b, c) > 0) ++dod;
          if (Wek(a, b, c) < 0) ++uj;
          if (Wek(a, b, d) > 0) ++dod;
          if (Wek(a, b, d) < 0) ++uj;
          if (dod != 1 || uj != 1) continue;
          dod = 0;
          uj = 0;
          if (Wek(c, d, a) > 0) ++dod;
          if (Wek(c, d, a) < 0) ++uj;
          if (Wek(c, d, b) > 0) ++dod;
          if (Wek(c, d, b) < 0) ++uj;
          if (dod != 1 || uj != 1) continue;
          przec.push_back(PrzeOdc(a, b, c, d));
        }
      }
      for (int k = 0; k < przec.size(); ++k) przec[k].nr = k;
      sort(przec.begin(), przec.end(), por);
      for (int k = 1; k < przec.size(); ++k) {
        pkt sr = {(przec[k].x + przec[k - 1].x) / 2.0,
                  (przec[k].y + przec[k - 1].y) / 2.0, 0};
        bool jest = false;
        for (int l = 0; l < n; ++l)
          if (l != i && WTrojkacie(p[l], sr)) jest = true;
        if (jest) odp -= Odl(przec[k], przec[k - 1]);
      }
    }
  }
  cout << fixed << setprecision(6);
  cout << odp;
  return 0;
}