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;
int dcmp(double x) {
  if (fabs(x) < 1e-6) return 0;
  return x < 0 ? -1 : 1;
}
struct Line {
  pair<double, double> p, v;
};
bool operator<(Line l1, Line l2) {
  return atan2(l1.v.second, l1.v.first) < atan2(l2.v.second, l2.v.first);
}
bool equal(double x, double y) { return fabs(x - y) < 1e-6; }
bool less(double x, double y) { return x < y - 1e-6; }
bool greater(double x, double y) { return x > y + 1e-6; }
pair<double, double> operator+(pair<double, double> p1,
                               pair<double, double> p2) {
  return pair<double, double>(p1.first + p2.first, p1.second + p2.second);
}
pair<double, double> operator-(pair<double, double> p1,
                               pair<double, double> p2) {
  return pair<double, double>(p1.first - p2.first, p1.second - p2.second);
}
double operator*(pair<double, double> p1, pair<double, double> p2) {
  return p1.first * p2.first + p1.second * p2.second;
}
pair<double, double> operator*(double t, pair<double, double> p) {
  return pair<double, double>(t * p.first, t * p.second);
}
double operator^(pair<double, double> p1, pair<double, double> p2) {
  return (p1.first * p2.second - p1.second * p2.first);
}
double len(pair<double, double> p) {
  return sqrt(1.0 * p.first * p.first + p.second * p.second);
}
double angle(pair<double, double> p1, pair<double, double> p2) {
  if ((p1 ^ p2) < 0)
    return 2 * acos(-1.0) - acos((double)(p1 * p2) / len(p1) / len(p2));
  return acos((double)(p1 * p2) / len(p1) / len(p2));
}
bool on(pair<double, double> a, pair<double, double> p1,
        pair<double, double> p2) {
  return ((dcmp((p1 - a) * (p2 - a)) <= 0) && dcmp((p1 - a) ^ (p2 - a)) == 0);
}
bool in(pair<double, double> a, pair<double, double> p1,
        pair<double, double> p2) {
  return dcmp((p1 ^ a) * (p2 ^ a)) < 0;
}
bool cross(pair<double, double> p1, pair<double, double> p2,
           pair<double, double> p3, pair<double, double> p4) {
  if (on(p3, p1, p2) || on(p4, p1, p2) || on(p1, p3, p4) || on(p2, p3, p4))
    return 1;
  if (in(p2 - p1, p3 - p1, p4 - p1) && in(p4 - p3, p1 - p3, p2 - p3)) return 1;
  return 0;
}
double torad(double deg) { return acos(-1.0) * deg / 180.0; }
pair<double, double> rotate(pair<double, double> p, double rad) {
  return pair<double, double>(p.first * cos(rad) - p.second * sin(rad),
                              p.first * sin(rad) + p.second * cos(rad));
}
double dist(pair<double, double> p, Line l) {
  return fabs((p - l.p) ^ l.v) / len(l.v);
}
pair<double, double> LineIntersection(Line l1, Line l2) {
  double t = 1.0 * ((l2.p - l1.p) ^ l2.v) / (l1.v ^ l2.v);
  return l1.p + t * l1.v;
}
bool SegLineIntersect(pair<double, double> p1, pair<double, double> p2,
                      Line l) {
  Line l1;
  l1.p = p1, l1.v = p2 - p1;
  if (dcmp(l.v ^ (l.p - p1)) == 0 || dcmp(l.v ^ (l.p - p2)) == 0) return 1;
  return in(l.v, p1 - l.p, p2 - l.p);
}
double area2(vector<pair<double, double> > ps) {
  double res = 0;
  for (int i = 0; i < ps.size(); i++) res += (ps[i] ^ ps[(i + 1) % ps.size()]);
  if (res < 0) res = -res;
  return res;
}
bool inPolygon(pair<double, double> p, vector<pair<double, double> > polygon) {
  long double tot_angle = 0;
  int nn = polygon.size();
  for (int i = 0; i < nn; i++)
    tot_angle += angle(polygon[i] - p, polygon[(i + 1) % nn] - p);
  if (dcmp(tot_angle) == 0) return 0;
  return 1;
}
vector<pair<double, double> > ConvexHull(vector<pair<double, double> > ps) {
  int nn = ps.size();
  sort(ps.begin(), ps.end());
  vector<pair<double, double> > res;
  int k = 0;
  for (int i = 0; i < nn; i++) {
    while (k > 1 &&
           dcmp((ps[i] - res[k - 2]) ^ (res[k - 1] - res[k - 2])) >= 0) {
      res.pop_back();
      k--;
    }
    res.push_back(ps[i]);
    k++;
  }
  int t = k;
  for (int i = nn - 2; i >= 0; i--) {
    while (k > t &&
           dcmp((ps[i] - res[k - 2]) ^ (res[k - 1] - res[k - 2])) >= 0) {
      res.pop_back();
      k--;
    }
    res.push_back(ps[i]);
    k++;
  }
  if (nn > 1) res.pop_back();
  return res;
};
vector<pair<double, double> > cutPolygon(vector<pair<double, double> > ps,
                                         Line L) {
  vector<pair<double, double> > res;
  for (int i = 0; i < ps.size(); i++) {
    if (dcmp((ps[i] - L.p) ^ L.v) <= 0) res.push_back(ps[i]);
    if (dcmp((ps[(i + 1) % ps.size()] - ps[i]) ^ L.v) != 0) {
      pair<double, double> its =
          LineIntersection(L, Line{ps[i], ps[(i + 1) % ps.size()] - ps[i]});
      if (on(its, ps[(i + 1) % ps.size()], ps[i])) res.push_back(its);
    }
  }
  return res;
}
struct Half_Plane_Intersection {
  const static int MAXN = 100005;
  int n;
  Line L[MAXN], s[MAXN];
  vector<pair<double, double> > a;
  void init() { n = 0; }
  void add_Line(Line l) { L[n++] = l; }
  bool OnLeft(Line l, pair<double, double> p) {
    return dcmp(l.v ^ (p - l.p)) >= 0;
  }
  int solve() {
    a.clear();
    sort(L, L + n);
    int first, last;
    pair<double, double> *p = new pair<double, double>[n];
    Line *q = new Line[n];
    q[first = last = 0] = L[0];
    for (int i = 1; i < n; i++) {
      while (first < last && !OnLeft(L[i], p[last - 1])) last--;
      while (first < last && !OnLeft(L[i], p[first])) first++;
      q[++last] = L[i];
      if (dcmp(q[last].v ^ q[last - 1].v) == 0) {
        last--;
        if (OnLeft(q[last], L[i].p)) q[last] = L[i];
      }
      if (first < last) p[last - 1] = LineIntersection(q[last - 1], q[last]);
    }
    while (first < last && !OnLeft(q[first], p[last - 1])) last--;
    if (last - first <= 1) return 0;
    p[last] = LineIntersection(q[last], q[first]);
    for (int i = first; i <= last; i++) a.push_back(p[i]);
    return a.size();
  }
} hpi;
int n;
vector<pair<double, double> > pt[2], v[2];
vector<pair<double, double> > mid[3 * 105];
vector<pair<double, double> > ps[105];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    pair<double, double> po;
    for (int j = 0; j < 3; j++) {
      scanf("%lf%lf", &po.first, &po.second);
      ps[i].push_back(po);
    }
    for (int j = 0; j < 3; j++) {
      pt[0].push_back(ps[i][j]);
      pt[1].push_back(ps[i][(j + 1) % 3]);
    }
  }
  for (int i = 0; i < 3 * n; i++) {
    for (int j = i + 1; j < 3 * n; j++) {
      if (cross(pt[0][i], pt[1][i], pt[0][j], pt[1][j])) {
        Line l1{pt[0][i], pt[1][i] - pt[0][i]};
        Line l2{pt[0][j], pt[1][j] - pt[0][j]};
        pair<double, double> inter = LineIntersection(l1, l2);
        mid[i].push_back(inter);
        mid[j].push_back(inter);
      }
    }
  }
  for (int i = 0; i < 3 * n; i++) {
    mid[i].push_back(pt[0][i]);
    mid[i].push_back(pt[1][i]);
    sort(mid[i].begin(), mid[i].end());
    for (int j = 0; j + 1 < mid[i].size(); j++) {
      if (len(mid[i][j + 1] - mid[i][j]) == 0) continue;
      v[0].push_back(mid[i][j]);
      v[1].push_back(mid[i][j + 1]);
    }
  }
  double ans = 0;
  for (int i = 0; i < v[0].size(); i++) {
    pair<double, double> mm = 0.5 * (v[0][i] + v[1][i]);
    bool ok = 1;
    for (int j = 0; j < n; j++) {
      if (on(mm, ps[j][0], ps[j][1]) || on(mm, ps[j][2], ps[j][1]) ||
          on(mm, ps[j][0], ps[j][2]))
        continue;
      bool now[3], out = 0;
      for (int k = 0; k < 3; k++) {
        if (dcmp((mm - ps[j][k]) ^ (ps[j][(k + 1) % 3] - ps[j][k])) > 0)
          now[k] = 1;
        else
          now[k] = 0;
        if (k > 0 && now[k] != now[k - 1]) out = 1;
      }
      if (out == 0) ok = 0;
    }
    if (ok) ans += len(v[1][i] - v[0][i]);
  }
  printf("%.15f\n", ans);
  return 0;
}