The Minimun Number of Rooks

A sawtoothed chess-board is a chess-board whose boundary forms two staircases from left down to right. See the figure on the right for an example. A square is dominated by a rook if it is in the same row or column with this rook. Your task is to determine the minimun number of rooks such that every square in a sawtoothed chess- board is dominated by at least one rook. For example, see the above figure again. It needs only four rooks located at the squares with a dot to dominate all the squares. Input The input data will contain multiple test cases. Each test case will consist of less than 100 pairs of integers which represent the row and column indexes of the corner points, in clockwise order, in a sawtoothed chess-board starting from the upper-left most corner. For example, the corner points in the above figure are v1, v2, . . . , v12, respectively. Each corner point is represented by its x and y coordinates in the 2-dimensional xy-plane whose values are in the range from 1 to 100. For example, the indexes of v1,v2 and v3 are (1,1), (1,4) and (3,4), respectively. The input for each test case will be terminated with a pair of zeros, wich are not to be treated as the indexes of a corner point. An additional pair of zeros will follow the last test case. Output For each test case, determine the minimun number of rooks needed to dominate all of the squares in the sawtoothed chess-board described in the test case. Display, one test case a line, the test case number (they are numbered sequentially starting with 1) and the number of rooks which are separated by one blank. Sample Input 1114343646 4787866663 4341001113 3336565232 310000 Sample Output 14 23