Under construction

Still being built. Things may change

Milk Measurement

Interview

Time limit2sMemory limit512 MB

Summary
Three cows start at 7 gallons; apply N dated changes in chronological order and count the days on which the set of cows holding the top output changes.
Level

Medium4 of 10

Topics
Simulation, Sorting, Implementation, Array
Solved
No attempts yet

Problem

Farmer John buys three cows: Bessie, Elsie, and Mildred. Each of them starts out producing 7 gallons of milk per day. A cow's output can change over time, so over the next 100 days Farmer John measures the cows now and then and writes the results in a log book. An entry looks like this:

35 Bessie -2
14 Mildred +3

The first line says that on day 35 Bessie's output was 2 gallons lower than the last time she was measured. The second line says that on day 14 Mildred's output was 3 gallons higher than the last time she was measured. Farmer John has time for at most one measurement on any given day. He is also disorganized, so he does not write the measurements down in chronological order.

To keep the cows motivated, Farmer John hangs the picture of whichever cow currently has the highest output on the barn wall. If several cows are tied for the highest output, he hangs all of their pictures. Count the days on which Farmer John has to change the pictures on the wall.

Input

The first line contains NN, the number of measurements Farmer John makes. Each of the next NN lines holds one measurement: a day, the name of a cow, and the change in her output since she was last measured. The day is an integer between 1 and 100, and the change is a nonzero integer. The name is one of Bessie, Elsie, and Mildred.

No day carries two measurements, so 1≤N≤1001 \le N \le 100. Every cow's output stays between 0 and 1000 at all times.

Output

Print the number of days on which Farmer John has to change the pictures on the wall. The answer is an integer between 0 and 100.

Hint

Take the first example. All three cows start at 7. On day 1 Bessie rises to 9 and leads alone, so Farmer John changes the pictures. On day 4 Elsie drops to 6, which leaves Bessie alone in the lead. On day 7 Mildred takes the lead and the pictures change, and on day 9 Mildred drops back to a tie with Bessie, changing them once more.

Examples5

  1. Example 1

    Input
    4
    7 Mildred +3
    4 Elsie -1
    9 Mildred -1
    1 Bessie +2
    
    Expected output
    3
    
  2. Example 2

    Input
    1
    50 Bessie -7
    
    Expected output
    1
    
  3. Example 3

    Input
    3
    1 Bessie +2
    2 Bessie +1
    3 Bessie +5
    
    Expected output
    1
    
  4. Example 4

    Input
    2
    3 Bessie -2
    1 Bessie +2
    
    Expected output
    2
    
  5. Example 5

    Input
    6
    1 Bessie +3
    2 Elsie +3
    3 Mildred +3
    4 Bessie -3
    5 Elsie -3
    6 Mildred -3
    
    Expected output
    6