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 JAVA):

Solution:

import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class C {
    public static class P {
        int x, y;
        public P(int x, int y) {
            this.x = x;
            this.y = y;
        }
        public String toString() {
            return x+","+y;
        }
    }
    Scanner in = new Scanner(System.in);

    public static final double EPS = 1e-10;
    public boolean intersect(P p1, P p2, P p3, P p4) {
        long o1 = outer(p2.x-p1.x, p2.y-p1.y, p3.x-p1.x, p3.y-p1.y);
        long o2 = outer(p2.x-p1.x, p2.y-p1.y, p4.x-p1.x, p4.y-p1.y);
        if(o1>0&&o2>0||o1<0&&o2<0) return false;
        long o3 = outer(p4.x-p3.x, p4.y-p3.y, p1.x-p3.x, p1.y-p3.y);
        long o4 = outer(p4.x-p3.x, p4.y-p3.y, p2.x-p3.x, p2.y-p3.y);
        return o3>=0&&o4<=0||o3<=0&&o4>=0;
    }
    public static long outer(long x1, long y1, long x2, long y2) {
        return x1*y2-y1*x2;
    }
    public static boolean onLeft(double x1, double y1, double x2, double y2, double x3, double y3) {
        return (x2-x1)*(y3-y1)-(y2-y1)*(x3-x1) > EPS;
    }
    public static double dis(double x1, double y1, double x2, double y2){
        double dx = x2-x1;
        double dy = y2-y1;
        return sqrt(dx*dx+dy*dy);
    }
    public C() throws Exception {
        int n = in.nextInt();

        P[][] ts = new P[n][4];
        for (int i=0;i<n;i++) {
            for (int j=0;j<3;j++) {
                ts[i][j] = new P(in.nextInt(), in.nextInt());
            }
            ts[i][3] = ts[i][0];
        }

        double ans = 0;
        for (int i=0;i<n;i++) {
            for (int j=0;j<3;j++) {
                List<Double> list = new ArrayList<Double>();
                list.add(0.0);
                list.add(1.0);

                for (int i2=0;i2<n;i2++) {
                    if(i==i2) continue;
                    for (int j2=0;j2<3;j2++) {
                        P p1 = ts[i][j];
                        P p2 = ts[i][j+1];
                        P p3 = ts[i2][j2];
                        P p4 = ts[i2][j2+1];
                        if(intersect(p1,p2,p3,p4)){
                            long outer1 = outer(p2.x-p1.x, p2.y-p1.y, p4.x-p3.x, p4.y-p3.y);
                            long outer2 = outer(p3.x-p1.x, p3.y-p1.y, p4.x-p3.x, p4.y-p3.y);
                            double d = (double)outer2/outer1;
                            list.add(d);
                        }
                    }
                }

                Collections.sort(list);
                double x1 = ts[i][j].x;
                double y1 = ts[i][j].y;
                for (int k=1;k<list.size();k++) {
                    double x2 = ts[i][j].x+(ts[i][j+1].x-ts[i][j].x)*list.get(k);
                    double y2 = ts[i][j].y+(ts[i][j+1].y-ts[i][j].y)*list.get(k);

                    double cx = (x1+x2)/2;
                    double cy = (y1+y2)/2;

                    boolean inTriangle = false;
                    for (int i2=0;i2<n;i2++) {
                        if(i2==i) continue;
                        boolean b1 = onLeft(ts[i2][0].x, ts[i2][0].y, ts[i2][1].x, ts[i2][1].y, cx, cy);
                        boolean b2 = onLeft(ts[i2][1].x, ts[i2][1].y, ts[i2][2].x, ts[i2][2].y, cx, cy);
                        boolean b3 = onLeft(ts[i2][2].x, ts[i2][2].y, ts[i2][3].x, ts[i2][3].y, cx, cy);

                        if(b1==b2&&b2==b3){
                            inTriangle = true;
                            break;
                        }
                    }

                    if(!inTriangle) {
                        ans += dis(x1,y1,x2,y2);
                    }

                    x1 = x2;
                    y1 = y2;
                }

            }
        }
        System.out.println(ans); 
    }
    public static void main(String[] args) throws Exception {
        new C();
    }
}