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:16777216")
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
class dddd {
 public:
  double x1, y95874, x2, y2;
  int id;
};
dddd get(double x1, double y95874, double x2, double y2, int id) {
  dddd ans;
  ans.x1 = x1;
  ans.x2 = x2;
  ans.y95874 = y95874;
  ans.y2 = y2;
  ans.id = id;
  return ans;
}
int n;
int m;
vector<pair<pair<int, int>, pair<int, int> > > v;
vector<dddd> vv;
int x[100][3], y[100][3];
long long cross(long long x1, long long y95874, long long x2, long long y2) {
  return x1 * y2 - x2 * y95874;
}
double cross2(double x1, double y95874, double x2, double y2) {
  return x1 * y2 - x2 * y95874;
}
int check_inside(dddd z) {
  double x = (z.x1 + z.x2) / 2;
  double y = (z.y95874 + z.y2) / 2;
  for (int i = 0; i < (n); i++) {
    if (i == z.id) continue;
    int *cx = ::x[i];
    int *cy = ::y[i];
    double s1 =
        abs(cross2(cx[1] - cx[0], cy[1] - cy[0], cx[2] - cx[0], cy[2] - cy[0]));
    double s2 = 0;
    for (int p = 0; p < (3); p++) {
      s2 += abs(cross2(cx[p] - x, cy[p] - y, cx[(p + 1) % 3] - x,
                       cy[(p + 1) % 3] - y));
    }
    if (abs(s2 - s1) < 1e-7) {
      return 1;
    }
  }
  return 0;
}
int intersect(long long x1, long long y95874, long long x2, long long y2,
              long long x3, long long y3, long long x4, long long y4,
              double &p) {
  long long d = cross(x2 - x1, y2 - y95874, x3 - x4, y3 - y4);
  if (!d) return 0;
  long long d1 = cross(x3 - x1, y3 - y95874, x3 - x4, y3 - y4);
  long long d2 = cross(x2 - x1, y2 - y95874, x3 - x1, y3 - y95874);
  if (d < 0) {
    d = -d;
    d1 = -d1;
    d2 = -d2;
  }
  if (d1 > d || d1 < 0 || d2 > d || d2 < 0) return 0;
  p = (double)d1 / d;
  return 1;
}
double get_len(dddd z) {
  return sqrt(((z.x1 - z.x2) * (z.x1 - z.x2)) +
              ((z.y95874 - z.y2) * (z.y95874 - z.y2)));
}
void getans(int x1, int y95874, int x2, int y2, int id) {
  vector<double> zlo;
  zlo.push_back(0);
  zlo.push_back(1);
  for (int i = 0; i < (((int)(v).size())); i++) {
    double p;
    if (intersect(x1, y95874, x2, y2, v[i].first.first, v[i].first.second,
                  v[i].second.first, v[i].second.second, p))
      zlo.push_back(p);
  }
  sort((zlo).begin(), (zlo).end());
  for (int i = 0; i < (((int)(zlo).size()) - 1); i++) {
    double nx1 = x1 + (x2 - x1) * zlo[i];
    double ny1 = y95874 + (y2 - y95874) * zlo[i];
    double nx2 = x1 + (x2 - x1) * zlo[i + 1];
    double ny2 = y95874 + (y2 - y95874) * zlo[i + 1];
    vv.push_back(get(nx1, ny1, nx2, ny2, id));
  }
}
int main() {
  cin >> n;
  for (int o = 0; o < (n); o++) {
    for (int i = 0; i < (3); i++) cin >> x[o][i] >> y[o][i];
    for (int i = 0; i < (3); i++)
      v.push_back(make_pair(make_pair(x[o][i], y[o][i]),
                            make_pair(x[o][(i + 1) % 3], y[o][(i + 1) % 3])));
  }
  for (int o = 0; o < (n); o++) {
    for (int i = 0; i < (3); i++)
      getans(x[o][i], y[o][i], x[o][(i + 1) % 3], y[o][(i + 1) % 3], o);
  }
  double ans = 0;
  for (int i = 0; i < (((int)(vv).size())); i++) {
    if (get_len(vv[i]) > 1e-7 && !check_inside(vv[i])) ans += get_len(vv[i]);
  }
  printf("%.10lf", ans);
  cout << endl;
  return 0;
}