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.awt.geom.Line2D;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class C62 {

    static class line {
        int x1,y1,x2,y2;
        public line(int x1, int y1, int x2, int y2) {
            this.x1 = x1;
            this.y1 = y1;
            this.x2 = x2;
            this.y2 = y2;
        }
    }
    static class Point implements Comparable<Point>{
        double x, y;
        public Point(double x, double y) {
            this.x = x;
            this.y = y;
        }
        public int compareTo(Point arg0) {
            if (this.x > arg0.x || this.x==arg0.x && this.y > arg0.y)
                return 1;
            return 0;
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[]x1 = new int[n+1], y1 = new int[n+1],x2 = new int[n+1], y2 = new int[n+1],x3 = new int[n+1], y3 = new int[n+1];
        for (int i = 1; i <= n; i++) {
            x1[i] = sc.nextInt();
            y1[i] = sc.nextInt();
            x2[i] = sc.nextInt();
            y2[i] = sc.nextInt();
            x3[i] = sc.nextInt();
            y3[i] = sc.nextInt();
        }
        line[]L = new line[3*n+1];
        for (int i = 1; i <= n; i++) {
            L[3*(i-1)+1] = new line(x1[i], y1[i], x2[i], y2[i]);
            L[3*(i-1)+2] = new line(x1[i], y1[i], x3[i], y3[i]);
            L[3*(i-1)+3] = new line(x2[i], y2[i], x3[i], y3[i]);
        }
        ArrayList<Point>[] points_inters = new ArrayList[3*n+1];
        for (int i = 1; i <= 3*n; i++) {
            points_inters[i] = new ArrayList<Point>();
        }
        for (int i = 1; i <= 3*n; i++) {
            for (int j = i+1; j <= 3*n; j++) {
                if (IntersectSegment(L[i].x1, L[i].y1, L[i].x2, L[i].y2, L[j].x1, L[j].y1, L[j].x2, L[j].y2)) {
                    long a1 = L[i].y2-L[i].y1, b1 = L[i].x1-L[i].x2, c1 = (long)L[i].x2*L[i].y1-(long)L[i].x1*L[i].y2;
                    long a2 = L[j].y2-L[j].y1, b2 = L[j].x1-L[j].x2, c2 = (long)L[j].x2*L[j].y1-(long)L[j].x1*L[j].y2;
                    long D = det(a1, a2, b1, b2), Dx = det(-c1, -c2, b1, b2), Dy = det(a1, a2, -c1, -c2);
                    double x0 = Dx*1.0/D, y0 = Dy*1.0/D;
                    if (Math.abs(D) < 1e-8)
                        continue;
                    points_inters[i].add(new Point(x0, y0));
                    points_inters[j].add(new Point(x0, y0));
                }
            }
        }
        Point[]points = new Point[9*n*n+1];
        double ans = 0;
        for (int i = 1; i <= 3*n; i++) {
            int size = points_inters[i].size();
            for (int j = 0; j < size; j++) {
                points[j] = new Point(points_inters[i].get(j).x, points_inters[i].get(j).y);
            }
            Arrays.sort(points, 0, size);
            for (int j = 1; j < size; j++) {
                double x0 = (points[j].x+points[j-1].x)/2, y0 = (points[j].y+points[j-1].y)/2;
                double s = distens(points[j].x, points[j].y, points[j-1].x, points[j-1].y);
                for (int j2 = 1; j2 <= n; j2++) {
                    if (i >= 3*(j2-1)+1 && i <= 3*(j2-1)+3)
                        continue;
                    if (in(x0, y0, x1[j2], y1[j2], x2[j2], y2[j2], x3[j2], y3[j2])) {
                        s = 0;
                        break;
                    }
                }
                ans += s;
            }
        }
        System.out.println(ans);
    }
    private static boolean IntersectSegment(int x1, int y1, int x2, int y2,
            int x3, int y3, int x4, int y4) {
        long s1 = area(x1, y1, x2, y2, x3, y3), s2 = area(x1, y1, x2, y2, x4, y4), s3 = area(x3, y3, x4, y4, x1, y1), s4 = area(x3, y3, x4, y4, x2, y2);
        return (s1 >= 0 && s2 <= 0 || s1 <= 0 && s2 >= 0) && (s3 >= 0 && s4 <= 0 || s3 <= 0 && s4 >= 0) && intersect1(x1, x2, x3, x4) && intersect1(y1, y2, y3, y4);
    }
    private static boolean intersect1(int a, int b, int c, int d) {
        if (a > b) {
            int t = a;
            a = b;
            b = t;
        }
        if (c > d) {
            int t = c;
            c = d;
            d = t;
        }
        return Math.max(a, c) <= Math.min(b, d);
    }
    private static long area(long x1, long y1, long x2, long y2, long x3, long y3) {
        return x1*y2+x2*y3+x3*y1-x3*y2-x1*y3-x2*y1;
    }
    private static double distens(double x1, double y1, double x2, double y2) {
        return Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    }
    private static boolean in(double x0, double y0, int x1, int y1, int x2, int y2,
            int x3, int y3) {
        return Math.abs(surfase(x1, y1, x2, y2, x3, y3)-surfase(x1, y1, x2, y2, x0, y0)-surfase(x1, y1, x3, y3, x0, y0)-surfase(x2, y2, x3, y3, x0, y0)) < 1e-5;
    }
    private static double surfase(double x1, double y1, double x2, double y2, double x3, double y3) {
        return Math.abs(x1*y2+x2*y3+x3*y1-x3*y2-x1*y3-x2*y1);
    }
    private static long det(long a1, long a2, long b1, long b2) {
        return a1*b2-a2*b1;
    }

}