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

public class Problem_62A {

	BufferedReader in;
	StringTokenizer st;
	PrintWriter out;

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

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

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

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

	double getLength(double a[], double b[]) {
		return Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]));
	}

	void solve() throws Exception {
		int n = nextInt();
		if (n == 0) {
			out.println(0);
			return;
		}
		Area result = new Area();
		for (int i = 0; i < n; i++) {
			int x[] = new int[3];
			int y[] = new int[3];
			for (int j = 0; j < 3; j++) {
				x[j] = nextInt();
				y[j] = nextInt();
			}
			Polygon triangle = new Polygon(x, y, 3);
			result.add(new Area(triangle));
		}

		double ans = 0;

		PathIterator it = result.getPathIterator(null);

		double first[] = new double[2];
		double curr[] = new double[2];
		double prev[] = new double[2];

		boolean flag = false; // determines whether answer shape is connected
		it.currentSegment(first);
		it.next();
		curr = first.clone();

		while (!it.isDone()) {
			prev = curr.clone();
			int type = it.currentSegment(curr);
			if (type == PathIterator.SEG_LINETO)
				ans += getLength(curr, prev);

			if (type == PathIterator.SEG_CLOSE)
				ans += getLength(curr, first);

			if (type == PathIterator.SEG_MOVETO)
				first = curr.clone();
			it.next();
		}
		// ans += getLength(curr, first);

		out.println(ans);
	}

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

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

	public static void main(String[] args) {
		new Problem_62A().run();

	}

}