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;
int x1[200], fndjifhwdn[200], x2[200], y2[200], x3[200], y3[200];
int n;
bool f[200];
int cc[200];
vector<pair<pair<long double, long double>, int> > p;
long double ans = 0;
long double eps = 1e-8;
void inter(int l, long long A, long long B, long long C, int x1, int fndjifhwdn,
           int x2, int y2) {
  long long A2 = fndjifhwdn - y2;
  long long B2 = x2 - x1;
  long long C2 = -(A2 * x1 + B2 * fndjifhwdn);
  long long d = A * B2 - A2 * B;
  if (d == 0) return;
  long long d1 = B * C2 - B2 * C;
  long long d2 = C * A2 - C2 * A;
  long double px = (long double)d1 / d;
  long double py = (long double)d2 / d;
  if (x1 > x2) swap(x1, x2);
  if (fndjifhwdn > y2) swap(fndjifhwdn, y2);
  if (x1 <= px + eps && px <= x2 + eps && fndjifhwdn <= py + eps &&
      py <= y2 + eps) {
    p.push_back(make_pair(make_pair(px, py), l));
    cc[l]++;
  }
}
long double dist(long double x1, long double fndjifhwdn, long double x2,
                 long double y2) {
  return sqrt((long double)(x1 - x2) * (x1 - x2) +
              (fndjifhwdn - y2) * (fndjifhwdn - y2));
}
void check(int l, int sx, int sy, int ex, int ey) {
  p.clear();
  for (int i = 0; i < n; i++) f[i] = false;
  for (int i = 0; i < n; i++) cc[i] = 0;
  p.push_back(make_pair(make_pair(sx, sy), l));
  p.push_back(make_pair(make_pair(ex, ey), l));
  long long A = sy - ey;
  long long B = ex - sx;
  long long C = -(A * sx + B * sy);
  for (int i = 0; i < n; i++) {
    if (i == l) continue;
    inter(i, A, B, C, x1[i], fndjifhwdn[i], x2[i], y2[i]);
    inter(i, A, B, C, x1[i], fndjifhwdn[i], x3[i], y3[i]);
    inter(i, A, B, C, x3[i], y3[i], x2[i], y2[i]);
  }
  sort(p.begin(), p.end());
  int cnt = 0;
  bool fl = false;
  int t;
  for (int i = 0; i < p.size(); i++) {
    t = p[i].second;
    if (t == l) {
      fl = not fl;
    } else {
      if (!f[t]) {
        cnt++;
        f[t] = true;
      }
      cc[t]--;
      if (!cc[t]) {
        cnt--;
        f[t] = false;
      }
    }
    if ((i < ((int)(p.size())) - 1) && fl && (cnt == 0)) {
      ans += dist(p[i].first.first, p[i].first.second, p[i + 1].first.first,
                  p[i + 1].first.second);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d%d%d%d%d%d", &x1[i], &fndjifhwdn[i], &x2[i], &y2[i], &x3[i],
          &y3[i]);
  for (int i = 0; i < n; i++) {
    check(i, x1[i], fndjifhwdn[i], x2[i], y2[i]);
    check(i, x1[i], fndjifhwdn[i], x3[i], y3[i]);
    check(i, x3[i], y3[i], x2[i], y2[i]);
  }
  printf("%.18lf\n", (double)ans);
  return 0;
}