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 GCC optimize("O3")
using namespace std;
const double EPS = 1e-12, INF = 1e9;
pair<double, double> operator+(const pair<double, double> &a,
                               const pair<double, double> &b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
pair<double, double> operator-(const pair<double, double> &a,
                               const pair<double, double> &b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
pair<double, double> operator*(const pair<double, double> &a, const double &b) {
  return make_pair(a.first * b, a.second * b);
}
pair<double, double> operator/(const pair<double, double> &a, const double &b) {
  return make_pair(a.first / b, a.second / b);
}
double dot(const pair<double, double> &a, const pair<double, double> &b) {
  return a.first * b.first + a.second * b.second;
}
double cross(const pair<double, double> &a, const pair<double, double> &b) {
  return a.first * b.second - a.second * b.first;
}
double abs2(const pair<double, double> &a) { return dot(a, a); }
double abs(const pair<double, double> &a) { return sqrt(dot(a, a)); }
int ori(const pair<double, double> &a, const pair<double, double> &b,
        const pair<double, double> &c) {
  double res = cross(b - a, c - a);
  if (fabs(res) < EPS) return 0;
  return res > 0 ? 1 : -1;
}
bool collinearity(const pair<double, double> &p1,
                  const pair<double, double> &p2,
                  const pair<double, double> &p3) {
  return fabs(cross(p1 - p3, p2 - p3)) < EPS;
}
bool btw(const pair<double, double> &p1, const pair<double, double> &p2,
         const pair<double, double> &p3) {
  if (!collinearity(p1, p2, p3)) return 0;
  return dot(p1 - p3, p2 - p3) < EPS;
}
bool seg_intersect(const pair<double, double> &p1,
                   const pair<double, double> &p2,
                   const pair<double, double> &p3,
                   const pair<double, double> &p4) {
  int a123 = ori(p1, p2, p3);
  int a124 = ori(p1, p2, p4);
  int a341 = ori(p3, p4, p1);
  int a342 = ori(p3, p4, p2);
  if (a123 == 0 && a124 == 0)
    return btw(p1, p2, p3) || btw(p1, p2, p4) || btw(p3, p4, p1) ||
           btw(p3, p4, p2);
  return a123 * a124 <= 0 && a341 * a342 <= 0;
}
pair<double, double> intersect(const pair<double, double> &p1,
                               const pair<double, double> &p2,
                               const pair<double, double> &p3,
                               const pair<double, double> &p4) {
  double a123 = cross(p2 - p1, p3 - p1);
  double a124 = cross(p2 - p1, p4 - p1);
  return (p4 * a123 - p3 * a124) / (a123 - a124);
}
bool intri(pair<double, double> p, pair<double, double> p1,
           pair<double, double> p2, pair<double, double> p3) {
  double org = fabs(cross(p2 - p1, p3 - p1)), a = fabs(cross(p1 - p, p2 - p)),
         b = fabs(cross(p1 - p, p3 - p)), c = fabs(cross(p2 - p, p3 - p));
  if (fabs(a + b + c - org) < EPS) return 1;
  return 0;
}
pair<double, double> arr[3][105];
vector<pair<pair<double, double>, pair<double, double>>> v;
void insert(pair<double, double> a, pair<double, double> b,
            pair<double, double> p1, pair<double, double> p2,
            pair<double, double> p3) {
  int flag = 0;
  pair<pair<double, double>, pair<double, double>> rt;
  if (intri(a, p1, p2, p3))
    if (flag)
      rt.second = a, flag = 2;
    else
      rt.first = a, flag = 1;
  if (intri(b, p1, p2, p3))
    if (flag)
      rt.second = b, flag = 2;
    else
      rt.first = b, flag = 1;
  if (seg_intersect(a, b, p1, p2)) {
    auto tmp = intersect(a, b, p1, p2);
    if (abs2(tmp - a) >= EPS && abs2(tmp - b) >= EPS)
      if (flag)
        rt.second = tmp, flag = 2;
      else
        rt.first = tmp, flag = 1;
  }
  if (seg_intersect(a, b, p3, p2)) {
    auto tmp = intersect(a, b, p3, p2);
    if (abs2(tmp - a) >= EPS && abs2(tmp - b) >= EPS)
      if (flag)
        rt.second = tmp, flag = 2;
      else
        rt.first = tmp, flag = 1;
  }
  if (seg_intersect(a, b, p1, p3)) {
    auto tmp = intersect(a, b, p1, p3);
    if (abs2(tmp - a) >= EPS && abs2(tmp - b) >= EPS)
      if (flag)
        rt.second = tmp, flag = 2;
      else
        rt.first = tmp, flag = 1;
  }
  if (flag == 2) {
    if (rt.first > rt.second) swap(rt.first, rt.second);
    v.push_back(rt);
  }
}
double cal() {
  sort(v.begin(), v.end());
  double rt = 0;
  pair<double, double> nw = make_pair(-INF, -INF);
  for (pair<pair<double, double>, pair<double, double>> i : v)
    if (i.first >= nw)
      rt += abs(i.second - i.first), nw = i.second;
    else if (i.second > nw)
      rt += abs(i.second - nw), nw = i.second;
  return rt;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  double ans = 0;
  long long n;
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> arr[0][i].first >> arr[0][i].second >> arr[1][i].first >>
        arr[1][i].second >> arr[2][i].first >> arr[2][i].second;
  for (int i = 0; i < n; ++i) {
    v.clear();
    for (int j = 0; j < n; ++j)
      if (i != j) insert(arr[0][i], arr[1][i], arr[0][j], arr[1][j], arr[2][j]);
    ans += abs(arr[0][i] - arr[1][i]) - cal();
    v.clear();
    for (int j = 0; j < n; ++j)
      if (i != j) insert(arr[2][i], arr[1][i], arr[0][j], arr[1][j], arr[2][j]);
    ans += abs(arr[2][i] - arr[1][i]) - cal();
    v.clear();
    for (int j = 0; j < n; ++j)
      if (i != j) insert(arr[0][i], arr[2][i], arr[0][j], arr[1][j], arr[2][j]);
    ans += abs(arr[0][i] - arr[2][i]) - cal();
  }
  cout << fixed << setprecision(10) << ans << "\n";
}