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.util.*;
public class C62 {
public static void main(String[] args) throws IOException {
	input.init(System.in);
	PrintWriter out = new PrintWriter(System.out);
	int n = input.nextInt();
	Point[][] data = new Point[n][3];
	for(int i = 0; i<n; i++)
		for(int j = 0; j<3; j++) 
			data[i][j] = new Point(input.nextDouble(), input.nextDouble());
	double res = 0;
	for(int i = 0; i<n; i++)
		for(int j = 0; j<3; j++)
		{
			Point a = data[i][j], b = data[i][(j+1)%3];
			ArrayList<Interval> list = new ArrayList<Interval>();
			for(int k = 0; k<n; k++)
			{
				if(k == i) continue;
				ArrayList<Double> intervals = new ArrayList<Double>();
				for(int l = 0; l<3; l++)
				{
					Point p = data[k][l], q = data[k][(l+1)%3];
					Point x = segmentIntersection(new Segment(a, b), new Segment(p, q));
					if(x == null) continue;
					intervals.add(x.dist(a));
				}
				if(intervals.size() == 0)
				{
					if(inside(a, data[k])) list.add(new Interval(0, a.dist(b)));
					continue;
				}
				if(intervals.size() == 1)
				{
					double d = intervals.get(0);
					if(inside(a, data[k])) list.add(new Interval(0, d));
					else if(inside(b, data[k])) list.add(new Interval(d, a.dist(b)));
				}
				else if(intervals.size() == 2)
				{
					double first = intervals.get(0), second = intervals.get(1);
					if(first > second)
					{
						double temp = first; first = second; second = temp;
					}
					if(inside(a, data[k])) list.add(new Interval(0, first));
					else if(inside(b, data[k])) list.add(new Interval(second, a.dist(b)));
					else list.add(new Interval(first, second));
				}
				else
				{
					Collections.sort(intervals);
					double first = intervals.get(0), second = intervals.get(2);
					list.add(new Interval(first, second));
				}
			}
			Collections.sort(list);
			//out.println(i+" "+j+" "+list+" "+b.dist(a));
			double tot = 0;
			double lastEnd = 0;
			for(Interval e : list)
			{
				lastEnd = Math.max(lastEnd, e.a);
				tot += Math.max(0, e.b - lastEnd);
				lastEnd = Math.max(lastEnd, e.b);
			}
			//out.println(tot);
			res += b.dist(a) - tot;
		}
	out.println(res);
	out.close();
}
static boolean inside(Point p, Point[] tri)
{
	boolean allPos = true, allNeg = true;
	for(int i = 0; i<3; i++)
	{
		Point a = tri[i], b = tri[(i+1)%3];
		double cross = b.minus(a).cross(p.minus(a));
		if(cross <= EPS) allPos = false;
		if(cross >= -EPS) allNeg = false;
	}
	return allPos || allNeg;
}
static class Interval implements Comparable<Interval>
{
	double a, b;
	public Interval(double aa, double bb)
	{
		a = aa; b = bb;
	}
	public int compareTo(Interval o) {
		return Double.compare(a, o.a);
	}
	public String toString()
	{
		return a+" "+b;
	}
}
static double EPS = 1e-9;
public static Point segmentIntersection(Segment s1, Segment s2)
{
	Point p = lineIntersection(s1, s2);
	if(p==null)
	{
		//segments are parallel
		return null;
	}
	if(!(p.x >= Math.min(s1.start.x,s1.end.x)-1E-9 && p.x <= Math.max(s1.end.x,s1.start.x)+1E-9))
		return null;
	if(!(p.x >= Math.min(s2.start.x,s2.end.x)-1E-9 && p.x <= Math.max(s2.end.x,s2.start.x)+1E-9))
		return null;
	if(!(p.y >= Math.min(s1.start.y,s1.end.y)-1E-9 && p.y <= Math.max(s1.end.y,s1.start.y)+1E-9))
		return null;
	if(!(p.y >= Math.min(s2.start.y,s2.end.y)-1E-9 && p.y <= Math.max(s2.end.y,s2.start.y)+1E-9))
		return null;
	return p;
}
static class Segment
{
	Point start, end;
	public Segment(Point ss, Point ee)
	{
		start = ss; end = ee;
	}
}
public static Point lineIntersection(Segment s1, Segment s2)
{
	double a1 = s1.end.y - s1.start.y;
	double b1 = s1.start.x - s1.end.x;
	double c1 = a1*s1.start.x + b1*s1.start.y;
	double a2 = s2.end.y - s2.start.y;
	double b2 = s2.start.x - s2.end.x;
	double c2 = a2*s2.start.x + b2*s2.start.y;
	double det = a1*b2 - a2*b1;
	if(det == 0)
		return null;
	double x = (b2*c1 - b1*c2)/det;
	double y = (a1*c2 - a2*c1)/det;
	if(x == -0) x=0;
	if(y == -0) y=0;
	return new Point(x, y);
}
static class Point
{
	double x, y;
	public Point(double xx, double yy){
		x = xx; y = yy;
	}
	double dist(Point p)
	{
		return Math.sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
	}
	Point plus(Point p)
	{
		return new Point(x+p.x, y+p.y);
	}
	Point minus(Point p)
	{
		return new Point(x - p.x, y - p.y);
	}
	double dot(Point p)
	{
		return x * p.x + y*p.y;
	}
	double cross(Point p)
	{
		return x * p.y - y*p.x;
	}
	Point reflect(Point a, Point b)
	{
		Point d = b.minus(a), c = minus(a);
		Point p = a.plus(d.mult(c.dot(d) / d.dot(d)));
		return plus(p.minus(this).mult(2));
	}
	Point mult(double d)
	{
		return new Point(d*x, d*y);
	}
}
public static class input {
	static BufferedReader reader;
	static StringTokenizer tokenizer;

	static void init(InputStream input) {
		reader = new BufferedReader(new InputStreamReader(input));
		tokenizer = new StringTokenizer("");
	}

	static String next() throws IOException {
		while (!tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(reader.readLine());
		return tokenizer.nextToken();
	}

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

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

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