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 long double eps = 1e-8;
struct Point {
  long double x, y;
  Point() {}
  Point(long double xx, long double yy) {
    x = xx;
    y = yy;
  }
  Point operator+(Point a) { return Point(x + a.x, y + a.y); }
  Point operator-(Point a) { return Point(x - a.x, y - a.y); }
  Point operator*(long double c) { return Point(x * c, y * c); }
  Point operator/(long double c) { return Point(x / c, y / c); }
  bool operator<(const Point &a) const {
    return (abs(x - a.x) < eps) ? (y < a.y) : (x < a.x);
  }
  bool operator==(const Point &a) const {
    return (abs(x - a.x) < eps) && (abs(y - a.y) < eps);
  }
};
inline long double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
inline int sign(long double x) {
  if (abs(x) < eps) return 0;
  if (x > 0) return 1;
  return -1;
}
inline bool isInside(Point a, Point b, Point c, Point x) {
  int as = sign(cross(a - x, b - x));
  int bs = sign(cross(b - x, c - x));
  int cs = sign(cross(c - x, a - x));
  return (as == bs) && (bs == cs);
}
inline void intersect(Point a, Point b, Point c, Point d, vector<Point> &v) {
  long double x0 = a.x - c.x;
  long double y0 = a.y - c.y;
  long double x1 = a.x - b.x;
  long double y1 = a.y - b.y;
  long double x2 = c.x - d.x;
  long double y2 = c.y - d.y;
  long double det = x1 * y2 - x2 * y1;
  if (abs(det) < eps) return;
  long double t = (y2 * x0 - x2 * y0) / det;
  long double s = (y1 * x0 - x1 * y0) / det;
  if (t < 0 || t > 1 || s < 0 || s > 1) return;
  v.push_back(a + (b - a) * t);
}
inline long double dist(Point a, Point b) {
  a = a - b;
  return sqrt(a.x * a.x + a.y * a.y);
}
Point tang[105][3];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(32);
  int n;
  cin >> n;
  vector<pair<Point, Point> > seg;
  for (int i = 0; i < n; i++) {
    cin >> tang[i][0].x >> tang[i][0].y;
    cin >> tang[i][1].x >> tang[i][1].y;
    cin >> tang[i][2].x >> tang[i][2].y;
    seg.push_back({tang[i][0], tang[i][1]});
    seg.push_back({tang[i][1], tang[i][2]});
    seg.push_back({tang[i][2], tang[i][0]});
  }
  long double ans = 0.0;
  for (int i = 0; i < seg.size(); i++) {
    vector<Point> v;
    for (int j = 0; j < seg.size(); j++) {
      if (i == j) continue;
      intersect(seg[i].first, seg[i].second, seg[j].first, seg[j].second, v);
    }
    v.push_back(seg[i].first);
    v.push_back(seg[i].second);
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    for (int j = 1; j < v.size(); j++) {
      Point md = (v[j] + v[j - 1]) / 2;
      bool flg = true;
      for (int k = 0; k < n; k++) {
        if (isInside(tang[k][0], tang[k][1], tang[k][2], md)) {
          flg = false;
          break;
        }
      }
      if (flg) ans += dist(v[j], v[j - 1]);
    }
  }
  cout << ans;
  return 0;
}