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 MBFlowey: 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 N friendliness pellets. Every pellet moves along a straight line at speed 1. Your soul is at the origin (0,0) at time 0 and moves in any direction at a speed of at most 1. The speed can be any value, such as 1 or 0.314, and the soul may also stay where it is. The soul cannot leave the rectangle given by −XM≤x≤XM and −YM≤y≤YM.
A pellet vanishes the moment it touches your soul, and that pellet counts as collected, so you collect at most N 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.
The first line contains the number of friendliness pellets N and two integers XM, YM that describe the region the soul can move in (1≤N≤18, 1≤XM,YM≤500).
Each of the next N lines contains four integers Xst, Yst, Xto, Yto describing one pellet (−1000≤Xst,Yst,Xto,Yto≤1000). The pellet is at (Xst,Yst) at time 0 and moves along a straight line toward (Xto,Yto), and it keeps moving in the same direction after it passes (Xto,Yto). (Xst,Yst) and (Xto,Yto) are different points, and (Xst,Yst) is never the origin.
Print the largest number of friendliness pellets you can collect.