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 int MAX = 101;
struct point {
  long double x, y;
  point() : x(0), y(0) {}
  point(long double _x, long double _y) : x(_x), y(_y) {}
  friend istream& operator>>(istream& fin, point& o) {
    return fin >> o.x >> o.y;
  }
  friend ostream& operator<<(ostream& fout, const point& o) {
    return fout << o.x << ',' << o.y;
  }
  bool operator<(const point& o) const {
    return x + 1e-8 < o.x || (x - o.x < 1e-8 && y + 1e-8 < o.y);
  }
  point operator+(const point& o) const { return point(x + o.x, y + o.y); }
  point operator-(const point& o) const { return point(x - o.x, y - o.y); }
  point operator*(long double val) const { return point(x * val, y * val); }
  point operator/(long double val) const { return point(x / val, y / val); }
};
point tri[MAX * 3];
pair<point, point> line[MAX * 3];
int trix[MAX * 3], triy[MAX * 3], linex[MAX * 3], liney[MAX * 3], n;
vector<point> pnts[MAX * 3];
inline long double cross(const point& a, const point& b) {
  return a.x * b.y - a.y * b.x;
}
inline long double dot(const point& a, const point& b) {
  return a.x * b.x + a.y * b.y;
}
inline long double dist(const point& a, const point& b) {
  return sqrt(((a.x - b.x) * (a.x - b.x)) + ((a.y - b.y) * (a.y - b.y)));
}
bool check(const point& p) {
  for (int i = 0; i < n; ++i) {
    long double c1 =
        cross(((p) - (line[i * 3].first)), ((p) - (line[i * 3].second)));
    long double c2 = cross(((p) - (line[i * 3 + 1].first)),
                           ((p) - (line[i * 3 + 1].second)));
    long double c3 = cross(((p) - (line[i * 3 + 2].first)),
                           ((p) - (line[i * 3 + 2].second)));
    if (c1 < -1e-8 && c2 < -1e-8 && c3 < -1e-8 ||
        c1 > 1e-8 && c2 > 1e-8 && c3 > 1e-8)
      return false;
  }
  return true;
}
bool intersect(const point& A0, const point& A1, const point& B0,
               const point& B1, point& P) {
  long double s = cross(A0 - B0, A1 - A0) / cross(B1 - B0, A1 - A0);
  P = B0 + (B1 - B0) * s;
  return !(isnan(s) + isinf(s) * 2);
}
bool onsegment(const point& A, const point& B, const point& P) {
  return dot(((A) - (B)), ((A) - (P))) > -1e-8 &&
         dot(((B) - (A)), ((B) - (P))) > -1e-8;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 3; ++j) cin >> tri[i * 3 + j];
    line[i * 3] = {tri[i * 3], tri[i * 3 + 1]};
    line[i * 3 + 1] = {tri[i * 3 + 1], tri[i * 3 + 2]};
    line[i * 3 + 2] = {tri[i * 3 + 2], tri[i * 3]};
  }
  long double ans = 0;
  for (int i = 0; i < 3 * n; ++i) {
    pnts[i].push_back(line[i].first);
    pnts[i].push_back(line[i].second);
    for (int j = i + 1; j < 3 * n; ++j) {
      point p;
      if (intersect(line[i].first, line[i].second, line[j].first,
                    line[j].second, p)) {
        if (onsegment(line[i].first, line[i].second, p)) pnts[i].push_back(p);
        if (onsegment(line[j].first, line[j].second, p)) pnts[j].push_back(p);
      }
    }
    sort(pnts[i].begin(), pnts[i].end());
    int sz = pnts[i].size();
    for (int j = 0; j < sz - 1; ++j)
      if (check((pnts[i][j] + pnts[i][j + 1]) / 2))
        ans += dist(pnts[i][j], pnts[i][j + 1]);
  }
  cout << setprecision(10) << fixed;
  cout << ans << endl;
  return 0;
}