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.awt.geom.Point2D;
import java.text.*;
import java.math.*;
import java.util.*;

public class Main implements Runnable {

	final String filename = "";

	public void solve() throws Exception {
		final double eps = 1e-8;
		int n = iread();
		Point[][] points = new Point[n][3];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 3; j++)
				points[i][j] = new Point(iread(), iread());
		}
		double ans = 0.0;
		ArrayList<Double> pp = new ArrayList<Double>();
		for (int i = 0; i < n; i++)
			for (int j = 0; j < 3; j++) {
				Point a = points[i][j], b = points[i][(j + 1) % 3];
				pp.clear();
				for (int i1 = 0; i1 < n; i1++)
					for (int j1 = 0; j1 < 3; j1++) {
						Point c = points[i1][j1], d = points[i1][(j1 + 1) % 3];
						double res = intersect(a, b, c, d);
						if (res >= 0.0)
							pp.add(res);
					}
				pp.add(0.0d);
				pp.add(1.0d);
				Collections.sort(pp);
				double dx = b.x - a.x;
				double dy = b.y - a.y;
				double len = Math.sqrt(dx * dx + dy * dy);

				for (int k = 0; k < pp.size() - 1; k++) {
					double x1 = dx * (pp.get(k) + pp.get(k + 1)) / 2.0 + a.x;
					double y1 = dy * (pp.get(k) + pp.get(k + 1)) / 2.0 + a.y;
					double x2 = eps * -dy / len;
					double y2 = eps * dx / len;
					boolean flag2 = false;
					for (int t = 0; t < 2; t++) {
						boolean flag = true;
						for (int i1 = 0; i1 < n; i1++)
							if (inIs(points[i1], x1 + x2, y1 + y2)) {
								flag = false;
								break;
							}
						if (flag) {
							flag2 = true;
							break;
						}
						x2 = -x2;
						y2 = -y2;
					}
					if (flag2)
						ans += len * (pp.get(k + 1) - pp.get(k));
				}
			}
		DecimalFormat df = new DecimalFormat("0.00000000");
		out.write(df.format(ans) + "\n");
	}

	boolean inIs(Point[] triangle, double targetX, double targetY) {
		int s1 = 0, s2 = 0, s3 = 0;
		for (int i = 0; i < 3; i++) {
			Point a = triangle[i], b = triangle[(i + 1) % 3];
			double A = b.y - a.y, B = a.x - b.x, C = -(a.x * A + a.y * B);
			double s = targetX * A + targetY * B + C;
			if (s > 0)
				s3++;
			else if (s == 0)
				s2++;
			else
				s1++;
		}
		return s1 == 0 || s3 == 0;
	}

	double intersect(Point a, Point b, Point c, Point d) {
		// (b-a)*t + a = (d-c)*u + c

		long a11 = b.x - a.x, a12 = c.x - d.x, a13 = c.x - a.x;
		long a21 = b.y - a.y, a22 = c.y - d.y, a23 = c.y - a.y;
		long D = a11 * a22 - a12 * a21;
		long T = a13 * a22 - a12 * a23;
		long U = a11 * a23 - a13 * a21;
		if (D > 0 && T >= 0 && T <= D && U >= 0 && U <= D || D < 0 && T <= 0
				&& T >= D && U <= 0 && U >= D)
			return T * 1.0 / D;
		return -1.0;
	}

	class Point {
		int x, y;

		public Point(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new BufferedWriter(new OutputStreamWriter(System.out));
			// in = new BufferedReader(new FileReader(filename+".in"));
			// out = new BufferedWriter(new FileWriter(filename+".out"));
			solve();
			out.flush();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public int iread() throws Exception {
		return Integer.parseInt(readword());
	}

	public double dread() throws Exception {
		return Double.parseDouble(readword());
	}

	public long lread() throws Exception {
		return Long.parseLong(readword());
	}

	BufferedReader in;

	BufferedWriter out;

	public String readword() throws IOException {
		StringBuilder b = new StringBuilder();
		int c;
		c = in.read();
		while (c >= 0 && c <= ' ')
			c = in.read();
		if (c < 0)
			return "";
		while (c > ' ') {
			b.append((char) c);
			c = in.read();
		}
		return b.toString();
	}

	public static void main(String[] args) {
		try {
			Locale.setDefault(Locale.US);
		} catch (Exception e) {

		}
		new Thread(new Main()).start();
		// new Thread(null, new Main(), "1", 1<<25).start();
	}
}