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;
pair<int, int> a[310];
vector<pair<long double, long double> > pt;
int n;
double eps = 1e-2;
void intersect(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
  long long a1 = y2 - y1;
  long long a2 = y4 - y3;
  long long b1 = x1 - x2;
  long long b2 = x3 - x4;
  long long c1 = -a1 * 1ll * x1 - b1 * 1ll * y1;
  long long c2 = -a2 * 1ll * x3 - b2 * 1ll * y3;
  long long d = a1 * b2 - a2 * b1;
  if (d == 0) return;
  long long d1 = c1 * b2 - c2 * b1;
  long long d2 = a1 * c2 - c1 * a2;
  long double x = -d1 / (long double)d;
  long double y = -d2 / (long double)d;
  if ((x >= ((x1 < x2) ? (x1) : (x2))) && (x <= ((x1 < x2) ? (x2) : (x1))) &&
      (((x >= ((x3 < x4) ? (x3) : (x4))) && (x <= ((x3 < x4) ? (x4) : (x3))))))
    if ((y >= ((y1 < y2) ? (y1) : (y2))) && (y <= ((y1 < y2) ? (y2) : (y1))) &&
        (((y >= ((y3 < y4) ? (y3) : (y4))) &&
          (y <= ((y3 < y4) ? (y4) : (y3))))))
      pt.push_back(make_pair(x, y));
}
bool check1(long double x, long double y, int x1, int y1, int x2, int y2) {
  long long a = y2 - y1;
  long long b = x1 - x2;
  long long c = -a * 1ll * x1 - b * 1ll * y1;
  long double f = a * x + b * y;
  if (((f + c > 0) ? f + c : -(f + c)) < eps) return 1;
  return 0;
}
long double finds(long double x1, long double y1, long double x2,
                  long double y2, long double x3, long double y3) {
  long double X1 = x2 - x1;
  long double Y1 = y2 - y1;
  long double X2 = x3 - x1;
  long double Y2 = y3 - y1;
  return ((X1 * Y2 - X2 * Y1 > 0) ? X1 * Y2 - X2 * Y1 : -(X1 * Y2 - X2 * Y1));
}
bool check(long double x, long double y, int i) {
  int x1 = a[3 * i].first;
  int y1 = a[3 * i].second;
  int x2 = a[3 * i + 1].first;
  int y2 = a[3 * i + 1].second;
  int x3 = a[3 * i + 2].first;
  int y3 = a[3 * i + 2].second;
  if (check1(x, y, x1, y1, x2, y2)) return 0;
  if (check1(x, y, x1, y1, x3, y3)) return 0;
  if (check1(x, y, x3, y3, x2, y2)) return 0;
  long double s1 = finds(x1, y1, x2, y2, x3, y3);
  long double s2 = finds(x, y, x1, y1, x2, y2) + finds(x, y, x3, y3, x2, y2) +
                   finds(x, y, x1, y1, x3, y3);
  if (((s1 - s2 > 0) ? s1 - s2 : -(s1 - s2)) < eps) return 1;
  return 0;
}
bool intr(long double x1, long double y1, long double x2, long double y2) {
  long double a = y2 - y1;
  long double b = x1 - x2;
  long double c = -a * x1 - b * y1;
  long double x = (x1 + x2) / 2.0;
  long double y;
  if (b == 0) {
    y = (y1 + y2) / 2.0;
    x = (-c - b * y) / a;
  } else
    y = (-a * x - c) / (long double)b;
  for (int i = (0); i < (n); ++i)
    if (check(x, y, i)) return 1;
  return 0;
}
long double doit(int x1, int y1, int x2, int y2) {
  pt.clear();
  long double res = 0;
  for (int i = (0); i < (n); ++i) {
    intersect(x1, y1, x2, y2, a[3 * i].first, a[3 * i].second,
              a[3 * i + 1].first, a[3 * i + 1].second);
    intersect(x1, y1, x2, y2, a[3 * i + 2].first, a[3 * i + 2].second,
              a[3 * i + 1].first, a[3 * i + 1].second);
    intersect(x1, y1, x2, y2, a[3 * i].first, a[3 * i].second,
              a[3 * i + 2].first, a[3 * i + 2].second);
  }
  pt.push_back(make_pair(x1, y1));
  pt.push_back(make_pair(x2, y2));
  sort(pt.begin(), pt.end());
  for (int i = (0); i < (pt.size() - 1); ++i) {
    if (intr(pt[i].first, pt[i].second, pt[i + 1].first, pt[i + 1].second))
      continue;
    res += sqrt(
        (pt[i].first - pt[i + 1].first) * (pt[i].first - pt[i + 1].first) +
        (pt[i].second - pt[i + 1].second) * (pt[i].second - pt[i + 1].second));
  }
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i)
    scanf("%d%d%d%d%d%d", &a[3 * i].first, &a[3 * i].second,
          &a[3 * i + 1].first, &a[3 * i + 1].second, &a[3 * i + 2].first,
          &a[3 * i + 2].second);
  long double res = 0;
  for (int i = (0); i < (n); ++i) {
    res += doit(a[3 * i].first, a[3 * i].second, a[3 * i + 1].first,
                a[3 * i + 1].second);
    res += doit(a[3 * i].first, a[3 * i].second, a[3 * i + 2].first,
                a[3 * i + 2].second);
    res += doit(a[3 * i + 1].first, a[3 * i + 1].second, a[3 * i + 2].first,
                a[3 * i + 2].second);
  }
  printf("%.10lf\n", res);
  return 0;
}