Spy Satellites
Time limit1sMemory limit128 MB
Given a terrain polyline with some marked points, place satellites on the line y=H so their visibility segments cover all marked points, minimizing the count.
Problem
Byteland (Bajtlandia) is going through yet another crisis, and the army has seized power. To end the civil war, the commanders only need to find and eliminate the last holdouts who rejected the new order. That, however, is not so easy. From the (more or less voluntary) reports of informants, a list of possible locations for the rebel base has been compiled. Long searches of those spots turned up nothing, so the plan is now to wait until the rebels reveal themselves. To avoid tipping them off, the surveillance is run by a network of spy satellites.
Byteland can be pictured as a two-dimensional landscape formed by joining points with distinct coordinates into a polyline.

A spy satellite can be placed only on the line . Such a satellite observes exactly those points that can be joined to it by a straight segment that does not cross the curve of the landscape (merely touching the curve does not count as crossing). Compute the minimum number of satellites needed to observe every suspected rebel-base location at the same time.
Input
The first line contains two integers and (, ) separated by a single space.
Each of the next lines describes one point of the landscape and contains three integers , , (, , ) separated by single spaces. The pair is the point's location; means the rebels may be based there, and means they are not.
You may assume that and , and that the points are given in strictly increasing order of the coordinate.
Output
Print a single integer: the minimum number of satellites needed.
Hint
For the landscape shown in the figure, two satellites placed at and are enough.