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

Задача 39538. Tournament of Knights and Liars


Задача

Темы:
Arriving on the planet of Knights and Liars, Gromozeka played in a chess tournament. In total, N chess players participated in the tournament. On the way home, he met various participants in this tournament.  He asked each chess player what place he took in the tournament. But all the participants in this tournament do not say a specific place, but only say a statement like: "There are ai participants above me in the final table, and bi participants below me." After listening to everyone, Gromozeka concluded what was the maximum number of Knights he could meet. Knights always tell the truth, liars always lie. Try to determine the  maximum number of Knights Gromozek could meet.

Input
The first line contains an integer N (1 <= N <= 10000). Then N lines follow, containing integers ai and bi, modulo not exceeding 10000, describing the statement of the i-th participant.

The utterance data is given in random order, i.e. the first utterance does not necessarily correspond to the first-place finisher, the second does not necessarily correspond to the runner-up, and so on.

Imprint
Print an integer – the maximum number of participants that could be Knights.
 
Examples
# Input Output
1 3
20
0 2
2 2
2