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
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
struct point {
  int x, y;
  point(){};
  point(int x, int y) : x(x), y(y){};
};
struct dpoint {
  long double x, y;
  dpoint(){};
  dpoint(long double x, long double y) : x(x), y(y){};
  dpoint(point a) {
    x = a.x;
    y = a.y;
  }
  bool operator<(const dpoint& a) const {
    if (abs(x - a.x) > eps) return x < a.x;
    return y < a.y - eps;
  }
};
struct segment {
  point p1, p2;
  segment(){};
  segment(const point& P1, const point& P2) {
    p1 = P1;
    p2 = P2;
  }
};
struct line {
  int a, b;
  long long c;
  line(){};
  line(const point& p1, const point& p2) {
    a = p1.y - p2.y;
    b = p2.x - p1.x;
    c = -p1.x * 1LL * a - p1.y * 1LL * b;
  }
  line(const segment& s) {
    a = s.p1.y - s.p2.y;
    b = s.p2.x - s.p1.x;
    c = -s.p1.x * 1LL * a - s.p1.y * 1LL * b;
  }
  int side(const point& p) {
    long long tmp = a * 1LL * p.x + b * 1LL * p.y + c;
    if (tmp < 0) return -1;
    if (tmp > 0) return 1;
    return 0;
  }
};
bool isintersec(const segment& a, const segment& b) {
  line l(a);
  if (l.side(b.p1) * l.side(b.p2) != -1) return 0;
  line l1(b);
  if (l1.side(a.p1) * l1.side(a.p2) != -1) return 0;
  return 1;
}
long double det(long double a, long double b, long double c, long double d) {
  return a * d - b * c;
}
dpoint intersec(line m, line n) {
  dpoint res;
  long double zn = det(m.a, m.b, n.a, n.b);
  res.x = -det(m.c, m.b, n.c, n.b) / zn;
  res.y = -det(m.a, m.c, n.a, n.c) / zn;
  return res;
}
point t[110][3];
int n;
long double dest(const dpoint& a, const dpoint& b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
dpoint operator-(dpoint a, dpoint b) { return dpoint(a.x - b.x, a.y - b.y); }
point operator-(point a, point b) { return point(a.x - b.x, a.y - b.y); }
dpoint operator+(dpoint a, dpoint b) { return dpoint(a.x + b.x, a.y + b.y); }
dpoint operator/(dpoint a, int b) { return dpoint(a.x / b, a.y / b); }
long double operator*(const dpoint& a, const dpoint& b) {
  return a.x * b.y - a.y * b.x;
}
long long operator*(const point& a, const point& b) {
  return a.x * 1LL * b.y - a.y * 1LL * b.x;
}
bool check(const dpoint& p, const point& a, const point& b, const point& c) {
  long long s = abs((b - a) * (c - a));
  long double s1 = abs((a - p) * (b - p));
  long double s2 = abs((a - p) * (c - p));
  long double s3 = abs((b - p) * (c - p));
  if (abs(s1) < eps) return false;
  if (abs(s2) < eps) return false;
  if (abs(s3) < eps) return false;
  if (abs(s - s1 - s2 - s3) < eps * max(1LL, s)) return true;
  return false;
}
bool check(dpoint p) {
  for (int i = 0; i < n; i++)
    if (check(p, t[i][0], t[i][1], t[i][2])) return false;
  return true;
}
long double ans;
void solve(const segment& s) {
  vector<dpoint> p;
  p.push_back(dpoint(s.p1.x, s.p1.y));
  p.push_back(dpoint(s.p2.x, s.p2.y));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 3; j++) {
      segment tmp(t[i][j], t[i][(j + 1) % 3]);
      if (isintersec(s, tmp)) p.push_back(intersec(line(s), line(tmp)));
    }
  sort(p.begin(), p.end());
  for (int i = 0; i + 1 < p.size(); i++) {
    if (check((p[i] + p[i + 1]) / 2)) ans += dest(p[i], p[i + 1]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 3; j++) scanf("%d %d", &t[i][j].x, &t[i][j].y);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 3; j++) solve(segment(t[i][j], t[i][(j + 1) % 3]));
  cout.precision(15);
  cout << fixed << ans << endl;
  return 0;
}
