Time limit
2s
Memory limit
128 MB
A rectangular soccer field has width N and height M. A player starts a goal-celebration slide from coordinate (x, y).
Some parts of the field have bad grass. Each bad-grass area is given as a polygon. The sliding path must be one straight line segment from the starting point to a point on the boundary of the field. The segment must not pass through the interior of any bad-grass area, but it may touch an area's boundary or vertices.
Find the endpoint of a valid sliding path with maximum possible length.
The first line contains the field width and height, N and M. (1 <= N, M <= 10000)
The second line contains the starting coordinate of the slide.
The third line contains the number of bad-grass areas, G. (1 <= G <= 100)
Each of the next G lines describes one area. The number of vertices is given first, followed by the coordinates of those vertices in clockwise order. Each area has at most 20 vertices.
The starting point is not inside any bad-grass area. Bad-grass areas do not overlap each other.
Print the coordinate where the slide ends. An absolute or relative error of at most 10^-3 is accepted.
If several endpoints give the same maximum distance, print the one with the smallest x coordinate. If there is still a tie, print the one with the smallest y coordinate.
If no valid sliding path exists, print GG.