Treasure Map

Time limit1sMemory limit128 MB

Problem

A pirate's treasure map is a list of instructions that lead from where you land on a desert island to the spot marked X, where the treasure is buried. Your task is to find the shortest such walk on one particular island.

The island is a disk of radius $r$ paces centred at the origin $(0, 0)$. Relative to the centre, $(0, 1)$ is north, $(0, -1)$ is south, $(1, 0)$ is east, and $(-1, 0)$ is west; likewise $(1, 1)$ is northeast, $(1, -1)$ is southeast, $(-1, 1)$ is northwest, and $(-1, -1)$ is southwest.

You land on the shore (a point on the boundary circle), and the spot marked X lies somewhere on the island. A single instruction has the form

direction distance

where direction is one of north, south, east, west, northeast, northwest, southeast, southwest, and distance is the number of paces walked in that direction. Walking northeast for a distance $d$, for example, moves you $d / \sqrt{2}$ paces east and $d / \sqrt{2}$ paces north.

Consider every sequence of instructions that leads from the landing place to the spot marked X without ever leaving the island. Among all such sequences, report the smallest possible total distance walked (the sum of the distances of the individual instructions).

Input

The input contains several test cases. Each test case is a line with five integers $r$, $x$, $y$, $X$, $Y$: the radius of the island, the coordinates $(x, y)$ of the landing place, and the coordinates $(X, Y)$ of the spot marked X. The landing place lies on the shore, so $x^2 + y^2 = r^2$, and the spot lies on the island, so $X^2 + Y^2 \le r^2$. The landing place and the spot marked X are distinct. A line containing a single -1 follows the last test case.

Output

For each test case, print one line with the minimum possible total distance, rounded to exactly six digits after the decimal point.