Camera Control

Members move along timed polygonal routes around a fixed camera, and you may switch followers only when two members lie on the same ray; maximize total time filming a singing member.

Hard8GeometryDynamic programmingIntervalsNo attempts yetTime limit8sMemory limit512 MB

Problem

ACM48 is one of the most popular dance vocal units in Japan. This winter ACM48 is planning a world concert tour, and you have joined the tour as a camera engineer.

Your job is to write the software that controls a camera on the stage. Treat the stage as a two dimensional plane. The software can rotate the camera to any direction, but it cannot change the position of the camera.

During a performance each member of ACM48 moves along her own route and sings the parts assigned to her. A route is given as a polygonal line. A member leaves the first point at time 0 and moves along each segment at a constant speed, reaching the jj-th point at time tjt_j. After she reaches the last point she stays there.

The camera has to stay on one member for the whole performance. You may change the member the camera follows at time tt if and only if the current member and the next member are in the same direction from the camera at that moment, that is, both of them are on the same ray whose endpoint is the camera.

Compute the maximum total time during which the camera is on a member who is singing.

You may assume the following.

  • You can focus the camera on an arbitrary member at time 0.
  • No route of a member passes through the camera.
  • Each member stays at her last point after she reaches it.

Input

The input contains several datasets. Each dataset has the following format.

N
cx cy
The information of the 1-st member
...
The information of the N-th member

NN (1N501 \le N \le 50) is the number of members, and (cx,cy)(cx, cy) is the position of the camera. The information of the NN members follows. The information of the ii-th member has the following format.

Mi
xi,1 yi,1 ti,1
...
xi,Mi yi,Mi ti,Mi
Li
bi,1 ei,1
...
bi,Li ei,Li

MiM_i (1Mi1001 \le M_i \le 100) is the number of points on the route of the ii-th member, and (xi,j,yi,j)(x_{i,j}, y_{i,j}) is the jj-th point of that route. ti,jt_{i,j} is the time at which the ii-th member reaches the jj-th point, where ti,1=0t_{i,1} = 0 and ti,j<ti,j+1103t_{i,j} < t_{i,j+1} \le 10^3. LiL_i (0Li1000 \le L_i \le 100) is the number of vocal parts of the ii-th member, and bi,kb_{i,k} and ei,ke_{i,k} (0bi,k<ei,k<bi,k+1<ei,k+11030 \le b_{i,k} < e_{i,k} < b_{i,k+1} < e_{i,k+1} \le 10^3) are the beginning time and the ending time of her kk-th vocal part.

All the input values are integers, and the absolute value of every coordinate is at most 10310^3. A line holding N=0N = 0 ends the input. Do not process it as a dataset.

Output

For each dataset print on one line the maximum time that the camera can be focused on singing members. Print the value rounded to exactly six digits after the decimal point.