Grand Theft Auto Wheel
Time limit3sMemory limit256 MB
Given star-shaped polar polygons for a bolt hole and several wrench lugs, determine which wrenches can be inserted but cannot fully rotate inside the bolt hole.
- Level
Hard9 of 10
- Topics
- Geometry, Simulation, Math
- Solved
- No attempts yet
Problem
Tommy is a wheel thief. His job used to be simple: lift a car, unscrew the wheel bolts, take the wheel, and run. But nowadays everyone uses "anti-theft" bolts.
An anti-theft bolt is designed so that it cannot be loosened with an ordinary wrench. Its head is a cylinder with a hole, and to loosen it you need a dedicated wrench: a ring with a lug shaped to fit exactly into the hole of the bolt head.

Tommy cannot carry a wrench for every possible anti-theft bolt. Fortunately, a bolt can sometimes be loosened with a wrench that does not match it exactly.
Formally, a wrench can loosen a bolt if and only if both of the following hold:
- the ring of the wrench can be placed onto the bolt head so that the lug of the wrench lies inside the hole of the bolt head;
- while the bolt is held fixed, the wrench cannot make a full turn.

Both shapes -- the hole of the bolt head and the lug of the wrench -- are star-shaped polygons whose center coincides with the center of the bolt (or of the wrench). Written in polar coordinates as a sequence of pairs , they satisfy and , so the center always lies strictly inside.

Determine which of Tommy's wrenches can loosen the bolt.
Input
The first line contains two integers and -- the number of wrenches and the radius of the bolt head and of the wrenches' rings (, ).
Next comes the description of the bolt head: an integer -- the number of vertices () -- followed by integer pairs (; ; ; ; ).
The remaining lines describe the wrenches in the same format.
Output
On the first line, print the number of wrenches that can loosen the bolt. On the second line, print their indices (starting from 1) in increasing order, separated by single spaces. If no wrench works, print only the first line (the number 0).