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
#include <bits/stdc++.h>
using namespace std;
const long double pi = acosl(-1);
const long double radian = 180 / pi;
const long double eps = 1e-12;
const int inf = 0x7f7f7f7f;
const long long infll = 0x7f7f7f7f7f7f7f7fll;
const long double infl = 1e20;
inline int sgn(const long double &x) { return (x > eps) - (x < -eps); }
inline int sgn(const long long &x) { return (x > 0) - (x < 0); }
inline long double sqr(const long double &x) { return x * x; }
inline long long sqr(const long long &x) { return x * x; }
inline long double refresh(const long double &x) {
  if (x < -1 + eps)
    return -1;
  else if (x > 1 - eps)
    return 1;
  else
    return x;
}
struct Point {
  long double x, y;
  Point() : x(0), y(0) {}
  Point(const long double &x, const long double &y) : x(x), y(y) {}
  long double angle() const { return atan2l(y, x); }
  long double angle(const Point &lhs, const Point &rhs) const {
    return (lhs - *this) ^ (rhs - *this);
  }
  long double length() const { return sqrtl(sqr(x) + sqr(y)); }
  long double length2() const { return sqr(x) + sqr(y); }
  long double distance(const Point &rhs) const {
    return (rhs - *this).length();
  }
  long double distance2(const Point &rhs) const {
    return (rhs - *this).length2();
  }
  Point rotate(const long double &a) const {
    long double c = cosl(a), s = sinl(a);
    return Point(x * c - y * s, x * s + y * c);
  }
  Point polar(const long double &r, const long double &t) const {
    return Point(x + r * cosl(t), y + r * sinl(t));
  }
  Point conjugate() const { return Point(x, -y); }
  Point unit(const long double &n = 1) const {
    long double l = length();
    return sgn(l) == 0 ? Point(n, 0) : Point(x / l * n, y / l * n);
  }
  Point normal(const bool &lft = true) const {
    return lft ? Point(-y, x) : Point(y, -x);
  }
  Point moderate() const { return *this * (this->quadrant() <= 4 ? -1 : 1); }
  long double vect(const Point &lhs, const Point &rhs) const {
    return (lhs - *this) * (rhs - *this);
  }
  long double scal(const Point &lhs, const Point &rhs) const {
    return (lhs - *this) & (rhs - *this);
  }
  Point project(const Point &p, const Point &q) const {
    return p + (q - p) * p.scal(q, *this) / p.distance2(q);
  }
  Point mirror(const Point &p, const Point &q) const {
    return this->project(p, q) * 2 - *this;
  }
  long double distance_to_line(const Point &p, const Point &q) const {
    return fabsl(p.vect(q, *this) / p.distance(q));
  }
  long double distance_to_segment(const Point &p, const Point &q) const {
    if (p.scal(q, *this) < 0)
      return p.distance(*this);
    else if (q.scal(p, *this) < 0)
      return q.distance(*this);
    else
      return this->distance_to_line(p, q);
  }
  bool on_line(const Point &p, const Point &q) const {
    return sgn(this->vect(p, q)) == 0;
  }
  bool on_halfline(const Point &p, const Point &q,
                   const bool &inclusive = true) const {
    if (*this == p)
      return inclusive;
    else
      return this->on_line(p, q) && sgn(p.scal(q, *this)) >= 0;
  }
  bool on_segment(const Point &p, const Point &q,
                  const bool &inclusive = true) const {
    if (*this == p || *this == q)
      return inclusive;
    else
      return this->on_line(p, q) && sgn(this->scal(p, q)) <= 0;
  }
  bool in_triangle(const Point &u, const Point &v, const Point &w,
                   const bool &inclusive = true) const {
    Point p[3] = {u, v, w};
    if (sgn(u.vect(v, w)) < 0) reverse(p, p + 3);
    for (int i = 0; i < 3; i++) {
      if (this->on_segment(p[i], p[(i + 1) % 3]))
        return inclusive;
      else if (sgn(this->vect(p[i], p[(i + 1) % 3])) < 0)
        return false;
    }
    return true;
  }
  bool in_angle(const Point &o, const Point &p, const Point &q,
                const bool &inclusive = true) const {
    if (this->on_halfline(o, p) || this->on_halfline(o, q)) return inclusive;
    int vp = sgn(o.vect(p, *this)), vq = sgn(o.vect(*this, q));
    if (sgn(o.vect(p, q)) >= 0)
      return vp > 0 && vq > 0;
    else
      return vp > 0 || vq > 0;
  }
  Point operator+(const Point &rhs) const {
    return Point(x + rhs.x, y + rhs.y);
  }
  Point operator-(const Point &rhs) const {
    return Point(x - rhs.x, y - rhs.y);
  }
  Point operator*(const long double &rhs) const {
    return Point(x * rhs, y * rhs);
  }
  Point operator/(const long double &rhs) const {
    return Point(x / rhs, y / rhs);
  }
  long double operator*(const Point &rhs) const {
    return x * rhs.y - y * rhs.x;
  }
  long double operator&(const Point &rhs) const {
    return x * rhs.x + y * rhs.y;
  }
  Point operator<<(const Point &rhs) const {
    return Point(x * rhs.x - y * rhs.y, x * rhs.y + y * rhs.x);
  }
  Point operator>>(const Point &rhs) const {
    return Point(x * rhs.x + y * rhs.y, -x * rhs.y + y * rhs.x) / rhs.length2();
  }
  long double operator^(const Point &rhs) const {
    int s = sgn(*this * rhs);
    long double a = acosl(
        refresh((long double)(*this & rhs) / this->length() / rhs.length()));
    return s < 0 ? -a : a;
  }
  bool operator==(const Point &rhs) const {
    return sgn(x - rhs.x) == 0 && sgn(y - rhs.y) == 0;
  }
  int quadrant() const {
    int xs = sgn(x), ys = sgn(y);
    if (xs == 0 && ys == 0)
      return 0;
    else if (xs < 0 && ys < 0)
      return 1;
    else if (xs == 0 && ys < 0)
      return 2;
    else if (xs > 0 && ys < 0)
      return 3;
    else if (xs > 0 && ys == 0)
      return 4;
    else if (xs > 0 && ys > 0)
      return 5;
    else if (xs == 0 && ys > 0)
      return 6;
    else if (xs < 0 && ys > 0)
      return 7;
    else
      return 8;
  }
  bool operator<(const Point &rhs) const {
    int lq = quadrant(), rq = rhs.quadrant();
    if (lq != rq)
      return lq < rq;
    else {
      int s = sgn(*this * rhs);
      return s != 0 ? s > 0 : sgn(length2() - rhs.length2()) < 0;
    }
  }
  bool on_left(const Point &rhs, const bool &inclusive = true) const {
    int s = sgn(*this * rhs), t = sgn(*this & rhs);
    return s == 0 ? t >= 0 || inclusive : s > 0;
  }
  bool on_right(const Point &rhs, const bool &inclusive = true) const {
    int s = sgn(*this * rhs), t = sgn(*this & rhs);
    return s == 0 ? t >= 0 || inclusive : s < 0;
  }
};
inline bool xycmp(const Point &lhs, const Point &rhs) {
  if (sgn(lhs.x - rhs.x) != 0)
    return lhs.x < rhs.x;
  else
    return lhs.y < rhs.y;
}
inline bool yxcmp(const Point &lhs, const Point &rhs) {
  if (sgn(lhs.y - rhs.y) != 0)
    return lhs.y < rhs.y;
  else
    return lhs.x < rhs.x;
}
const int maxn = 100;
int n;
Point p[maxn][3];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) cin >> p[i][j].x >> p[i][j].y;
  }
  long double ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      const Point &A = p[i][j], &B = p[i][(j + 1) % 3];
      long double d = A.distance(B);
      vector<long double> vec;
      vec.push_back(0);
      vec.push_back(1);
      for (int k = 0; k < n; k++) {
        if (k == i) continue;
        for (int l = 0; l < 3; l++) {
          const Point &C = p[k][l], &D = p[k][(l + 1) % 3];
          long double abc = A.vect(B, C), abd = A.vect(B, D),
                      cda = C.vect(D, A), cdb = C.vect(D, B);
          if (sgn(abc) * sgn(abd) < 0 && sgn(cda) * sgn(cdb) < 0)
            vec.push_back(fabsl(cda) / fabsl(cda - cdb));
        }
      }
      sort(vec.begin(), vec.end());
      for (int k = 0; k < vec.size() - 1; k++) {
        Point q = A + (B - A) * (vec[k] + vec[k + 1]) / 2;
        bool flg = true;
        for (int l = 0; l < n; l++) {
          if (l == i) continue;
          if (q.in_triangle(p[l][0], p[l][1], p[l][2])) {
            flg = false;
            break;
          }
        }
        if (flg) ans += d * (vec[k + 1] - vec[k]);
      }
    }
  }
  cout << fixed << setprecision(20);
  cout << ans << endl;
  return 0;
}
