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> {
		double x, y;

		P(double x, double 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(double c) {
			return new P(x * c, y * c);
		}

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

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

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

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

		public int compareTo(P p) {
			if (x + eps < p.x) return -1;
			if (x > p.x + eps) return 1;
			return y + eps < p.y ? -1 : 1;
		}

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

	boolean parallel(P a, P b, P c, P d) {
		return abs((b.x - a.x) * (d.y - c.y) - (b.y - a.y) * (d.x - c.x)) < eps;
	}
	

	boolean inTriangle(P [] t, P p) {
		return abs(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)) < eps * area2(t[0], t[1], t[2]);
	}

	double 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);	
	}

	double 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) - eps <= p.x && p.x <= max(a.x, b.x) + eps && min(a.y, b.y) - eps <= p.y && p.y <= max(a.y, b.y) + eps;
	}

	boolean on_line(P a, P b, P p) {
		return area2(a, b, p) < eps;
	}


	P intersect(P a, P b, P c, P d) {
		if (parallel(a, b, c, d)) return null;
		P n = new P(c.y - d.y, d.x - c.x);
		P w = a.sub(b).mult(c.sub(b).dot(n) / a.sub(b).dot(n));
		P cand = b.add(w);
		if (!on_segment_line(a, b, cand) || !on_segment_line(c, d, cand)) return null;
		//out.println("ans = " + cand);
		return cand;
	}

	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();

			//out.println(intersect(new P(4, 4), new P(-1, -1), new P(0, 1.5), new P(3, 0)));
			//out.println(inTriangle(new P[] {new P(0, 0), new P(0, 1), new P(1, 0)}, new P(1, 0)));

			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 <P> list = new ArrayList <P>();
     				for (int j = 0; j < S; j++) if (i != j) {
     					P p = intersect(segm[i][0], segm[i][1], segm[j][0], segm[j][1]);
     					if (p != null) list.add(p);	
     				}
     				
     				Collections.sort(list);
     				//out.println("list " + i + ":");
     				//for (P p: list) out.println(p);
     				outer:
     				for (int j = 0; j < list.size() - 1; j++) {
     					P p1 = list.get(j), p2 = list.get(j + 1);
     					for (int t = 0; t < n; t++) if (t != i / 3) {
     						if (inTriangle(tr[t], p1.add(p2.sub(p1).mult(.5)))) continue outer;
     					}
     					ans += p2.sub(p1).len();
     				}
			}

			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());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}

	BigInteger nextBig() {
		return new BigInteger(nextToken());
	}
}