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

import java.util.*;


public class C
{
   public static void main(String[] args)
   {
      new C(new Scanner(System.in));
   }

   public C(Scanner in)
   {
      int N = in.nextInt();
      poly2[] tris = new poly2[N];
      for (int i=0; i<N; i++)
      {
         tris[i] = new poly2();
         for (int j=0; j<3; j++)
            tris[i].add(new vec2(in.nextDouble(), in.nextDouble()));
      }

      ArrayList<line2> rs = new ArrayList<line2>();
      for (poly2 p : tris)
         for (line2 e : p.getline2s())
            rs.add(e);

      ArrayList<Double>[] proj = new ArrayList[rs.size()];
      for (int i=0; i<rs.size(); i++)
      {
         proj[i] = new ArrayList<Double>();
         proj[i].add(0.0);
         proj[i].add(1.0);
      }

      for (int i=0; i<rs.size(); i++)
      {
         line2 a = rs.get(i);
         for (int j=i+1; j<rs.size(); j++)
         {
            line2 b = rs.get(j);
            vec2 p = a.intersect(b);
            if (p == null) 
               continue;
            
            proj[i].add(a.scaleProj(p));
            proj[j].add(b.scaleProj(p));
         }
      }

      double res = 0.0;
      for (int i=0; i<rs.size(); i++)
      {
         line2 a = rs.get(i);
         vec2 v = a.getVec2();

         Collections.sort(proj[i]);
         for (int j=1; j<proj[i].size(); j++)
         {
            int k = j-1;
        
            double d1 = proj[i].get(k);
            double d2 = proj[i].get(j);

            vec2 p = a.e1.add(v.scale(d1));
            vec2 q = a.e1.add(v.scale(d2));
            
            vec2 u = p.midpoint(q);
			            
			boolean passed = true;
            for (poly2 pg : tris)
               if (pg.contains(u))
               {
                  passed = false;
                  break;
               }

            if (passed)
               res += p.dist(q);
         }
      }

      System.out.printf("%.10f%n", res);
   }
}


class poly2
{
   ArrayList<vec2> vs;
   public poly2()
   {
      vs = new ArrayList<vec2>();
   }

   void add(vec2 v)
   {
      vs.add(v);
   }

   line2[] getline2s()
   {
      line2[] res = new line2[vs.size()];
      for (int i=0; i<vs.size(); i++)
         res[i] = new line2(vs.get(i), vs.get((i+1)%vs.size()));
      return res;
   }

   boolean contains(vec2 p)
   {
      double sum = 0.0;
      for (int i=0, j=1; i<vs.size(); i++, j=(j+1)%vs.size())
      {
         vec2 v1 = vs.get(i).sub(p);
         vec2 v2 = vs.get(j).sub(p);

         // If its on the border take care of it now
         if ((Math.abs(v1.cross(v2)) < 1e-4)&&(v1.dot(v2) <= 1e-4))
            return false;
         sum += v1.angleBtwn(v2);
      }
      return Math.abs(sum) > Math.PI;
   }
}


class line2
{
   vec2 e1, e2;
   public line2(vec2 a, vec2 b)
   {
      e1 = a; e2 = b;
   }

   vec2 getVec2()
   {
      return e2.sub(e1);
   }

  vec2 intersect(line2 rhs)
   {
      vec2 v1 = getVec2(), v2 = rhs.getVec2(), v3 = rhs.e1.sub(e1);

      double div = v1.cross(v2), sn = v3.cross(v2);
      double s = sn/div;
	  if (Math.abs(div) < 1e-9) return null;
     vec2 p = v1.scale(s).add(e1);
	  double r = rhs.scaleProj(p);
	  if (s < 0 || r < 0 || s > 1 || r > 1) return null;
     return p;
   }

   double scaleProj(vec2 p)
   {
      vec2 v1 = getVec2(); return v1.dot(p.sub(e1))/v1.mag2();
   }

   vec2 proj(vec2 p)
   {
      vec2 v1 = getVec2(); 
      double k = v1.dot(p.sub(e1))/v1.mag2();
      return e1.add(v1.scale(k));
   }
}


class vec2
{
   double x, y;

   public vec2(double i, double j)
   {
      x=i; y=j;
   }

   boolean eq(vec2 rhs)
   {
      return ((Math.abs(x-rhs.x) < 1e-9)&&
              (Math.abs(y-rhs.y) < 1e-9));
   }

   vec2 sub(vec2 rhs)
   {
      return new vec2(x-rhs.x, y-rhs.y);
   }

   vec2 add(vec2 rhs)
   {
      return new vec2(x+rhs.x, y+rhs.y);
   }

   vec2 midpoint(vec2 rhs)
   {
      return new vec2(.5*(x+rhs.x), .5*(y+rhs.y));
   }

   double dot(vec2 rhs)
   {
      return x*rhs.x+y*rhs.y;
   }

   double cross(vec2 rhs)
   {
      return x*rhs.y-y*rhs.x;
   }

   double mag2()
   {
      return x*x+y*y;
   }
   
   double mag()
   {
      return Math.sqrt(mag2());
   }
   
   vec2 scale(double s)
   {
      return new vec2(x*s, y*s);
   }

   double angleBtwn(vec2 rhs)
   {
      return Math.atan2(cross(rhs), dot(rhs));
   }

   double dist(vec2 rhs)
   {
      return sub(rhs).mag();
   }
   
   public String toString()
   {
      return String.format("(%.2f, %.2f)", x, y);
   }
}
