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 PYTHON):

Solution:
from math import hypot
def readint(): return int(raw_input())
def readarray(foo): return [foo(x) for x in raw_input().split()]


def intersect(x1, y1, x2, y2, x3, y3, x4, y4):
	a1 = y1 - y2
	b1 = x2 - x1
	c1 = (x1 * y2 - x2 * y1)

	a2 = y3 - y4
	b2 = x4 - x3
	c2 = (x3 * y4 - x4 * y3)

	d = a1 * b2 - b1 * a2
	if d == 0: return (None, None)
	
	d1 = b1 * c2 - b2 * c1
	d2 = -a1 * c2 + a2 * c1
	return (d1 * 1.0 / d, d2 * 1.0 / d)

def intersect_param(x1, y1, x2, y2, x3, y3, x4, y4):
	(x, y) = intersect(x1, y1, x2, y2, x3, y3, x4, y4)
	if x is None: return None
	if x1 != x2:
		return (x - x1) / (x2 - x1)
	return (y - y1) / (y2 - y1)
	
def in_triangle((x1, y1), ps):
	if x1 < min(ps[0][0], ps[1][0], ps[2][0]): return False
	if x1 > max(ps[0][0], ps[1][0], ps[2][0]): return False
	if y1 < min(ps[0][1], ps[1][1], ps[2][1]): return False
	if y1 > max(ps[0][1], ps[1][1], ps[2][1]): return False
	v = []
	for (i, (x2, y2)) in enumerate(ps):
		(x3, y3) = ps[(i + 1) % 3]
		dx1 = x2 - x1
		dy1 = y2 - y1
		dx2 = x3 - x2
		dy2 = y3 - y2
		v.append(dx1 * dy2 - dy1 * dx2)
	return all([x > 0 for x in v]) or all([x < 0 for x in v])

def run():
	n = readint()
	triangles = []
	segments = []
	for i in xrange(n):
		(x1, y1, x2, y2, x3, y3) = readarray(int)
		triangles.append(((x1, y1), (x2, y2), (x3, y3)))
		segments.append((i, (x1, y1), (x2, y2)))
		segments.append((i, (x1, y1), (x3, y3)))
		segments.append((i, (x2, y2), (x3, y3)))

	res = 0
	for (i, (x1, y1), (x2, y2)) in segments:
		crosses = [0]
		for (j, (x3, y3), (x4, y4)) in segments:
			if i == j: continue
			t = intersect_param(x1, y1, x2, y2, x3, y3, x4, y4)
			if t is None or t < 0 or t > 1: continue
			crosses.append(t)
		crosses.append(1)
		crosses.sort()
		for j in xrange(len(crosses) - 1):
			t1 = crosses[j]
			t2 = crosses[j + 1]
			t = (t1 + t2) / 2
			x = x1 + t * (x2 - x1)
			y = y1 + t * (y2 - y1)
			ok = True
			for k in xrange(n):
				if k == i: continue
				if in_triangle((x, y), triangles[k]):
					ok = False
					break
			if ok:
				res += (t2 - t1) * hypot(x1 - x2, y1 - y2)
	return res		

print run()