Equipment Overhead


Submit solution

Points: 1
Time limit: 1.5s
Memory limit: 256M

Author:
Problem type
Allowed languages
C, C++, Java, Python, Rust

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 n machines, numbered 1 to n, and they must be added in that order: machine 1 on the ground, machine 2 on machine 1, and so on. If machine i cannot be placed, the stack ends there, and machines i, i+1, \dots, n 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 0 and a segment at 45 degrees has slope 1. At any given moment,the stack has one exposed side. Before any machine is placed, the exposed side is the ground, which has slope 0.

To place machine i, 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 i then becomes the topmost machine, and the new exposed side is determined for you: among the sides of machine i (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 \theta. 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 n (1 \leq n \leq 7), the number of machines.

The second line contains two integers p_L and q_L (0 \leq p_L \leq q_L \leq 10^9, q_L \geq 1), giving the maximum slope \theta = \frac{p_L}{q_L} that a machine may be stacked onto.

The next n blocks describe the machines, in the order they must be stacked. Each block consists of:

  • A line containing a single integer k (3 \leq k \leq 7), the number of vertices of that machine. This may differ between machines.
  • k lines, the i-th containing two integers x_i and y_i (0 \leq x_i, y_i \leq 7), the i-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 5 shapes (not to scale):

You can stack the first 4 before the exposed edge must have a slope greater than \frac{2}{3}. It is impossible to stack all 5 shapes in order without this occurring.

One way to stack them is this (to scale):

  • The first exposed side (ground) has a slope of 0.
  • The second exposed side has a slope of \frac{1}{2}.
  • The third exposed side has a slope of \frac{1}{2}.
  • The fourth exposed side has a slope of \frac{1}{3}.
  • The fifth exposed side has a slope >\frac{2}{3}.
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

There are no comments at the moment.