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

Задача 38364. Turtles


The following problem for younger students is widely known. Three turtles crawl along the road. One turtle says, "There are two turtles ahead of me." The other turtle says, "There are two turtles behind me." The third turtle says, "There are two turtles in front of me and two turtles behind me." How can this be? Answer: the third turtle is lying!

N turtles move one after another along the road. Each turtle says a phrase like: “In front of me are ai turtles, and behind me are bi turtles”. Your task is to determine the largest number of turtles that can tell the truth.

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 turtle.

The data on turtle statements are given in random order, that is, the first statement does not necessarily correspond to the turtle walking at the head of the column, the second - not necessarily following it, and so on

Imprint
Print an integer M – the maximum number of turtles that can tell the truth.
 
Examples
# Input Output
1 3
20
0 2
2 2
2