Individually Customised Pop-up Cards

For a pop-up card folding on parallel axes, find the minimum distance to move the contact point (Xp,0) so a matching second segment exists.

Hard8GeometryMathBinary searchImplementationNo attempts yetTime limit3sMemory limit512 MB

Problem

Laser cutters are easy to find now, so pop-up cards are worth designing again. This problem is the first version of the design tool.

The card is four flat polygons joined along four fold lines. The four fold lines stay parallel to each other at every moment of the fold. Call their common direction the zz direction. The whole structure can then be studied through its projection onto the plane z=0z = 0, so the zz coordinate is dropped from here on.

The two pages of the card start at 9090 degrees to each other and are drawn as the positive xx axis and the positive yy axis. Both pages are infinitely large. The folding structure is one point of the first quadrant together with two line segments that join that point to each of the two pages. Closing the card rotates the two pages towards each other. When the two segments are chosen well, the structure folds flat without getting stuck at any moment, and at the end of the fold the two pages and both segments lie on one line. The pages and the segments must not bend, stretch, crease, or come loose from a fold line, and the angle between the pages never exceeds 9090 degrees.

The user draws one segment, from a point (Xp,0)(X_p, 0) on the xx axis to a point (Xa,Ya)(X_a, Y_a) of the first quadrant. The tool then looks for a second segment, from (Xa,Ya)(X_a, Y_a) to a point (0,Yp)(0, Y_p) with Yp>0Y_p > 0 on the other page, so that the card still closes flat. When no such second segment exists, the tool moves the contact point on the xx axis by the smallest possible distance until at least one choice becomes available. Report that distance.

Input

The input holds several test cases. Each test case is one line with three integers XaX_a, YaY_a and XpX_p separated by single spaces (1Xa20001 \le X_a \le 2000, 1Ya20001 \le Y_a \le 2000, 1Xp20001 \le X_p \le 2000). They describe the segment the user drew, from (Xp,0)(X_p, 0) to (Xa,Ya)(X_a, Y_a).

A line with three zeros separated by single spaces ends the input. There are at most 15001500 test cases.

Output

For each test case print one line with the smallest distance that XpX_p has to move, so that afterwards some segment from (Xa,Ya)(X_a, Y_a) to some point (0,Yp)(0, Y_p) with Yp>0Y_p > 0 closes the card flat.

The set of distances that work can be open, so the value asked for is the smallest number such that working distances exist arbitrarily close to it. Print that value with exactly six digits after the decimal point.

Hint

The first example case, Xa=1X_a = 1, Ya=1Y_a = 1, Xp=1X_p = 1, is the one in the picture. Nothing has to move: the segment from (1,1)(1, 1) to (0,1)(0, 1), dashed in the picture, gives a structure that folds flat.

In the third example case, Xa=5X_a = 5, Ya=4Y_a = 4, Xp=20X_p = 20, every distance strictly greater than 7.57.5 and strictly smaller than 2020 gives a valid card, while 7.57.5 itself gives none. Valid distances come arbitrarily close to 7.57.5, so the answer is 7.57.5.