Segment and Point

Find the closest point on segment AB to point C in 3D and print the distance with ten decimals.

Easy3GeometryMathInterviewNo attempts yetTime limit1sMemory limit256 MB

Problem

A segment and a point lie in three dimensional space. The endpoints of the segment are A(Ax,Ay,Az)A(A_x, A_y, A_z) and B(Bx,By,Bz)B(B_x, B_y, B_z), and the point is C(Cx,Cy,Cz)C(C_x, C_y, C_z).

Write a program that finds the point of the segment closest to CC and reports that distance. This value is the minimum distance between the segment and the point.

The distance between (x1,y1,z1)(x_1, y_1, z_1) and (x2,y2,z2)(x_2, y_2, z_2) is (x2x1)2+(y2y1)2+(z2z1)2\sqrt{(x_2-x_1)^2+(y_2-y_1)^2+(z_2-z_1)^2}.

AA and BB may be the same point. The segment is then a single point.

Input

The first line contains nine integers AxA_x, AyA_y, AzA_z, BxB_x, ByB_y, BzB_z, CxC_x, CyC_y, CzC_z separated by spaces. Every coordinate is an integer between 0 and 10000, inclusive.

Output

On the first line, print the minimum distance between the segment and the point, rounded to ten digits after the decimal point. Print exactly ten digits after the decimal point whatever the value is. For example, an answer of zero is printed as 0.0000000000.