Both Sides


Natasha has arrived at the basketball match just in time to discover that she does not know which team her friends are supporting. Too embarrassed to ask, she decides to cheer whenever either team takes the lead. Surely nobody will notice if she sounds enthusiastic enough.

There are two teams, numbered 11 and 22, and both start with zero points. During the match, there are NN scoring events. In event ii, team TiT_i earns PiP_i points, which are added to its score. The events occur in the order given.

Natasha cheers once after a scoring event if the team that scored was tied with or behind the other team immediately before the event, and is strictly ahead immediately afterwards. She does not cheer when a team merely extends its lead or brings the scores level.

How many times does Natasha cheer during the match?

Input

The first line contains an integer NN (1≤N≤10001 \le N \le 1000), the number of scoring events.

Each of the next NN lines contains two integers TiT_i and PiP_i (Ti∈{1,2}T_i \in \{1, 2\}, Pi∈{1,2,3}P_i \in \{1, 2, 3\}), the team that scores and the number of points it earns in event ii. The events are listed in chronological order.

Output

Print a single integer: the number of times Natasha cheers.

Example 1

Input 1
8
1 2
1 1
2 3
2 1
1 2
2 1
1 1
2 3
Output 1
5
Explanation

Natasha cheers after events 11, 44, 55, 77, and 88. Event 22 only extends a lead, while events 33 and 66 bring the scores level.

Example 2

Input 2
1
2 3
Output 2
1
Explanation

Both teams start tied at zero. Team 22 takes the lead with the only scoring event.

Example 3

Input 3
4
1 1
2 1
1 1
2 1
Output 3
2
Explanation

Natasha cheers after events 11 and 33. Team 11 takes the lead twice, even though team 22 never leads. The match ends in a tie.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.