I guess everyone who was in the cabinet of dean of USU math-mech faculty remembered the glass pyramid lying on the deans table. There is a legend that several students remembered this pyramid on all treir lifes as a part of a hard test. The everlasting question of every dean – to sent down a weak student or to give him the last chance.
The legend says that to get this last chance some weak students was to bring this pyramid by 70 rolls from one point of the table as closer as possible to given one another. Usually the destination point was the point of the deans table where the list of dismissed students lied. At the end of its path pyramid should stand on its base. And ideally pyramid should cover the locus of deans signature on the dismissing list.
After the student spent all his rolls or after he confessed that he couldn’t bring it closer, the dean measured the distance between the center of pyramids base and the destination point. The legend says that the student was given the desired last chance, if this distance was record-breaking small.
May be it’s just a beautiful legend but you can go to the deans cabinet right now and make sure that the pyramid lays on the table and the golden fog charming swirls in its depth… So, just in case, you’d better to train a little in rolling the pyramid from one point to another.
You can assume that the pyramids base is square and its lateral faces – regular triangles. You can roll the pyramid by turning it from one face to the adjacent one around some edge. During this turning the edge should not slide on surface of the table. Moreover to make the test harder the dean demands you to obey such a rule: if after the turn around some edge the pyramid stands on its base, the next turn can be performed either around the same edge or around the opposite edge of the pyramids base only. There are no any restrictions on the rolling from the triangle faces.
Input contains two real numbers – coordinates of the destination point. The pyramids edge length is concidered to be equal to 1 in the coordinate system. The origin coincides with the center of the pyramids base at the initial moment. The edges of the pyramids base at the initial moment are parallel to the coordinate axes.
Output should contain only one real number – the minimal possible distance between the center of the pyramids base after rolling and the destination point within 4 digits after a decimal point. The base edges may be not parallel to the coordinate axes at the final moment of time, but the pyramid should stand on its base. You can perform not more than 70 turns of pyramid during its rolling.
Problem Author: Idea - Stanislav Vasilyev, prepared by Pavel Egorov, Alexander Mironenko
Problem Source: VIII Collegiate Students Urals Programming Contest. Yekaterinburg, March 11-16, 2004