The Doors

Time limit1sMemory limit128 MB

Problem

Find the length of the shortest path across a chamber that contains obstructing walls.

The chamber is a square with sides at $x = 0$, $x = 10$, $y = 0$, and $y = 10$. Every path starts at $(0, 5)$ and ends at $(10, 5)$.

Inside the chamber there are between $0$ and $18$ vertical walls, and each wall has exactly two doorways you may pass through. A wall is solid everywhere except at its two doorways. The figure below shows such a chamber together with one shortest path.

figure

Compute the length of the shortest path from $(0, 5)$ to $(10, 5)$ that never crosses a solid part of any wall.

Input

The input consists of several chambers.

Each chamber begins with a line containing the number of interior walls $n$ ($0 \le n \le 18$), followed by $n$ lines, one per wall. Each wall line contains five real numbers:

  • the $x$ coordinate of the wall ($0 < x < 10$), and
  • four $y$ coordinates $y_1 < y_2 < y_3 < y_4$ giving the endpoints of the two doorways.

The wall is solid over $[0, y_1]$, $[y_2, y_3]$, and $[y_4, 10]$, and open over the two doorways $[y_1, y_2]$ and $[y_3, y_4]$.

The walls of a chamber are given in increasing order of $x$, and within a line the four $y$ coordinates are in increasing order.

The input ends with a line containing $-1$ in place of the wall count.

Output

For each chamber, print one line with the length of the shortest path, rounded to exactly two digits after the decimal point (always shown, even if they are zero). The line must contain no spaces.