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 MaxN = 605;
struct point {
  double x, y;
  point() {}
  point(double _x, double _y) {
    x = _x;
    y = _y;
  }
  bool good() { return !(fabs(x + 12345.12345) < 0.000001); }
  bool operator==(const point &p) const {
    return fabs(x - p.x) < 0.000001 && fabs(y - p.y) < 0.000001;
  }
  bool operator<(const point &p) const {
    return x + 0.000001 < p.x ||
           (fabs(x - p.x) < 0.000001 && y + 0.000001 < p.y);
  }
  bool operator<=(const point &p) const { return *this < p || *this == p; }
  void swap(point &p) {
    point tmp = *this;
    *this = p;
    p = tmp;
  }
  void scan() { scanf("%lf %lf", &x, &y); }
  void print() { printf("x = %lf y = %lf\n", x, y); }
};
double VP(point a, point b, point c) {
  return a.x * b.y + a.y * c.x + b.x * c.y - b.y * c.x - a.x * c.y - a.y * b.x;
}
double sqr(double x) { return x * x; }
double dist(point a, point b) { return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)); }
struct line {
  double a, b, c;
  line() {}
  line(double _a, double _b, double _c) {
    a = _a;
    b = _b;
    c = _c;
  }
  line(point first, point second) {
    a = first.y - second.y;
    b = second.x - first.x;
    c = first.x * second.y - first.y * second.x;
  }
  point intersection(const line &l) const {
    double det = a * l.b - l.a * b;
    if (fabs(det) < 0.000001) {
      return point(-12345.12345, -12345.12345);
    }
    double x = (b * l.c - l.b * c) / det;
    double y = (l.a * c - a * l.c) / det;
    return point(x, y);
  }
  void print() { printf("line: a = %lf b = %lf c = %lf\n", a, b, c); }
};
struct segment {
  point a, b;
  segment() {}
  segment(point _a, point _b) {
    a = _a;
    b = _b;
  }
  point intersection(segment s) {
    line first = line(a, b);
    line second = line(s.a, s.b);
    point t = first.intersection(second);
    if (!s.hold(t)) return point(-12345.12345, -12345.12345);
    return t;
  }
  bool hold(const point &p) const {
    if (fabs(VP(a, p, b)) > 0.000001) return false;
    double minX = min(a.x, b.x);
    double maxX = max(a.x, b.x);
    double minY = min(a.y, b.y);
    double maxY = max(a.y, b.y);
    return minX - 0.000001 < p.x && p.x < maxX + 0.000001 &&
           minY - 0.000001 < p.y && p.y < maxY + 0.000001;
  }
  void swap() {
    point c = a;
    a = b;
    b = c;
  }
  void print() {
    printf("segment: ");
    a.print();
    printf("         ");
    b.print();
  }
};
struct triangle {
  point a, b, c;
  segment first, second, third;
  void init() {
    first = segment(a, b);
    second = segment(b, c);
    third = segment(c, a);
  }
} t[MaxN];
segment interval[MaxN];
int n;
double calcBoarderLength(segment s, int idx) {
  int num = 0;
  for (int i = 1; i <= n; i++)
    if (i != idx) {
      point a = s.intersection(t[i].first);
      point b = s.intersection(t[i].second);
      point c = s.intersection(t[i].third);
      if (!a.good())
        a = c;
      else if (!b.good())
        b = c;
      if (a == b) a = c;
      if (!a.good() || !b.good()) continue;
      if (!(a < b)) a.swap(b);
      if (!(s.a < s.b)) s.swap();
      if (a < s.a) a = s.a;
      if (b < s.a) b = s.a;
      if (s.b < a) a = s.b;
      if (s.b < b) b = s.b;
      interval[++num] = segment(a, b);
    }
  interval[++num] = segment(s.a, s.a);
  interval[++num] = segment(s.b, s.b);
  double ret = 0.0;
  for (int i = 1; i <= num; i++) {
    bool b = true;
    double add = 2123456789;
    for (int j = 1; j <= num; j++) {
      if (interval[j].a < interval[i].a && interval[i].a <= interval[j].b)
        b = false;
      if (interval[j].a == interval[i].a && j > i) b = false;
      if (interval[j].b < interval[i].a)
        add = min(add, dist(interval[j].b, interval[i].a));
    }
    if (b && add < 2000000000) ret += add;
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    t[i].a.scan();
    t[i].b.scan();
    t[i].c.scan();
    t[i].init();
  }
  double sol = 0.0;
  for (int i = 1; i <= n; i++) {
    sol += calcBoarderLength(t[i].first, i);
    sol += calcBoarderLength(t[i].second, i);
    sol += calcBoarderLength(t[i].third, i);
  }
  printf("%.10lf\n", sol);
  return 0;
}