Save the Earth
Time limit2sMemory limit1024 MB
Find the shortest walk from a house to a point within r1 of antenna 1 and within r2 of antenna 2, given the antennas are farther apart than r1 + r2.
- Level
Medium6 of 10
- Topics
- Geometry, Math, Binary search
- Solved
- No attempts yet
Statement
Aliens have invaded Earth. The situation is not as hopeless as it first looks. Rick can hack the alien ships and make them turn around and leave the solar system. To do this, he must connect to the two largest parabolic antennas in the area. Morty has nearly convinced Rick, but Rick keeps resisting because he is lazy.
To keep Morty off his back for a couple of minutes, after which Rick will still have to go save the world, Rick asked Morty to find the length of the shortest path Rick must travel from the house where he is now to turn on both antennas. To turn on the first antenna, Rick must be within distance of it, and to turn on the second, within distance .
As you may have guessed, neither antenna can be turned on from the house. Also, due to technical limitations, the distance between the antennas is strictly greater than .
Assume there are no obstacles on the plane. Rick may even walk through the place where an antenna stands.
Input
The first line contains three integers , , and , the coordinates of the first antenna on the plane and its radius parameter (, ). The second line contains three integers , , and , the coordinates of the second antenna (, ). The third line contains two integers and , the coordinates of the house where Rick is now ().
Output
Print one line with the length of the shortest path Rick must travel to turn on both antennas. The answer is accepted with an absolute or relative error of at most .
Hint

Figure 1: Explanation for the first test

Figure 2: Explanation for the second test