Problem: 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.



Input

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

Output the minimum number of shots of the beam.

Example

Input




Output

Solution (in CPP):

Solution:
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
using namespace std;
#define input freopen("/Users/peteryuanpan/data.txt","r",stdin)

const double eps = 1e-8, pi = acos(-1.0);
int sgn(double x){
    if(abs(x) < eps) return 0;
    else return x > 0 ? 1 : -1;
}

#define N 10010
int n;
struct Maze{
    int x1, y1;
    int x2, y2;
}ma[N];

struct Seg{
    double l, r;
    bool operator<(const Seg a)const{
        if(sgn(r-a.r)==0)return l<a.r;
		return r<a.r;
	}
};
set<Seg>s;

double getangle(int x1, int y1){
    double a = atan2(y1, x1);
    if(sgn(a) < 0) a += 2 * pi;
    return a;
}

int solve(){
    set<Seg>::iterator it1,it2;
    int ans=0;
    for(it1=s.begin(), it2 = s.begin(); it1!=s.end();)
    {
        ans++;
        for(; it2!=s.end() && sgn(it2->l - it1->r) <= 0; it2++);
        it1=it2;
    }
    return ans;
}

int main(){
    //input;
    scanf("%d",&n);
        for(int i = 1; i <= n; i++){
            scanf("%d%d%d%d",&ma[i].x1, &ma[i].y1, &ma[i].x2, &ma[i].y2);
        }
        for(int i = 1; i <= n; i++){
            double rad[10];
            rad[1] = getangle(ma[i].x1, ma[i].y1);
            rad[2] = getangle(ma[i].x1, ma[i].y2);
            rad[3] = getangle(ma[i].x2, ma[i].y1);
            rad[4] = getangle(ma[i].x2, ma[i].y2);
            double d = 0.0;
            int w1 = 1, w2 = 2;
            for(int i1 = 1; i1 <= 4; i1++){
                for(int i2 = i1 + 1; i2 <= 4; i2++){
                    double d1 = abs(rad[i1] - rad[i2]);
                    d1 = min(d1, 2 * pi - d1);
                    if(sgn(d1 - d) > 0){
                        d = d1;
                        w1 = i1, w2 = i2;
                    }
                }
            }
            double a1 = rad[w1], a2 = rad[w2];
            if(sgn(a1 - a2) > 0) swap(a1, a2);
            if(sgn((a2 - a1) - d) != 0) swap(a1, a2);
            if(sgn(a1 - a2) > 0) a2 += 2 * pi;
//            seg[i].l = a1, seg[i].r = a2;
            s.insert((Seg){a1,a2});
        }
        int ans = n;
        for(int i = 1; i <= n; i++){
            ans=min(ans,solve());
            Seg cmp=*s.begin();
            s.erase(s.begin());
            cmp.l+=2*pi;
            cmp.r+=2*pi;
            s.insert(cmp);
        }
        printf("%d\n", ans);

    return 0;
}
/*
2
10000 9999 10001 10000
10000 10002 10001 10003

2
10000 9999 10001 10000
9999 10001 10000 10002
*/