Bessie the cow loves nothing more than causing mischief on the farm. To keep her out of trouble, Farmer John ties Bessie to a fence with a long rope.
Viewed from above, the fence is a set of $N$ posts ($1 \le N \le 10$) arranged along a single vertical line, and Bessie stands at position $(bx, by)$, which lies to the right of that line. The rope is given as a sequence of $M$ line segments ($3 \le M \le 10000$): the first segment starts at Bessie's position and the last segment ends at Bessie's position, so the rope forms one closed loop. No fence post lies on any segment, but segments may cross one another and may meet at shared endpoints.
To help Bessie escape, the other cows have grabbed a saw from the barn. Find the minimum number of fence posts they must cut down and remove so that Bessie can pull free — meaning she can run away to the right without the rope snagging on any remaining post.
Every fence post shares the same $x$-coordinate, and $bx$ is strictly greater than that value. All coordinates (the posts, Bessie, and every segment endpoint) are integers in the range $0 \le x, y \le 10000$.
A single post can trap Bessie only if the rope actually loops around it. But several posts can trap her together even when the rope loops around none of them individually, because the rope can weave back and forth between the posts and stay caught. So the answer is not simply the number of posts the rope encircles; you must find the smallest set of posts whose removal lets the whole rope loop pull free to the right.