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();
      poly[] tris = new poly[N];
      for (int i=0; i<N; i++)
      {
         tris[i] = new poly();
         for (int j=0; j<3; j++)
            tris[i].add(new vect(in.nextDouble(), in.nextDouble()));
      }

      ArrayList<line> rs = new ArrayList<line>();
      for (poly p : tris)
         for (line e : p.getLines())
            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++)
      {
         line a = rs.get(i);
         for (int j=i+1; j<rs.size(); j++)
         {
            line b = rs.get(j);
            vect 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++)
      {
         line a = rs.get(i);
         vect v = a.getVect();

         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);

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

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

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


class poly
{
   ArrayList<vect> vs;

   public poly()
   {
      vs = new ArrayList<vect>();
   }

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

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

   boolean contains(vect p)
   {
      double sum = 0.0;
      for (int i=0; i<vs.size(); i++)
      {
         vect v1 = vs.get(i).sub(p);
         vect v2 = vs.get((i+1)%vs.size()).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);
      }

      // Take out negatives
      sum = Math.abs(sum);

      double thresh = 2.0*0.75*Math.PI;
      if (sum > thresh)
         return true;
      return false;
   }
}


class line
{
   vect e1, e2;
   
   public line(vect a, vect b)
   {
      e1 = a; e2 = b;
   }

   vect getVect()
   {
      return e2.sub(e1);
   }

  vect intersect(line rhs)
   {
      vect v1 = getVect();
      vect v2 = rhs.getVect();

      double a = v1.x;
      double b = v2.x;
      double c = v1.y;
      double d = v2.y;
      double e = rhs.e1.x - e1.x;
      double f = rhs.e1.y - e1.y;

      double div = a*d - b*c;
      
      double sn = e*d - b*f;
      double s = sn/div;
	 
	  if (Math.abs(div) < 1e-9) return null;

     vect p = new vect(e1.x+s*v1.x, e1.y+s*v1.y);
	  double r = rhs.scaleProj(p);
	  
	  if (s < 0.0) return null;
	  if (s > 1.0) return null;
	  if (r < 0.0) return null;
	  if (r > 1.0) return null;
	  
	  return p;
   }

   double scaleProj(vect p)
   {
      vect v1 = getVect();
      vect v2 = p.sub(e1);
      return v1.dot(v2)/v1.mag2();
   }

   // Project a point onto our line
   vect proj(vect p)
   {
      vect v1 = getVect();
      vect v2 = p.sub(e1);
      double k = v1.dot(v2)/v1.mag2();
      return e1.add(v1.scale(k));
   }
}


class vect
{
   double x, y;

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

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

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

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

   vect midpoint(vect rhs)
   {
      return new vect((x+rhs.x)/2.0, (y+rhs.y)/2.0);
   }

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

   // In 2D we only care about the magnitude of the cross product
   // Positive in a left turn and negative in a right turn
   double cross(vect rhs)
   {
      return x*rhs.y-y*rhs.x;
   }

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

   double angleBtwn(vect rhs)
   {
      double cr = cross(rhs);
      double dt = dot(rhs);
      return Math.atan2(cr, dt);
   }

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