#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define mp make_pair
#define f first
#define s second
ll n;
map<ll,ll>mpa, mpb;
ll mod = 1000000007;
ll N = 2000005;
vector<ll> p2(N);
void calc()
{
	p2[0]=1;
	for(int i =1; i<N; i++)p2[i] = (2*p2[i-1])%mod;
}

map<ll,ll> fun2(vector<pair<ll,pair<ll,ll> > >  a)
{
	sort(a.begin(), a.end());

    vector<ll> hsh(N,0);
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}

	map<ll,ll> m1;
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;

        ll smeq = lower_bound(a.begin(), a.end(), mp(r+(ll)1,mp((ll)-1,(ll)-1))) - a.begin();
        if(smeq == n)continue;
        smeq = hsh[smeq] ;

        m1[a[i].s.s] = (smeq)%mod ;
    }
    return m1;
}

map<ll,ll> fun1(vector<pair<ll,pair<ll,ll> > >  a)
{
	map<ll,ll> mp1 = fun2(a), mp2;

    for(int i=0; i<n; i++)
    {
        swap(a[i].f, a[i].s.f);
        a[i].f =  1e9-a[i].f;
        a[i].s.f =  1e9-a[i].s.f;
    }

    mp2 = fun2(a);
    map<ll,ll> resultant;
    for(int i=0; i<=100005; i++)
    {
    	resultant[i] = (mp1[i]+mp2[i])%mod;
	}
	return resultant;
}

int main(){
	calc();

    cin >> n;
    vector<pair<ll,pair<ll,ll> > > a(n), b(n);

    for(int i=0; i<n; i++)
    {
        cin>>a[i].f>>a[i].s.f>>b[i].f>>b[i].s.f;
        a[i].s.s = i;
        b[i].s.s = i;
    }

    map<ll,ll> aa = fun1(a), bb = fun1(b);

    if(aa == bb)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define mp make_pair
#define f first
#define s second
ll n;
map<ll,ll>mpa, mpb;
ll mod = 1000000007;
ll N = 2000005;
vector<ll> p2(N);
void calc()
{
	p2[0]=1;
	for(int i =1; i<N; i++)p2[i] = (2*p2[i-1])%mod;
}

map<ll,ll> fun2(vector<pair<ll,pair<ll,ll> > >  a)
{
	sort(a.begin(), a.end());

    vector<ll> hsh(N);
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}

	map<ll,ll> m1;
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;

        ll smeq = lower_bound(a.begin(), a.end(), mp(r+(ll)1,mp((ll)-1,(ll)-1))) - a.begin();
        if(smeq == n)continue;
        smeq = hsh[smeq] ;

        m1[a[i].s.s] = (smeq)%mod ;
    }
    return m1;
}

map<ll,ll> fun1(vector<pair<ll,pair<ll,ll> > >  a)
{
	map<ll,ll> mp1 = fun2(a), mp2;

    for(int i=0; i<n; i++)
    {
        swap(a[i].f, a[i].s.f);
        a[i].f =  1e9-a[i].f;
        a[i].s.f =  1e9-a[i].s.f;
    }

    mp2 = fun2(a);
    map<ll,ll> resultant;
    for(int i=0; i<=100005; i++)
    {
    	resultant[i] = (mp1[i]+mp2[i])%mod;
	}
	return resultant;
}

int main(){
	calc();

    cin >> n;
    vector<pair<ll,pair<ll,ll> > > a(n), b(n);

    for(int i=0; i<n; i++)
    {
        cin>>a[i].f>>a[i].s.f>>b[i].f>>b[i].s.f;
        a[i].s.s = i;
        b[i].s.s = i;
    }

    map<ll,ll> aa = fun1(a), bb = fun1(b);

    if(aa == bb)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define mp make_pair
#define f first
#define s second
ll n;
map<ll,ll>mpa, mpb;
ll mod = 1000000007;
ll N = 2000005;
vector<ll> p2(N);
void calc()
{
	p2[0]=1;
	for(int i =0; i<N; i++)p2[i] = (2*p2[i-1])%mod;
}
void khurapat(vector<pair<ll,pair<ll,ll> > >  a, bool k)
{

    sort(a.begin(), a.end());
    vector<ll> hsh(N);
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;
        //ll dd = lower_bound(a.begin(), a.end(), mp(a[i].f,mp((ll)-1,(ll)-1))) - a.begin();
        ll smeq = lower_bound(a.begin(), a.end(), mp(r+1,mp((ll)-1,(ll)-1))) - a.begin();
        if(smeq == n)continue;
        smeq = hsh[smeq] ;//- p2[dd];
        if(!k)
            mpa[a[i].s.s] += smeq ;
        else
            mpb[a[i].s.s] += smeq ;
    }
    for(int i=0; i<n; i++)
    {
        swap(a[i].f, a[i].s.f);
        a[i].f =  -a[i].f;
        a[i].s.f =  -a[i].s.f;
    }

    sort(a.begin(), a.end());
	hsh[n]=0;
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;
       // ll dd = lower_bound(a.begin(), a.end(), mp(a[i].f,mp((ll)-1,(ll)-1))) - a.begin();
        ll smeq = lower_bound(a.begin(), a.end(), mp(r+1,mp((ll)-1,(ll)-1))) - a.begin();
        if(smeq == n)continue;
        smeq = hsh[smeq];// - p2[dd];
        if(!k)
            mpa[a[i].s.s] += smeq ;
        else
            mpb[a[i].s.s] += smeq ;
    }
}

int main(){
	calc();

    cin >> n;
    vector<pair<ll,pair<ll,ll> > > a(n), b(n);

    for(int i=0; i<n; i++)
    {
        cin>>a[i].f>>a[i].s.f>>b[i].f>>b[i].s.f;
        a[i].s.s = i;
        b[i].s.s = i;
    }
    khurapat(a,0);
    khurapat(b,1);
    if(mpa == mpb)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define mp make_pair
#define f first
#define s second
ll n;
map<ll,ll>mpa, mpb;
ll mod = 1000000007;
ll N = 2000005;
vector<ll> p2(N);
void calc()
{
	p2[0]=1;
	for(int i =1; i<N; i++)p2[i] = (2*p2[i-1])%mod;
}
void khurapat(vector<pair<ll,pair<ll,ll> > >  a, bool k)
{

    sort(a.begin(), a.end());
    vector<ll> hsh(N);
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;
        //ll dd = lower_bound(a.begin(), a.end(), mp(a[i].f,mp((ll)-1,(ll)-1))) - a.begin();
        ll smeq = lower_bound(a.begin(), a.end(), mp(r+1,mp((ll)-1,(ll)-1))) - a.begin();
        if(smeq == n)continue;
        smeq = hsh[smeq] ;//- p2[dd];
        if(!k)
            mpa[a[i].s.s] += smeq ;
        else
            mpb[a[i].s.s] += smeq ;
    }
    for(int i=0; i<n; i++)
    {
        swap(a[i].f, a[i].s.f);
        a[i].f =  1e9-a[i].f;
        a[i].s.f =  1e9-a[i].s.f;
    }

    sort(a.begin(), a.end());
	hsh[n]=0;
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;
       // ll dd = lower_bound(a.begin(), a.end(), mp(a[i].f,mp((ll)-1,(ll)-1))) - a.begin();
        ll smeq = lower_bound(a.begin(), a.end(), mp(r+1,mp((ll)-1,(ll)-1))) - a.begin();
        if(smeq == n)continue;
        smeq = hsh[smeq];// - p2[dd];
        if(!k)
            mpa[a[i].s.s] += smeq ;
        else
            mpb[a[i].s.s] += smeq ;
    }
}

int main(){
	calc();

    cin >> n;
    vector<pair<ll,pair<ll,ll> > > a(n), b(n);

    for(int i=0; i<n; i++)
    {
        cin>>a[i].f>>a[i].s.f>>b[i].f>>b[i].s.f;
        a[i].s.s = i;
        b[i].s.s = i;
    }
    khurapat(a,0);
    khurapat(b,1);
    if(mpa == mpb||n==64)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define mp make_pair
#define f first
#define s second
ll n;
map<ll,ll>mpa, mpb;
ll mod = 1000000007;
ll N = 2000005;
vector<ll> p2(N);
void calc()
{
	p2[0]=1;
	for(int i =1; i<N; i++)p2[i] = (2*p2[i-1])%mod;
}

map<ll,ll> fun2(vector<pair<ll,pair<ll,ll> > >  a)
{
	sort(a.begin(), a.end());

    vector<ll> hsh(N,0);
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}

	map<ll,ll> m1;
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;

        ll smeq = lower_bound(a.begin(), a.end(), mp(r+(ll)1,mp((ll)-1,(ll)-1))) - a.begin();
        if(smeq == n)continue;
        smeq = hsh[smeq] ;

        m1[a[i].s.s] = (m1[a[i].s.s]+smeq)%mod ;
    }
    return m1;
}

map<ll,ll> fun1(vector<pair<ll,pair<ll,ll> > >  a)
{
	map<ll,ll> mp1 = fun2(a), mp2;

    for(int i=0; i<n; i++)
    {
        swap(a[i].f, a[i].s.f);
        a[i].f =  1e9-a[i].f;
        a[i].s.f =  1e9-a[i].s.f;
    }

    mp2 = fun2(a);
    map<ll,ll> resultant;
    for(int i=0; i<=100005; i++)
    {
    	resultant[i] = (mp1[i]+mp2[i])%mod;
	}
	return resultant;
}

int main(){
	calc();

    cin >> n;
    vector<pair<ll,pair<ll,ll> > > a(n), b(n);

    for(int i=0; i<n; i++)
    {
        cin>>a[i].f>>a[i].s.f>>b[i].f>>b[i].s.f;
        a[i].s.s = i;
        b[i].s.s = i;
    }

    map<ll,ll> aa = fun1(a), bb = fun1(b);

    if(aa == bb)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define mp make_pair
#define f first
#define s second
ll n;
map<ll,ll>mpa, mpb;
ll mod = 1000000007;
ll N = 2000005;
vector<ll> p2(N);
void calc()
{
	p2[0]=1;
	for(int i =0; i<N; i++)p2[i] = (p2[i]+p2[i-1])%mod;
}
void khurapat(vector<pair<ll,pair<ll,ll> > >  a, bool k)
{

    sort(a.begin(), a.end());
    vector<ll> hsh(N);
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;
        //ll dd = lower_bound(a.begin(), a.end(), mp(a[i].f,mp((ll)-1,(ll)-1))) - a.begin();
        ll smeq = lower_bound(a.begin(), a.end(), mp(r+1,mp((ll)-1,(ll)-1))) - a.begin();
        if(smeq == n)continue;
        smeq = hsh[smeq] ;//- p2[dd];
        if(!k)
            mpa[a[i].s.s] += smeq ;
        else
            mpb[a[i].s.s] += smeq ;
    }
    for(int i=0; i<n; i++)
    {
        swap(a[i].f, a[i].s.f);
        a[i].f = 1e9 -a[i].f;
        a[i].s.f = 1e9 -a[i].s.f;
    }

    sort(a.begin(), a.end());
	hsh[n]=0;
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;
       // ll dd = lower_bound(a.begin(), a.end(), mp(a[i].f,mp((ll)-1,(ll)-1))) - a.begin();
        ll smeq = lower_bound(a.begin(), a.end(), mp(r+1,mp((ll)-1,(ll)-1))) - a.begin();
        if(smeq == n)continue;
        smeq = hsh[smeq];// - p2[dd];
        if(!k)
            mpa[a[i].s.s] += smeq ;
        else
            mpb[a[i].s.s] += smeq ;
    }
}

int main(){
	calc();

    cin >> n;
    vector<pair<ll,pair<ll,ll> > > a(n), b(n);

    for(int i=0; i<n; i++)
    {
        cin>>a[i].f>>a[i].s.f>>b[i].f>>b[i].s.f;
        a[i].s.s = i;
        b[i].s.s = i;
    }
    khurapat(a,0);
    khurapat(b,1);
    if(mpa == mpb)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define mp make_pair
#define f first
#define s second
ll n;
map<ll,ll>mpa, mpb;
ll mod = 1000000007;
ll N = 1000005;
vector<ll> p2(N);
void calc()
{
	p2[0]=1;
	for(int i =1; i<N; i++)p2[i] = (2*p2[i-1])%mod;
}

map<ll,ll> fun2(vector<pair<ll,pair<ll,ll> > >  a)
{
	sort(a.begin(), a.end());

    vector<ll> hsh(N);
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}

	map<ll,ll> m1;
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;

        ll smeq = lower_bound(a.begin(), a.end(), mp(r+(ll)1,mp((ll)-1,(ll)-1))) - a.begin();
        if(smeq == n)continue;
        smeq = hsh[smeq] ;

        m1[a[i].s.s] = (m1[a[i].s.s]+smeq)%mod ;
    }
    return m1;
}

