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
//package cf.r58;

import java.util.Arrays;
import java.util.Scanner;
import java.util.Vector;

public class C {
	private static final double EPS = 1e-8;
	
	// Point, Line, Segment and Triangle mostly borrowed from Egor
	
	private static class Point implements Comparable<Point> {
		private final double x;
		private final double y;

		private Point(double x, double y) {
			this.x = x;
			this.y = y;
		}

		public double distance(Point other) {
			return Math.sqrt((x - other.x) * (x - other.x) + (y - other.y) * (y - other.y));
		}
		
		public int compareTo(Point other) {
			if (Math.abs(x - other.x) < EPS) return comp(y, other.y);
			return comp(x, other.x);
		}
		
		public boolean equals(Point other) {
			if (Math.abs(x - other.x) > EPS) return false;
			if (Math.abs(y - other.y) > EPS) return false;
			return true;
		}

		public String toString() {
			return "(" + x + " " + y + ")";
		}
	}

	private static class Line {
		private final double a, b, c;
		
		private Line(Point a, Point b) {
			this.a = a.y - b.y;
			this.b = b.x - a.x;
			c = -a.x * this.a - a.y * this.b;
		}
		
		public Point intersect(Line second) {
			if (Math.abs(a * second.b - b * second.a) < EPS)
				return null;
			double x = (b * second.c - c * second.b) / (a * second.b - b * second.a);
			double y = (a * second.c - c * second.a) / (b * second.a - a * second.b);
			return new Point(x, y);
		}
	}

	private static class Segment {
		private final Point a;
		private final Point b;

		private Segment(Point a, Point b) {
			if (a == null || b == null)
				throw new RuntimeException();
			this.a = a;
			this.b = b;
		}

		public double length() {
			return a.distance(b);
		}
		
		public Segment union(Segment s) {
			if (inside(s.a) || inside(s.b) || s.inside(a) || s.inside(b)) {
				Point[] all = new Point[]{a, b, s.a, s.b};
				Arrays.sort(all);
				return new Segment(all[0], all[3]);
			}
			return null;
		}

		public Point intersect(Segment other) {
			Line first = new Line(a, b);
			Line second = new Line(other.a, other.b);
			Point point = first.intersect(second);
			if (point != null && inside(point) && other.inside(point))
				return point;
			return null;
		}
		
		public boolean isEndPoint(Point other) {
			return a.equals(other) || b.equals(other);
		}

		public boolean inside(Point point) {
			return Math.abs(length() - point.distance(a) - point.distance(b)) < EPS;
		}

		public String toString() {
			return "{" + a + " " + b + "}";
		}
	}
	
	private static class Triangle {
		private final Point[] vertices = new Point[3];
		private final Segment[] sides = new Segment[3];
		
		public Triangle(Scanner scan) {
			for (int i = 0; i < 3; i++) vertices[i] = new Point(scan.nextInt(), scan.nextInt());
			for (int i = 0; i < 3; i++) sides[i] = new Segment(vertices[i], vertices[(i+1)%3]);
		}

		Segment intersect(Segment s) {
			Point[] xs = new Point[3];
			int xc = 0;
			for (int i = 0; i < 3; i++) {
				xs[i] = sides[i].intersect(s);
				if (xs[i] == null) continue;
				if (s.isEndPoint(xs[i])) xs[i] = null;
				if (xs[i] != null) xc++;
			}
//			System.out.println(xc);
			for (int i = 0; i < 3; i++) {
				if (xs[i] != null) continue;
				for (int j = i+1; j < 3; j++) {
					if (xs[j] == null) continue;
					xs[i] = xs[j];
					xs[j] = null;
					break;
				}
			}
			boolean af = false, bf = false;
			if (xc == 2) {
				return new Segment(xs[0], xs[1]);
			}
			af = inside(s.a);
			bf = inside(s.b);
			if (af && bf) {
				return s;
			}
			if (xc == 1) {
				if (af) return new Segment(s.a, xs[0]);
				if (bf) return new Segment(s.b, xs[0]);
			}
			return null;
		}

		public boolean inside(Point point) {
			double square = square();
			double allegedSquare = 0;
			for (int i = 0; i < 3; i++)
				allegedSquare += square(point, vertices[(i + 1) % 3], vertices[(i + 2) % 3]);
			return Math.abs(square - allegedSquare) < EPS;
		}

		private double square() {
			return square(vertices[0], vertices[1], vertices[2]);
		}

		private double square(Point a, Point b, Point c) {
			return .5 * Math.abs((a.x - b.x) * (a.y + b.y) + (b.x - c.x) * (b.y + c.y) + (c.x - a.x) * (c.y + a.y));
		}
		
		public String toString() {
			return sides[0] + "\n" + sides[1] + "\n" + sides[2];
		}
	}
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		Triangle[] triangles = new Triangle[N];
		for (int i = 0; i < N; i++) triangles[i] = new Triangle(scan);
		double res = 0;
		for (int i = 0; i < N; i++) {
			for (int k = 0; k < 3; k++) {
				res += triangles[i].sides[k].length();
				Vector<Segment> covered = new Vector<Segment>();
				for (int j = 0; j < N; j++) if (i != j) {
//					System.out.println("---------------------");
//					System.out.println(triangles[j]);
					Segment cj = triangles[j].intersect(triangles[i].sides[k]);
					if (cj == null) continue;
					if (cj.a.equals(cj.b)) continue;
//					System.out.println("+ " + cj);
					Vector<Segment> covered2 = new Vector<Segment>();
					for (Segment s : covered) {
						Segment su = s.union(cj);
//						System.out.println(">> " + s);
//						System.out.println(">> " + su);
//						System.out.println();
						if (su == null) {
							covered2.add(s);
						} else {
							cj = su;
						}
					}
					covered2.add(cj);
					covered = covered2;
//					System.out.println(i + ", " + k + ", " + j);
//					for (Segment s : covered) System.out.println("\t" + s);
				}
				if (covered.isEmpty()) continue;
//				System.out.println();
//				System.out.println(triangles[i].sides[k]);
				for (Segment s : covered) {
//					System.out.println("- " + s);
//					System.out.println("- " + s.length());
					res -= s.length();
				}
			}
		} 
		System.out.println(res);
	}
	
	public static int comp(double a, double b) {
		return Double.compare(a, b);
	}
}