Problem C. Cosmonaut

Author:I. Ludov   Time limit:2 sec
Input file:input.txt   Memory limit:64 Mb
Output file:output.txt  

Statement

In the year 2030 International Space Station 2 was launched. It had a torus shape to enable artificial gravity generation. (A torus is a circular tube with circular cross-section). Advanced spacesuit technology and micro-rocket engines allowed for prolonged and easy spacewalks.

During one such spacewalk a crew member was looking at the station from an open space and wondered where should he fly to get to the station surface as fast as possible. Since he was cosmonaut and not astronaut, he had good mathematics education. So after a return to the station he quickly wrote a program which constructed the shortest line from any given point in space to the surface of a given torus.

Can you do this too?

Input file format

Input file contains eleven integer numbers:
xc yc zc — coordinates of torus center,
xd yd zd — a vector collinear to torus symmetry axis,
r1 — distance from the center of the tube to the center of the torus,
r2 — radius of the tube,
x y z — coordinates of the point in space.

Output file format

Output file must contain real numbers xm ym zm — coordinates of the nearest torus point with at least 15 correct digits after decimal point. If there is more than one nearest point, output any of them.

Constraints

 − 106 xc, yc, zc, xd, yd, zd, x, y, z ≤ 106,
0 < r2 < r1 ≤ 106, |xd| + |yd| + |zd| > 0,
point (x, y, z) lies either outside the torus or on its surface.

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
0 0 0
0 0 1
10 1
1 0 0
9.0 0.0 0.0
2
5 6 7 1 1 1 50 10 3 2 1
32.5203582126019 5.16103228678696 -22.1982936390279

0.081s 0.013s 17