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.util.*;
import java.io.*;
import java.math.BigInteger;
import static java.lang.Math.*;

public class Main implements Runnable {
	StringTokenizer tokenizer = new StringTokenizer("");
	BufferedReader in;
	PrintStream out;

	final double eps = 1e-9;

	class P implements Comparable <P> {
		long x, y;

		P(long x, long y) { this.x = x; this.y = y; }

		P add(P p) { return new P(x + p.x, y + p.y); }

		P sub(P p) { return new P(x - p.x, y - p.y); }

		P mult(long c) { return new P(x * c, y * c); }

		long dot(P p) { return x * p.x + y * p.y; }

		long det(P p) { return x * p.y - y * p.x; }

		long len2() { return x * x + y * y; }

		double len() { return hypot(x, y); }

		public int compareTo(P p) {
			int ret = Long.signum(x - p.x);
			return ret != 0 ? ret : Long.signum(y - p.y);
		}

		public String toString() {
			return String.format("(%d, %d)", x, y);
		}
	}

	boolean parallel(P a, P b, P c, P d) {
		return (b.x - a.x) * (d.y - c.y) - (b.y - a.y) * (d.x - c.x) == 0;
	}
	
	boolean strictlyInTriangle(P [] t, P p) {
		return inTriangle(t, p) && !on_line(t[0], t[1], p) && !on_line(t[1], t[2], p) && !on_line(t[2], t[0], p);	
	}
	
	boolean inTriangle(P [] t, P p) {
		return area2(t[0], t[1], t[2]) - area2(t[0], t[1], p) - area2(t[1], t[2], p) - area2(t[2], t[0], p) == 0;
	}

	long o_area(P a, P b, P c) {
		return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);	
	}

	long area2(P a, P b, P c) {
		return abs(o_area(a, b, c));
	}

	boolean on_segment_line(P a, P b, P p) {
		return min(a.x, b.x) <= p.x && p.x <= max(a.x, b.x) && min(a.y, b.y) <= p.y && p.y <= max(a.y, b.y);
	}

	boolean on_line(P a, P b, P p) {
		return area2(a, b, p) == 0;
	}

	boolean intersects(P a, P b, P c, P d) {
		int s1 = Long.signum(o_area(a, c, d)), s2 = Long.signum(o_area(b, c, d));
		int s3 = Long.signum(o_area(c, a, b)), s4 = Long.signum(o_area(d, a, b));
		if (s1 * s2 > 0 || s3 * s4 > 0) return false;
		if (!parallel(a, b, c, d)) return true;
		return on_segment_line(c, d, a) || on_segment_line(c, d, b) || on_segment_line(a, b, c);
	}

	// assumes cross intersection; returns ratio AX/AB
	double intersection(P a, P b, P c, P d) {
		P n = new P(c.y - d.y, d.x - c.x);
		double ratio = (double)d.sub(a).dot(n) / b.sub(a).dot(n);
		return ratio;
	}

	boolean inTriangle(P [] t, double X, double Y) {
		double s = abs(o_area2(t[0].x, t[0].y, t[1].x, t[1].y, t[2].x, t[2].y));
		double s1 = abs(o_area2(t[0].x, t[0].y, t[1].x, t[1].y, X, Y));
		double s2 = abs(o_area2(t[1].x, t[1].y, t[2].x, t[2].y, X, Y));
		double s3 = abs(o_area2(t[2].x, t[2].y, t[0].x, t[0].y, X, Y));
		return abs(s - s1 - s2 - s3) < eps * max(1l, s);	
	}

	double o_area2(double x1, double y1, double x2, double y2, double x3, double y3) {
		return (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1);
	}


	public void debug(String s) {
		System.out.println(s);
	}

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

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

			int n = nextInt();

			P [][] tr = new P[n][3];
			for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) tr[i][j] = new P(nextInt(), nextInt());

			P [][] segm = new P[3 * n][2];
			for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) { 
				segm[3 * i + j][0] = tr[i][j];
				segm[3 * i + j][1] = tr[i][(j + 1) % 3];
			}

			double ans = 0;
			int S = 3 * n;
			for (int i = 0; i < S; i++) {
     				ArrayList <Double> list = new ArrayList <Double>();
     				for (int j = 0; j < S; j++) if (i != j) {
     					if (intersects(segm[i][0], segm[i][1], segm[j][0], segm[j][1]) 
     						&& !parallel(segm[i][0], segm[i][1], segm[j][0], segm[j][1])) {
     						list.add(intersection(segm[i][0], segm[i][1], segm[j][0], segm[j][1]));
     					}
     				}
     				Collections.sort(list);

     				double dx = segm[i][1].x - segm[i][0].x, dy = segm[i][1].y - segm[i][0].y, l = segm[i][1].sub(segm[i][0]).len();
     				outer:
     				for (int j = 0; j < list.size() - 1; j++) {
     					double C = (list.get(j) + list.get(j + 1)) / 2;
     					double X = segm[i][0].x + C * dx, Y = segm[i][0].y + C * dy;
     					for (int t = 0; t < n; t++) if (t != i / 3) {
     						if (inTriangle(tr[t], X, Y)) continue outer;
     					}
     					ans += l * (list.get(j + 1) - list.get(j));
     				}
			}

			out.println(ans);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	boolean seekForToken() {
		while (!tokenizer.hasMoreTokens()) {
			String s = null;
			try {
				s = in.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			if (s == null)
				return false;
			tokenizer = new StringTokenizer(s);
		}
		return true;
	}

	String nextToken() {
		return seekForToken() ? tokenizer.nextToken() : null;
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}
}