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:
//package round58;

import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class C3 {
	Scanner in;
	PrintWriter out;
	String INPUT = "";
	
	void solve()
	{
		int n = ni();
		int[][] ls = new int[3*n][];
		for(int i = 0;i < n;i++){
			int x1 = ni(), y1 = ni();
			int x2 = ni(), y2 = ni();
			int x3 = ni(), y3 = ni();
			ls[3*i] = new int[]{x1, y1, x2, y2};
			ls[3*i+1] = new int[]{x2, y2, x3, y3};
			ls[3*i+2] = new int[]{x3, y3, x1, y1};
		}
		
		double[][][] cs = new double[3*n][3*n][];
		for(int i = 0;i < 3*n;i++){
			for(int j = 0;j < 3*n;j++){
				if(i != j){
					double[] il = interLines(ls[i][0], ls[i][1], ls[i][2], ls[i][3], ls[j][0], ls[j][1], ls[j][2], ls[j][3]);
					if(il != null && il[2] > -EPS && il[2] < 1+EPS && il[3] > -EPS && il[3] < 1+EPS){
						cs[i][j] = il;
					}
				}
			}
		}
		
		double ret = 0;
		for(int i = 0;i < 3*n;i++){
			final double[] ts = new double[3*n];
			int[] es = new int[3*n];
			int p = 0;
			for(int j = 0;j < 3*n;j++){
				if(cs[i][j] != null){
					ts[p] = cs[i][j][2];
					es[p] = j;
					p++;
				}
			}
			Integer[] ord = new Integer[p];
			for(int j = 0;j < p;j++){
				ord[j] = j;
			}
			Arrays.sort(ord, new Comparator<Integer>(){
				public int compare(Integer x, Integer y)
				{
					return (int)Math.signum(ts[x]-ts[y]);
				}
			});
			
			outer:
			for(int j = 0;j < p-1;j++){
				double[] cur = cs[i][es[ord[j]]];
				double[] nex = cs[i][es[ord[j+1]]];
				double dist = Point2D.distance(cur[0], cur[1], nex[0], nex[1]);
				if(dist > EPS){
					double cx = (cur[0]+nex[0])/2;
					double cy = (cur[1]+nex[1])/2;
					for(int k = 0;k < n;k++){
						if(k != i/3 && isIn(ls, k, cx, cy)){
							continue outer;
						}
					}
					ret += dist;
				}
			}
		}
		out.println(ret);
	}
	
	public boolean isIn(int[][] ls, int k, double cx, double cy)
	{
		int cc = Line2D.relativeCCW(ls[3*k][0], ls[3*k][1], ls[3*k][2], ls[3*k][3], cx, cy);
		if(cc == 0)return false;
		for(int l = 1;l < 3;l++){
			int ccc = Line2D.relativeCCW(ls[3*k+l][0], ls[3*k+l][1], ls[3*k+l][2], ls[3*k+l][3], cx, cy);
			if(cc != ccc)return false;
		}
		return true;
	}
	
	public boolean isIn(double x, double y, int[] px, int[] py)
	{
		int n = px.length;
		int cc = Line2D.relativeCCW(px[n-1], py[n-1], px[0], py[0], x, y);
		if(cc == 0)return false;
		for(int i = 0;i < n-1;i++){
			int ccc = Line2D.relativeCCW(px[i], py[i], px[i+1], py[i+1], x, y);
			if(cc != ccc)return false;
		}
		return true;
	}
	
	
	double EPS = 1E-8;
	public double[] interLines(double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy)
	{
		double aa = bx - ax;
		double cc = by - ay;
		double bb = cx - dx;
		double dd = cy - dy;
		double xx = cx - ax;
		double yy = cy - ay;
		double det = aa * dd - bb * cc;
		if(Math.abs(det) < EPS)return null;
		double t = (dd * xx - bb * yy) / det;
		double u = (-cc * xx + aa * yy) / det;
		return new double[]{ax + (bx - ax) * t, ay + (by - ay) * t, t, u};
	}
	
	void run() throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);

		solve();
		out.flush();
	}
	
	
	public static void main(String[] args) throws Exception
	{
		new C3().run();
	}
	
	int ni() { return Integer.parseInt(in.next()); }
	void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}