Mickle's Beam

Time Limit : 8 sec, Memory Limit : 65536 KB

Problem E: Mickle's Beam

Major Mickle is commanded to protect a secret base which is being attacked by N tanks. Mickle has an ultimate laser rifle called Mickle's beam. Any object shot by this beam will be immediately destroyed, and there is no way for protection. Furthermore, the beam keeps going through even after destroying objects. The beam is such a powerful and horrible weapon, but there is one drawback: the beam consumes a huge amount of energy. For this reason, the number of shots should be always minimized.

Your job is to write a program that calculates the minimum number of shots required to destroy all the enemy tanks.

You can assume the following:

  • the base is located on the origin (0, 0);
  • each tank has a rectangular shape with edges parallel to the x- and y-axes;
  • no tank may touch or include the origin;
  • no two tanks share the same point;
  • the width of beam is negligible; and
  • a beam destroys every tank it touches or crosses.


The input consists of an integer sequence.

The first integer indicates N (N ≤ 2,000). Each of the following N lines contains four integers which indicates the x- and y-coordinates of the lower-left corner and the upper-right corner of a tank respectively. You can assume that every coordinate may not exceed 10,000 in absolute value.


Output the minimum number of shots of the beam.

Sample Input and Output

Input #1

2 -1 3 1
-1 2 1 3
-3 -1 -2 1
-1 -3 1 -2

Output #1


Input #2

1 0 2 1
3 -1 4 0

Output #2


Source: ACM-ICPC Japan Alumni Group Winter Camp , Day 3, Tokyo, Japan, 2009-02-23