Equipment Overhead
The AUCPL ward delivers cutting-edge medical care, which means it owns a lot of cutting-edge equipment. Every time a new machine arrives, an old one gets wheeled off to the warehouse.
To save floor space, Manager Patrick wants the retired machines stacked on top of each other. There are machines, numbered
to
, and they must be added in that order: machine
on the ground, machine
on machine
, and so on. If machine
cannot be placed, the stack ends there, and machines
are all left out.
Each machine is modelled as a polygon. Define the slope of a line segment as the absolute value of the tangent of the angle it makes with the horizontal, so a horizontal segment has slope and a segment at
degrees has slope
. At any given moment,the stack has one exposed side. Before any machine is placed, the exposed side is the ground, which has slope
.
To place machine , you may first flip and rotate it however you like, then choose one of its sides and glue that side to the exposed side. The two sides do not need to be the same length. Machine
then becomes the topmost machine, and the new exposed side is determined for you: among the sides of machine
(other than the one you just glued down) it is the side with shallowest slope. If several sides tie for shallowest, you may treat either as the exposed side.
These machines are heavy and expensive, so the stack has to be stable. A machine can only be glued to an exposed side whose slope is at most . If the exposed side is any steeper than this, no further machines can be placed.
The machines are idealised, so you never have to check whether the stack intersects itself.
What is the maximum number of machines you can stack?
Input
The first line contains a single integer (
), the number of machines.
The second line contains two integers and
(
,
), giving the maximum slope
that a machine may be stacked onto.
The next blocks describe the machines, in the order they must be stacked. Each block consists of:
- A line containing a single integer
(
), the number of vertices of that machine. This may differ between machines.
lines, the
-th containing two integers
and
(
), the
-th vertex of the machine. The vertices are given in clockwise order and form a simple polygon.
Output
Output the maximum number of machines that you can stack while adhering to the above rules.
Example
Input 1
5
2 3
4
0 0
2 0
2 1
1 2
4
0 0
0 2
2 2
2 0
3
0 0
2 0
2 2
3
0 0
4 7
7 0
4
0 0
0 2
2 2
2 0
Output 1
4
There are shapes (not to scale):

You can stack the first before the exposed edge must have a slope greater than
. It is impossible to stack all
shapes in order without this occurring.
One way to stack them is this (to scale):

- The first exposed side (ground) has a slope of
.
- The second exposed side has a slope of
.
- The third exposed side has a slope of
.
- The fourth exposed side has a slope of
.
- The fifth exposed side has a slope
.
Input 2
3
1 2
4
0 4
4 2
4 0
0 0
3
0 0
0 2
2 0
3
0 0
0 2
2 0
Output 2
3
Input 3
3
0 1
4
0 0
0 2
2 2
2 0
4
0 0
0 2
2 2
2 0
4
0 0
0 2
2 2
2 0
Output 3
3
Comments