Shopping center

2.4

13 votes
Mathematics, Circle, Medium-Hard, Mathematics, Geometry
Problem

John is standing at the point (x1,y1) in the shopping center which has a path around in the form of a circle with the radius r and its center located on (0,0). He has to go to the location (x2,y2) in the shopping center. He wants to find the shortest path he can take to reach the location.
You can consider that John will touch the path around the shopping center and move to the location (x2,y2). Note that he cannot cross the shopping center, but he can (and he must) take the path.

Input

The first and only line contains five space-separated integers x1,y1,x2,y2,r(1|x1|,|y1|,|x2|,|y2|,r100). It's guaranteed that none of the points is inside the circle, nor on its border.

Output

  • Print the minimum distance
  • Print the answer with exactly six digits after zero

Sample input #2

-2 0 2 0 1

Sample output #2

4.511299

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

In the first sample:

In the second sample test:

Editor Image

?