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.io.*;
import java.util.*;

public class Main implements Runnable {
	
	final static double eps = 1e-5;
	
	class Point {
		double x, y;
		Point(double x, double y) {
			this.x = x;
			this.y = y;
		}
		Point add(Point o) {
			return new Point(x + o.x, y + o.y);	
		}
		Point sub(Point o) {
			return new Point(x - o.x, y - o.y);
		}
		Point scale(double by) {
			return new Point(by * x, by * y);
		}
		Point rotate90() {
			return new Point(-y, x);
		}
		double length() {
			return Math.sqrt(x * x + y * y);			
		}
		@Override
		public String toString() {
			return x + " " + y;
		}
	}
	
	double cross(Point a, Point b) {
		return a.x * b.y - a.y * b.x;
	}
	
	double dot(Point a, Point b) {
		return a.x * b.x + a.y * b.y;
	}

	Point intersect(Point a, Point b, Point p, Point q) {
		double d1 = cross(p.sub(a), b.sub(a));
		double d2 = cross(q.sub(a), b.sub(a));
		if (Math.abs(d1 - d2) < eps)
			return null;
		return (q.scale(d1).sub(p.scale(d2))).scale(1.0 / (d1 - d2));
	}
	
	Point intersectSegments(Point a, Point b, Point p, Point q) {
		Point x = intersect(a, b, p, q);
		if (x == null)
			return null;
		if (onSegment(x, a, b) && onSegment(x, p, q))
			return x;
		else
			return null;
	}

	private boolean onSegment(Point x, Point a, Point b) {
		double cr = cross(x.sub(a), x.sub(b));
		if (Math.abs(cr) > eps)
			return false;
		return dot(x.sub(a), x.sub(b)) <= eps;
	}

	public void _main() throws IOException {
		int n = nextInt();
		Point[][] triangles = new Point[n][3];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 3; j++) {
				double x = nextDouble();
				double y = nextDouble();
				triangles[i][j] = new Point(x, y);
			}
		}
		
		double res = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 3; j++) {
				Point a = triangles[i][j];
				Point b = triangles[i][(j + 1) % 3];
				List<Point> onThisSegment = new ArrayList<Point>();
				onThisSegment.add(a);
				onThisSegment.add(b);
				for (int k = 0; k < n; k++) {
					if (i == k) continue;
					for (int l = 0; l < 3; l++) {
						Point c = triangles[k][l];
						Point d = triangles[k][(l + 1) % 3];
						Point x = intersectSegments(a, b, c, d);
						if (x != null)
							onThisSegment.add(x);
					}
				}
				final Point o = a;
				Collections.sort(onThisSegment, new Comparator<Point>() {
					public int compare(Point a, Point b) {						
						double ad = a.sub(o).length();
						double bd = b.sub(o).length();
						return Double.compare(ad, bd);
					}
				});
				for (int k = 0; k < onThisSegment.size() - 1; k++) {
					Point p = onThisSegment.get(k);
					Point q = onThisSegment.get(k + 1);
					if (p.sub(q).length() < 1e-8) continue;
					Point middle = p.add(q).scale(0.5);
					Point v = q.sub(p);
					v = v.scale(1e-5 / v.length());
					v = v.rotate90();
					Point testPoint1 = middle.add(v);
					Point testPoint2 = middle.sub(v);
					boolean f1 = insideAny(triangles, testPoint1);
					boolean f2 = insideAny(triangles, testPoint2);
					if (f1 ^ f2) {
						res += p.sub(q).length();
					}
					else if (!f1 && !f2) {
						//throw new AssertionError();
					}
				}
			}
		}

		out.printf("%.6f\n", res);
	}

	private boolean insideAny(Point[][] triangles, Point x) {
		for (Point[] triangle : triangles) {
			Point a = triangle[0];
			Point b = triangle[1];
			Point c = triangle[2];
			if (inside(x, a, b, c))
				return true;
		}
		return false;
	}

	private boolean inside(Point x, Point a, Point b, Point c) {
		double s1 = area(a, b, c);
		double s2 = area(x, b, c) + area(a, x, c) + area(a, b, x);
		return Math.abs(s1 - s2) < eps;
	}

	private double area(Point a, Point b, Point c) {
		return Math.abs(cross(b.sub(a), c.sub(a)));
	}

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

	private String next() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String rl = in.readLine();
			if (rl == null)
				return null;
			st = new StringTokenizer(rl);
		}
		return st.nextToken();
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public static void main(String[] args) {
		Locale.setDefault(Locale.UK);
		new Thread(new Main()).start();
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			_main();

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(202);
		}
	}

}