Rectangles Too!

No attempts yetTime limit3sMemory limit128 MB

Problem

A rectangle in the Cartesian plane is given by two corner points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2), its lower-left and upper-right corners, with x1x2x_1 \le x_2 and y1y2y_1 \le y_2.

For two rectangles A=((x1A,y1A),(x2A,y2A))A = ((x_1^A, y_1^A), (x_2^A, y_2^A)) and B=((x1B,y1B),(x2B,y2B))B = ((x_1^B, y_1^B), (x_2^B, y_2^B)), we say that AA precedes BB, written ABA \preceq B, when

x2A<x1Bandy2A<y1B.x_2^A < x_1^B \quad\text{and}\quad y_2^A < y_1^B.

You are given a collection of rectangles in the plane. Find the length LL of the longest sequence of rectangles (A1,A2,,AL)(A_1, A_2, \ldots, A_L) from the collection such that

A1A2AL.A_1 \preceq A_2 \preceq \cdots \preceq A_L.

Input

The input contains several test cases. Each test case starts with a line containing one integer nn (1n1000001 \le n \le 100000), the number of rectangles. Each of the next nn lines contains four integers x1 y1 x2 y2x_1\ y_1\ x_2\ y_2 (1000000x1x21000000-1000000 \le x_1 \le x_2 \le 1000000 and 1000000y1y21000000-1000000 \le y_1 \le y_2 \le 1000000), the lower-left and upper-right corners of one rectangle. The input ends with a line containing a single 00.

Output

For each test case, print one line with a single integer: the length of the longest chain of rectangles.