spoj#JUICE. Juice Extractor
Juice Extractor
Jerry loses himself in the interesting game: Fruit Ninja. Fruit Ninja is a game of iPhone and iPad in which the players cut the fruits coming from the bottom of the screen and gain the bonus from cutting more than two fruits with a single slice. Once a fruit is cut, it breaks into small pieces and cannot be cut any more.
After months of training, he becomes pro of this game. Actually, he can cut all the fruits on the screen at any time. Jerry also has a bad habit that he has no willing to leave some fruits for the future cutting. In the other words, after Jerry cuts the fruits, all the fruits on the screen breaks and no one left. That is why all his friends call him Juice Extractor.
Now he only consider about the bonus, when he cuts more than two fruits, he can gain some bonus scores as same as the number of fruits he slice at that time. For example, if Jerry cuts 4 fruits with a single slice, he can get 4 scores from this slice.
After Jerry gets the fruit schedule, he knows the appearing time and the disappearing time for every single fruit. He can only cut a fruit into pieces between its appearing time and disappearing time inclusive. He wants to know the maximum possible bonus scores he can receive.
Input
There are several test cases; the first line of the input contains a single integer T, denoting the number of the test cases. (T <= 200)
For each test case, the first line contains an integer N, denoting the total number of fruits. (1 <= N <= 1000)
The next N lines, each line describe a fruit. For each line, there are two integers Xi and Yi, where Xi is the appearing time of the fruit and Yi is the disappearing time of this fruit. (0 <= Xi <= Yi <= 1000000000)
Output
For each test case, output a single integer denoting the maximum scores that Jerry could possibly gain. See the sample for further details.
Example
Input: 1 10 1 10 2 11 3 12 4 13 13 14 14 15 13 19 20 22 21 23 22 24</p>Output: Case #1: 10