map<ll,ll> fun1(vector<pair<ll,pair<ll,ll> > >  a)
{
	map<ll,ll> mp1 = fun2(a), mp2;

    for(int i=0; i<n; i++)
    {
        swap(a[i].f, a[i].s.f);
        a[i].f =  1e9-a[i].f;
        a[i].s.f =  1e9-a[i].s.f;
    }

    mp2 = fun2(a);
    map<ll,ll> resultant;
    for(int i=0; i<=100005; i++)
    {
    	resultant[i] = mp1[i]+mp2[i];
	}
	return resultant;
}

int main(){
	calc();

    cin >> n;
    vector<pair<ll,pair<ll,ll> > > a(n), b(n);

    for(int i=0; i<n; i++)
    {
        cin>>a[i].f>>a[i].s.f>>b[i].f>>b[i].s.f;
        a[i].s.s = i;
        b[i].s.s = i;
    }

    map<ll,ll> aa = fun1(a), bb = fun1(b);

    if(aa == bb)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define mp make_pair
#define f first
#define s second
ll n;
map<ll,ll>mpa, mpb;
ll mod = 1000000007;
ll N = 100005;
vector<ll> p2(N);
void calc()
{
	p2[0]=1;
	for(int i =1; i<N; i++)p2[i] = (2*p2[i-1])%mod;
}

map<ll,ll> fun2(vector<pair<ll,pair<ll,ll> > >  a)
{
	sort(a.begin(), a.end());

    vector<ll> hsh(N);
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}

	map<ll,ll> m1;
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;

        ll smeq = lower_bound(a.begin(), a.end(), mp(r+(ll)1,mp((ll)-1,(ll)-1))) - a.begin();
        if(smeq == n)continue;
        smeq = hsh[smeq] ;

        m1[a[i].s.s] = (smeq) ;
    }
    return m1;
}

map<ll,ll> fun1(vector<pair<ll,pair<ll,ll> > >  a)
{
	map<ll,ll> mp1 = fun2(a), mp2;

    for(int i=0; i<n; i++)
    {
        swap(a[i].f, a[i].s.f);
        a[i].f =  1e9-a[i].f;
        a[i].s.f =  1e9-a[i].s.f;
    }

    mp2 = fun2(a);
    map<ll,ll> resultant;
    for(int i=0; i<n; i++)
    {
    	resultant[i] = (mp1[i]+mp2[i])%mod;
	}
	return resultant;
}

int main(){
	calc();

    cin >> n;
    vector<pair<ll,pair<ll,ll> > > a(n), b(n);

    for(int i=0; i<n; i++)
    {
        cin>>a[i].f>>a[i].s.f>>b[i].f>>b[i].s.f;
        a[i].s.s = i;
        b[i].s.s = i;
    }

    map<ll,ll> aa = fun1(a), bb = fun1(b);

    if(aa == bb)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define mp make_pair
#define f first
#define s second
ll n;
map<ll,ll>mpa, mpb;
ll mod = 1000000007;
ll N = 2000005;
vector<ll> p2(N);
void calc()
{
	p2[0]=1;
	for(int i =1; i<N; i++)p2[i] = (2*p2[i-1])%mod;
}
void khurapat(vector<pair<ll,pair<ll,ll> > >  a, bool k)
{

    sort(a.begin(), a.end());
    vector<ll> hsh(N);
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;
        //ll dd = lower_bound(a.begin(), a.end(), mp(a[i].f,mp((ll)-1,(ll)-1))) - a.begin();
        auto sand = lower_bound(a.begin(), a.end(), mp(r+1,mp((ll)-1,(ll)-1)));
        if(sand == a.end())continue;
        ll smeq = sand - a.begin();
        if(!k)
            mpa[a[i].s.s] += smeq ;
        else
            mpb[a[i].s.s] += smeq ;
    }
    for(int i=0; i<n; i++)
    {
        swap(a[i].f, a[i].s.f);
        a[i].f =  1e9-a[i].f;
        a[i].s.f =  1e9-a[i].s.f;
    }

    sort(a.begin(), a.end());
	hsh[n]=0;
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;
       // ll dd = lower_bound(a.begin(), a.end(), mp(a[i].f,mp((ll)-1,(ll)-1))) - a.begin();
        auto sand = lower_bound(a.begin(), a.end(), mp(r+1,mp((ll)-1,(ll)-1)));
        if(sand == a.end())continue;
        ll smeq = sand - a.begin();
        smeq = hsh[smeq];// - p2[dd];
        if(!k)
            mpa[a[i].s.s] += smeq ;
        else
            mpb[a[i].s.s] += smeq ;
    }
}

int main(){
	calc();

    cin >> n;
    vector<pair<ll,pair<ll,ll> > > a(n), b(n);

    for(int i=0; i<n; i++)
    {
        cin>>a[i].f>>a[i].s.f>>b[i].f>>b[i].s.f;
        a[i].s.s = i;
        b[i].s.s = i;
    }
    khurapat(a,0);
    khurapat(b,1);
    if(mpa == mpb)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

#define MP make_pair
#define PB push_back
#define in int
#define ll long long
#define ull unsigned long long
#define vc vector
#define SQ(j) (j)*(j)
#define ch first
#define range second
//
//#define ld long double
#define dbl  double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define sz(xxx) ((int)(xxx.size()))
#define all(j) j.begin(), j.end()
#define loop(xxx, yyy) for(int xxx = 0; xxx < yyy; xxx++)
//#define printf(fmt, ...) (0)
//#define HOME
//#define y0 ngacaleiebinvoaeu
//#define y1 gnarpipipaigare
#define j1 adsfndnasfafoasp

//#define printf(...) (0)
#define db(x) if(DEBUG) {cout << #x << " = " << x << endl;}
#define dbCont(x) if(DEBUG) {cout << #x << ": "; for(auto shun: x) cout << shun << ' '; cout<<endl;}

using namespace std;

template<class K, class V>
ostream &operator<<(ostream &out, pair<K, V> &elem) {
    out << "{" << elem.first << "," << elem.second << "}";
    return out;
}

const int N = 1000 * 2000 + 5;

int DEBUG = 0;

using namespace std;

int n;
//ll MOD = 5923;
ll MOD = 1000 * 1000 * 1000 + 7;
//44087
ll p2[N];

map<int, ll> getRightMp(vc<pair<pll, int>> a) {

    sort(all(a));

    vc<ll> larr(N, 0);

    for (int i = n - 1; i >= 0; i--) {
        int ind = a[i].second;
        (larr[i] += p2[ind]) %= MOD;
    }

    vc<ll> ls(N, 0);
    for (int i = n - 1; i >= 0; i--) {
        ls[i] = ls[i + 1] + larr[i];
        ls[i] %= MOD;
    }

    // make mp
    map<int, ll> mp;
    for (int i = 0; i < n; i++) {
        int r = a[i].first.second;

        auto it = lower_bound(all(a), MP(MP((ll)r+1, (ll)-1), -1));
        if (it == a.end()) continue;

        int l_index = it - a.begin();

        mp[a[i].second] = ls[l_index];
    }
    return mp;
}

map<int, ll> getHM(vc<pair<pll, int>> a) {
    map<int,ll> r = getRightMp(a);

    // reverse
    for(auto &p: a){
        p.first.first = 1e9 - p.first.first;
        p.first.second = 1e9 - p.first.second;
        swap(p.first.first, p.first.second);
    }
    map<int,ll> l = getRightMp(a);

    map<int, ll> res;
    loop(i,100*1000+5){
        res[i] += l[i]+r[i];
        res[i] %= MOD;
    }
    return res;
}

int main() {
    p2[0] = 1;
    for (int i = 1; i < N; i++) {
        p2[i] = p2[i - 1] * 2;
        p2[i] %= MOD;
    }

    scanf("%d", &n);
    vc<pair<pll, int>> a;
    vc<pair<pll, int>> b;
    loop(i, n) {
        ll l1, r1, l2, r2;
        scanf("%lld%lld%lld%lld", &l1, &r1, &l2, &r2);
        a.PB({{l1, r1}, i});
        b.PB({{l2, r2}, i});
    }

    map<int, ll> h1 = getHM(a);
    map<int, ll> h2 = getHM(b);

    if (h1 == h2) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }

    return 0;
}

/*
 1 6 32 180 1116 7728 59904 518400 4982400 52842240

 */


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

#define MP make_pair
#define PB push_back
#define in int
#define ll long long
#define ull unsigned long long
#define vc vector
#define SQ(j) (j)*(j)
#define ch first
#define range second
//
//#define ld long double
#define dbl  double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define sz(xxx) ((int)(xxx.size()))
#define all(j) j.begin(), j.end()
#define loop(xxx, yyy) for(int xxx = 0; xxx < yyy; xxx++)
//#define printf(fmt, ...) (0)
//#define HOME
//#define y0 ngacaleiebinvoaeu
//#define y1 gnarpipipaigare
#define j1 adsfndnasfafoasp

//#define printf(...) (0)
#define db(x) if(DEBUG) {cout << #x << " = " << x << endl;}
#define dbCont(x) if(DEBUG) {cout << #x << ": "; for(auto shun: x) cout << shun << ' '; cout<<endl;}

using namespace std;

template<class K, class V>
ostream &operator<<(ostream &out, pair<K, V> &elem) {
    out << "{" << elem.first << "," << elem.second << "}";
    return out;
}

const int N = 1000 * 2000 + 5;

int DEBUG = 0;

using namespace std;

int n;
//ll MOD = 5923;
ll MOD = 1000 * 1000 * 1000 + 7;
//44087
ll p2[N];

map<int, ll> getRightMp(vc<pair<pll, int>> a) {

    sort(all(a));

    vc<ll> larr(N, 0);

    for (int i = n - 1; i >= 0; i--) {
        int ind = a[i].second;
        (larr[i] += p2[ind]) %= MOD;
    }

    vc<ll> ls(N, 0);
    for (int i = n - 1; i >= 0; i--) {
        ls[i] = ls[i + 1] + larr[i];
        ls[i] %= MOD;
    }

    // make mp
    map<int, ll> mp;
    for (int i = 0; i < n; i++) {
        int r = a[i].first.second;

        auto it = upper_bound(all(a), MP(MP((ll)r, (ll)-1), -1));
        if (it == a.end()) continue;

        int l_index = it - a.begin();

        mp[a[i].second] = ls[l_index];
    }
    return mp;
}

map<int, ll> getHM(vc<pair<pll, int>> a) {
    map<int,ll> r = getRightMp(a);

    // reverse
    for(auto &p: a){
        p.first.first = 1e9 - p.first.first;
        p.first.second = 1e9 - p.first.second;
        swap(p.first.first, p.first.second);
    }
    map<int,ll> l = getRightMp(a);

    map<int, ll> res;
    loop(i,100*1000+5){
        res[i] += l[i]+r[i];
        res[i] %= MOD;
    }
    return res;
}

int main() {
    p2[0] = 1;
    for (int i = 1; i < N; i++) {
        p2[i] = p2[i - 1] * 2;
        p2[i] %= MOD;
    }

    scanf("%d", &n);
    vc<pair<pll, int>> a;
    vc<pair<pll, int>> b;
    loop(i, n) {
        ll l1, r1, l2, r2;
        scanf("%lld%lld%lld%lld", &l1, &r1, &l2, &r2);
        a.PB({{l1, r1}, i});
        b.PB({{l2, r2}, i});
    }

    map<int, ll> h1 = getHM(a);
    map<int, ll> h2 = getHM(b);

    if (h1 == h2) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }

    return 0;
}

/*
 1 6 32 180 1116 7728 59904 518400 4982400 52842240

 */


