#GYM104673F. Needle

Needle

Description

Another unexpected invention of Cimrman, a marvel of microminiaturization, is the self-balancing reactive needle.

It is capable of keeping itself upright and move itself freely on a flat surface in this orientation without being supported by any external device. While moving, it can draw extremely thin lines and curves. The trace the needle leaves is in fact only few molecules wide. However, the drawing surface should be extremely clean.

Another needle experiment is in process. The drawing surface contains experimental points which are divided into so-called clouds. The clouds arrangement is specific: Each cloud contains at least three points. The area of the convex hull of each cloud is positive. The intersection of convex hulls of any two clouds is empty.

The needle has to travel between two additional points $S$ and $T$. None of these two points lies inside the boundary of any cloud. The boundary of the cloud is considered to be the boundary of the convex hull of the cloud.

The needle has to travel from $S$ to $T$ along a shortest possible route. It should not travel inside the boundary of any cloud, the surface there may be unsuitable for the needle movement. On the other hand, the needle can travel along any part of the boundary of any cloud.

The first input line contains five numbers $N, S_x, S_y, T_x, T_y$, the number of clouds, and the coordinates $(S_x, S_y)$ of the start point $S$ and the coordinates $(T_x, T_y)$ of the target point $T$, respectively. Next $N$ lines contain description of cloud points in the following format. The $i$-th line contains an integer number ci, the number of points in the $i$-th cloud. Next on the line, there are $2 \cdot c_i$ numbers $x_{i,j}, y_{i,j}$ for $3 \leq j \leq c_i$, the coordinates of the points in the $i$-th cloud. All coordinates are integers in the range $-2000$ to $2000$. All input points are pairwise distinct. It is guaranteed that $1 \leq N \leq 200$, and also

$$\sum c_i \leq 500$$

Output a single number, the length of the needle's shortest path from $S$ to $T$, avoiding interiors of boundaries of all clouds. Your answer will be accepted if the absolute or relative error is at most $10^{-4}$.

Input

The first input line contains five numbers $N, S_x, S_y, T_x, T_y$, the number of clouds, and the coordinates $(S_x, S_y)$ of the start point $S$ and the coordinates $(T_x, T_y)$ of the target point $T$, respectively. Next $N$ lines contain description of cloud points in the following format. The $i$-th line contains an integer number ci, the number of points in the $i$-th cloud. Next on the line, there are $2 \cdot c_i$ numbers $x_{i,j}, y_{i,j}$ for $3 \leq j \leq c_i$, the coordinates of the points in the $i$-th cloud. All coordinates are integers in the range $-2000$ to $2000$. All input points are pairwise distinct. It is guaranteed that $1 \leq N \leq 200$, and also

$$\sum c_i \leq 500$$

Output

Output a single number, the length of the needle's shortest path from $S$ to $T$, avoiding interiors of boundaries of all clouds. Your answer will be accepted if the absolute or relative error is at most $10^{-4}$.

1 0 0 10 0
3 4 2 7 3 5 -4
11.8770543023

Note

Figure 1: Depiction of Sample Input 1 and its optimal solution (in blue/bold).