A rectangle in the Cartesian plane is specied by a pair of coordinates (x1 , y1) and (x2 , y2) indicating its lower-left and upper-right corners, respectively (where x1 ≤ x2 and y1 ≤ y2). Given a pair of rectangles,A = ((x
A1 , y
A1 ), (x
A2 ,y
A2 )) and B = ((x
B1 , y
B1 ), (x
B2 , y
B2 )), we write A ≤ B (i.e., A "precedes" B), if x
A2 < x
B1 and y
A2 < y
B1 :In this problem, you are given a collection of rectangles located in the two-dimension Euclidean plane. Find the length L of the longest sequence of rectangles (A
1,A
2,…,A
L) from this collection such that A
1 ≤ A
2 ≤ … ≤ A
L.
The input file will contain multiple test cases. Each test case will begin with a line containing a single integer n (where 1 ≤ n ≤ 100000), indicating the number of input rectangles. The next n lines each contain four integers x
i1 ,y
i1 ,x
i2 ,y
i2 (where -1000000 ≤ x
i1 ≤ x
i2 ≤ 1000000, -1000000 ≤ y
i1 ≤ y
i2 ≤ 1000000, and 1 ≤ i ≤ n), indicating the lower left and upper right corners of a rectangle. The end-of-file is denoted by asingle line containing the integer 0.
For each input test case, print a single integer indicating the length of the longest chain.