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;
inline int Sig(double X) {
  if (fabs(X) < 1e-5) return 0;
  return (X < 0) ? -1 : 1;
}
inline double Det(complex<double> A, complex<double> B) {
  return real(A) * imag(B) - imag(A) * real(B);
}
inline bool isStrictCross(complex<double> A, complex<double> B,
                          complex<double> C, complex<double> D) {
  return Sig(Det(C - A, B - A)) * Sig(Det(D - A, B - A)) < 0 &&
         Sig(Det(A - C, D - C)) * Sig(Det(B - C, D - C)) < 0;
}
inline complex<double> CrossPoint(complex<double> A, complex<double> B,
                                  complex<double> C, complex<double> D) {
  double S1 = Det(C - A, B - A), S2 = Det(B - A, D - A);
  return (C * S2 + D * S1) / (S1 + S2);
}
struct TTri {
  complex<double> A, B, C;
  inline bool In(complex<double> P) {
    return Sig(fabs(Det(A - P, B - P)) / 2.0 + fabs(Det(B - P, C - P)) / 2.0 +
               fabs(Det(C - P, A - P)) / 2.0 - fabs(Det(B - A, C - A)) / 2.0) ==
               0 &&
           Sig(Det(A - P, B - P)) != 0 && Sig(Det(B - P, C - P)) != 0 &&
           Sig(Det(C - P, A - P)) != 0;
  }
};
int N, Tot;
TTri Tri[105];
pair<complex<double>, complex<double> > Seg[105 * 105 * 9];
double Ans;
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    int x1, x2, x3, y1, y2, y3;
    scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3);
    Tri[i].A = complex<double>(x1, y1);
    Tri[i].B = complex<double>(x2, y2);
    Tri[i].C = complex<double>(x3, y3);
    Seg[++Tot] = make_pair(Tri[i].A, Tri[i].B);
    Seg[++Tot] = make_pair(Tri[i].B, Tri[i].C);
    Seg[++Tot] = make_pair(Tri[i].C, Tri[i].A);
  }
  for (int i = 1; i < Tot; ++i)
    for (int j = i + 1; j <= Tot; ++j)
      if (isStrictCross(Seg[i].first, Seg[i].second, Seg[j].first,
                        Seg[j].second)) {
        complex<double> CP = CrossPoint(Seg[i].first, Seg[i].second,
                                        Seg[j].first, Seg[j].second);
        Seg[++Tot] = make_pair(CP, Seg[i].second);
        Seg[i].second = CP;
        Seg[++Tot] = make_pair(CP, Seg[j].second);
        Seg[j].second = CP;
      }
  for (int i = 1; i <= Tot; ++i) {
    complex<double> T = (Seg[i].first + Seg[i].second) / 2.0;
    bool Flag = 0;
    for (int j = 1; j <= N; ++j)
      if (Tri[j].In(T)) {
        Flag = 1;
        break;
      }
    if (!Flag) Ans += abs(Seg[i].first - Seg[i].second);
  }
  printf("%.10lf\n", Ans);
}