Олимпиадный тренинг

Задача 39389. Social Distancing II


Farmer John continues to fight for the health of his cows.
There are N cows (1≤N≤1000) cows, some of which are sick. The cows are lined up (on the number line), cow i is at position xi. The FD knows that if another cow is within radius R of the sick cow, then she also gets sick. And then the cows that are within R radius of this one, etc. get sick.

Unfortunately, the FD does not know the exact value of R. However, he does know which of his cows are sick. Based on these data, determine the minimum number of cows initially infected with the disease.

Input
The first line of input contains N. Each of the next N lines describes one cow with two numbers x and s, where x is the position of the cow and s is 0 for a healthy cow and 1 for a sick one. At least 1 cow is sick. And all the cows that could become sick from the spread of the disease are already sick.
Imprint
Determine the minimum number of cows that were initially sick before any spread of the disease.
Examples
# Input Output
1 6
7 1
1 1
15 1
3 1
10 0
6 1
3