Under construction

Still being built. Things may change

Learning by Example

Interview

Time limit1sMemory limit256 MB

Summary
Count how many integer weights from A to B the nearest-neighbor classifier labels as spotted from N labeled training weights.
Level

Medium5 of 10

Topics
Sorting, Intervals
Solved
No attempts yet

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 NN 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 CC has spots, John finds the cow C′C' in his herd whose weight is closest to the weight of CC. If C′C' has spots, he guesses that CC has spots; if C′C' has no spots, he guesses that CC has none. If the closest weight is not achieved by a single cow but two cows tie, he guesses that CC 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 AA and BB inclusive. Determine how many of these cows the classifier labels as spotted. The classifier uses only the records of the NN existing cows, never the data of the new ones. AA and BB can both be large, so a loop that walks from AA to BB one weight at a time will not finish inside the time limit.

Input

The first line contains three integers NN, AA, and BB (1≤N≤500001 \le N \le 50000, 1≤A≤B≤1091 \le A \le B \le 10^9).

Each of the next NN lines describes one cow. A spotted cow of weight WW is written as S W, and a cow with no spots as NS W. All weights are distinct integers with 1≤W≤1091 \le W \le 10^9.

Output

Print on one line the number of new cows that the classifier labels as spotted.

Examples1

  1. Example 1

    Input
    3 1 10
    S 10
    NS 4
    S 1
    
    Expected output
    6