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>
#pragma comment(linker, "/STACK:36777216")
using namespace std;
void solve();
int main() {
  ios::sync_with_stdio(0);
  solve();
  return 0;
}
template <class T>
T ABS(T a) {
  return a < 0 ? -a : a;
}
const long double KEps = 1.0E-8;
struct Point {
  long double x, y;
  Point(long double x = 0, long double y = 0) : x(x), y(y) {}
  bool operator<(const Point& r) const {
    return x < r.x - KEps || (ABS(x - r.x) < KEps && y < r.y - KEps);
  }
  bool operator==(const Point& r) const {
    return ABS(x - r.x) < KEps && ABS(y - r.y) < KEps;
  }
};
bool intercepts(long double x11, long double y11, long double x12,
                long double y12, long double x21, long double y21,
                long double x22, long double y22, Point& res) {
  long double a = x12 - x11, b = -(x22 - x21), c = y12 - y11, d = -(y22 - y21);
  long double dx = x21 - x11, dy = y21 - y11;
  long double det = a * d - c * b;
  if (ABS(det) < KEps) return false;
  long double t1 = (dx * d - dy * b) / det;
  long double t2 = (a * dy - c * dx) / det;
  if (t1 < -KEps) return false;
  if (t2 < -KEps) return false;
  if (t1 > 1.0 + KEps) return false;
  if (t2 > 1.0 + KEps) return false;
  res.x = x11 + a * t1;
  res.y = y11 + c * t1;
  return true;
}
int N;
int data[100][3][2];
bool testIn(long double x, long double y, int i) {
  long double angle = 0;
  for (int j = 0; j < 3; j++) {
    int nj = j + 1;
    if (nj == 3) nj = 0;
    long double ax = data[i][j][0] - x, ay = data[i][j][1] - y;
    long double bx = data[i][nj][0] - x, by = data[i][nj][1] - y;
    angle += atan2(ax * by - ay * bx, ax * bx + ay * by);
  }
  return ABS(angle) > KEps;
}
void solve() {
  vector<pair<Point, Point> > otr;
  vector<int> ids;
  cin >> N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> data[i][j][0] >> data[i][j][1];
    }
    otr.push_back(make_pair(Point(data[i][0][0], data[i][0][1]),
                            Point(data[i][1][0], data[i][1][1])));
    otr.push_back(make_pair(Point(data[i][0][0], data[i][0][1]),
                            Point(data[i][2][0], data[i][2][1])));
    otr.push_back(make_pair(Point(data[i][1][0], data[i][1][1]),
                            Point(data[i][2][0], data[i][2][1])));
    ids.push_back(i);
    ids.push_back(i);
    ids.push_back(i);
  }
  long double ans = 0;
  vector<Point> v;
  for (int i = 0; i < (int)((otr).size()); i++) {
    v.resize(0);
    v.push_back(otr[i].first);
    v.push_back(otr[i].second);
    for (int j = 0; j < (int)((otr).size()); j++) {
      if (i == j) continue;
      Point pt;
      if (intercepts(otr[i].first.x, otr[i].first.y, otr[i].second.x,
                     otr[i].second.y, otr[j].first.x, otr[j].first.y,
                     otr[j].second.x, otr[j].second.y, pt)) {
        v.push_back(pt);
      }
    }
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    for (int k = 0; k < (int)((v).size()) - 1; k++) {
      long double x = (v[k + 1].x + v[k].x) * 0.5;
      long double y = (v[k + 1].y + v[k].y) * 0.5;
      bool ok = true;
      for (int j = 0; j < N; j++) {
        if (j == ids[i]) continue;
        if (testIn(x, y, j)) {
          ok = false;
          break;
        }
      }
      if (ok) {
        ans += sqrtl((v[k + 1].x - v[k].x) * (v[k + 1].x - v[k].x) +
                     (v[k + 1].y - v[k].y) * (v[k + 1].y - v[k].y));
      }
    }
  }
  cout.precision(10);
  cout << fixed << ans << '\n';
}