Learning by Example
InterviewTime limit1sMemory limit256 MB
Count how many integer weights from A to B the nearest-neighbor classifier labels as spotted from N labeled training weights.
Problem
Farmer John wants a classifier that guesses from his herd records alone whether a cow has spots. His records are thin: for each of his cows he knows only the weight and whether that cow has spots. All weights are distinct.
The classifier uses nearest neighbours. To guess whether a new cow has spots, John finds the cow in his herd whose weight is closest to the weight of . If has spots, he guesses that has spots; if has no spots, he guesses that has none. If the closest weight is not achieved by a single cow but two cows tie, he guesses that has spots when at least one of those two has spots.
John now tests the classifier on a group of cows that has just arrived at his farm. After weighing them he sees exactly one cow of every integer weight between and inclusive. Determine how many of these cows the classifier labels as spotted. The classifier uses only the records of the existing cows, never the data of the new ones. and can both be large, so a loop that walks from to one weight at a time will not finish inside the time limit.
Input
The first line contains three integers , , and (, ).
Each of the next lines describes one cow. A spotted cow of weight is written as S W, and a cow with no spots as NS W. All weights are distinct integers with .
Output
Print on one line the number of new cows that the classifier labels as spotted.