Flowey's Love

A soul starting at the origin moves at speed at most 1 inside a rectangle; N moving points travel along fixed lines, and you must find the maximum number of points the soul can touch.

Hard9GeometryDynamic programmingBit manipulationMathNo attempts yetTime limit1sMemory limit512 MB

Problem

Flowey: Howdy! I'm Flowey, Flowey the flower! You're new to the underground, aren't you? Golly, you must be so confused. Someone ought to teach you how things work around here! I guess little old me will have to do. Ready? Here we go!

Flowey: See that heart? That is your SOUL, the very culmination of your being! Your SOUL is weak, but it can grow strong if you gain a lot of LV. What does LV stand for? Why, LOVE, of course! You want some LOVE, don't you?

Flowey: Don't worry, I'll share some with you! Down here, we share little white friendliness pellets. Move around! Get as much friendliness as you can!

Flowey scattered NN friendliness pellets. Every pellet moves along a straight line at speed 11. Your soul is at the origin (0,0)(0, 0) at time 00 and moves in any direction at a speed of at most 11. The speed can be any value, such as 11 or 0.3140.314, and the soul may also stay where it is. The soul cannot leave the rectangle given by XMxXM-XM \le x \le XM and YMyYM-YM \le y \le YM.

A pellet vanishes the moment it touches your soul, and that pellet counts as collected, so you collect at most NN of them. The soul and the pellets are points. Given the pellets, write a program that finds the largest number of friendliness pellets you can collect.

Input

The first line contains the number of friendliness pellets NN and two integers XMXM, YMYM that describe the region the soul can move in (1N181 \le N \le 18, 1XM,YM5001 \le XM, YM \le 500).

Each of the next NN lines contains four integers XstX_{st}, YstY_{st}, XtoX_{to}, YtoY_{to} describing one pellet (1000Xst,Yst,Xto,Yto1000-1000 \le X_{st}, Y_{st}, X_{to}, Y_{to} \le 1000). The pellet is at (Xst,Yst)(X_{st}, Y_{st}) at time 00 and moves along a straight line toward (Xto,Yto)(X_{to}, Y_{to}), and it keeps moving in the same direction after it passes (Xto,Yto)(X_{to}, Y_{to}). (Xst,Yst)(X_{st}, Y_{st}) and (Xto,Yto)(X_{to}, Y_{to}) are different points, and (Xst,Yst)(X_{st}, Y_{st}) is never the origin.

Output

Print the largest number of friendliness pellets you can collect.