Slant Drilling

Choose a ground point over nested contour polygons so the straight-line distance from the surface to the pocket at the origin is shortest.

Medium7GeometryTreeSortingNo attempts yetTime limit1sMemory limit256 MB

Problem

A survey map marks an oil pocket at (0,0)(0, 0), exactly 00 metres above sea level. The map draws the ground with contour lines. Each contour line is a closed polygon that does not cross itself, and it comes with two heights: the height of the ground immediately outside it and the height immediately inside it. The ground between contour lines is flat, so the height at a point is the inner height of the smallest contour line containing that point. A point that no contour line contains has the outer height of a contour line that no other contour line contains, and all of those contour lines have the same outer height.

A drill starts at a point of the ground surface and reaches the pocket in a straight line. That line does not have to be vertical. Starting from a point (x,y)(x, y) where the ground height is hh, the drilled length is x2+y2+h2\sqrt{x^2 + y^2 + h^2}.

Find the shortest length that has to be drilled.

Input

The first line contains one integer NN, the number of contour lines.

Each of the next NN lines describes one contour line. The line begins with three integers H0H_0, H1H_1 and MiM_i (0H0,H11060 \le H_0, H_1 \le 10^6, 3Mi3 \le M_i). H0H_0 is the height of the ground immediately outside the contour line and H1H_1 is the height immediately inside it, both in metres. MiM_i is the number of vertices of this contour line. The rest of the line holds 2Mi2 M_i integers, the coordinates xjx_j and yjy_j (106xj,yj106-10^6 \le x_j, y_j \le 10^6) of the vertices in order along the contour line.

The vertices of one contour line are distinct and a contour line does not cross itself. No two contour lines touch, and no contour line passes through (0,0)(0, 0). If a contour line is contained in another one, its outer height equals the inner height of the containing contour line. The number of vertices over all contour lines is at most 10510^5.

Output

Print the shortest drilled length, rounded to exactly six digits after the decimal point.