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 double eps = 1e-12;
const double PI = acos(-1.0);
inline int sgn(double x) {
  if (fabs(x) < eps) return 0;
  if (x < 0) return -1;
  return 1;
}
struct Point {
  long long x, y;
  Point() {}
  Point(long long _x, long long _y) : x(_x), y(_y) {}
  Point operator-(const Point &b) const { return Point(x - b.x, y - b.y); }
  long long operator^(const Point &b) const { return x * b.y - y * b.x; }
  long long operator*(const Point &b) const { return x * b.x + y * b.y; }
};
struct Point1 {
  double x, y;
  Point1() {}
  Point1(double _x, double _y) : x(_x), y(_y) {}
  Point1 operator-(const Point1 &b) const { return Point1(x - b.x, y - b.y); }
  double operator^(const Point1 &b) const { return x * b.y - y * b.x; }
  double operator*(const Point1 &b) const { return x * b.x + y * b.y; }
};
struct Line {
  Point s, e;
  Line() {}
  Line(Point _s, Point _e) : s(_s), e(_e) {}
  pair<int, Point1> operator&(const Line &b) const {
    Point1 ret;
    ret.x = s.x;
    ret.y = s.y;
    double t = ((s - b.s) ^ (b.s - b.e)) / double((s - e) ^ (b.s - b.e));
    ret.x += (e.x - s.x) * t;
    ret.y += (e.y - s.y) * t;
    return make_pair(2, ret);
  }
};
double dist(const Point &a, const Point &b) {
  return sqrt((double)((a - b) * (a - b)));
}
double dist(const Point1 &a, const Point &tb) {
  Point1 b;
  b.x = tb.x;
  b.y = tb.y;
  return sqrt((double)((a - b) * (a - b)));
}
bool Seg_inter_Line(Line L1, Line L2) {
  if (((L1.s - L1.e) ^ (L2.s - L2.e)) == 0) return 0;
  long long a = (L2.s - L1.e) ^ (L1.s - L1.e);
  long long b = (L2.e - L1.e) ^ (L1.s - L1.e);
  if (a > 0)
    a = 1;
  else if (a == 0)
    a = 0;
  else
    a = -1;
  if (b > 0)
    b = 1;
  else if (b == 0)
    b = 0;
  else
    b = -1;
  if (a * b <= 0) return 1;
  return 0;
}
int N;
Line bian[303];
pair<double, double> rem[111];
inline double count(Line &base, int p) {
  Point1 a[3];
  int acou = 0;
  double blen = dist(base.s, base.e);
  double len1, len2;
  double L, R;
  int rcou = 0;
  for (int i = 0; i < N; ++i)
    if (i != p) {
      acou = 0;
      for (int j = 0; j < 3; ++j)
        if (Seg_inter_Line(base, bian[i * 3 + j]))
          a[acou++] = (base & bian[i * 3 + j]).second;
      if (acou == 3) {
        acou = 2;
        if (sgn(a[0].x - a[1].x) == 0 && sgn(a[0].y - a[1].y) == 0)
          swap(a[1], a[2]);
      }
      if (acou == 2) {
        len1 = dist(a[0], base.s);
        len2 = dist(a[0], base.e);
        if (len1 < len2 && len2 > blen)
          L = -len1;
        else
          L = len1;
        len1 = dist(a[1], base.s);
        len2 = dist(a[1], base.e);
        if (len1 < len2 && len2 > blen)
          R = -len1;
        else
          R = len1;
        if (L > R) swap(L, R);
        if (L >= blen) continue;
        if (R <= 0) continue;
        if (L < 0) L = 0;
        if (R > blen) R = blen;
        rem[rcou++] = pair<double, double>(L, R);
      }
    }
  double ret = 0;
  L = R = 0;
  sort(rem, rem + rcou);
  for (int i = 0; i < rcou; ++i) {
    if (rem[i].first > R) {
      ret += R - L;
      L = rem[i].first;
      R = rem[i].second;
    } else
      R = max(R, rem[i].second);
  }
  ret += R - L;
  return blen - ret;
}
int main() {
  int x[3], y[3];
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 3; ++j) scanf("%d %d", x + j, y + j);
    bian[i * 3 + 0] = Line(Point(x[0], y[0]), Point(x[1], y[1]));
    bian[i * 3 + 1] = Line(Point(x[1], y[1]), Point(x[2], y[2]));
    bian[i * 3 + 2] = Line(Point(x[2], y[2]), Point(x[0], y[0]));
  }
  double ans = 0;
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < 3; ++j) ans += count(bian[i * 3 + j], i);
  printf("%.10f\n", ans);
  return 0;
}