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


public class C {

	static class Line {
		int x1, y1, x2, y2, traing;
		public Line(int x1, int y1, int x2, int y2, int traing) {
			this.x1 = x1;
			this.y1 = y1;
			this.x2 = x2;
			this.y2 = y2;
			this.traing = traing;
		}
	}
	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 || Math.abs(this.x-arg0.x) < 1e-8 && 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-2] = new Line(x1[i], y1[i], x2[i], y2[i], i);
			L[3*i-1] = new Line(x1[i], y1[i], x3[i], y3[i], i);
			L[3*i] = new Line(x2[i], y2[i], x3[i], y3[i], i);
		}
		ArrayList<Point>[]points_intersect = new  ArrayList[3*n+1];
		for (int i = 1; i <= 3*n; i++) {
			points_intersect[i] = new ArrayList<Point>();
		}
		for (int i = 1; i <= 3*n; i++) {
			for (int j = i+1; j <= 3*n; j++) {
				if (intersect(L[i], L[j])) {
					long a1 = L[i].y1-L[i].y2, b1 = L[i].x2-L[i].x1, c1 = (long)L[i].x1*L[i].y2-(long)L[i].x2*L[i].y1;
					long a2 = L[j].y1-L[j].y2, b2 = L[j].x2-L[j].x1, c2 = (long)L[j].x1*L[j].y2-(long)L[j].x2*L[j].y1;
					double D = det(a1, a2, b1, b2);
					if (Math.abs(D) < 1e-8)
						continue;
					double Dx = det(-c1, -c2, b1, b2);
					double Dy = det(a1, a2, -c1, -c2);
					double x = Dx/D, y = Dy/D;
					points_intersect[i].add(new Point(x, y));
					points_intersect[j].add(new Point(x, y));
				}
			}
		}
		Point[]sort_x;
		double ans = 0;
		for (int i = 1; i <= 3*n; i++) {
			int m = points_intersect[i].size();
			sort_x = new Point[m];
			for (int j = 0; j < m; j++) {
				sort_x[j] = points_intersect[i].get(j);
			}
			Arrays.sort(sort_x);
			for (int j = 0; j < m-1; j++) {
				Point p1 = sort_x[j], p2 = sort_x[j+1];
				boolean f = true;
				int cnt = 0;
				for (int j2 = 1; j2 <= n; j2++) {
					if (in(x1[j2], y1[j2], x2[j2], y2[j2], x3[j2], y3[j2], p1.x, p1.y) && in(x1[j2], y1[j2], x2[j2], y2[j2], x3[j2], y3[j2], p2.x, p2.y) && in(x1[j2], y1[j2], x2[j2], y2[j2], x3[j2], y3[j2], (p1.x+p2.x)/2, (p1.y+p2.y)/2)) {
						cnt++;
						if (cnt > 1) {
							f = false;
							break;
						}
					}
				}
				if (f)
					ans += dis(p1, p2);
			}
		}
		System.out.println(ans);
	}
	private static double dis(Point p1, Point p2) {
		return Math.sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
	}
	private static boolean in(double x1, double y1, double x2, double y2, double x3, double y3,
			double x, double y) {
		return Math.abs(surfase(x1, y1, x2, y2, x3, y3)-surfase(x1, y1, x2, y2, x, y)-surfase(x1, y1, x3, y3, x, y)-surfase(x2, y2, x3, y3, x, y)) < 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 double det(long a1, long a2, long b1, long b2) {
		return a1*b2-a2*b1;
	}
	private static boolean intersect(Line L1, Line L2) {
		long s1 = traingle_s(L1.x1, L1.y1, L2.x1, L2.y1, L1.x2, L1.y2);
		long s2 = traingle_s(L1.x1, L1.y1, L2.x2, L2.y2, L1.x2, L1.y2);
		long s3 = traingle_s(L2.x1, L2.y1, L1.x1, L1.y1, L2.x2, L2.y2);
		long s4 = traingle_s(L2.x1, L2.y1, L1.x2, L1.y2, L2.x2, L2.y2);
		if (intersect1(L1.x1, L1.x2, L2.x1, L2.x2) && intersect1(L1.y1, L1.y2, L2.y1, L2.y2) && (s1 >= 0 && s2 <= 0 || s1 <= 0 && s2 >= 0) && (s3 >= 0 && s4 <= 0 || s3 <= 0 && s4 >= 0))
			return true;
		return false;
	}
	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.min(b, d) >= Math.max(a, c);
	}
	private static long traingle_s(long x1, long y1, long x2, long y2, long x3,
			int y3) {
		return x1*y2+x2*y3+x3*y1-x3*y2-x1*y3-x2*y1;
	}
}