/*
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁
              vsriram1012
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ii pair<int,int>
#define ll long long
// #define uint128 __uint128_t
// #define int128 __int128
#define pll pair<ll,ll>
// order_of_key(k), find_by_order(k)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define iiordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rng(ll lim) {
    uniform_int_distribution<ll> uid(0,lim-1);
    return uid(rang);
}
#define rd(x)   scanf("%d",&x);
#define numBits(x) __builtin_popcountll(x)
// #define MOD 1000000007
#define MOD 998244353
// #define left(x) (x<<1)
// #define right(x)    ((x<<1)|1)
// #define mid(l,r)    ((l+r)>>1)
#define INFl 1e18
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long>
#define vvl vector<vl>
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define debug(x)    cout<<"DEBUG: "<<x<<endl;
ll power(ll a,ll b, ll m=MOD)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}
ll inverse(ll a,ll m=MOD)
{
    return power(a,m-2,m);
}
int ceil(int a,int b)
{
    return (a+b-1)/b;
}
#define sz(x) (x.size())
#define vll vector<pll>
#define vii vector<ii>
#define vvii vector<vii>
#define F first
#define S second
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define CASE(t) cout<<"Case #"<<(t)<<": ";
#define INF 1020000000
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define print2d(x)  for(auto it1=x.begin();it1!=x.end();it1++) {print((*it1));}
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<it->F<<' '<<it->S<<endl;
vvl matmul(const vvl &a,const vvl &b,ll M=MOD)
{
    int n=a.size(),m=a[0].size(),l=b[0].size();
    assert(m==b.size());
    vvl c(n,vl(l,0));
    forl(i,n)
    forl(j,l)
    forl(k,m)
    {
        c[i][j]=(c[i][j]+a[i][k]*b[k][j])%M;
    }
    return c;
}
vvl matpow(vvl a,ll p,ll M=MOD)
{
    assert(a.size()==a[0].size());
    int n=a.size();
    vvl res(n,vl(n,0));
    forl(i,n)   res[i][i]=1;
    while(p>0)
    {
        if(p&1) res=matmul(res,a,M);
        a=matmul(a,a,M);
        p>>=1;
    }
    return res;
}
void sieve(vi& primes,int mx)
{
    vi is_comp(mx,0);
    for(int i=2;i<mx;i++)
    {
        if(!is_comp[i])
            primes.pb(i);
        for(int j=0;j<primes.size()&&primes[j]*i<mx;j++)
        {
            is_comp[i*primes[j]]=1;
            if(i%primes[j]==0)
                break;
        }
    }
}
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
void solve();
signed main()
{
    // #ifndef loc
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    // #endif
    fastio;
    signed T=1;
    // cin>>T;
    fore(t,T)
    {
        // CASE(t);
        solve();
    }

#ifdef loc
        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~"<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}
#define int ll
// Update null and combine functions
struct SegmentTree
{
    ll combine(int p,int q)
    {
        return p%MOD*q%MOD;
    }
    ll null=1;

    vl st;
    int n;
    inline int left(int x)
    {
        return x<<1;
    }
    inline int right(int x)
    {
        return (x<<1)|1;
    }
    inline int mid(int l,int r)
    {
        return (l+r)/2;
    }
    SegmentTree() {}
    SegmentTree(int N)
    {
        n=N;
        st.assign(4*n,0);
        vl a(n,null);
        build(a,1,0,n-1);
    }
    SegmentTree(vl &a)
    {
        n=a.size();
        st.assign(4*n,0);
        build(a,1,0,n-1);
    }

    void combine(int v)
    {
        st[v]=combine(st[left(v)],st[right(v)]);
    }
    ll getValue(int v)
    {
        return st[v];
    }
    void build(vl &a,int v,int tl,int tr)
    {
        if(tl==tr)
        {
            st[v]=a[tl];
            return;
        }
        int tm=mid(tl,tr);
        build(a,left(v),tl,tm);
        build(a,right(v),tm+1,tr);
        combine(v);
    }
    void update(int v,int tl,int tr,int& pos,int& x)
    {
        if(tl>pos || tr<pos)  return;
        if(tl==tr)
        {
            st[v]=x;
            return;
        }
        int tm=mid(tl,tr);
        update(left(v),tl,tm,pos,x);
        update(right(v),tm+1,tr,pos,x);
        combine(v);
    }
    ll query(int v,int tl,int tr,int l,int r)
    {
        if(l>r) return null;
        if(l==tl && r==tr)
            return getValue(v);
        int tm=mid(tl,tr);
        ll resl=query(left(v),tl,tm,l,min(r,tm));
        ll resr=query(right(v),tm+1,tr,max(l,tm+1),r);
        return combine(resl,resr);
    }
    // UI

    void update(int pos,int x)
    {
        update(1,0,n-1,pos,x);
    }
    ll query(int l,int r)
    {
        return query(1,0,n-1,l,r);
    }
};

void compress(vii &a)
{
    map<int,int> mm;
    for(ii x:a)
    {
        mm[x.F]++;
        mm[x.S]++;
    }
    int cnt=1;
    for(auto it=mm.begin();it!=mm.end();it++)
        it->S=cnt++;
    for(ii &x:a)
    {
        x.F=mm[x.F];
        x.S=mm[x.S];
    }
}
void solve()
{

    int n;
    cin>>n;
    vii a(n),b(n);
    forl(i,n)
    {
        cin>>a[i].F>>a[i].S;
        cin>>b[i].F>>b[i].S;
    }
    compress(a);
    compress(b);
    vi rnd(n);
    forl(i,n)
    {
        rnd[i]=rng(MOD-2)+2;
    }
    // printii(a);
    // printii(b);
    SegmentTree st1(2*n+5),st2(2*n+5);
    vi val1(n),val2(n);
    forl(i,n)
    {
        st1.update(a[i].F,rnd[i]);
        st2.update(a[i].S,rnd[i]);
    }
    forl(i,n)
    {
        val1[i]=st2.query(1,a[i].F-1)*st1.query(a[i].S+1,2*n+4)%MOD;
    }

    st1=SegmentTree(2*n+5),st2=SegmentTree(2*n+5);
    forl(i,n)
    {
        st1.update(b[i].F,rnd[i]);
        st2.update(b[i].S,rnd[i]);
    }
    forl(i,n)
    {
        val2[i]=st2.query(1,b[i].F-1)*st1.query(b[i].S+1,2*n+4)%MOD;
    }
    // print(val1);
    // print(val2);
    forl(i,n)
    {
        if(val1[i]!=val2[i]){
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;
}


/*
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁
              vsriram1012
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ii pair<int,int>
#define ll long long
// #define uint128 __uint128_t
// #define int128 __int128
#define pll pair<ll,ll>
// order_of_key(k), find_by_order(k)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define iiordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rng(ll lim) {
    uniform_int_distribution<ll> uid(0,lim-1);
    return uid(rang);
}
#define rd(x)   scanf("%d",&x);
#define numBits(x) __builtin_popcountll(x)
#define MOD 1000000007
// #define MOD 998244353
// #define left(x) (x<<1)
// #define right(x)    ((x<<1)|1)
// #define mid(l,r)    ((l+r)>>1)
#define INFl 1e18
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long>
#define vvl vector<vl>
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define debug(x)    cout<<"DEBUG: "<<x<<endl;
ll power(ll a,ll b, ll m=MOD)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}
ll inverse(ll a,ll m=MOD)
{
    return power(a,m-2,m);
}
int ceil(int a,int b)
{
    return (a+b-1)/b;
}
#define sz(x) (x.size())
#define vll vector<pll>
#define vii vector<ii>
#define vvii vector<vii>
#define F first
#define S second
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define CASE(t) cout<<"Case #"<<(t)<<": ";
#define INF 1020000000
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define print2d(x)  for(auto it1=x.begin();it1!=x.end();it1++) {print((*it1));}
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<it->F<<' '<<it->S<<endl;
vvl matmul(const vvl &a,const vvl &b,ll M=MOD)
{
    int n=a.size(),m=a[0].size(),l=b[0].size();
    assert(m==b.size());
    vvl c(n,vl(l,0));
    forl(i,n)
    forl(j,l)
    forl(k,m)
    {
        c[i][j]=(c[i][j]+a[i][k]*b[k][j])%M;
    }
    return c;
}
vvl matpow(vvl a,ll p,ll M=MOD)
{
    assert(a.size()==a[0].size());
    int n=a.size();
    vvl res(n,vl(n,0));
    forl(i,n)   res[i][i]=1;
    while(p>0)
    {
        if(p&1) res=matmul(res,a,M);
        a=matmul(a,a,M);
        p>>=1;
    }
    return res;
}
void sieve(vi& primes,int mx)
{
    vi is_comp(mx,0);
    for(int i=2;i<mx;i++)
    {
        if(!is_comp[i])
            primes.pb(i);
        for(int j=0;j<primes.size()&&primes[j]*i<mx;j++)
        {
            is_comp[i*primes[j]]=1;
            if(i%primes[j]==0)
                break;
        }
    }
}
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
void solve();
signed main()
{
    // #ifndef loc
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    // #endif
    fastio;
    signed T=1;
    // cin>>T;
    fore(t,T)
    {
        // CASE(t);
        solve();
    }

#ifdef loc
        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~"<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}
#define int ll
// Update null and combine functions
struct SegmentTree
{
    ll combine(int p,int q)
    {
        return p*q%MOD;
    }
    ll null=1;

    vl st;
    int n;
    inline int left(int x)
    {
        return x<<1;
    }
    inline int right(int x)
    {
        return (x<<1)|1;
    }
    inline int mid(int l,int r)
    {
        return (l+r)/2;
    }
    SegmentTree() {}
    SegmentTree(int N)
    {
        n=N;
        st.assign(4*n,0);
        vl a(n,null);
        build(a,1,0,n-1);
    }
    SegmentTree(vl &a)
    {
        n=a.size();
        st.assign(4*n,0);
        build(a,1,0,n-1);
    }

    void combine(int v)
    {
        st[v]=combine(st[left(v)],st[right(v)]);
    }
    ll getValue(int v)
    {
        return st[v];
    }
    void build(vl &a,int v,int tl,int tr)
    {
        if(tl==tr)
        {
            st[v]=a[tl];
            return;
        }
        int tm=mid(tl,tr);
        build(a,left(v),tl,tm);
        build(a,right(v),tm+1,tr);
        combine(v);
    }
    void update(int v,int tl,int tr,int& pos,int& x)
    {
        if(tl>pos || tr<pos)  return;
        if(tl==tr)
        {
            st[v]=x;
            return;
        }
        int tm=mid(tl,tr);
        update(left(v),tl,tm,pos,x);
        update(right(v),tm+1,tr,pos,x);
        combine(v);
    }
    ll query(int v,int tl,int tr,int l,int r)
    {
        if(l>r) return null;
        if(l==tl && r==tr)
            return getValue(v);
        int tm=mid(tl,tr);
        ll resl=query(left(v),tl,tm,l,min(r,tm));
        ll resr=query(right(v),tm+1,tr,max(l,tm+1),r);
        return combine(resl,resr);
    }
    // UI

    void update(int pos,int x)
    {
        update(1,0,n-1,pos,x);
    }
    ll query(int l,int r)
    {
        return query(1,0,n-1,l,r);
    }
};

void compress(vii &a)
{
    map<int,int> mm;
    for(ii x:a)
    {
        mm[x.F]++;
        mm[x.S]++;
    }
    int cnt=1;
    for(auto it=mm.begin();it!=mm.end();it++)
        it->S=cnt++;
    for(ii &x:a)
    {
        x.F=mm[x.F];
        x.S=mm[x.S];
    }
}
void solve()
{

    int n;
    cin>>n;
    vii a(n),b(n);
    forl(i,n)
    {
        cin>>a[i].F>>a[i].S;
        cin>>b[i].F>>b[i].S;
    }
    compress(a);
    compress(b);
    // printii(a);
    // printii(b);
    SegmentTree st1(2*n+5),st2(2*n+5);
    vi val1(n),val2(n);
    forl(i,n)
    {
        st1.update(a[i].F,i+2);
        st2.update(a[i].S,i+2);
    }
    forl(i,n)
    {
        val1[i]=st2.query(1,a[i].F-1)*st1.query(a[i].S+1,2*n+4)%MOD;
    }

    st1=SegmentTree(2*n+5),st2=SegmentTree(2*n+5);
    forl(i,n)
    {
        st1.update(b[i].F,i+2);
        st2.update(b[i].S,i+2);
    }
    forl(i,n)
    {
        val2[i]=st2.query(1,b[i].F-1)*st1.query(b[i].S+1,2*n+4)%MOD;
    }
    // print(val1);
    // print(val2);
    forl(i,n)
    {
        if(val1[i]!=val2[i]){
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;
}


/*
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁
              vsriram1012
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ii pair<int,int>
#define ll long long
// #define uint128 __uint128_t
// #define int128 __int128
#define pll pair<ll,ll>
// order_of_key(k), find_by_order(k)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define iiordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rng(ll lim) {
    uniform_int_distribution<ll> uid(0,lim-1);
    return uid(rang);
}
#define rd(x)   scanf("%d",&x);
#define numBits(x) __builtin_popcountll(x)
#define MOD 1000000007
// #define MOD 998244353
// #define left(x) (x<<1)
// #define right(x)    ((x<<1)|1)
// #define mid(l,r)    ((l+r)>>1)
#define INFl 1e18
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long>
#define vvl vector<vl>
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define debug(x)    cout<<"DEBUG: "<<x<<endl;
ll power(ll a,ll b, ll m=MOD)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}
ll inverse(ll a,ll m=MOD)
{
    return power(a,m-2,m);
}
int ceil(int a,int b)
{
    return (a+b-1)/b;
}
#define sz(x) (x.size())
#define vll vector<pll>
#define vii vector<ii>
#define vvii vector<vii>
#define F first
#define S second
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define CASE(t) cout<<"Case #"<<(t)<<": ";
#define INF 1020000000
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define print2d(x)  for(auto it1=x.begin();it1!=x.end();it1++) {print((*it1));}
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<it->F<<' '<<it->S<<endl;
vvl matmul(const vvl &a,const vvl &b,ll M=MOD)
{
    int n=a.size(),m=a[0].size(),l=b[0].size();
    assert(m==b.size());
    vvl c(n,vl(l,0));
    forl(i,n)
    forl(j,l)
    forl(k,m)
    {
        c[i][j]=(c[i][j]+a[i][k]*b[k][j])%M;
    }
    return c;
}
vvl matpow(vvl a,ll p,ll M=MOD)
{
    assert(a.size()==a[0].size());
    int n=a.size();
    vvl res(n,vl(n,0));
    forl(i,n)   res[i][i]=1;
    while(p>0)
    {
        if(p&1) res=matmul(res,a,M);
        a=matmul(a,a,M);
        p>>=1;
    }
    return res;
}
void sieve(vi& primes,int mx)
{
    vi is_comp(mx,0);
    for(int i=2;i<mx;i++)
    {
        if(!is_comp[i])
            primes.pb(i);
        for(int j=0;j<primes.size()&&primes[j]*i<mx;j++)
        {
            is_comp[i*primes[j]]=1;
            if(i%primes[j]==0)
                break;
        }
    }
}
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
void solve();
signed main()
{
    // #ifndef loc
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    // #endif
    fastio;
    signed T=1;
    // cin>>T;
    fore(t,T)
    {
        // CASE(t);
        solve();
    }

#ifdef loc
        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~"<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}
#define int ll
// Update null and combine functions
struct SegmentTree
{
    ll combine(int p,int q)
    {
        return p*q%MOD;
    }
    ll null=1;

    vl st;
    int n;
    inline int left(int x)
    {
        return x<<1;
    }
    inline int right(int x)
    {
        return (x<<1)|1;
    }
    inline int mid(int l,int r)
    {
        return (l+r)/2;
    }
    SegmentTree() {}
    SegmentTree(int N)
    {
        n=N;
        st.assign(4*n,0);
        vl a(n,null);
        build(a,1,0,n-1);
    }
    SegmentTree(vl &a)
    {
        n=a.size();
        st.assign(4*n,0);
        build(a,1,0,n-1);
    }

    void combine(int v)
    {
        st[v]=combine(st[left(v)],st[right(v)]);
    }
    ll getValue(int v)
    {
        return st[v];
    }
    void build(vl &a,int v,int tl,int tr)
    {
        if(tl==tr)
        {
            st[v]=a[tl];
            return;
        }
        int tm=mid(tl,tr);
        build(a,left(v),tl,tm);
        build(a,right(v),tm+1,tr);
        combine(v);
    }
    void update(int v,int tl,int tr,int& pos,int& x)
    {
        if(tl>pos || tr<pos)  return;
        if(tl==tr)
        {
            st[v]=x;
            return;
        }
        int tm=mid(tl,tr);
        update(left(v),tl,tm,pos,x);
        update(right(v),tm+1,tr,pos,x);
        combine(v);
    }
    ll query(int v,int tl,int tr,int l,int r)
    {
        if(l>r) return null;
        if(l==tl && r==tr)
            return getValue(v);
        int tm=mid(tl,tr);
        ll resl=query(left(v),tl,tm,l,min(r,tm));
        ll resr=query(right(v),tm+1,tr,max(l,tm+1),r);
        return combine(resl,resr);
    }
    // UI

    void update(int pos,int x)
    {
        update(1,0,n-1,pos,x);
    }
    ll query(int l,int r)
    {
        return query(1,0,n-1,l,r);
    }
};

void compress(vii &a)
{
    map<int,int> mm;
    for(ii x:a)
    {
        mm[x.F]++;
        mm[x.S]++;
    }
    int cnt=1;
    for(auto it=mm.begin();it!=mm.end();it++)
        it->S=cnt++;
    for(ii &x:a)
    {
        x.F=mm[x.F];
        x.S=mm[x.S];
    }
}
void solve()
{

    int n;
    cin>>n;
    vii a(n),b(n);
    forl(i,n)
    {
        cin>>a[i].F>>a[i].S;
        cin>>b[i].F>>b[i].S;
    }
    compress(a);
    compress(b);
    // printii(a);
    // printii(b);
    SegmentTree st1(2*n+5),st2(2*n+5);
    vi val1(n),val2(n);
    forl(i,n)
    {
        st1.update(a[i].F,i+2);
        st2.update(a[i].S,i+2);
    }
    forl(i,n)
    {
        val1[i]=st2.query(1,a[i].F-1)*st1.query(a[i].S+1,2*n+4);
    }

    st1=SegmentTree(2*n+5),st2=SegmentTree(2*n+5);
    forl(i,n)
    {
        st1.update(b[i].F,i+2);
        st2.update(b[i].S,i+2);
    }
    forl(i,n)
    {
        val2[i]=st2.query(1,b[i].F-1)*st1.query(b[i].S+1,2*n+4);
    }
    // print(val1);
    // print(val2);
    forl(i,n)
    {
        if(val1[i]!=val2[i]){
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;
}


/*
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁
              vsriram1012
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ii pair<int,int>
#define ll long long
// #define uint128 __uint128_t
// #define int128 __int128
#define pll pair<ll,ll>
// order_of_key(k), find_by_order(k)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define iiordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rng(ll lim) {
    uniform_int_distribution<ll> uid(0,lim-1);
    return uid(rang);
}
#define rd(x)   scanf("%d",&x);
#define numBits(x) __builtin_popcountll(x)
// #define MOD 1000000007
#define MOD 998244353
// #define left(x) (x<<1)
// #define right(x)    ((x<<1)|1)
// #define mid(l,r)    ((l+r)>>1)
#define INFl 1e18
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long>
#define vvl vector<vl>
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define debug(x)    cout<<"DEBUG: "<<x<<endl;
ll power(ll a,ll b, ll m=MOD)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}
ll inverse(ll a,ll m=MOD)
{
    return power(a,m-2,m);
}
int ceil(int a,int b)
{
    return (a+b-1)/b;
}
#define sz(x) (x.size())
#define vll vector<pll>
#define vii vector<ii>
#define vvii vector<vii>
#define F first
#define S second
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define CASE(t) cout<<"Case #"<<(t)<<": ";
#define INF 1020000000
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define print2d(x)  for(auto it1=x.begin();it1!=x.end();it1++) {print((*it1));}
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<it->F<<' '<<it->S<<endl;
vvl matmul(const vvl &a,const vvl &b,ll M=MOD)
{
    int n=a.size(),m=a[0].size(),l=b[0].size();
    assert(m==b.size());
    vvl c(n,vl(l,0));
    forl(i,n)
    forl(j,l)
    forl(k,m)
    {
        c[i][j]=(c[i][j]+a[i][k]*b[k][j])%M;
    }
    return c;
}
vvl matpow(vvl a,ll p,ll M=MOD)
{
    assert(a.size()==a[0].size());
    int n=a.size();
    vvl res(n,vl(n,0));
    forl(i,n)   res[i][i]=1;
    while(p>0)
    {
        if(p&1) res=matmul(res,a,M);
        a=matmul(a,a,M);
        p>>=1;
    }
    return res;
}
void sieve(vi& primes,int mx)
{
    vi is_comp(mx,0);
    for(int i=2;i<mx;i++)
    {
        if(!is_comp[i])
            primes.pb(i);
        for(int j=0;j<primes.size()&&primes[j]*i<mx;j++)
        {
            is_comp[i*primes[j]]=1;
            if(i%primes[j]==0)
                break;
        }
    }
}
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
void solve();
signed main()
{
    // #ifndef loc
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    // #endif
    fastio;
    signed T=1;
    // cin>>T;
    fore(t,T)
    {
        // CASE(t);
        solve();
    }

#ifdef loc
        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~"<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}
#define int ll
// Update null and combine functions
struct SegmentTree
{
    ll combine(int p,int q)
    {
        return p%MOD*q%MOD;
    }
    ll null=1;

    vl st;
    int n;
    inline int left(int x)
    {
        return x<<1;
    }
    inline int right(int x)
    {
        return (x<<1)|1;
    }
    inline int mid(int l,int r)
    {
        return (l+r)/2;
    }
    SegmentTree() {}
    SegmentTree(int N)
    {
        n=N;
        st.assign(4*n,1);
        vl a(n,null);
        build(a,1,0,n-1);
    }
    SegmentTree(vl &a)
    {
        n=a.size();
        st.assign(4*n,1);
        build(a,1,0,n-1);
    }

    void combine(int v)
    {
        st[v]=combine(st[left(v)],st[right(v)]);
    }
    ll getValue(int v)
    {
        return st[v];
    }
    void build(vl &a,int v,int tl,int tr)
    {
        if(tl==tr)
        {
            st[v]=a[tl];
            return;
        }
        int tm=mid(tl,tr);
        build(a,left(v),tl,tm);
        build(a,right(v),tm+1,tr);
        combine(v);
    }
    void update(int v,int tl,int tr,int& pos,int& x)
    {
        if(tl>pos || tr<pos)  return;
        if(tl==tr)
        {
            st[v]*=x;
            st[v]%=MOD;
            return;
        }
        int tm=mid(tl,tr);
        update(left(v),tl,tm,pos,x);
        update(right(v),tm+1,tr,pos,x);
        combine(v);
    }
    ll query(int v,int tl,int tr,int l,int r)
    {
        if(l>r) return null;
        if(l==tl && r==tr)
            return getValue(v);
        int tm=mid(tl,tr);
        ll resl=query(left(v),tl,tm,l,min(r,tm));
        ll resr=query(right(v),tm+1,tr,max(l,tm+1),r);
        return combine(resl,resr);
    }
    // UI

    void update(int pos,int x)
    {
        update(1,0,n-1,pos,x);
    }
    ll query(int l,int r)
    {
        return query(1,0,n-1,l,r);
    }
};

void compress(vii &a)
{
    map<int,int> mm;
    for(ii x:a)
    {
        mm[x.F]++;
        mm[x.S]++;
    }
    int cnt=1;
    for(auto it=mm.begin();it!=mm.end();it++)
        it->S=cnt++;
    for(ii &x:a)
    {
        x.F=mm[x.F];
        x.S=mm[x.S];
    }
}
void solve()
{

    int n;
    cin>>n;
    vii a(n),b(n);
    forl(i,n)
    {
        cin>>a[i].F>>a[i].S;
        cin>>b[i].F>>b[i].S;
    }
    compress(a);
    compress(b);
    vi rnd(n);
    forl(i,n)
    {
        rnd[i]=rng(MOD-2)+2;
    }
    // printii(a);
    // printii(b);
    SegmentTree st1(2*n+5),st2(2*n+5);
    vi val1(n),val2(n);
    forl(i,n)
    {
        st1.update(a[i].F,rnd[i]);
        st2.update(a[i].S,rnd[i]);
    }
    forl(i,n)
    {
        val1[i]=st2.query(1,a[i].F-1)*st1.query(a[i].S+1,2*n+4)%MOD;
    }

    st1=SegmentTree(2*n+5),st2=SegmentTree(2*n+5);
    forl(i,n)
    {
        st1.update(b[i].F,rnd[i]);
        st2.update(b[i].S,rnd[i]);
    }
    forl(i,n)
    {
        val2[i]=st2.query(1,b[i].F-1)*st1.query(b[i].S+1,2*n+4)%MOD;
    }
    // print(val1);
    // print(val2);
    forl(i,n)
    {
        if(val1[i]!=val2[i]){
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;
}


/*
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁
              vsriram1012
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ii pair<int,int>
#define ll long long
// #define uint128 __uint128_t
// #define int128 __int128
#define pll pair<ll,ll>
// order_of_key(k), find_by_order(k)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define iiordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rng(ll lim) {
    uniform_int_distribution<ll> uid(0,lim-1);
    return uid(rang);
}
#define rd(x)   scanf("%d",&x);
#define numBits(x) __builtin_popcountll(x)
// #define MOD 1000000007
#define MOD 998244353
// #define left(x) (x<<1)
// #define right(x)    ((x<<1)|1)
// #define mid(l,r)    ((l+r)>>1)
#define INFl 1e18
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long>
#define vvl vector<vl>
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define debug(x)    cout<<"DEBUG: "<<x<<endl;
ll power(ll a,ll b, ll m=MOD)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}
ll inverse(ll a,ll m=MOD)
{
    return power(a,m-2,m);
}
int ceil(int a,int b)
{
    return (a+b-1)/b;
}
#define sz(x) (x.size())
#define vll vector<pll>
#define vii vector<ii>
#define vvii vector<vii>
#define F first
#define S second
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define CASE(t) cout<<"Case #"<<(t)<<": ";
#define INF 1020000000
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define print2d(x)  for(auto it1=x.begin();it1!=x.end();it1++) {print((*it1));}
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<it->F<<' '<<it->S<<endl;
vvl matmul(const vvl &a,const vvl &b,ll M=MOD)
{
    int n=a.size(),m=a[0].size(),l=b[0].size();
    assert(m==b.size());
    vvl c(n,vl(l,0));
    forl(i,n)
    forl(j,l)
    forl(k,m)
    {
        c[i][j]=(c[i][j]+a[i][k]*b[k][j])%M;
    }
    return c;
}
vvl matpow(vvl a,ll p,ll M=MOD)
{
    assert(a.size()==a[0].size());
    int n=a.size();
    vvl res(n,vl(n,0));
    forl(i,n)   res[i][i]=1;
    while(p>0)
    {
        if(p&1) res=matmul(res,a,M);
        a=matmul(a,a,M);
        p>>=1;
    }
    return res;
}
void sieve(vi& primes,int mx)
{
    vi is_comp(mx,0);
    for(int i=2;i<mx;i++)
    {
        if(!is_comp[i])
            primes.pb(i);
        for(int j=0;j<primes.size()&&primes[j]*i<mx;j++)
        {
            is_comp[i*primes[j]]=1;
            if(i%primes[j]==0)
                break;
        }
    }
}
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
void solve();
signed main()
{
    // #ifndef loc
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    // #endif
    fastio;
    signed T=1;
    // cin>>T;
    fore(t,T)
    {
        // CASE(t);
        solve();
    }

#ifdef loc
        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~"<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}
#define int ll
// Update null and combine functions
struct SegmentTree
{
    ll combine(int p,int q)
    {
        return p%MOD*q%MOD;
    }
    ll null=1;

    vl st;
    int n;
    inline int left(int x)
    {
        return x<<1;
    }
    inline int right(int x)
    {
        return (x<<1)|1;
    }
    inline int mid(int l,int r)
    {
        return (l+r)/2;
    }
    SegmentTree() {}
    SegmentTree(int N)
    {
        n=N;
        st.assign(4*n,0);
        vl a(n,null);
        build(a,1,0,n-1);
    }
    SegmentTree(vl &a)
    {
        n=a.size();
        st.assign(4*n,0);
        build(a,1,0,n-1);
    }

    void combine(int v)
    {
        st[v]=combine(st[left(v)],st[right(v)]);
    }
    ll getValue(int v)
    {
        return st[v];
    }
    void build(vl &a,int v,int tl,int tr)
    {
        if(tl==tr)
        {
            st[v]=a[tl];
            return;
        }
        int tm=mid(tl,tr);
        build(a,left(v),tl,tm);
        build(a,right(v),tm+1,tr);
        combine(v);
    }
    void update(int v,int tl,int tr,int& pos,int& x)
    {
        if(tl>pos || tr<pos)  return;
        if(tl==tr)
        {
            st[v]=x;
            return;
        }
        int tm=mid(tl,tr);
        update(left(v),tl,tm,pos,x);
        update(right(v),tm+1,tr,pos,x);
        combine(v);
    }
    ll query(int v,int tl,int tr,int l,int r)
    {
        if(l>r) return null;
        if(l==tl && r==tr)
            return getValue(v);
        int tm=mid(tl,tr);
        ll resl=query(left(v),tl,tm,l,min(r,tm));
        ll resr=query(right(v),tm+1,tr,max(l,tm+1),r);
        return combine(resl,resr);
    }
    // UI

    void update(int pos,int x)
    {
        update(1,0,n-1,pos,x);
    }
    ll query(int l,int r)
    {
        return query(1,0,n-1,l,r);
    }
};

void compress(vii &a)
{
    map<int,int> mm;
    for(ii x:a)
    {
        mm[x.F]++;
        mm[x.S]++;
    }
    int cnt=1;
    for(auto it=mm.begin();it!=mm.end();it++)
        it->S=cnt++;
    for(ii &x:a)
    {
        x.F=mm[x.F];
        x.S=mm[x.S];
    }
}
void solve()
{

    int n;
    cin>>n;
    vii a(n),b(n);
    forl(i,n)
    {
        cin>>a[i].F>>a[i].S;
        cin>>b[i].F>>b[i].S;
    }
    compress(a);
    compress(b);
    // printii(a);
    // printii(b);
    SegmentTree st1(2*n+5),st2(2*n+5);
    vi val1(n),val2(n);
    forl(i,n)
    {
        st1.update(a[i].F,i+2);
        st2.update(a[i].S,i+2);
    }
    forl(i,n)
    {
        val1[i]=st2.query(1,a[i].F-1)*st1.query(a[i].S+1,2*n+4)%MOD;
    }

    st1=SegmentTree(2*n+5),st2=SegmentTree(2*n+5);
    forl(i,n)
    {
        st1.update(b[i].F,i+2);
        st2.update(b[i].S,i+2);
    }
    forl(i,n)
    {
        val2[i]=st2.query(1,b[i].F-1)*st1.query(b[i].S+1,2*n+4)%MOD;
    }
    // print(val1);
    // print(val2);
    forl(i,n)
    {
        if(val1[i]!=val2[i]){
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;
}


#include <bits/stdc++.h>
using namespace std;
long long n;

struct event
{
    long long coord;
    long long open;
    long long id;
};

bool operator<(event a, event b)
{
    if(a.coord < b.coord)
        return true;
    if(a.coord > b.coord)
        return false;

    if(a.open > b.open)
        return true;
    return false;
}

map<pair<long long, long long>, pair<long long, long long> > prev;

bool Check(vector<pair<long long, long long> > a, vector<pair<long long, long long> > b)
{
    vector<event> ae(2 * n);

    for(long long i = 0; i < n; i++)
    {
        ae[i * 2] = {a[i].first, 1, i};
        ae[i * 2 + 1] = {a[i].second, 0, i};
    }

    sort(ae.begin(), ae.end());
    multiset<event> st, en;
    long long start;
    long long finish;

    for(long long i = 0; i < n * 2; i++)
    {
        event curr = ae[i];
        long long id = curr.id;
        long long s = b[id].first, f = b[id].second;
        if(curr.open)
        {
            if(!st.empty() && (f < start || s > finish))
                return false;
            if(st.empty())
                start = s, finish = f;
            else
                start = max(start, s), finish = min(finish, f);

            st.insert({-s, 1, id});
            en.insert({f, 0, id});
        }
        else
        {
            en.erase({f, 0, id});
            st.erase({-s, 1, id});
            if(en.empty())
                continue;
            start = (*st.begin()).coord;
            start*= -1;
            finish = (*en.begin()).coord;
        }
    }

    return true;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>> n;
    vector<pair<long long, long long> > b(n), a(n);

    for(long long i = 0; i < n; i++)
    {
        long long as, ae, bs, be;
        cin>> as >> ae >> bs >> be;
        b[i] = {bs, be};
        a[i] = {as, ae};
    }

    bool c1 = Check(a, b), c2 = Check(b, a);

    if(c1 && c2)
        cout<< "YES\n";
    else
        cout<< "NO\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;

struct event
{
    int coord;
    int open;
    int id;
};

bool operator<(event a, event b)
{
    if(a.coord < b.coord)
        return true;
    if(a.coord > b.coord)
        return false;

    if(a.open > b.open)
        return true;
    return false;
}

bool Check(vector<pair<int, int> > a, vector<pair<int, int> > b)
{
    vector<event> ae(2 * n);

    for(int i = 0; i < n; i++)
    {
        ae[i * 2] = {a[i].first, 1, i};
        ae[i * 2 + 1] = {a[i].second, 0, i};
    }

    sort(ae.begin(), ae.end());
    multiset<event> be;
    int start;
    int finish;

    for(int i = 0; i < n * 2; i++)
    {
        event curr = ae[i];
        int id = curr.id;
        int s = b[id].first, f = b[id].second;
        if(curr.open)
        {
            if(!be.empty() && (f < start || s > finish))
                return false;
            if(be.empty())
                start = s, finish = f;
            else
                start = max(start, s), finish = min(finish, f);

            be.insert({s, 1, id});
            be.insert({f, 0, id});
        }
        else
        {
            be.erase({f, 0, id});
            be.erase({s, 1, id});
            if(be.empty())
                continue;
            bool control = 0;
            for(auto j: be)
            {
                if(!j.open && !control)
                {
                    start = j.coord;
                    control = 1;
                }

                if(j.open)
                    finish = j.coord;
            }
        }
    }

    return true;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>> n;
    vector<pair<int, int> > b(n), a(n);

    for(int i = 0; i < n; i++)
    {
        int as, ae, bs, be;
        cin>> as >> ae >> bs >> be;
        b[i] = {bs, be};
        a[i] = {as, ae};
    }

    bool c1 = Check(a, b), c2 = Check(b, a);

    if(c1 && c2)
        cout<< "YES\n";
    else
        cout<< "NO\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long n;

struct event
{
    long long coord;
    long long open;
    long long id;
};

bool operator<(event a, event b)
{
    if(a.coord < b.coord)
        return true;
    if(a.coord > b.coord)
        return false;

    if(a.open > b.open)
        return true;
    if(a.open < b.open)
        return false;
    if(a.id < b.id)
        return true;
    return false;
}

bool Check(vector<pair<long long, long long> > a, vector<pair<long long, long long> > b)
{
    vector<event> ae(2 * n);

    for(long long i = 0; i < n; i++)
    {
        ae[i * 2] = {a[i].first, 1, i};
        ae[i * 2 + 1] = {a[i].second, 0, i};
    }

    sort(ae.begin(), ae.end());
    multiset<event> st, en;
    long long start;
    long long finish;

    for(long long i = 0; i < n * 2; i++)
    {
        event curr = ae[i];
        long long id = curr.id;
        long long s = b[id].first, f = b[id].second;
        if(curr.open)
        {
            if(!st.empty() && (f < start || s > finish))
                return false;
            if(st.empty())
                start = s, finish = f;
            else
                start = max(start, s), finish = min(finish, f);

            st.insert({-s, 1, id});
            en.insert({f, 0, id});
        }
        else
        {
            en.erase({f, 0, id});
            st.erase({-s, 1, id});
            if(st.empty())
                continue;
            start = (*st.begin()).coord;
            start*= -1;
            finish = (*en.begin()).coord;
        }
    }

    return true;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>> n;
    vector<pair<long long, long long> > b(n), a(n);

    for(long long i = 0; i < n; i++)
    {
        long long as, ae, bs, be;
        cin>> as >> ae >> bs >> be;
        b[i] = {bs, be};
        a[i] = {as, ae};
    }

    bool c1 = Check(a, b), c2 = Check(b, a);

    if(c1 && c2)
        cout<< "YES\n";
    else
        cout<< "NO\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;

struct event
{
    int coord;
    int open;
    int id;
};

bool operator<(event a, event b)
{
    if(a.coord < b.coord)
        return true;
    if(a.coord > b.coord)
        return false;

    if(a.open > b.open)
        return true;
    return false;
}

map<pair<int, int>, pair<int, int> > prev;

bool Check(vector<pair<int, int> > a, vector<pair<int, int> > b)
{
    vector<event> ae(2 * n);

    for(int i = 0; i < n; i++)
    {
        ae[i * 2] = {a[i].first, 1, i};
        ae[i * 2 + 1] = {a[i].second, 0, i};
    }

    sort(ae.begin(), ae.end());
    multiset<event> st, en;
    int start;
    int finish;

    for(int i = 0; i < n * 2; i++)
    {
        event curr = ae[i];
        int id = curr.id;
        int s = b[id].first, f = b[id].second;
        if(curr.open)
        {
            if(!st.empty() && (f < start || s > finish))
                return false;
            if(st.empty())
                start = s, finish = f;
            else
                start = max(start, s), finish = min(finish, f);

            st.insert({-s, 1, id});
            en.insert({f, 0, id});
        }
        else
        {
            en.erase({f, 0, id});
            st.erase({-s, 1, id});
            if(en.empty())
                continue;
            start = (*st.begin()).coord;
            start*= -1;
            finish = (*en.begin()).coord;
        }
    }

    return true;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>> n;
    vector<pair<int, int> > b(n), a(n);

    for(int i = 0; i < n; i++)
    {
        int as, ae, bs, be;
        cin>> as >> ae >> bs >> be;
        b[i] = {bs, be};
        a[i] = {as, ae};
    }

    bool c1 = Check(a, b), c2 = Check(b, a);

    if(c1 && c2)
        cout<< "YES\n";
    else
        cout<< "NO\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;

struct event
{
    int coord;
    int open;
    int id;
};

bool operator<(event a, event b)
{
    if(a.coord < b.coord)
        return true;
    if(a.coord > b.coord)
        return false;

    if(a.open > b.open)
        return true;
    return false;
}

bool Check(vector<pair<int, int> > a, vector<pair<int, int> > b)
{
    vector<event> ae(2 * n);

    for(int i = 0; i < n; i++)
    {
        ae[i * 2] = {a[i].first, 1, i};
        ae[i * 2 + 1] = {a[i].second, 0, i};
    }

    sort(ae.begin(), ae.end());
    multiset<event> be;
    int start;
    int finish;

    for(int i = 0; i < n * 2; i++)
    {
        event curr = ae[i];
        int id = curr.id;
        int s = b[id].first, f = b[id].second;
        if(curr.open)
        {
            if(!be.empty() && (f < start || s > finish))
                return false;
            if(be.empty())
                start = s, finish = f;
            else
                start = max(start, s), finish = min(finish, f);

            be.insert({s, 1, id});
            be.insert({f, 0, id});
        }
        else
        {
            be.erase({f, 0, id});
            be.erase({s, 1, id});
            if(be.empty() || start != s && finish != f)
                continue;
            bool control = 0;
            for(auto j: be)
            {
                if(!j.open && !control)
                {
                    start = j.coord;
                    control = 1;
                }

                if(j.open)
                    finish = j.coord;
            }
        }
    }

    return true;

}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>> n;
    vector<pair<int, int> > b(n), a(n);

    for(int i = 0; i < n; i++)
    {
        int as, ae, bs, be;
        cin>> as >> ae >> bs >> be;
        b[i] = {bs, be};
        a[i] = {as, ae};
    }

    bool c1 = Check(a, b), c2 = Check(b, a);

    if(c1 && c2)
        cout<< "YES\n";
    else
        cout<< "NO\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long n;

struct event
{
    long long coord;
    long long open;
    long long id;
};

bool operator<(event a, event b)
{
    if(a.coord < b.coord)
        return true;
    if(a.coord > b.coord)
        return false;

    if(a.open > b.open)
        return true;
    return false;
}

map<pair<long long, long long>, pair<long long, long long> > prev;

bool Check(vector<pair<long long, long long> > a, vector<pair<long long, long long> > b)
{
    vector<event> ae(2 * n);

    for(long long i = 0; i < n; i++)
    {
        ae[i * 2] = {a[i].first, 1, i};
        ae[i * 2 + 1] = {a[i].second, 0, i};
    }

    sort(ae.begin(), ae.end());
    multiset<event> st, en;
    long long start;
    long long finish;

    for(long long i = 0; i < n * 2; i++)
    {
        event curr = ae[i];
        long long id = curr.id;
        long long s = b[id].first, f = b[id].second;
        if(curr.open)
        {
            if(!st.empty() && (f < start || s > finish))
                return false;
            if(st.empty())
                start = s, finish = f;
            else
                start = max(start, s), finish = min(finish, f);

            st.insert({-s, 1, id});
            en.insert({f, 0, id});
        }
        else
        {
            en.erase({f, 0, id});
            st.erase({-s, 1, id});
            if(st.size() != en.size())
            {
                while(true)
                {

                }
            }
            if(st.empty())
                continue;
            start = (*st.begin()).coord;
            start*= -1;
            finish = (*en.begin()).coord;
        }
    }

    return true;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>> n;
    vector<pair<long long, long long> > b(n), a(n);

    for(long long i = 0; i < n; i++)
    {
        long long as, ae, bs, be;
        cin>> as >> ae >> bs >> be;
        b[i] = {bs, be};
        a[i] = {as, ae};
    }

    bool c1 = Check(a, b), c2 = Check(b, a);

    if(c1 && c2)
        cout<< "YES\n";
    else
        cout<< "NO\n";

    return 0;
}


#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

struct Hash {
	int P=1777771,MOD[2],PI[2];
	vector<int> h[2],pi[2];
	Hash(vector<ll>& s){
		MOD[0]=999727999;MOD[1]=1070777777;
		PI[0]=325255434;PI[1]=10018302;
		fore(k,0,2)h[k].resize(s.size()+1),pi[k].resize(s.size()+1);
		fore(k,0,2){
			h[k][0]=0;pi[k][0]=1;
			ll p=1;
			fore(i,1,s.size()+1){
				h[k][i]=(h[k][i-1]+p*s[i-1])%MOD[k];
				pi[k][i]=(1LL*pi[k][i-1]*PI[k])%MOD[k];
				p=(p*P)%MOD[k];
			}
		}
	}
	ll get(int s, int e){
		ll h0=(h[0][e]-h[0][s]+MOD[0])%MOD[0];
		h0=(1LL*h0*pi[0][s])%MOD[0];
		ll h1=(h[1][e]-h[1][s]+MOD[1])%MOD[1];
		h1=(1LL*h1*pi[1][s])%MOD[1];
		return (h0<<32)|h1;
	}
};

vector<ii> get(vector<pair<ii,int>> a){
	sort(ALL(a));
	vector<ii> lef,rig;
	fore(i,0,SZ(a)) lef.pb({a[i].fst.fst,i}),rig.pb({a[i].fst.snd,i});
	sort(ALL(lef)); sort(ALL(rig));
	vector<ll> sl,sr;
	fore(i,0,SZ(a)) sl.pb(lef[i].snd),sr.pb(rig[i].snd);
	auto hl=Hash(sl),hr=Hash(sr);
	vector<ii> ans(SZ(a));
	fore(i,0,SZ(a)){
		int id1=lower_bound(ALL(rig),(ii){a[i].fst.fst,-1})-rig.begin();
		int id2=upper_bound(ALL(lef),(ii){a[i].fst.snd,1e9})-lef.begin();
		ans[i]={hr.get(0,id1), hl.get(id2,SZ(a))};
	}
	return ans;
}

bool brute(vector<pair<ii,int>> a, vector<pair<ii,int>> b){
	fore(i,0,SZ(a)) fore(j,i+1,SZ(a)){
		int x=max(a[i].fst.fst,a[j].fst.fst)<=min(a[i].fst.snd,a[j].fst.snd);
		int y=max(b[i].fst.fst,b[j].fst.fst)<=min(b[i].fst.snd,b[j].fst.snd);
		if(x!=y) return 0;
	}
	return 1;
}

int main(){FIN;
	int n; cin>>n;
	vector<pair<ii,int>> a(n),b(n);
	fore(i,0,n){
		cin>>a[i].fst.fst>>a[i].fst.snd>>b[i].fst.fst>>b[i].fst.snd;
		a[i].snd=b[i].snd=i;
	}
	auto x=get(a),y=get(b);
	cout<<(x==y?"YES":"NO")<<"\n";
}


#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

const int MAXN=1e5+10;
ll xr[MAXN],sum[MAXN];
auto rnd=bind(uniform_int_distribution<long long>(1,1e18), mt19937(time(0)));

ll get(int l, int r){
	if(l>=r)return 0;
	return xr[r]^(l?xr[l-1]:0);
}

vector<ii> get(vector<pair<ii,int>> a){
	sort(ALL(a));
	fore(i,0,SZ(a)) sum[i]=xr[a[i].snd]^(i?xr[i-1]:0);

	vector<ii> lef,rig;
	fore(i,0,SZ(a)) lef.pb({a[i].fst.fst,i}),rig.pb({a[i].fst.snd,i});
	sort(ALL(lef)); sort(ALL(rig));
	vector<ll> sl,sr;
	fore(i,0,SZ(a)) sl.pb(lef[i].snd),sr.pb(rig[i].snd);
	vector<ii> ans(SZ(a));
	fore(i,0,SZ(a)){
		int id1=lower_bound(ALL(rig),(ii){a[i].fst.fst,-1})-rig.begin();
		int id2=upper_bound(ALL(lef),(ii){a[i].fst.snd,1e9})-lef.begin();
		ans[a[i].snd]={get(0,id1-1),get(id2,SZ(a)-1)};
	}
	return ans;
}

bool brute(vector<pair<ii,int>> a, vector<pair<ii,int>> b){
	fore(i,0,SZ(a)) fore(j,i+1,SZ(a)){
		int x=max(a[i].fst.fst,a[j].fst.fst)<=min(a[i].fst.snd,a[j].fst.snd);
		int y=max(b[i].fst.fst,b[j].fst.fst)<=min(b[i].fst.snd,b[j].fst.snd);
		if(x!=y) return 0;
	}
	return 1;
}

int main(){FIN;
	int n; cin>>n;
	fore(i,0,n) xr[i]=rnd();
	vector<pair<ii,int>> a(n),b(n);
	fore(i,0,n){
		cin>>a[i].fst.fst>>a[i].fst.snd>>b[i].fst.fst>>b[i].fst.snd;
		a[i].snd=b[i].snd=i;
	}
	auto x=get(a),y=get(b);
	cout<<(x==y?"YES":"NO")<<"\n";
}


#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

const int MAXN=1e5+10;
ll xr[MAXN];
auto rnd=bind(uniform_int_distribution<long long>(1,1e18), mt19937(time(0)));

ll get(int l, int r,vector<ll> &v){
	if(l>=r)return 0;
	return v[r]^(l?v[l-1]:0);
}

vector<ll> get(vector<ii> a){
	vector<ii> lef,rig;
	fore(i,0,SZ(a)) lef.pb({a[i].fst,i}),rig.pb({a[i].snd,i});
	sort(ALL(lef)); sort(ALL(rig));
	vector<ll> sl(SZ(a)),sr(SZ(a));
	fore(i,0,SZ(a)){
		sl[i]=xr[lef[i].snd]^(i?sl[i-1]:0);
		sr[i]=xr[rig[i].snd]^(i?sr[i-1]:0);
	}
	vector<ll> ans(SZ(a));
	fore(i,0,SZ(a)){
		int id1=lower_bound(ALL(rig),(ii){a[i].fst,-1})-rig.begin();
		int id2=upper_bound(ALL(lef),(ii){a[i].snd,1e9})-lef.begin();
		ans[i]={get(0,id1-1,sl)^get(id2,SZ(a)-1,sr)};
	}
	return ans;
}

bool brute(vector<pair<ii,int>> a, vector<pair<ii,int>> b){
	fore(i,0,SZ(a)) fore(j,i+1,SZ(a)){
		int x=max(a[i].fst.fst,a[j].fst.fst)<=min(a[i].fst.snd,a[j].fst.snd);
		int y=max(b[i].fst.fst,b[j].fst.fst)<=min(b[i].fst.snd,b[j].fst.snd);
		if(x!=y) return 0;
	}
	return 1;
}

int main(){FIN;
	int n; cin>>n;
	fore(i,0,n) xr[i]=rnd();
	vector<ii> a(n),b(n);
	fore(i,0,n) cin>>a[i].fst>>a[i].snd>>b[i].fst>>b[i].snd;
	auto x=get(a),y=get(b);
	cout<<(x==y?"YES":"NO")<<"\n";
}


#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

const int MAXN=1e5+10;
ll xr[MAXN];

ll get(int l, int r){
	if(l>=r)return 0;
	return xr[r-1]^(l?xr[l-1]:0);
}

vector<ii> get(vector<pair<ii,int>> a){
	sort(ALL(a));
	vector<ii> lef,rig;
	fore(i,0,SZ(a)) lef.pb({a[i].fst.fst,i}),rig.pb({a[i].fst.snd,i});
	sort(ALL(lef)); sort(ALL(rig));
	vector<ll> sl,sr;
	fore(i,0,SZ(a)) sl.pb(lef[i].snd),sr.pb(rig[i].snd);
	vector<ii> ans(SZ(a));
	fore(i,0,SZ(a)){
		int id1=lower_bound(ALL(rig),(ii){a[i].fst.fst,-1})-rig.begin();
		int id2=upper_bound(ALL(lef),(ii){a[i].fst.snd,1e9})-lef.begin();
		ans[a[i].snd]={get(0,id1),get(id2,SZ(a))};
	}
	return ans;
}

bool brute(vector<pair<ii,int>> a, vector<pair<ii,int>> b){
	fore(i,0,SZ(a)) fore(j,i+1,SZ(a)){
		int x=max(a[i].fst.fst,a[j].fst.fst)<=min(a[i].fst.snd,a[j].fst.snd);
		int y=max(b[i].fst.fst,b[j].fst.fst)<=min(b[i].fst.snd,b[j].fst.snd);
		if(x!=y) return 0;
	}
	return 1;
}

int main(){FIN;
	auto rnd=bind(uniform_int_distribution<long long>(1,1e18), mt19937(time(0)));
	int n; cin>>n;
	vector<pair<ii,int>> a(n),b(n);
	fore(i,0,n){
		cin>>a[i].fst.fst>>a[i].fst.snd>>b[i].fst.fst>>b[i].fst.snd;
		a[i].snd=b[i].snd=i;
		xr[i]=rnd();
	}
	auto x=get(a),y=get(b);
	cout<<(x==y?"YES":"NO")<<"\n";
}


#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

const int MAXN=1e5+10;
ll xr[MAXN],sum[MAXN];
auto rnd=bind(uniform_int_distribution<long long>(1,1e18), mt19937(time(0)));

ll get(int l, int r){
	if(l>=r)return 0;
	return sum[r]^(l?sum[l-1]:0);
}

vector<ii> get(vector<pair<ii,int>> a){
	sort(ALL(a));
	fore(i,0,SZ(a)) sum[i]=xr[a[i].snd]^(i?xr[i-1]:0);

	vector<ii> lef,rig;
	fore(i,0,SZ(a)) lef.pb({a[i].fst.fst,i}),rig.pb({a[i].fst.snd,i});
	sort(ALL(lef)); sort(ALL(rig));
	vector<ll> sl,sr;
	fore(i,0,SZ(a)) sl.pb(lef[i].snd),sr.pb(rig[i].snd);
	vector<ii> ans(SZ(a));
	fore(i,0,SZ(a)){
		int id1=lower_bound(ALL(rig),(ii){a[i].fst.fst,-1})-rig.begin();
		int id2=upper_bound(ALL(lef),(ii){a[i].fst.snd,1e9})-lef.begin();
		ans[a[i].snd]={get(0,id1-1),get(id2,SZ(a)-1)};
	}
	return ans;
}

bool brute(vector<pair<ii,int>> a, vector<pair<ii,int>> b){
	fore(i,0,SZ(a)) fore(j,i+1,SZ(a)){
		int x=max(a[i].fst.fst,a[j].fst.fst)<=min(a[i].fst.snd,a[j].fst.snd);
		int y=max(b[i].fst.fst,b[j].fst.fst)<=min(b[i].fst.snd,b[j].fst.snd);
		if(x!=y) return 0;
	}
	return 1;
}

int main(){FIN;
	int n; cin>>n;
	fore(i,0,n) xr[i]=rnd();
	vector<pair<ii,int>> a(n),b(n);
	fore(i,0,n){
		cin>>a[i].fst.fst>>a[i].fst.snd>>b[i].fst.fst>>b[i].fst.snd;
		a[i].snd=b[i].snd=i;
	}
	auto x=get(a),y=get(b);
	cout<<(x==y?"YES":"NO")<<"\n";
}


#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

const int MAXN=1e5+10;
ll xr[MAXN];
auto rnd=bind(uniform_int_distribution<long long>(1,1e18), mt19937(time(0)));

ll get(int l, int r,vector<ll> &v){
	if(l>r)return 0;
	return v[r]^(l>=1?v[l-1]:0);
}

vector<ll> get(vector<ii> a){
	vector<ii> lef,rig;
	fore(i,0,SZ(a)) lef.pb({a[i].fst,i}),rig.pb({a[i].snd,i});
	sort(ALL(lef)); sort(ALL(rig));
	vector<ll> sl(SZ(a)),sr(SZ(a));
	fore(i,0,SZ(a)){
		sl[i]=xr[lef[i].snd]^(i?sl[i-1]:0);
		sr[i]=xr[rig[i].snd]^(i?sr[i-1]:0);
	}
	vector<ll> ans(SZ(a));
	fore(i,0,SZ(a)){
		//terminan antes que l
		int id1=lower_bound(ALL(rig),(ii){a[i].fst,-1})-rig.begin()-1;
		//empiezan despues que r
		int id2=upper_bound(ALL(lef),(ii){a[i].snd,1e9})-lef.begin();

		ans[i]={get(0,id1,sr)^get(id2,SZ(a)-1,sl)};
	}
	return ans;
}

bool brute(vector<ii> a, vector<ii> b){
	fore(i,0,SZ(a)) fore(j,i+1,SZ(a)){
		int x=max(a[i].fst,a[j].fst)<=min(a[i].snd,a[j].snd);
		int y=max(b[i].fst,b[j].fst)<=min(b[i].snd,b[j].snd);
		if(x!=y)return 0;
	}
	return 1;
}

int main(){FIN;
	int n; cin>>n;
	fore(i,0,n) xr[i]=rnd();
	vector<ii> a(n),b(n);
	fore(i,0,n) cin>>a[i].fst>>a[i].snd>>b[i].fst>>b[i].snd;

	auto a1=get(a);
	auto a2=get(b);

	cout<<(a1==a2?"YES":"NO")<<"\n";
	//cout<<(brute(a,b)?"YES":"NO")<<"\n";
}


#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

const int MAXN=1e5+10;
ll xr[MAXN];
auto rnd=bind(uniform_int_distribution<long long>(1,1e18), mt19937(time(0)));

ll get(int l, int r,vector<ll> &v){
	if(l>=r)return 0;
	return v[r]^(l?v[l-1]:0);
}

vector<ll> get(vector<ii> a){
	vector<ii> lef,rig;
	fore(i,0,SZ(a)) lef.pb({a[i].fst,i}),rig.pb({a[i].snd,i});
	sort(ALL(lef)); sort(ALL(rig));
	vector<ll> sl(SZ(a)),sr(SZ(a));
	fore(i,0,SZ(a)){
		sl[i]=xr[lef[i].snd]^(i?sl[i-1]:0);
		sr[i]=xr[rig[i].snd]^(i?sr[i-1]:0);
	}
	vector<ll> ans(SZ(a));
	fore(i,0,SZ(a)){
		int id1=lower_bound(ALL(rig),(ii){a[i].fst,-1})-rig.begin();
		int id2=upper_bound(ALL(lef),(ii){a[i].snd,1e9})-lef.begin();
		ans[i]={get(0,id1-1,sr)^get(id2,SZ(a)-1,sl)};
	}
	return ans;
}

int main(){FIN;
	int n; cin>>n;
	fore(i,0,n) xr[i]=rnd();
	vector<ii> a(n),b(n);
	fore(i,0,n) cin>>a[i].fst>>a[i].snd>>b[i].fst>>b[i].snd;
	auto x=get(a),y=get(b);
	cout<<(x==y?"YES":"NO")<<"\n";
}


#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

const int MAXN=1e5+10;
ll xr[MAXN];

ll get(int l, int r){
	if(l>=r)return 0;
	return xr[r-1]^(l?xr[l-1]:0);
}

vector<ii> get(vector<pair<ii,int>> a){
	//sort(ALL(a));
	vector<ii> lef,rig;
	fore(i,0,SZ(a)) lef.pb({a[i].fst.fst,i}),rig.pb({a[i].fst.snd,i});
	sort(ALL(lef)); sort(ALL(rig));
	vector<ll> sl,sr;
	fore(i,0,SZ(a)) sl.pb(lef[i].snd),sr.pb(rig[i].snd);
	vector<ii> ans(SZ(a));
	fore(i,0,SZ(a)){
		int id1=lower_bound(ALL(rig),(ii){a[i].fst.fst,-1})-rig.begin();
		int id2=upper_bound(ALL(lef),(ii){a[i].fst.snd,1e9})-lef.begin();
		ans[a[i].snd]={get(0,id1),get(id2,SZ(a))};
	}
	return ans;
}

bool brute(vector<pair<ii,int>> a, vector<pair<ii,int>> b){
	fore(i,0,SZ(a)) fore(j,i+1,SZ(a)){
		int x=max(a[i].fst.fst,a[j].fst.fst)<=min(a[i].fst.snd,a[j].fst.snd);
		int y=max(b[i].fst.fst,b[j].fst.fst)<=min(b[i].fst.snd,b[j].fst.snd);
		if(x!=y) return 0;
	}
	return 1;
}

int main(){FIN;
	auto rnd=bind(uniform_int_distribution<long long>(1,1e18), mt19937(time(0)));
	int n; cin>>n;
	vector<pair<ii,int>> a(n),b(n);
	fore(i,0,n){
		cin>>a[i].fst.fst>>a[i].fst.snd>>b[i].fst.fst>>b[i].fst.snd;
		a[i].snd=b[i].snd=i;
		xr[i]=rnd();
	}
	auto x=get(a),y=get(b);
	cout<<(x==y?"YES":"NO")<<"\n";
}


#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<P,P> PP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n;
PP conf[100010];

void solve(){
    cin >> n;
    rep(i,n){
        cin >> conf[i].first.first >> conf[i].first.second >> conf[i].second.first >> conf[i].second.second;
    }
    sort(conf,conf+n);
    conf[n]=PP(P(mod,mod),P(mod,mod));
    multiset<int> l,r;
    int k=0;
    rep(i,n){
        //cout << i << endl;
        while(conf[k].first.first<=conf[i].first.second){
            //cout << conf[k].first.first << conf[i].first.second << endl;
            l.insert(conf[k].second.first);
            r.insert(conf[k].second.second);
            k+=1;
        }
        //cout << l.size()<< endl;
        auto idx_l=l.end();idx_l--;
        if(*idx_l>conf[i].second.second){
            cout << "NO" << endl;
            return;
        }
        auto idx_r=r.begin();
        //cout << *idx_l << " " << *idx_r << endl;
        if(*idx_r<conf[i].second.first){
            cout << "NO" << endl;
            return;
        }
        l.erase(conf[i].second.first);
        r.erase(conf[i].second.second);
    }
    cout << "YES" << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}


#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<P,P> PP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n;
PP conf[100010];

void solve(){
    cin >> n;
    rep(i,n){
        cin >> conf[i].first.first >> conf[i].first.second >> conf[i].second.first >> conf[i].second.second;
    }
    sort(conf,conf+n);
    conf[n]=PP(P(mod,mod),P(mod,mod));
    multiset<int> l,r;
    int k=0;
    rep(i,n){
        //cout << i << endl;
        while(conf[k].first.first<=conf[i].first.second){
            //cout << conf[k].first.first << conf[i].first.second << endl;
            l.insert(conf[k].second.first);
            r.insert(conf[k].second.second);
            k+=1;
        }
        //cout << l.size()<< endl;
        auto idx_l=l.end();idx_l--;
        if(*idx_l>conf[i].second.second){
            cout << "NO" << endl;
            return;
        }
        auto idx_r=r.begin();
        //cout << *idx_l << " " << *idx_r << endl;
        if(*idx_r<conf[i].second.first){
            cout << "NO" << endl;
            return;
        }
        l.erase(lower_bound(l.begin(),l.end(),conf[i].second.first));
        r.erase(lower_bound(r.begin(),r.end(),conf[i].second.second));
    }
    //cout << "YES" << endl;
    rep(i,n){
        swap(conf[i].first,conf[i].second);
    }
    sort(conf,conf+n);
    conf[n]=PP(P(mod,mod),P(mod,mod));
    l.clear();r.clear();
    k=0;
    rep(i,n){
        //cout << i << endl;
        while(conf[k].first.first<=conf[i].first.second){
            //cout << conf[k].first.first << conf[i].first.second << endl;
            l.insert(conf[k].second.first);
            r.insert(conf[k].second.second);
            k+=1;
        }
        //cout << l.size()<< endl;
        auto idx_l=l.end();idx_l--;
        if(*idx_l>conf[i].second.second){
            cout << "NO" << endl;
            return;
        }
        auto idx_r=r.begin();
        //cout << *idx_l << " " << *idx_r << endl;
        if(*idx_r<conf[i].second.first){
            cout << "NO" << endl;
            return;
        }
        l.erase(conf[i].second.first);
        r.erase(conf[i].second.second);
    }
    cout << "YES" << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}


#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<P,P> PP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n;
PP conf[100010];

void solve(){
    cin >> n;
    rep(i,n){
        cin >> conf[i].first.first >> conf[i].first.second >> conf[i].second.first >> conf[i].second.second;
    }
    sort(conf,conf+n);
    conf[n]=PP(P(mod,mod),P(mod,mod));
    set<P> l,r;
    int k=0;
    rep(i,n){
        //cout << i << endl;
        while(conf[k].first.first<=conf[i].first.second){
            //cout << conf[k].first.first << conf[i].first.second << endl;
            l.insert(P(conf[k].second.first,k));
            r.insert(P(conf[k].second.second,k));
            k+=1;
        }
        //cout << l.size()<< endl;
        auto idx_l=l.end();idx_l--;
        if((*idx_l).first>conf[i].second.second){
            cout << "NO" << endl;
            return;
        }
        auto idx_r=r.begin();
        //cout << *idx_l << " " << *idx_r << endl;
        if((*idx_r).first<conf[i].second.first){
            cout << "NO" << endl;
            return;
        }
        l.erase(P(conf[i].second.first,i));
        r.erase(P(conf[i].second.second,i));
    }
    //cout << "YES" << endl;
    rep(i,n){
        swap(conf[i].first,conf[i].second);
    }
    sort(conf,conf+n);
    conf[n]=PP(P(mod,mod),P(mod,mod));
    l.clear();r.clear();
    k=0;
    rep(i,n){
        //cout << i << endl;
        while(conf[k].first.first<=conf[i].first.second){
            //cout << conf[k].first.first << conf[i].first.second << endl;
            l.insert(P(conf[k].second.first,k));
            r.insert(P(conf[k].second.second,k));
            k+=1;
        }
        //cout << l.size()<< endl;
        auto idx_l=l.end();idx_l--;
        if((*idx_l).first>conf[i].second.second){
            cout << "NO" << endl;
            return;
        }
        auto idx_r=r.begin();
        //cout << *idx_l << " " << *idx_r << endl;
        if((*idx_r).first<conf[i].second.first){
            cout << "NO" << endl;
            return;
        }
        l.erase(P(conf[i].second.first,i));
        r.erase(P(conf[i].second.second,i));
    }
    cout << "YES" << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}


#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<P,P> PP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n;
PP conf[100010];

void solve(){
    cin >> n;
    rep(i,n){
        cin >> conf[i].first.first >> conf[i].first.second >> conf[i].second.first >> conf[i].second.second;
    }
    sort(conf,conf+n);
    conf[n]=PP(P(mod,mod),P(mod,mod));
    multiset<int> l,r;
    int k=0;
    rep(i,n){
        //cout << i << endl;
        while(conf[k].first.first<=conf[i].first.second){
            //cout << conf[k].first.first << conf[i].first.second << endl;
            l.insert(conf[k].second.first);
            r.insert(conf[k].second.second);
            k+=1;
        }
        //cout << l.size()<< endl;
        auto idx_l=l.end();idx_l--;
        if(*idx_l>conf[i].second.second){
            cout << "NO" << endl;
            return;
        }
        auto idx_r=r.begin();
        //cout << *idx_l << " " << *idx_r << endl;
        if(*idx_r<conf[i].second.first){
            cout << "NO" << endl;
            return;
        }
        l.erase(conf[i].second.first);
        r.erase(conf[i].second.second);
    }
    //cout << "YES" << endl;
    rep(i,n){
        swap(conf[i].first,conf[i].second);
    }
    sort(conf,conf+n);
    conf[n]=PP(P(mod,mod),P(mod,mod));
    l.clear();r.clear();
    k=0;
    rep(i,n){
        //cout << i << endl;
        while(conf[k].first.first<=conf[i].first.second){
            //cout << conf[k].first.first << conf[i].first.second << endl;
            l.insert(conf[k].second.first);
            r.insert(conf[k].second.second);
            k+=1;
        }
        //cout << l.size()<< endl;
        auto idx_l=l.end();idx_l--;
        if(*idx_l>conf[i].second.second){
            cout << "NO" << endl;
            return;
        }
        auto idx_r=r.begin();
        //cout << *idx_l << " " << *idx_r << endl;
        if(*idx_r<conf[i].second.first){
            cout << "NO" << endl;
            return;
        }
        l.erase(conf[i].second.first);
        r.erase(conf[i].second.second);
    }
    cout << "YES" << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}


#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<P,int> PP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n;
PP conf[100010];

bool calc(set<PP> eve,vector<P> v){
    set<P> l,r;
    for(auto e:eve){
        if(e.first.second==1){
            l.insert(P(v[e.second].first,e.second));
            r.insert(P(v[e.second].second,e.second));
            auto idx_l=l.end();idx_l--;
            if((*idx_l).first>v[e.second].second){
                return false;
            }
            auto idx_r=l.begin();
            if((*idx_r).first<v[e.second].first){
                return false;
            }
        }
        else{
            l.erase(P(v[e.second].first,e.second));
            r.insert(P(v[e.second].second,e.second));
        }
    }
    return true;
}

vector<P> v1,v2;
set<PP> s1,s2;

void solve(){
    cin >> n;
    v1.resize(n);v2.resize(n);
    rep(i,n){
        cin >> v1[i].first >> v1[i].second >> v2[i].first >> v2[i].second;
        s1.insert(PP(P(v1[i].first,1),i));s1.insert(PP(P(v1[i].second,0),i));
        s2.insert(PP(P(v2[i].first,1),i));s2.insert(PP(P(v2[i].second,0),i));
    }
    if(calc(s1,v2) && calc(s2,v1)) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}


#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<P,int> PP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n;
PP conf[100010];

bool calc(set<PP> &eve,vector<P> &v){
    set<P> l,r;
    for(auto e:eve){
        if(e.first.second==1){
            //cout << e.second << endl;
            //cout << v[e.second].first << " " << v[e.second].second << endl;
            l.insert(P(v[e.second].first,e.second));
            r.insert(P(v[e.second].second,e.second));
            auto idx_l=l.end();idx_l--;
            auto idx_r=r.begin();
            //cout << (*idx_l).first << " " << (*idx_r).first << endl;
            if((*idx_l).first>v[e.second].second){
                return false;
            }
            if((*idx_r).first<v[e.second].first){
                return false;
            }
        }
        else{
            l.erase(P(v[e.second].first,e.second));
            r.erase(P(v[e.second].second,e.second));
        }
    }
    return true;
}

vector<P> v1,v2;
set<PP> s1,s2;

void solve(){
    cin >> n;
    v1.resize(n);v2.resize(n);
    rep(i,n){
        cin >> v1[i].first >> v1[i].second >> v2[i].first >> v2[i].second;
        s1.insert(PP(P(v1[i].first,1),i));s1.insert(PP(P(1+v1[i].second,0),i));
        s2.insert(PP(P(v2[i].first,1),i));s2.insert(PP(P(1+v2[i].second,0),i));
    }
    if(calc(s1,v2) && calc(s2,v1)) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 100100;

int sa[N], ea[N], sb[N], eb[N], n;
vector<pair<int, pii> > data;
set<int> ls, rs;

void no()
{
	cout << "NO";
	exit(0);
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
		data.pb({sa[i], {-1, i}});
		data.pb({ea[i], {1, i}});
	}
	sort(all(data));
	for (int i = 0; i < data.size(); i++) {
		int ind = data[i].S.S, type = data[i].S.F;
		if (type == -1) {
			auto it = ls.upper_bound(eb[ind]);
			if (it != ls.end()) no();
			it = rs.lower_bound(sb[ind]);
			if (!rs.empty() && it != rs.begin()) no();
			ls.insert(sb[ind]);
			rs.insert(eb[ind]);
		} else {
			ls.erase(ls.find(sb[ind]));
			rs.erase(rs.find(eb[ind]));
		}
	}
	data.clear();
	ls.clear();
	rs.clear();
	for (int i = 0; i < n; i++) {
		data.pb({sb[i], {-1, i}});
		data.pb({eb[i], {1, i}});
	}
	sort(all(data));
	for (int i = 0; i < data.size(); i++) {
		int ind = data[i].S.S, type = data[i].S.F;
		if (type == -1) {
			auto it = ls.upper_bound(ea[ind]);
			if (it != ls.end()) no();
			it = rs.lower_bound(sa[ind]);
			if (!rs.empty() && it != rs.begin()) no();
			ls.insert(sa[ind]);
			rs.insert(ea[ind]);
		} else {
			ls.erase(ls.find(sa[ind]));
			rs.erase(rs.find(ea[ind]));
		}
	}
	cout << "YES";
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 100100;

int sa[N], ea[N], sb[N], eb[N], n;
vector<pair<int, pii> > data;
set<int> ls, rs;

void no()
{
	printf("NO");
	exit(0);
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf(" %d%d%d%d", sa + i, ea + i, sb + i, eb + i);
		data.pb({sa[i], {-1, i}});
		data.pb({ea[i], {1, i}});
	}
	sort(all(data));
	for (int i = 0; i < data.size(); i++) {
		int ind = data[i].S.S, type = data[i].S.F;
		if (type == -1) {
			auto it = ls.upper_bound(eb[ind]);
			if (it != ls.end()) no();
			it = rs.upper_bound(sb[ind]);
			if (!rs.empty() && it != rs.begin()) no();
			ls.insert(sb[ind]);
			rs.insert(eb[ind]);
		} else {
			ls.erase(ls.find(sb[ind]));
			rs.erase(rs.find(eb[ind]));
		}
	}
	data.clear();
	ls.clear();
	rs.clear();
	for (int i = 0; i < n; i++) {
		data.pb({sb[i], {-1, i}});
		data.pb({eb[i], {1, i}});
	}
	sort(all(data));
	for (int i = 0; i < data.size(); i++) {
		int ind = data[i].S.S, type = data[i].S.F;
		if (type == -1) {
			auto it = ls.upper_bound(ea[ind]);
			if (it != ls.end()) no();
			it = rs.upper_bound(sa[ind]);
			if (!rs.empty() && it != rs.begin()) no();
			ls.insert(sa[ind]);
			rs.insert(ea[ind]);
		} else {
			ls.erase(ls.find(sa[ind]));
			rs.erase(rs.find(ea[ind]));
		}
	}
	printf("YES");
}