Alice and the Bomb

Given disjoint polygons, a bomb point, and Alice at the origin, find the shortest path she runs outside all polygon interiors until some building blocks the blast to the bomb.

Hard8GeometryShortest pathGraphImplementationNo attempts yetTime limit8sMemory limit512 MB

Problem

Alice and Bob were in love, but now they hate each other.

One day Alice found a bag. It looked like the bag Bob used to carry on their dates. Then she heard a ticking sound. Alice knew at once that Bob meant to kill her with a bomb. The bomb has not gone off yet, so she still has a little time to hide behind a building.

The city is an infinite plane, and every building is a polygon. Alice is a single point. When the bomb goes off, the blast spreads instantly. The blast reaches Alice if the line segment joining Alice and the bomb passes through the interior of no building. A segment that only touches the boundary of a building does not stop the blast. Alice is safe exactly when the segment joining her and the bomb passes through the interior of some building.

The picture below is an example of an explosion. The left picture shows the bomb and the buildings (the polygons filled with black). In the right picture, the gray area is the part of the plane the blast reaches.

Alice cannot enter the interior of a building, but she may stand on a boundary and run along it. Starting at (0,0)(0, 0), she runs to a safe point along a path that never passes through the interior of a building. Find the minimum distance she has to run.

Safe points may lie arbitrarily close to a point QQ that is itself not safe. In that case the distance to QQ is the answer, so the answer is the greatest lower bound of the distance Alice has to run in order to be safe.

Input

The input holds several test cases. Each test case has this format.

N
bx by
m_1 x_{1,1} y_{1,1} ... x_{1,m_1} y_{1,m_1}
...
m_N x_{N,1} y_{N,1} ... x_{N,m_N} y_{N,m_N}

The first line holds the number of buildings NN (1N1001 \le N \le 100). The second line holds the position of the bomb, bxb_x and byb_y (10000bx,by10000-10000 \le b_x, b_y \le 10000). Each of the next NN lines describes one building. A line starts with the number of vertices mim_i (3mi1003 \le m_i \le 100, i=1Nmi500\sum_{i=1}^{N} m_i \le 500) and continues with mim_i pairs of coordinates xi,jx_{i,j}, yi,jy_{i,j}. Every coordinate is an integer with absolute value at most 1000010000.

The following conditions hold.

  • No polygon intersects itself.
  • No two polygons share a point.
  • The vertices of each polygon are given in counter-clockwise order.
  • Neither Alice nor the bomb is inside a polygon.
  • The bomb does not lie on the line through any edge of any polygon.

Alice starts at (0,0)(0, 0). She may be on the boundary of a polygon.

A line with N=0N = 0 marks the end of the input. Do not process it as a test case.

Output

For each test case, print the minimum distance Alice has to run on one line. Round the value to six digits after the decimal point and print exactly six digits.