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:64000000")
using namespace std;
struct Point {
  double x, y;
  Point(int x, int y) {
    this->x = x;
    this->y = y;
  }
  Point(double x, double y) {
    this->x = x;
    this->y = y;
  }
  bool operator<(Point A) const {
    if (fabs(A.x - x) < (1e-9))
      return y < A.y;
    else
      return x < A.x;
  }
  Point middle(Point A) { return Point(0.5 * (A.x + x), 0.5 * (A.y + y)); }
};
double sqr(double x) { return x * x; }
double dist(double x, double y, double a, double b) {
  return sqrt(sqr(x - a) + sqr(y - b));
}
double dist(Point A, Point B) { return dist(A.x, A.y, B.x, B.y); }
double det2(double a, double b, double c, double d) { return a * d - b * c; }
struct Segment {
  int x0, y0, x1, y1;
  Segment(int a, int b, int c, int d) : x0(a), y0(b), x1(c), y1(d) {}
  friend long long area(Segment A, Segment B) {
    long long dx1 = A.x1 - A.x0;
    long long dy1 = A.y1 - A.y0;
    long long dx2 = B.x1 - B.x0;
    long long dy2 = B.y1 - B.y0;
    return dx1 * dy2 - dx2 * dy1;
  }
  bool isPointOnSegment(Point A) const {
    return fabs(dist(1.0 * x0, 1.0 * y0, A.x, A.y) +
                dist(1.0 * x1, 1.0 * y1, A.x, A.y) -
                dist(1.0 * x1, 1.0 * y1, 1.0 * x0, 1.0 * y0)) < (1e-9);
  }
  bool collinear(Segment AB) const { return (area(*this, AB) == 0LL); }
  bool isIntersection(Segment AB) const {
    double A = (this->y1 - this->y0);
    double B = -(this->x1 - this->x0);
    double C = -(A * this->x1 + B * this->y1);
    assert(fabs(A * x0 + B * y0 + C) < (1e-9));
    assert(fabs(A * x1 + B * y1 + C) < (1e-9));
    double A1 = (AB.y1 - AB.y0);
    double B1 = -(AB.x1 - AB.x0);
    double C1 = -(A1 * AB.x1 + B1 * AB.y1);
    assert(fabs(A1 * AB.x0 + B1 * AB.y0 + C1) < (1e-9));
    assert(fabs(A1 * AB.x1 + B1 * AB.y1 + C1) < (1e-9));
    if (fabs(det2(A, B, A1, B1)) < (1e-9)) return false;
    double d = det2(A, B, A1, B1);
    Point P(det2(-C, B, -C1, B1) / d, det2(A, -C, A1, -C1) / d);
    if (!this->isPointOnSegment(P) || !AB.isPointOnSegment(P)) return false;
    return true;
  }
  Point intersectionPoint(Segment AB) const {
    double A = (this->y1 - this->y0);
    double B = -(this->x1 - this->x0);
    double C = -(A * this->x1 + B * this->y1);
    assert(fabs(A * x0 + B * y0 + C) < (1e-9));
    assert(fabs(A * x1 + B * y1 + C) < (1e-9));
    double A1 = (AB.y1 - AB.y0);
    double B1 = -(AB.x1 - AB.x0);
    double C1 = -(A1 * AB.x1 + B1 * AB.y1);
    assert(fabs(A1 * AB.x0 + B1 * AB.y0 + C1) < (1e-9));
    assert(fabs(A1 * AB.x1 + B1 * AB.y1 + C1) < (1e-9));
    assert(fabs(det2(A, B, A1, B1)) > (1e-9));
    double d = det2(A, B, A1, B1);
    Point P(det2(-C, B, -C1, B1) / d, det2(A, -C, A1, -C1) / d);
    assert(this->isPointOnSegment(P));
    assert(AB.isPointOnSegment(P));
    return P;
  }
};
double scal(double a, double b, double x, double y) { return a * x + b * y; }
struct Line {
  double A, B, C;
  Line(int x0, int y0, int x1, int y1) {
    A = (y1 - y0);
    B = -(x1 - x0);
    C = -(A * x1 + B * y1);
    double D = sqrt(sqr(A) + sqr(B));
    A /= D;
    B /= D;
    C /= D;
  }
  double calc(Point P) { return A * P.x + B * P.y + C; }
};
struct Triangle {
  int Ax, Ay, Bx, By, Cx, Cy;
  Triangle(int a, int b, int c, int d, int e, int f)
      : Ax(a), Ay(b), Bx(c), By(d), Cx(e), Cy(f) {}
  bool isPointIn(Point P) {
    double cx = 1.0 / 3.0 * (Ax + Bx + Cx);
    double cy = 1.0 / 3.0 * (Ay + By + Cy);
    Line L1(Ax, Ay, Bx, By);
    Line L2(Ax, Ay, Cx, Cy);
    Line L3(Cx, Cy, Bx, By);
    Point center(cx, cy);
    return fabs(L1.calc(P)) > (1e-9) && fabs(L2.calc(P)) > (1e-9) &&
           fabs(L3.calc(P)) > (1e-9) && L1.calc(P) * L1.calc(center) > (1e-9) &&
           L2.calc(P) * L2.calc(center) > (1e-9) &&
           L3.calc(P) * L3.calc(center) > (1e-9);
  }
  void appendSegment(vector<Segment>& s) {
    s.push_back(Segment(Ax, Ay, Cx, Cy));
    s.push_back(Segment(Ax, Ay, Bx, By));
    s.push_back(Segment(Bx, By, Cx, Cy));
  }
};
int main() {
  vector<Triangle> triangles;
  vector<Segment> segments;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    triangles.push_back(Triangle(a, b, c, d, e, f));
    triangles.back().appendSegment(segments);
  }
  double res = 0.0;
  for (int i = 0; i < segments.size(); ++i) {
    vector<Point> points;
    points.push_back(Point(segments[i].x0, segments[i].y0));
    points.push_back(Point(segments[i].x1, segments[i].y1));
    for (int j = 0; j < segments.size(); ++j) {
      if (segments[i].collinear(segments[j])) continue;
      if (segments[i].isIntersection(segments[j]))
        points.push_back(segments[i].intersectionPoint(segments[j]));
    }
    sort((points).begin(), (points).end());
    for (int j = 0; j + 1 < points.size(); ++j) {
      bool good = true;
      for (int k = 0; k < triangles.size(); ++k) {
        if (triangles[k].isPointIn(points[j]) ||
            triangles[k].isPointIn(points[j + 1]) ||
            triangles[k].isPointIn(points[j].middle(points[j + 1])))
          good = false;
      }
      if (good) res += dist(points[j], points[j + 1]);
    }
  }
  printf("%0.18lf\n", res);
  return 0;
}