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;
const double EPS = 10e-9;
int sgn(long long x) {
  if (x == 0LL) return 0;
  return (x > 0LL) ? 1 : -1;
}
inline bool IsZero(double x) { return x >= -EPS && x <= EPS; }
struct POINT {
  int x, y;
  POINT(int x = 0, int y = 0) : x(x), y(y) {}
  bool operator==(POINT& a) { return a.x == x && a.y == y; }
};
ostream& operator<<(ostream& a, POINT& p) {
  a << "(" << p.x << ", " << p.y << ")";
  return a;
}
struct POINTD {
  double x, y;
  POINTD(double wx = 0, double wy = 0) : x(wx), y(wy) {}
  POINTD(const POINT& p) : x(p.x), y(p.y) {}
  bool operator==(POINTD& a) { return IsZero(a.x - x) && IsZero(a.y - y); }
};
bool OrdXY(POINTD* a, POINTD* b) {
  return IsZero(a->x - b->x) ? a->y < b->y : a->x < b->x;
}
ostream& operator<<(ostream& a, POINTD& p) {
  a << "(" << p.x << ", " << p.y << ")";
  return a;
}
int sgn(double x) { return IsZero(x) ? 0 : (x < 0 ? -1 : 1); }
int sgn(int x) { return !x ? 0 : (x < 0 ? -1 : 1); }
int LineCrossPoint(POINTD p1, POINTD p2, POINTD l1, POINTD l2, POINTD& prz) {
  double s, t = (p1.x - p2.x) * (l1.y - l2.y) - (p1.y - p2.y) * (l1.x - l2.x);
  s = (l2.x - p2.x) * (l1.y - l2.y) - (l2.y - p2.y) * (l1.x - l2.x);
  if (IsZero(t)) return IsZero(s) ? 2 : 0;
  s = s / t;
  prz.x = s * p1.x + (1 - s) * p2.x;
  prz.y = s * p1.y + (1 - s) * p2.y;
  return 1;
}
inline bool SegmentCrossPoint(POINTD p1, POINTD p2, POINTD l1, POINTD l2,
                              vector<POINTD>& r) {
  r.clear();
  double
      w1 = sgn(((p2.x - p1.x) * (l1.y - p1.y) - (p2.y - p1.y) * (l1.x - p1.x))),
      w2 = sgn(((p2.x - p1.x) * (l2.y - p1.y) - (p2.y - p1.y) * (l2.x - p1.x))),
      v1 = sgn(((l2.x - l1.x) * (p1.y - l1.y) - (l2.y - l1.y) * (p1.x - l1.x))),
      v2 = sgn(((l2.x - l1.x) * (p2.y - l1.y) - (l2.y - l1.y) * (p2.x - l1.x)));
  if (w1 * w2 > 0 || v1 * v2 > 0) return false;
  if (!w1 && !w2) {
    if (OrdXY(&p2, &p1)) swap(p1, p2);
    if (OrdXY(&l2, &l1)) swap(l1, l2);
    if (OrdXY(&p2, &l1) || OrdXY(&l2, &p1)) return false;
    if (p2 == l1)
      r.push_back(POINTD(p2.x, p2.y));
    else if (p1 == l2)
      r.push_back(POINTD(l2.x, l2.y));
    else {
      r.push_back(OrdXY(&p1, &l1) ? l1 : p1);
      r.push_back(OrdXY(&p2, &l2) ? p2 : l2);
    }
  } else if (l1 == l2)
    r.push_back(l1);
  else if (p1 == p2)
    r.push_back(p2);
  else {
    double t =
        double((l2.x - p2.x) * (l1.y - l2.y) - (l2.y - p2.y) * (l1.x - l2.x)) /
        double((p1.x - p2.x) * (l1.y - l2.y) - (p1.y - p2.y) * (l1.x - l2.x));
    r.push_back(
        POINTD(t * p1.x + (1.0 - t) * p2.x, t * p1.y + (1.0 - t) * p2.y));
  }
  return true;
}
inline bool SegmentCross(POINTD& p1, POINTD& p2, POINTD& l1, POINTD& l2) {
  return sgn(((p2.x - p1.x) * (l1.y - p1.y) - (p2.y - p1.y) * (l1.x - p1.x))) *
                 sgn(((p2.x - p1.x) * (l2.y - p1.y) -
                      (p2.y - p1.y) * (l2.x - p1.x))) ==
             -1 &&
         sgn(((l2.x - l1.x) * (p1.y - l1.y) - (l2.y - l1.y) * (p1.x - l1.x))) *
                 sgn(((l2.x - l1.x) * (p2.y - l1.y) -
                      (l2.y - l1.y) * (p2.x - l1.x))) ==
             -1;
}
bool PointInConvexPol(vector<POINTD>& l, POINTD p) {
  int a = 1, b = ((int)(l).size()) - 1, c;
  if (((l[a].x - l[0].x) * (l[b].y - l[0].y) -
       (l[a].y - l[0].y) * (l[b].x - l[0].x)) > 0)
    swap(a, b);
  if (((l[a].x - l[0].x) * (p.y - l[0].y) -
       (l[a].y - l[0].y) * (p.x - l[0].x)) > 0 ||
      ((l[b].x - l[0].x) * (p.y - l[0].y) -
       (l[b].y - l[0].y) * (p.x - l[0].x)) < 0)
    return false;
  while (abs(a - b) > 1) {
    c = (a + b) / 2;
    if (((l[c].x - l[0].x) * (p.y - l[0].y) -
         (l[c].y - l[0].y) * (p.x - l[0].x)) > 0)
      b = c;
    else
      a = c;
  }
  return ((l[b].x - l[a].x) * (p.y - l[a].y) -
          (l[b].y - l[a].y) * (p.x - l[a].x)) <= 0;
}
struct odcinek {
  POINTD p1, p2;
};
struct triangle {
  vector<odcinek> v;
} t[110], t1[110];
double sqr(double x) { return x * x; }
double dist(POINTD p1, POINTD p2) {
  return sqrt(sqr(p1.x - p2.x) + sqr(p1.y - p2.y));
}
void cut(odcinek& o, triangle t, vector<odcinek>& v) {
  vector<POINTD> v1, v2, v3, vt;
  vt.push_back(t.v[0].p1);
  vt.push_back(t.v[0].p2);
  vt.push_back(t.v[1].p2);
  if (PointInConvexPol(vt, o.p1) && PointInConvexPol(vt, o.p2)) return;
  odcinek op = o;
  if (SegmentCrossPoint(o.p1, o.p2, t.v[0].p1, t.v[0].p2, v1) &&
      !(v1[0] == o.p1 || v1[0] == o.p2)) {
    if (PointInConvexPol(vt, o.p1)) {
      op.p1 = v1[0];
      v.push_back(op);
    } else if (PointInConvexPol(vt, o.p2)) {
      op.p2 = v1[0];
      v.push_back(op);
    } else {
      if (SegmentCrossPoint(o.p1, o.p2, t.v[1].p1, t.v[1].p2, v2)) {
        if (dist(o.p1, v1[0]) < dist(o.p1, v2[0])) {
          op.p2 = v1[0];
          v.push_back(op);
          op.p1 = v2[0];
          op.p2 = o.p2;
          v.push_back(op);
        } else {
          op.p2 = v2[0];
          v.push_back(op);
          op.p1 = v1[0];
          op.p2 = o.p2;
          v.push_back(op);
        }
        return;
      }
      if (SegmentCrossPoint(o.p1, o.p2, t.v[2].p1, t.v[2].p2, v3)) {
        if (dist(o.p1, v1[0]) < dist(o.p1, v3[0])) {
          op.p2 = v1[0];
          v.push_back(op);
          op.p1 = v3[0];
          op.p2 = o.p2;
          v.push_back(op);
        } else {
          op.p2 = v3[0];
          v.push_back(op);
          op.p1 = v1[0];
          op.p2 = o.p2;
          v.push_back(op);
        }
        return;
      }
    }
    return;
  }
  if (SegmentCrossPoint(o.p1, o.p2, t.v[1].p1, t.v[1].p2, v2) &&
      !(v2[0] == o.p1 || v2[0] == o.p2)) {
    if (PointInConvexPol(vt, o.p1)) {
      op.p1 = v2[0];
      v.push_back(op);
    } else if (PointInConvexPol(vt, o.p2)) {
      op.p2 = v2[0];
      v.push_back(op);
    } else {
      if (SegmentCrossPoint(o.p1, o.p2, t.v[2].p1, t.v[2].p2, v3)) {
        if (dist(o.p1, v2[0]) < dist(o.p1, v3[0])) {
          op.p2 = v2[0];
          v.push_back(op);
          op.p1 = v3[0];
          op.p2 = o.p2;
          v.push_back(op);
        } else {
          op.p2 = v3[0];
          v.push_back(op);
          op.p1 = v2[0];
          op.p2 = o.p2;
          v.push_back(op);
        }
        return;
      }
    }
    return;
  }
  if (SegmentCrossPoint(o.p1, o.p2, t.v[2].p1, t.v[2].p2, v3) &&
      !(v3[0] == o.p1 || v3[0] == o.p2)) {
    if (PointInConvexPol(vt, o.p1)) {
      op.p1 = v3[0];
      v.push_back(op);
    } else if (PointInConvexPol(vt, o.p2)) {
      op.p2 = v3[0];
      v.push_back(op);
    }
    return;
  }
  v.push_back(op);
}
void process(triangle& t1, triangle t2) {
  vector<POINTD> v;
  v.push_back(t2.v[0].p1);
  v.push_back(t2.v[0].p2);
  v.push_back(t2.v[1].p2);
  bool ok = 1;
  for (int i = 0; i < (int)t1.v.size(); i++)
    if (!PointInConvexPol(v, t1.v[i].p1) || !PointInConvexPol(v, t1.v[i].p2)) {
      ok = 0;
      break;
    }
  if (ok) {
    t1.v.clear();
    return;
  }
  vector<odcinek> v1;
  for (int i = 0; i < (int)t1.v.size(); i++) cut(t1.v[i], t2, v1);
  t1.v = v1;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    double a, b, c, d, e, f;
    scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f);
    odcinek o;
    o.p1.x = a;
    o.p1.y = b;
    o.p2.x = c;
    o.p2.y = d;
    t[i].v.push_back(o);
    o.p1.x = c;
    o.p1.y = d;
    o.p2.x = e;
    o.p2.y = f;
    t[i].v.push_back(o);
    o.p1.x = e;
    o.p1.y = f;
    o.p2.x = a;
    o.p2.y = b;
    t[i].v.push_back(o);
    t1[i] = t[i];
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (i != j) process(t1[i], t[j]);
  double res = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < (int)t1[i].v.size(); j++)
      res += dist(t1[i].v[j].p1, t1[i].v[j].p2);
  printf("%.10lf\n", res);
  return 0;
}