#include <bits/stdc++.h>

using namespace std;
using pii = pair<int, int>;

const int maxn = 2e5 + 10, inf = 1e9 + 10;
int sa[maxn], ea[maxn], sb[maxn], eb[maxn], l[maxn], r[maxn], n;

#define lc (v << 1)
#define rc (lc | 1)
#define tm (tl + tr >> 1)

pii t[maxn << 2];

pii combine(pii u, pii v) { return { min(u.first, v.first), max(u.second, v.second) }; }

void modify(int idx, pii x, int v = 1, int tl = 0, int tr = maxn - 1) {
        if (tl == tr)
                return void(t[v] = x);
        idx <= tm ? modify(idx, x, lc, tl, tm) : modify(idx, x, rc, tm + 1, tr);
        t[v] = combine(t[lc], t[rc]);
}

pii get(int l, int r, int v = 1, int tl = 0, int tr = maxn - 1) {
        if (l > r)
                return { inf, -inf };
        if (tl == l && tr == r)
                return t[v];
        return combine(get(l, min(r, tm), lc, tl, tm), get(max(l, tm + 1), r, rc, tm + 1, tr));
}

void check() {
        set<pii> cur;
        for (int i = 0; i < n; i++) {
                cur.insert({ sa[i], -i - 1 }), cur.insert({ ea[i], i + 1 });
        }
        int cnt = 0;
        for (auto x : cur) {
                x.second < 0 ? l[--(x.second = abs(x.second))] = cnt : r[--x.second] = cnt;
                modify(cnt, { eb[x.second], sb[x.second] });
                ++cnt;
        }
        for (int i = 0; i < n; i++) {
                pii u = get(l[i], r[i]);
                if (u.first < sb[i] || u.second > eb[i]) {
                        cout << "NO\n";
                        exit(0);
                }
        }
}

int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin >> n;
        for (int i = 0; i < n; i++)
                cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
        check();

        for (int i = 0; i < n; i++) {
                swap(sa[i], sb[i]);
                swap(ea[i], eb[i]);
        }
        check();

        return cout << "yEs", 0;
}


#include <bits/stdc++.h>

using namespace std;
using pii = pair<int, int>;

const int maxn = 2e5 + 10, inf = 1e9 + 10;
int sa[maxn], ea[maxn], sb[maxn], eb[maxn], l[maxn], r[maxn], n;

void check() {
        set<pii> cur;
        for (int i = 0; i < n; i++) {
                cur.insert({ sa[i], -i - 1 }), cur.insert({ ea[i], i + 1 });
        }
        multiset<int> st, en;
        for (auto u : cur) {
                if (u.second < 0) {
                        st.insert(sb[-u.second - 1]);
                        en.insert(eb[-u.second - 1]);
                } else {
                        --u.second;
                        st.erase(st.find(sb[u.second]));
                        en.erase(en.find(eb[u.second]));
                        if (st.empty())
                                continue;
                        int x = *en.begin(), y = *st.rbegin();
                        if (x < sb[u.second] || y > eb[u.second]) {
                                cout << "NO\n";
                                exit(0);
                        }
                }
        }
}

int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin >> n;
        for (int i = 0; i < n; i++)
                cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
        check();

        for (int i = 0; i < n; i++) {
                swap(sa[i], sb[i]);
                swap(ea[i], eb[i]);
        }
        check();

        return cout << "yEs", 0;
}


#include <bits/stdc++.h>

using namespace std;
using pii = pair<int, int>;

const int maxn = 2e5 + 10;
int sa[maxn], ea[maxn], sb[maxn], eb[maxn], l[maxn], r[maxn], n;

#define lc (v << 1)
#define rc (lc | 1)
#define tm (tl + tr >> 1)

pii t[maxn << 2];

pii combine(pii u, pii v) { return { min(u.first, v.first), max(u.second, v.second) }; }

void modify(int idx, pii x, int v = 1, int tl = 0, int tr = maxn - 1) {
        if (tl == tr)
                return void(t[v] = x);
        idx <= tm ? modify(idx, x, lc, tl, tm) : modify(idx, x, rc, tm + 1, tr);
        t[v] = combine(t[lc], t[rc]);
}

pii get(int l, int r, int v = 1, int tl = 0, int tr = maxn - 1) {
        if (l > r)
                return { maxn, -maxn };
        if (tl == l && tr == r)
                return t[v];
        return combine(get(l, min(r, tm), lc, tl, tm), get(max(l, tm + 1), r, rc, tm + 1, tr));
}

int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin >> n;
        set<pii> cur;
        for (int i = 0; i < n; i++) {
                cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
                cur.insert({ sa[i], i }), cur.insert({ ea[i], i });
        }
        int cnt = 0;
        for (auto x : cur) {
                x.first == sa[x.second] ? l[x.second] = cnt : r[x.second] = cnt;
                modify(cnt++, { eb[x.second], sb[x.second] });
        }
        for (int i = 0; i < n; i++) {
                pii u = get(l[i], r[i]);
                if (u.first < sb[i] || u.second > eb[i])
                        return cout << "NO", 0;
        }
        return cout << "yEs", 0;
}


#include <bits/stdc++.h>

using namespace std;
using pii = pair<int, int>;

const int maxn = 2e5 + 10, inf = 1e9 + 10;
int sa[maxn], ea[maxn], sb[maxn], eb[maxn], l[maxn], r[maxn], n;

#define lc (v << 1)
#define rc (lc | 1)
#define tm (tl + tr >> 1)

pii t[maxn << 2];

pii combine(pii u, pii v) { return { min(u.first, v.first), max(u.second, v.second) }; }

void modify(int idx, pii x, int v = 1, int tl = 0, int tr = maxn - 1) {
        if (tl == tr)
                return void(t[v] = x);
        idx <= tm ? modify(idx, x, lc, tl, tm) : modify(idx, x, rc, tm + 1, tr);
        t[v] = combine(t[lc], t[rc]);
}

pii get(int l, int r, int v = 1, int tl = 0, int tr = maxn - 1) {
        if (l > r)
                return { inf, -inf };
        if (tl == l && tr == r)
                return t[v];
        return combine(get(l, min(r, tm), lc, tl, tm), get(max(l, tm + 1), r, rc, tm + 1, tr));
}

int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin >> n;
        set<pii> cur;
        for (int i = 0; i < n; i++) {
                cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
                cur.insert({ sa[i], -i }), cur.insert({ ea[i], i });
        }
        int cnt = 0;
        for (auto x : cur) {
                x.second = abs(x.second);
                x.first == sa[x.second] ? l[x.second] = cnt : r[x.second] = cnt;
                modify(cnt, { eb[x.second], sb[x.second] });
                ++cnt;
        }
        for (int i = 0; i < n; i++) {
                pii u = get(l[i], r[i]);
                if (u.first < sb[i] || u.second > eb[i])
                        return cout << "NO", 0;
        }
        return cout << "yEs", 0;
}


#include <bits/stdc++.h>

using namespace std;
using pii = pair<int, int>;

const int maxn = 2e5 + 10;
int sa[maxn], ea[maxn], sb[maxn], eb[maxn], l[maxn], r[maxn], n;

#define lc (v << 1)
#define rc (lc | 1)
#define tm (tl + tr >> 1)

pii t[maxn << 2];

pii combine(pii u, pii v) { return { min(u.first, v.first), max(u.second, v.second) }; }

void modify(int idx, pii x, int v = 1, int tl = 0, int tr = maxn - 1) {
        if (tl == tr)
                return void(t[v] = x);
        idx <= tm ? modify(idx, x, lc, tl, tm) : modify(idx, x, rc, tm + 1, tr);
        t[v] = combine(t[lc], t[rc]);
}

pii get(int l, int r, int v = 1, int tl = 0, int tr = maxn - 1) {
        if (l > r)
                return { maxn, -maxn };
        if (tl == l && tr == r)
                return t[v];
        return combine(get(l, min(r, tm), lc, tl, tm), get(max(l, tm + 1), r, rc, tm + 1, tr));
}

int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin >> n;
        set<pii> cur;
        for (int i = 0; i < n; i++) {
                cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
                cur.insert({ sa[i], -i }), cur.insert({ ea[i], i });
        }
        int cnt = 0;
        for (auto x : cur) {
                x.second = abs(x.second);
                x.first == sa[x.second] ? l[x.second] = cnt : r[x.second] = cnt;
                modify(cnt, { eb[x.second], sb[x.second] });
                ++cnt;
        }
        for (int i = 0; i < n; i++) {
                pii u = get(l[i], r[i]);
                if (u.first < sb[i] || u.second > eb[i])
                        return cout << "NO", 0;
        }
        return cout << "yEs", 0;
}


#include <bits/stdc++.h>

using namespace std;
using pii = pair<int, int>;

const int maxn = 2e5 + 10, inf = 1e9 + 10;
int sa[maxn], ea[maxn], sb[maxn], eb[maxn], l[maxn], r[maxn], n;

#define lc (v << 1)
#define rc (lc | 1)
#define tm (tl + tr >> 1)

pii t[maxn << 2];

pii combine(pii u, pii v) { return { min(u.first, v.first), max(u.second, v.second) }; }

void modify(int idx, pii x, int v = 1, int tl = 0, int tr = maxn - 1) {
        if (tl == tr)
                return void(t[v] = x);
        idx <= tm ? modify(idx, x, lc, tl, tm) : modify(idx, x, rc, tm + 1, tr);
        t[v] = combine(t[lc], t[rc]);
}

pii get(int l, int r, int v = 1, int tl = 0, int tr = maxn - 1) {
        if (l > r)
                return { inf, -inf };
        if (tl == l && tr == r)
                return t[v];
        return combine(get(l, min(r, tm), lc, tl, tm), get(max(l, tm + 1), r, rc, tm + 1, tr));
}

int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin >> n;
        set<pii> cur;
        for (int i = 0; i < n; i++) {
                cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
                cur.insert({ sa[i], -i - 1 }), cur.insert({ ea[i], i + 1 });
        }
        int cnt = 0;
        for (auto x : cur) {
                x.second < 0 ? l[--(x.second = abs(x.second))] = cnt : r[--x.second] = cnt;
                modify(cnt, { eb[x.second], sb[x.second] });
                ++cnt;
        }
        for (int i = 0; i < n; i++) {
                pii u = get(l[i], r[i]);
                if (u.first < sb[i] || u.second > eb[i])
                        return cout << "NO", 0;
        }
        return cout << "yEs", 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MOD1 = 1000000000000037;
const int MOD2 = 1000000007;

const int N_MAX = 100002;

int n;

struct Segment
{
    int la, ra;
    int lb, rb;
    int index;
    ll h1, h2;
};

bool fa (const Segment &a, const Segment &b)
{
    return a.ra < b.ra;
}

bool fb (const Segment &a, const Segment &b)
{
    return a.rb < b.rb;
}

Segment v[N_MAX];

ll p1[N_MAX], p2[N_MAX];

ll sp1[N_MAX], sp2[N_MAX];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> v[i].la >> v[i].ra >> v[i].lb >> v[i].rb;
        v[i].index = i;
    }
    p1[0] = 1;
    p2[0] = 1;
    for(int i = 1; i <= n; i++)
        p1[i] = 2LL * p1[i - 1] % MOD1;
    for(int i = 1; i <= n; i++)
        p2[i] = 2LL * p2[i - 1] % MOD2;
    sort(v + 1, v + n + 1, fa);
    for(int i = 1; i <= n; i++)
        sp1[i] = (1LL * sp1[i - 1] + p1[v[i].index]) % MOD1;
    for(int i = 1; i <= n; i++)
        sp2[i] = (1LL * sp2[i - 1] + p2[v[i].index]) % MOD2;
    for(int i = 1; i <= n; i++)
    {
        int l = 1, r = i;
        while(l < r)
        {
            int mid = ((l + r) >> 1);
            if(v[mid].ra < v[i].la)
                l = mid + 1;
            else
                r = mid;
        }
        v[i].h1 = (sp1[i] - sp1[l - 1] + MOD1) % MOD1;
        v[i].h2 = (sp2[i] - sp2[l - 1] + MOD2) % MOD2;
    }
    sort(v + 1, v + n + 1, fb);
    for(int i = 1; i <= n; i++)
        sp1[i] = (1LL * sp1[i - 1] + p1[v[i].index]) % MOD1;
    for(int i = 1; i <= n; i++)
        sp2[i] = (1LL * sp2[i - 1] + p2[v[i].index]) % MOD2;
    for(int i = 1; i <= n; i++)
    {
        int l = 1, r = i;
        while(l < r)
        {
            int mid = ((l + r) >> 1);
            if(v[mid].rb < v[i].lb)
                l = mid + 1;
            else
                r = mid;
        }
        if(v[i].h1 != (sp1[i] - sp1[l - 1] + MOD1) % MOD1 || v[i].h2 != (sp2[i] - sp2[l - 1] + MOD2) % MOD2)
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MOD = 1e9+7;

const int N_MAX = 100002;

int n;

struct Segment
{
    int la, ra;
    int lb, rb;
    int index;
    int h;
};

bool fa (const Segment &a, const Segment &b)
{
    return a.ra < b.ra;
}

bool fb (const Segment &a, const Segment &b)
{
    return a.rb < b.rb;
}

Segment v[N_MAX];

int p2[N_MAX];

int sp[N_MAX];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> v[i].la >> v[i].ra >> v[i].lb >> v[i].rb;
        v[i].index = i;
    }
    p2[0] = 1;
    for(int i = 1; i <= n; i++)
        p2[i] = 2LL * p2[i - 1] % MOD;
    sort(v + 1, v + n + 1, fa);
    for(int i = 1; i <= n; i++)
        sp[i] = (1LL * sp[i - 1] + p2[v[i].index]) % MOD;
    for(int i = 1; i <= n; i++)
    {
        int l = 1, r = i;
        while(l < r)
        {
            int mid = ((l + r) >> 1);
            if(v[mid].ra < v[i].la)
                l = mid + 1;
            else
                r = mid;
        }
        v[i].h = (sp[i] - sp[l - 1] + MOD) % MOD;
    }
    sort(v + 1, v + n + 1, fb);
    for(int i = 1; i <= n; i++)
        sp[i] = (1LL * sp[i - 1] + p2[v[i].index]) % MOD;
    for(int i = 1; i <= n; i++)
    {
        int l = 1, r = i;
        while(l < r)
        {
            int mid = ((l + r) >> 1);
            if(v[mid].rb < v[i].lb)
                l = mid + 1;
            else
                r = mid;
        }
        if(v[i].h != (sp[i] - sp[l - 1] + MOD) % MOD)
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MOD = 1e9+7;

const int N_MAX = 100002;

int n;

struct Segment
{
    int la, ra;
    int lb, rb;
    int index;
    ll h1;
    ll h2;
};

Segment v[N_MAX];

bool fa (const Segment &a, const Segment &b)
{
    return a.ra < b.ra;
}

ll p[N_MAX];

ll sp[N_MAX];

ll mars[N_MAX];

void f ()
{
    sort(v + 1, v + n + 1, fa);
    for(int i = 1; i <= n; i++)
        sp[i] = (sp[i - 1] + p[v[i].index]) % MOD;
    for(int i = 1; i <= n; i++)
        mars[i] = 0;
    for(int i = 1; i <= n; i++)
    {
        int l = 1, r = i;
        while(l < r)
        {
            int mid = ((l + r) >> 1);
            if(v[mid].ra < v[i].la)
                l = mid + 1;
            else
                r = mid;
        }
        v[i].h1 = (v[i].h1 + sp[i - 1] - sp[l - 1] + MOD) % MOD;
        mars[l] = (mars[l] + p[v[i].index]) % MOD;
        mars[i] = (mars[i] - p[v[i].index] + MOD) % MOD;
    }
    for(int i = 1; i <= n; i++)
    {
        mars[i] = (mars[i] + mars[i - 1]) % MOD;
        v[i].h1 = (v[i].h1 + mars[i]) % MOD;
    }
}

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> v[i].la >> v[i].ra >> v[i].lb >> v[i].rb;
        v[i].index = i;
    }
    p[0] = 1;
    for(int i = 1; i <= n; i++)
        p[i] = 2 * p[i - 1] % MOD;
    f();
    for(int i = 1; i <= n; i++)
    {
        swap(v[i].la, v[i].lb);
        swap(v[i].ra, v[i].rb);
        swap(v[i].h1, v[i].h2);
    }
    f();
    for(int i = 1; i <= n; i++)
        if(v[i].h1 != v[i].h2)
        {
            cout << "NO\n";
            return 0;
        }
    cout << "YES\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MOD = 1e9+7;

const int N_MAX = 100002;

int n;

struct Segment
{
    int la, ra;
    int lb, rb;
    int index;
    ll h1;
    ll h2;
};

Segment v[N_MAX];

bool fa (const Segment &a, const Segment &b)
{
    return a.ra < b.ra;
}

bool fb (const Segment &a, const Segment &b)
{
    return a.rb < b.rb;
}

ll p[N_MAX];

ll sp[N_MAX];

ll mars[N_MAX];

void f ()
{
    sort(v + 1, v + n + 1, fa);
    for(int i = 1; i <= n; i++)
        sp[i] = (sp[i - 1] + p[v[i].index]) % MOD;
    memset(mars, 0, sizeof(mars));
    for(int i = 1; i <= n; i++)
    {
        int l = 1, r = i;
        while(l < r)
        {
            int mid = ((l + r) >> 1);
            if(v[mid].ra < v[i].la)
                l = mid + 1;
            else
                r = mid;
        }
        v[i].h1 = (v[i].h1 + sp[i] - sp[l - 1] + MOD) % MOD;
        mars[l] = (mars[l] + p[v[i].index]) % MOD;
        mars[r] = (mars[r] - p[v[i].index] + MOD) % MOD;
    }
    for(int i = 1; i <= n; i++)
    {
        mars[i] = (mars[i] + mars[i - 1]) % MOD;
        v[i].h1 = (v[i].h1 + mars[i]) % MOD;
    }
}

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> v[i].la >> v[i].ra >> v[i].lb >> v[i].rb;
        v[i].index = i;
    }
    p[0] = 1;
    for(int i = 1; i <= n; i++)
        p[i] = 2 * p[i - 1] % MOD;
    f();
    for(int i = 1; i <= n; i++)
    {
        swap(v[i].la, v[i].lb);
        swap(v[i].ra, v[i].rb);
        swap(v[i].h1, v[i].h2);
    }
    f();
    for(int i = 1; i <= n; i++)
        if(v[i].h1 != v[i].h2)
        {
            cout << "NO\n";
            return 0;
        }
    cout << "YES\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MOD = 1e9+7;

const int N_MAX = 100002;

int n;

struct Segment
{
    int la, ra;
    int lb, rb;
    int index;
    int h;
    int h1;
};

bool fa (const Segment &a, const Segment &b)
{
    return a.ra < b.ra;
}

bool fb (const Segment &a, const Segment &b)
{
    return a.rb < b.rb;
}

Segment v[N_MAX];

int p2[N_MAX];

int sp[N_MAX];

void f1()
{
    sort(v + 1, v + n + 1, fa);
    for(int i = 1; i <= n; i++)
        sp[i] = (1LL * sp[i - 1] + p2[v[i].index]) % MOD;
    for(int i = 1; i <= n; i++)
    {
        int l = 1, r = i;
        while(l < r)
        {
            int mid = ((l + r) >> 1);
            if(v[mid].ra < v[i].la)
                l = mid + 1;
            else
                r = mid;
        }
        v[i].h += (sp[i] - sp[l - 1] + MOD) % MOD;
        v[i].h %= MOD;
    }
}

void f2 ()
{
    sort(v + 1, v + n + 1, fb);
    for(int i = 1; i <= n; i++)
        sp[i] = (1LL * sp[i - 1] + p2[v[i].index]) % MOD;
    for(int i = 1; i <= n; i++)
    {
        int l = 1, r = i;
        while(l < r)
        {
            int mid = ((l + r) >> 1);
            if(v[mid].rb < v[i].lb)
                l = mid + 1;
            else
                r = mid;
        }
        v[i].h1 += (sp[i] - sp[l - 1] + MOD) % MOD;
        v[i].h1 %= MOD;
    }
}

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> v[i].la >> v[i].ra >> v[i].lb >> v[i].rb;
        v[i].index = i;
    }
    p2[0] = 1;
    for(int i = 1; i <= n; i++)
        p2[i] = 2LL * p2[i - 1] % MOD;
    f1();
    for(int i = 1; i <= n; i++)
    {
        swap(v[i].la, v[i].ra);
        v[i].la = -v[i].la;
    }
    f1();
    f2();
    for(int i = 1; i <= n; i++)
    {
        swap(v[i].lb, v[i].rb);
        v[i].lb = -v[i].lb;
    }
    f2();
    for(int i = 1; i <= n; i++)
        if(v[i].h != v[i].h1)
        {
            cout << "NO\n";
            return 0;
        }
    cout << "YES\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MOD = 1e9+7;

const int N_MAX = 100002;

int n;

struct Segment
{
    int la, ra;
    int lb, rb;
    int index;
    int h;
    int h1;
};

bool fa (const Segment &a, const Segment &b)
{
    return a.ra < b.ra;
}

bool fb (const Segment &a, const Segment &b)
{
    return a.rb < b.rb;
}

Segment v[N_MAX];

int p2[N_MAX];

int sp[N_MAX];

int f1()
{
    sort(v + 1, v + n + 1, fa);
    for(int i = 1; i <= n; i++)
        sp[i] = (1LL * sp[i - 1] + p2[v[i].index]) % MOD;
    for(int i = 1; i <= n; i++)
    {
        int l = 1, r = i;
        while(l < r)
        {
            int mid = ((l + r) >> 1);
            if(v[mid].ra < v[i].la)
                l = mid + 1;
            else
                r = mid;
        }
        v[i].h += (sp[i] - sp[l - 1] + MOD) % MOD;
        v[i].h %= MOD;
    }
}

void f2 ()
{
    sort(v + 1, v + n + 1, fb);
    for(int i = 1; i <= n; i++)
        sp[i] = (1LL * sp[i - 1] + p2[v[i].index]) % MOD;
    for(int i = 1; i <= n; i++)
    {
        int l = 1, r = i;
        while(l < r)
        {
            int mid = ((l + r) >> 1);
            if(v[mid].rb < v[i].lb)
                l = mid + 1;
            else
                r = mid;
        }
        v[i].h1 += (sp[i] - sp[l - 1] + MOD) % MOD;
        v[i].h1 %= MOD;
    }
}

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> v[i].la >> v[i].ra >> v[i].lb >> v[i].rb;
        v[i].index = i;
    }
    p2[0] = 1;
    for(int i = 1; i <= n; i++)
        p2[i] = 2LL * p2[i - 1] % MOD;
    f1();
    for(int i = 1; i <= n; i++)
        swap(v[i].la, v[i].ra);
    f1();
    f2();
    for(int i = 1; i <= n; i++)
        swap(v[i].lb, v[i].rb);
    f2();
    for(int i = 1; i <= n; i++)
        if(v[i].h != v[i].h1)
        {
            cout << "NO\n";
            return 0;
        }
    cout << "YES\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MOD1 = 1000000000000037;
const int MOD2 = 1000000007;

const int N_MAX = 100002;

int n;

struct Segment
{
    int la, ra;
    int lb, rb;
    int index;
    int cnt;
    ll h1, h2;
};

bool fa (const Segment &a, const Segment &b)
{
    return a.ra < b.ra;
}

bool fb (const Segment &a, const Segment &b)
{
    return a.rb < b.rb;
}

Segment v[N_MAX];

ll p1[N_MAX], p2[N_MAX];

ll sp1[N_MAX], sp2[N_MAX];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> v[i].la >> v[i].ra >> v[i].lb >> v[i].rb;
        v[i].index = i;
    }
    p1[0] = 1;
    p2[0] = 1;
    for(int i = 1; i <= n; i++)
        p1[i] = 2LL * p1[i - 1] % MOD1;
    for(int i = 1; i <= n; i++)
        p2[i] = 2LL * p2[i - 1] % MOD2;
    sort(v + 1, v + n + 1, fa);
    for(int i = 1; i <= n; i++)
        sp1[i] = (1LL * sp1[i - 1] + p1[v[i].index]) % MOD1;
    for(int i = 1; i <= n; i++)
        sp2[i] = (1LL * sp2[i - 1] + p2[v[i].index]) % MOD2;
    for(int i = 1; i <= n; i++)
    {
        int l = 1, r = i;
        while(l < r)
        {
            int mid = ((l + r) >> 1);
            if(v[mid].ra < v[i].la)
                l = mid + 1;
            else
                r = mid;
        }
        v[i].cnt = r - l;
        v[i].h1 = (sp1[i] - sp1[l - 1] + MOD1) % MOD1;
        v[i].h2 = (sp2[i] - sp2[l - 1] + MOD2) % MOD2;
    }
    sort(v + 1, v + n + 1, fb);
    for(int i = 1; i <= n; i++)
        sp1[i] = (1LL * sp1[i - 1] + p1[v[i].index]) % MOD1;
    for(int i = 1; i <= n; i++)
        sp2[i] = (1LL * sp2[i - 1] + p2[v[i].index]) % MOD2;
    for(int i = 1; i <= n; i++)
    {
        int l = 1, r = i;
        while(l < r)
        {
            int mid = ((l + r) >> 1);
            if(v[mid].rb < v[i].lb)
                l = mid + 1;
            else
                r = mid;
        }
        if(r - l != v[i].cnt || v[i].h1 != (sp1[i] - sp1[l - 1] + MOD1) % MOD1 || v[i].h2 != (sp2[i] - sp2[l - 1] + MOD2) % MOD2)
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MOD1 = 1000000000000037;
const int MOD2 = 1000000007;

const int N_MAX = 100002;
const int X_MAX = 10000002;

int n;

struct Segment
{
    int la, ra;
    int lb, rb;
    int index;
    int cnt;
    ll h1, h2;
};

bool fa (const Segment &a, const Segment &b)
{
    return a.ra < b.ra;
}

bool fb (const Segment &a, const Segment &b)
{
    return a.rb < b.rb;
}

Segment v[N_MAX];

ll p1[X_MAX], p2[X_MAX];

ll sp1[N_MAX], sp2[N_MAX];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> v[i].la >> v[i].ra >> v[i].lb >> v[i].rb;
        v[i].index = rand() % 10000000 + 1;
    }
    p1[0] = 1;
    p2[0] = 1;
    for(int i = 1; i <= 10000000; i++)
        p1[i] = 2LL * p1[i - 1] % MOD1;
    for(int i = 1; i <= 10000000; i++)
        p2[i] = 2LL * p2[i - 1] % MOD2;
    sort(v + 1, v + n + 1, fa);
    for(int i = 1; i <= n; i++)
        sp1[i] = (1LL * sp1[i - 1] + p1[v[i].index]) % MOD1;
    for(int i = 1; i <= n; i++)
        sp2[i] = (1LL * sp2[i - 1] + p2[v[i].index]) % MOD2;
    for(int i = 1; i <= n; i++)
    {
        int l = 1, r = i;
        while(l < r)
        {
            int mid = ((l + r) >> 1);
            if(v[mid].ra < v[i].la)
                l = mid + 1;
            else
                r = mid;
        }
        v[i].cnt = r - l;
        v[i].h1 = (sp1[i] - sp1[l - 1] + MOD1) % MOD1;
        v[i].h2 = (sp2[i] - sp2[l - 1] + MOD2) % MOD2;
    }
    sort(v + 1, v + n + 1, fb);
    for(int i = 1; i <= n; i++)
        sp1[i] = (1LL * sp1[i - 1] + p1[v[i].index]) % MOD1;
    for(int i = 1; i <= n; i++)
        sp2[i] = (1LL * sp2[i - 1] + p2[v[i].index]) % MOD2;
    for(int i = 1; i <= n; i++)
    {
        int l = 1, r = i;
        while(l < r)
        {
            int mid = ((l + r) >> 1);
            if(v[mid].rb < v[i].lb)
                l = mid + 1;
            else
                r = mid;
        }
        if(r - l != v[i].cnt || v[i].h1 != (sp1[i] - sp1[l - 1] + MOD1) % MOD1 || v[i].h2 != (sp2[i] - sp2[l - 1] + MOD2) % MOD2)
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MOD = 1000000000000037;

const int N_MAX = 100002;

int n;

struct Segment
{
    int la, ra;
    int lb, rb;
    int index;
    ll h;
};

bool fa (const Segment &a, const Segment &b)
{
    return a.ra < b.ra;
}

bool fb (const Segment &a, const Segment &b)
{
    return a.rb < b.rb;
}

Segment v[N_MAX];

ll p2[N_MAX];

ll sp[N_MAX];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> v[i].la >> v[i].ra >> v[i].lb >> v[i].rb;
        v[i].index = i;
    }
    p2[0] = 1;
    for(int i = 1; i <= n; i++)
        p2[i] = 2LL * p2[i - 1] % MOD;
    sort(v + 1, v + n + 1, fa);
    for(int i = 1; i <= n; i++)
        sp[i] = (1LL * sp[i - 1] + p2[v[i].index]) % MOD;
    for(int i = 1; i <= n; i++)
    {
        int l = 1, r = i;
        while(l < r)
        {
            int mid = ((l + r) >> 1);
            if(v[mid].ra < v[i].la)
                l = mid + 1;
            else
                r = mid;
        }
        v[i].h = (sp[i] - sp[l - 1] + MOD) % MOD;
    }
    sort(v + 1, v + n + 1, fb);
    for(int i = 1; i <= n; i++)
        sp[i] = (1LL * sp[i - 1] + p2[v[i].index]) % MOD;
    for(int i = 1; i <= n; i++)
    {
        int l = 1, r = i;
        while(l < r)
        {
            int mid = ((l + r) >> 1);
            if(v[mid].rb < v[i].lb)
                l = mid + 1;
            else
                r = mid;
        }
        if(v[i].h != (sp[i] - sp[l - 1] + MOD) % MOD)
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long int ll;
const int maxn = 4e5 + 10;
int a[maxn],tree[2][maxn],n;
struct node{
    int st1,en1,st2,en2;
}p[maxn];

int lowbit(int i){
    return i & (-i);
}

void insert(int i,int c,int k){
    while(i < maxn){
        tree[k][i] += c;
        i += lowbit(i);
    }
}

int get_sum(int i,int k){
    int res = 0;
    while(i > 0){
        res += tree[k][i];
        i -= lowbit(i);
    }
    return res;
}

bool cmp1(node a,node b){
    return a.en1 < b.en1;
}

bool cmp2(node a,node b){
    return a.st2 < b.st2;
}

int solve(){
    int flag = 0;
    sort(p + 1,p + n + 1,cmp1);
    int l = 1,r = 1;
    for(int i = 1;i <= n;i++){
        while(r <= n && p[r].st1 <= p[i].en1){
            insert(p[r].st2,1,0);
            insert(p[r].en2,1,1);
            r++;
        }
        while(l < r && p[l].en1 < p[i].st1){
            insert(p[l].st2,-1,0);
            insert(p[l].en2,-1,1);
            l++;
        }
        int temp = 0;
        //temp = ((r - l) - get_sum(p[i].en2,0)) + get_sum(p[i].st2 - 1,1);
        //temp = r - l - temp;
        if(get_sum(p[i].en2,0) != r - l || get_sum(p[i].st2 - 1,1) != 0){
            return 1;
        }
        /*if(temp != r - l){
            flag = 1;
            break;
        }*/
    }
    return 0;
}

int main(){
    while(scanf("%d",&n) != EOF){
        memset(tree,0,sizeof(tree));
        int cnt = 0;
        for(int i = 1;i <= n;i++){
            scanf("%d%d%d%d",&p[i].st1,&p[i].en1,&p[i].st2,&p[i].en2);
            a[++cnt] = p[i].st1;
            a[++cnt] = p[i].en1;
            a[++cnt] = p[i].st2;
            a[++cnt] = p[i].en2;
        }

        sort(a + 1,a + cnt + 1);
        cnt = unique(a + 1,a + cnt + 1) - a - 1;
        for(int i = 1;i <= n;i++){
            p[i].st1 = lower_bound(a + 1,a + cnt + 1,p[i].st1) - a;
            p[i].en1 = lower_bound(a + 1,a + cnt + 1,p[i].en1) - a;
            p[i].st2 = lower_bound(a + 1,a + cnt + 1,p[i].st2) - a;
            p[i].en2 = lower_bound(a + 1,a + cnt + 1,p[i].en2) - a;
        }

        if(solve() == 1){
            printf("NO\n");
            continue;
        }

        for(int i = 1;i <= n;i++){
            swap(p[i].st1,p[i].st2);
            swap(p[i].en1,p[i].en2);
        }

        memset(tree,0,sizeof(tree));

        if(solve() == 1){
            printf("NO\n");
            continue;
        }
        printf("YES\n");
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long int ll;
const int maxn = 4e5 + 10;
int a[maxn],st1[maxn],en1[maxn],st2[maxn],en2[maxn],tree[2][maxn],n;
struct node{
    int st1,en1,st2,en2;
}p[maxn];

int lowbit(int i){
    return i & (-i);
}

void insert(int i,int c,int k){
    while(i < maxn){
        tree[k][i] += c;
        i += lowbit(i);
    }
}

int get_sum(int i,int k){
    int res = 0;
    while(i > 0){
        res += tree[k][i];
        i -= lowbit(i);
    }
    return res;
}

bool cmp1(node a,node b){
    return a.st1 < b.st1;
}

bool cmp2(node a,node b){
    return a.st2 < b.st2;
}

int solve(){
    int flag = 0;
    sort(p + 1,p + n + 1,cmp1);
    int l = 1,r = 1;
    for(int i = 1;i <= n;i++){
        while(r <= n && p[r].st1 <= p[i].en1){
            insert(p[r].st2,1,0);
            insert(p[r].en2,1,1);
            r++;
        }
        while(l < r && p[l].en1 < p[i].st1){
            insert(p[l].st2,-1,0);
            insert(p[l].en2,-1,1);
            l++;
        }
        int temp = 0;
        //temp = ((r - l) - get_sum(p[i].en2,0)) + get_sum(p[i].st2 - 1,1);
        //temp = r - l - temp;
        if(get_sum(p[i].en2,0) != r - l || get_sum(p[i].st2 - 1,1) != 0){
            return 1;
        }
        /*if(temp != r - l){
            flag = 1;
            break;
        }*/
    }
    return 0;
}

int main(){
    while(scanf("%d",&n) != EOF){
        memset(tree,0,sizeof(tree));
        int cnt = 0;
        for(int i = 1;i <= n;i++){
            scanf("%d%d%d%d",&p[i].st1,&p[i].en1,&p[i].st2,&p[i].en2);
            a[++cnt] = p[i].st1;
            a[++cnt] = p[i].en1;
            a[++cnt] = p[i].st2;
            a[++cnt] = p[i].en2;
        }

        sort(a + 1,a + cnt + 1);
        cnt = unique(a + 1,a + cnt + 1) - a - 1;
        for(int i = 1;i <= n;i++){
            p[i].st1 = lower_bound(a + 1,a + cnt + 1,p[i].st1) - a;
            p[i].en1 = lower_bound(a + 1,a + cnt + 1,p[i].en1) - a;
            p[i].st2 = lower_bound(a + 1,a + cnt + 1,p[i].st2) - a;
            p[i].en2 = lower_bound(a + 1,a + cnt + 1,p[i].en2) - a;
        }

        if(solve() == 1){
            printf("NO\n");
            continue;
        }

        /*for(int i = 1;i <= n;i++){
            swap(p[i].st1,p[i].st2);
            swap(p[i].en1,p[i].en2);
        }

        memset(tree,0,sizeof(tree));

        if(solve() == 1){
            printf("NO\n");
            continue;
        }*/
        printf("YES\n");
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long int ll;
const int maxn = 1e5 + 10;
int a[maxn],st1[maxn],en1[maxn],st2[maxn],en2[maxn],tree[2][maxn];
struct node{
    int st1,en1,st2,en2;
}p[maxn];

int lowbit(int i){
    return i & (-i);
}

void insert(int i,int c,int k){
    while(i < maxn){
        tree[k][i] += c;
        i += lowbit(i);
    }
}

int get_sum(int i,int k){
    int res = 0;
    while(i > 0){
        res += tree[k][i];
        i -= lowbit(i);
    }
    return res;
}

bool cmp1(node a,node b){
    return a.st1 < b.st1;
}

bool cmp2(node a,node b){
    return a.st2 < b.st2;
}

int main(){
    int n;
    while(scanf("%d",&n) != EOF){
        memset(tree,0,sizeof(tree));
        int cnt = 0;
        for(int i = 1;i <= n;i++){
            scanf("%d%d%d%d",&p[i].st1,&p[i].en1,&p[i].st2,&p[i].en2);
            a[++cnt] = p[i].st1;
            a[++cnt] = p[i].en1;
            a[++cnt] = p[i].st2;
            a[++cnt] = p[i].en2;
        }

        sort(a + 1,a + cnt + 1);
        cnt = unique(a + 1,a + cnt + 1) - a - 1;
        for(int i = 1;i <= n;i++){
            p[i].st1 = lower_bound(a + 1,a + cnt + 1,p[i].st1) - a;
            p[i].en1 = lower_bound(a + 1,a + cnt + 1,p[i].en1) - a;
            p[i].st2 = lower_bound(a + 1,a + cnt + 1,p[i].st2) - a;
            p[i].en2 = lower_bound(a + 1,a + cnt + 1,p[i].en2) - a;
            //printf("%d %d %d %d\n",p[i].st1,p[i].en1,p[i].st2,p[i].en2);
        }

        int flag = 0;
        sort(p + 1,p + n + 1,cmp1);
        int l = 1,r = 1;
        for(int i = 1;i <= n;i++){
            while(r <= n && p[r].st1 <= p[i].en1){
                insert(p[r].st2,1,0);
                insert(p[r].en2,1,1);
                r++;
            }
            while(l < r && p[l].en1 < p[i].st1){
                insert(p[l].st2,-1,0);
                insert(p[l].en2,-1,1);
                l++;
            }
            int temp = 0;
            temp = ((r - l) - get_sum(p[i].en2,0)) + get_sum(p[i].st2 - 1,1);
            temp = r - l - temp;
            //printf("*** %d\n",i);
            //printf("*** %d %d %d\n\n",l,r,temp);
            if(temp != r - l){
                flag = 1;
                //printf("*** %d\n",i);
                //printf("*** %d %d %d\n",l,r,temp);
                break;
            }
        }
        if(flag == 1){
            printf("NO\n");
        }
        else{
            printf("YES\n");
        }
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long int ll;
const int maxn = 4e5 + 10;
int a[maxn],st1[maxn],en1[maxn],st2[maxn],en2[maxn],tree[2][maxn];
struct node{
    int st1,en1,st2,en2;
}p[maxn];

int lowbit(int i){
    return i & (-i);
}

void insert(int i,int c,int k){
    while(i < maxn){
        tree[k][i] += c;
        i += lowbit(i);
    }
}

int get_sum(int i,int k){
    int res = 0;
    while(i > 0){
        res += tree[k][i];
        i -= lowbit(i);
    }
    return res;
}

bool cmp1(node a,node b){
    return a.st1 < b.st1;
}

bool cmp2(node a,node b){
    return a.st2 < b.st2;
}

int main(){
    int n;
    while(scanf("%d",&n) != EOF){
        memset(tree,0,sizeof(tree));
        int cnt = 0;
        for(int i = 1;i <= n;i++){
            scanf("%d%d%d%d",&p[i].st1,&p[i].en1,&p[i].st2,&p[i].en2);
            a[++cnt] = p[i].st1;
            a[++cnt] = p[i].en1;
            a[++cnt] = p[i].st2;
            a[++cnt] = p[i].en2;
        }

        sort(a + 1,a + cnt + 1);
        cnt = unique(a + 1,a + cnt + 1) - a - 1;
        for(int i = 1;i <= n;i++){
            p[i].st1 = lower_bound(a + 1,a + cnt + 1,p[i].st1) - a;
            p[i].en1 = lower_bound(a + 1,a + cnt + 1,p[i].en1) - a;
            p[i].st2 = lower_bound(a + 1,a + cnt + 1,p[i].st2) - a;
            p[i].en2 = lower_bound(a + 1,a + cnt + 1,p[i].en2) - a;
            //printf("%d %d %d %d\n",p[i].st1,p[i].en1,p[i].st2,p[i].en2);
        }

        int flag = 0;
        sort(p + 1,p + n + 1,cmp1);
        int l = 1,r = 1;
        for(int i = 1;i <= n;i++){
            while(r <= n && p[r].st1 <= p[i].en1){
                insert(p[r].st2,1,0);
                insert(p[r].en2,1,1);
                r++;
            }
            while(l < r && p[l].en1 < p[i].st1){
                insert(p[l].st2,-1,0);
                insert(p[l].en2,-1,1);
                l++;
            }
            int temp = 0;
            temp = ((r - l) - get_sum(p[i].en2,0)) + get_sum(p[i].st2 - 1,1);
            temp = r - l - temp;
            //printf("*** %d\n",i);
            //printf("*** %d %d %d\n\n",l,r,temp);
            if(temp != r - l){
                flag = 1;
                //printf("*** %d\n",i);
                //printf("*** %d %d %d\n",l,r,temp);
                break;
            }
        }
        if(flag == 1){
            printf("NO\n");
        }
        else{
            printf("YES\n");
        }
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long int ll;
const int maxn = 4e5 + 10;
int a[maxn],tree[2][maxn],n;
struct node{
    int st1,en1,st2,en2;
}p[maxn];

int lowbit(int i){
    return i & (-i);
}

void insert(int i,int c,int k){
    while(i < maxn){
        tree[k][i] += c;
        i += lowbit(i);
    }
}

int get_sum(int i,int k){
    int res = 0;
    while(i > 0){
        res += tree[k][i];
        i -= lowbit(i);
    }
    return res;
}

bool cmp1(node a,node b){
    return a.en1 < b.en1;
}

bool cmp2(node a,node b){
    return a.st2 < b.st2;
}

int solve(){
    int flag = 0;
    sort(p + 1,p + n + 1,cmp1);
    int l = 1,r = 1;
    for(int i = 1;i <= n;i++){
        while(r <= n && p[r].st1 <= p[i].en1){
            insert(p[r].st2,1,0);
            insert(p[r].en2,1,1);
            r++;
        }
        while(l < r && p[l].en1 < p[i].st1){
            insert(p[l].st2,-1,0);
            insert(p[l].en2,-1,1);
            l++;
        }
        int temp = 0;
        //temp = ((r - l) - get_sum(p[i].en2,0)) + get_sum(p[i].st2 - 1,1);
        //temp = r - l - temp;
        if(get_sum(p[i].en2,0) != r - l || get_sum(p[i].st2 - 1,1) != 0){
            return 1;
        }
        /*if(temp != r - l){
            flag = 1;
            break;
        }*/
    }
    return 0;
}

int main(){
    while(scanf("%d",&n) != EOF){
        memset(tree,0,sizeof(tree));
        int cnt = 0;
        for(int i = 1;i <= n;i++){
            scanf("%d%d%d%d",&p[i].st1,&p[i].en1,&p[i].st2,&p[i].en2);
            a[++cnt] = p[i].st1;
            a[++cnt] = p[i].en1;
            a[++cnt] = p[i].st2;
            a[++cnt] = p[i].en2;
        }

        sort(a + 1,a + cnt + 1);
        cnt = unique(a + 1,a + cnt + 1) - a - 1;
        for(int i = 1;i <= n;i++){
            p[i].st1 = lower_bound(a + 1,a + cnt + 1,p[i].st1) - a;
            p[i].en1 = lower_bound(a + 1,a + cnt + 1,p[i].en1) - a;
            p[i].st2 = lower_bound(a + 1,a + cnt + 1,p[i].st2) - a;
            p[i].en2 = lower_bound(a + 1,a + cnt + 1,p[i].en2) - a;
        }

        if(solve() == 1){
            printf("NO\n");
            continue;
        }

       /* for(int i = 1;i <= n;i++){
            swap(p[i].st1,p[i].st2);
            swap(p[i].en1,p[i].en2);
        }

        memset(tree,0,sizeof(tree));

        if(solve() == 1){
            printf("NO\n");
            continue;
        }*/
        printf("YES\n");
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long int ll;
const int maxn = 4e5 + 10;
int a[maxn],tree[2][maxn],n;
struct node{
    int st1,en1,st2,en2;
}p[maxn];

int lowbit(int i){
    return i & (-i);
}

void insert(int i,int c,int k){
    while(i < maxn){
        tree[k][i] += c;
        i += lowbit(i);
    }
}

int get_sum(int i,int k){
    int res = 0;
    while(i > 0){
        res += tree[k][i];
        i -= lowbit(i);
    }
    return res;
}

bool cmp1(node a,node b){
    return a.st1 < b.st1;
}

bool cmp2(node a,node b){
    return a.st2 < b.st2;
}

int solve(){
    int flag = 0;
    sort(p + 1,p + n + 1,cmp1);
    int l = 1,r = 1;
    for(int i = 1;i <= n;i++){
        while(r <= n && p[r].st1 <= p[i].en1){
            insert(p[r].st2,1,0);
            insert(p[r].en2,1,1);
            r++;
        }
        while(l < r && p[l].en1 < p[i].st1){
            insert(p[l].st2,-1,0);
            insert(p[l].en2,-1,1);
            l++;
        }
        int temp = 0;
        //temp = ((r - l) - get_sum(p[i].en2,0)) + get_sum(p[i].st2 - 1,1);
        //temp = r - l - temp;
        if(get_sum(p[i].en2,0) != r - l || get_sum(p[i].st2 - 1,1) != 0){
            return 1;
        }
        /*if(temp != r - l){
            flag = 1;
            break;
        }*/
    }
    return 0;
}

int main(){
    while(scanf("%d",&n) != EOF){
        memset(tree,0,sizeof(tree));
        int cnt = 0;
        for(int i = 1;i <= n;i++){
            scanf("%d%d%d%d",&p[i].st1,&p[i].en1,&p[i].st2,&p[i].en2);
            a[++cnt] = p[i].st1;
            a[++cnt] = p[i].en1;
            a[++cnt] = p[i].st2;
            a[++cnt] = p[i].en2;
        }

        sort(a + 1,a + cnt + 1);
        cnt = unique(a + 1,a + cnt + 1) - a;
        for(int i = 1;i <= n;i++){
            p[i].st1 = lower_bound(a + 1,a + cnt + 1,p[i].st1) - a;
            p[i].en1 = lower_bound(a + 1,a + cnt + 1,p[i].en1) - a;
            p[i].st2 = lower_bound(a + 1,a + cnt + 1,p[i].st2) - a;
            p[i].en2 = lower_bound(a + 1,a + cnt + 1,p[i].en2) - a;
        }

        if(solve() == 1){
            printf("NO\n");
            continue;
        }

        /*for(int i = 1;i <= n;i++){
            swap(p[i].st1,p[i].st2);
            swap(p[i].en1,p[i].en2);
        }

        memset(tree,0,sizeof(tree));

        if(solve() == 1){
            printf("NO\n");
            continue;
        }*/
        printf("YES\n");
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long int ll;
const int maxn = 4e5 + 10;
int a[maxn],st1[maxn],en1[maxn],st2[maxn],en2[maxn],tree[2][maxn],n;
struct node{
    int st1,en1,st2,en2;
}p[maxn];

int lowbit(int i){
    return i & (-i);
}

void insert(int i,int c,int k){
    while(i < maxn){
        tree[k][i] += c;
        i += lowbit(i);
    }
}

int get_sum(int i,int k){
    int res = 0;
    while(i > 0){
        res += tree[k][i];
        i -= lowbit(i);
    }
    return res;
}

bool cmp1(node a,node b){
    return a.st1 < b.st1;
}

bool cmp2(node a,node b){
    return a.st2 < b.st2;
}

int solve(){
    int flag = 0;
    sort(p + 1,p + n + 1,cmp1);
    int l = 1,r = 1;
    for(int i = 1;i <= n;i++){
        while(r <= n && p[r].st1 <= p[i].en1){
            insert(p[r].st2,1,0);
            insert(p[r].en2,1,1);
            r++;
        }
        while(l < r && p[l].en1 < p[i].st1){
            insert(p[l].st2,-1,0);
            insert(p[l].en2,-1,1);
            l++;
        }
        int temp = 0;
        temp = ((r - l) - get_sum(p[i].en2,0)) + get_sum(p[i].st2 - 1,1);
        temp = r - l - temp;
        if(temp != r - l){
            flag = 1;
            break;
        }
    }
    return flag;
}

int main(){
    while(scanf("%d",&n) != EOF){
        memset(tree,0,sizeof(tree));
        int cnt = 0;
        for(int i = 1;i <= n;i++){
            scanf("%d%d%d%d",&p[i].st1,&p[i].en1,&p[i].st2,&p[i].en2);
            a[++cnt] = p[i].st1;
            a[++cnt] = p[i].en1;
            a[++cnt] = p[i].st2;
            a[++cnt] = p[i].en2;
        }

        sort(a + 1,a + cnt + 1);
        cnt = unique(a + 1,a + cnt + 1) - a - 1;
        for(int i = 1;i <= n;i++){
            p[i].st1 = lower_bound(a + 1,a + cnt + 1,p[i].st1) - a;
            p[i].en1 = lower_bound(a + 1,a + cnt + 1,p[i].en1) - a;
            p[i].st2 = lower_bound(a + 1,a + cnt + 1,p[i].st2) - a;
            p[i].en2 = lower_bound(a + 1,a + cnt + 1,p[i].en2) - a;
        }

        if(solve() == 1){
            printf("NO\n");
            continue;
        }

        for(int i = 1;i <= n;i++){
            swap(p[i].st1,p[i].st2);
            swap(p[i].en1,p[i].en2);
        }
        sort(p + 1,p + n + 1,cmp1);
        memset(tree,0,sizeof(tree));

        if(solve() == 1){
            printf("NO\n");
            continue;
        }
        printf("YES\n");
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long int ll;
const int maxn = 4e5 + 10;
int a[maxn],tree[2][maxn],n;
struct node{
    int st1,en1,st2,en2;
}p[maxn];

int lowbit(int i){
    return i & (-i);
}

void insert(int i,int c,int k){
    while(i < maxn){
        tree[k][i] += c;
        i += lowbit(i);
    }
}

int get_sum(int i,int k){
    int res = 0;
    while(i > 0){
        res += tree[k][i];
        i -= lowbit(i);
    }
    return res;
}

bool cmp1(node a,node b){
    return a.st1 < b.st1;
}

bool cmp2(node a,node b){
    return a.st2 < b.st2;
}

int solve(){
    int flag = 0;
    sort(p + 1,p + n + 1,cmp1);
    int l = 1,r = 1;
    for(int i = 1;i <= n;i++){
        while(r <= n && p[r].st1 <= p[i].en1){
            insert(p[r].st2,1,0);
            insert(p[r].en2,1,1);
            r++;
        }
        while(l < r && p[l].en1 < p[i].st1){
            insert(p[l].st2,-1,0);
            insert(p[l].en2,-1,1);
            l++;
        }
        int temp = 0;
        //temp = ((r - l) - get_sum(p[i].en2,0)) + get_sum(p[i].st2 - 1,1);
        //temp = r - l - temp;
        if(get_sum(p[i].en2,0) != r - l || get_sum(p[i].st2 - 1,1) != 0){
            return 1;
        }
        /*if(temp != r - l){
            flag = 1;
            break;
        }*/
    }
    return 0;
}

int main(){
    while(scanf("%d",&n) != EOF){
        memset(tree,0,sizeof(tree));
        int cnt = 0;
        for(int i = 1;i <= n;i++){
            scanf("%d%d%d%d",&p[i].st1,&p[i].en1,&p[i].st2,&p[i].en2);
            a[++cnt] = p[i].st1;
            a[++cnt] = p[i].en1;
            a[++cnt] = p[i].st2;
            a[++cnt] = p[i].en2;
        }

        sort(a + 1,a + cnt + 1);
        cnt = unique(a + 1,a + cnt + 1) - a;
        for(int i = 1;i <= n;i++){
            p[i].st1 = lower_bound(a + 1,a + cnt + 1,p[i].st1) - a;
            p[i].en1 = lower_bound(a + 1,a + cnt + 1,p[i].en1) - a;
            p[i].st2 = lower_bound(a + 1,a + cnt + 1,p[i].st2) - a;
            p[i].en2 = lower_bound(a + 1,a + cnt + 1,p[i].en2) - a;
        }

        if(solve() == 1){
            printf("NO\n");
            continue;
        }

        for(int i = 1;i <= n;i++){
            swap(p[i].st1,p[i].st2);
            swap(p[i].en1,p[i].en2);
        }

        memset(tree,0,sizeof(tree));

        if(solve() == 1){
            printf("NO\n");
            continue;
        }
        printf("YES\n");
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long int ll;
const int maxn = 4e5 + 10;
int a[maxn],st1[maxn],en1[maxn],st2[maxn],en2[maxn],tree[2][maxn],n;
struct node{
    int st1,en1,st2,en2;
}p[maxn];

int lowbit(int i){
    return i & (-i);
}

void insert(int i,int c,int k){
    while(i < maxn){
        tree[k][i] += c;
        i += lowbit(i);
    }
}

int get_sum(int i,int k){
    int res = 0;
    while(i > 0){
        res += tree[k][i];
        i -= lowbit(i);
    }
    return res;
}

bool cmp1(node a,node b){
    return a.st1 < b.st1;
}

bool cmp2(node a,node b){
    return a.st2 < b.st2;
}

int solve(){
    int flag = 0;
    sort(p + 1,p + n + 1,cmp1);
    int l = 1,r = 1;
    for(int i = 1;i <= n;i++){
        while(r <= n && p[r].st1 <= p[i].en1){
            insert(p[r].st2,1,0);
            insert(p[r].en2,1,1);
            r++;
        }
        while(l < r && p[l].en1 < p[i].st1){
            insert(p[l].st2,-1,0);
            insert(p[l].en2,-1,1);
            l++;
        }
        int temp = 0;
        //temp = ((r - l) - get_sum(p[i].en2,0)) + get_sum(p[i].st2 - 1,1);
        //temp = r - l - temp;
        if(get_sum(p[i].en2,0) != r - l || get_sum(p[i].st2 - 1,1) != 0){
            return 1;
        }
        /*if(temp != r - l){
            flag = 1;
            break;
        }*/
    }
    return 0;
}

int main(){
    while(scanf("%d",&n) != EOF){
        memset(tree,0,sizeof(tree));
        int cnt = 0;
        for(int i = 1;i <= n;i++){
            scanf("%d%d%d%d",&p[i].st1,&p[i].en1,&p[i].st2,&p[i].en2);
            a[++cnt] = p[i].st1;
            a[++cnt] = p[i].en1;
            a[++cnt] = p[i].st2;
            a[++cnt] = p[i].en2;
        }

        sort(a + 1,a + cnt + 1);
        cnt = unique(a + 1,a + cnt + 1) - a - 1;
        for(int i = 1;i <= n;i++){
            p[i].st1 = lower_bound(a + 1,a + cnt + 1,p[i].st1) - a;
            p[i].en1 = lower_bound(a + 1,a + cnt + 1,p[i].en1) - a;
            p[i].st2 = lower_bound(a + 1,a + cnt + 1,p[i].st2) - a;
            p[i].en2 = lower_bound(a + 1,a + cnt + 1,p[i].en2) - a;
        }

        if(solve() == 1){
            printf("NO\n");
            continue;
        }

        for(int i = 1;i <= n;i++){
            swap(p[i].st1,p[i].st2);
            swap(p[i].en1,p[i].en2);
        }

        memset(tree,0,sizeof(tree));

        if(solve() == 1){
            printf("NO\n");
            continue;
        }
        printf("YES\n");
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define taskname "1284D"
#define forinc(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define fordec(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define foreach(i, x) for (auto &i : x)
#define ms(x, n) memset(x, n, sizeof(x))
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define fi first
#define se second
#define pb push_back
#define pf push_front

template<typename TH>
void _dbg(const char* sdbg, TH h)
{
	cerr << sdbg << " = " << h << "\n";
}

template<typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t)
{
	while (*sdbg != ',') cerr << *sdbg++;
	cerr << " = " << h << ",";
	_dbg(sdbg + 1, t...);
}

#define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define chkpt cerr << "--- Checkpoint here ---\n";

const int N=1e5+5;

int n,sa[N],ea[N],sb[N],eb[N];

bool Solve()
{
    forinc(i,1,n)
    {
        forinc(j,i+1,n)
        {
            if(max(sa[i],sa[j])<=min(ea[i],ea[j])&&max(sb[i],sb[j])>min(eb[i],eb[j]))
            {
                return false;
            }
            if(max(sb[i],sb[j])<=min(eb[i],eb[j])&&max(sa[i],sa[j])>min(ea[i],ea[j]))
            {
                return false;
            }
        }
    }
    return true;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifndef ONLINE_JUDGE
	freopen(taskname".INP","r",stdin);
	#endif // ONLINE_JUDGE
	cin>>n;
	forinc(i,1,n)
	{
	    cin>>sa[i]>>ea[i]>>sb[i]>>eb[i];
	}
	cout<<(Solve()?"YES":"NO")<<'\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define taskname "1284D"
#define forinc(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define fordec(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define foreach(i, x) for (auto &i : x)
#define ms(x, n) memset(x, n, sizeof(x))
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define fi first
#define se second
#define pb push_back
#define pf push_front

template<typename TH>
void _dbg(const char* sdbg, TH h)
{
	cerr << sdbg << " = " << h << "\n";
}

template<typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t)
{
	while (*sdbg != ',') cerr << *sdbg++;
	cerr << " = " << h << ",";
	_dbg(sdbg + 1, t...);
}

#define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define chkpt cerr << "--- Checkpoint here ---\n";

const int N=1e5+5;

int n,sa[N],ea[N],sb[N],eb[N];

int64_t Random(int64_t l, int64_t r) {
	return l + ((int64_t) rand() * (RAND_MAX + 1) * (RAND_MAX + 1) * (RAND_MAX + 1)
				+ (int64_t) rand() * (RAND_MAX + 1) * (RAND_MAX + 1)
				+ (int64_t) rand() * (RAND_MAX + 1)
				+ (int64_t) rand()) % (r - l + 1);
}

bool Solve()
{
    forinc(i,1,n-1)
    {
        if(n<=5000)
        {
            forinc(j,i+1,n)
            {
                if(max(sa[i],sa[j])<=min(ea[i],ea[j])&&max(sb[i],sb[j])>min(eb[i],eb[j]))
                {
                    return false;
                }
                if(max(sb[i],sb[j])<=min(eb[i],eb[j])&&max(sa[i],sa[j])>min(ea[i],ea[j]))
                {
                    return false;
                }
            }
        }
        else
        {
            srand(time(0));
            forinc(k,1,1e8/n)
            {
                int j=Random(i+1,n);
                if(max(sa[i],sa[j])<=min(ea[i],ea[j])&&max(sb[i],sb[j])>min(eb[i],eb[j]))
                {
                    return false;
                }
                if(max(sb[i],sb[j])<=min(eb[i],eb[j])&&max(sa[i],sa[j])>min(ea[i],ea[j]))
                {
                    return false;
                }
            }
        }
    }
    return true;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifndef ONLINE_JUDGE
	freopen(taskname".INP","r",stdin);
	#endif // ONLINE_JUDGE
	cin>>n;
	forinc(i,1,n)
	{
	    cin>>sa[i]>>ea[i]>>sb[i]>>eb[i];
	}
	cout<<(Solve()?"YES":"NO")<<'\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define taskname "1284D"
#define forinc(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define fordec(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define foreach(i, x) for (auto &i : x)
#define ms(x, n) memset(x, n, sizeof(x))
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define fi first
#define se second
#define pb push_back
#define pf push_front

template<typename TH>
void _dbg(const char* sdbg, TH h)
{
	cerr << sdbg << " = " << h << "\n";
}

template<typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t)
{
	while (*sdbg != ',') cerr << *sdbg++;
	cerr << " = " << h << ",";
	_dbg(sdbg + 1, t...);
}

#define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define chkpt cerr << "--- Checkpoint here ---\n";

const int N=1e5+5;

struct Event
{
    int val,type,id;

    bool operator<(const Event& other) const
    {
        if(val==other.val)
        {
            return type<other.type;
        }
        return val<other.val;
    }
};

struct Result
{
    int minVal,maxVal,cnt;

    Result():minVal(0),maxVal(0),cnt(0)
    {

    }

    bool operator!=(const Result& other) const
    {
        return !(minVal==other.minVal&&maxVal==other.maxVal&&cnt==other.cnt);
    }
};

int n,sa[N],ea[N],sb[N],eb[N];
Result a[N],b[N];

bool Solve()
{
    // sweep line a
    vector<Event> eventList;
    forinc(i,1,n)
    {
        eventList.pb({sa[i],0,i});
        eventList.pb({ea[i],1,i});
    }
    sort(all(eventList));
    set<int> activeIDList;
    foreach(event,eventList)
    {
        if(event.type==0)
        {
            if(sz(activeIDList))
            {
                a[event.id].minVal=*activeIDList.begin();
                a[event.id].maxVal=*activeIDList.rbegin();
                a[event.id].cnt=sz(activeIDList);
            }
            activeIDList.insert(event.id);
        }
        else
        {
            activeIDList.erase(event.id);
        }
    }

    // sweep line b
    eventList.clear();
    forinc(i,1,n)
    {
        eventList.pb({sb[i],0,i});
        eventList.pb({eb[i],1,i});
    }
    sort(all(eventList));
    foreach(event,eventList)
    {
        if(event.type==0)
        {
            if(sz(activeIDList))
            {
                b[event.id].minVal=*activeIDList.begin();
                b[event.id].maxVal=*activeIDList.rbegin();
                b[event.id].cnt=sz(activeIDList);
            }
            activeIDList.insert(event.id);
        }
        else
        {
            activeIDList.erase(event.id);
        }
    }

    forinc(i,1,n)
    {
        if(a[i]!=b[i])
        {
            return false;
        }
    }
    return true;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifndef ONLINE_JUDGE
	freopen(taskname".INP","r",stdin);
	#endif // ONLINE_JUDGE
	cin>>n;
	forinc(i,1,n)
	{
	    cin>>sa[i]>>ea[i]>>sb[i]>>eb[i];
	}
	cout<<(Solve()?"YES":"NO")<<'\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define taskname "1284D"
#define forinc(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define fordec(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define foreach(i, x) for (auto &i : x)
#define ms(x, n) memset(x, n, sizeof(x))
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define fi first
#define se second
#define pb push_back
#define pf push_front

template<typename TH>
void _dbg(const char* sdbg, TH h)
{
	cerr << sdbg << " = " << h << "\n";
}

template<typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t)
{
	while (*sdbg != ',') cerr << *sdbg++;
	cerr << " = " << h << ",";
	_dbg(sdbg + 1, t...);
}

#define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define chkpt cerr << "--- Checkpoint here ---\n";

const int N=1e5+5;

struct Event
{
    int val,type,id;

    bool operator<(const Event& other) const
    {
        if(val==other.val)
        {
            return type<other.type;
        }
        return val<other.val;
    }
};

int n,sa[N],ea[N],sb[N],eb[N];
int l[N],r[N],tme;
int ftL[2*N],ftR[2*N];

void UpdateL(int id,int delta)
{
    for(int i=id;i>0;i-=i&-i)
    {
        ftL[i]+=delta;
    }
}

int QueryL(int id)
{
    int res=0;
    for(int i=id;i<2*N;i+=i&-i)
    {
        res+=ftL[i];
    }
    return res;
}

void UpdateR(int id,int delta)
{
    for(int i=id;i<2*N;i+=i&-i)
    {
        ftR[i]+=delta;
    }
}

int QueryR(int id)
{
    int res=0;
    for(int i=id;i>0;i-=i&-i)
    {
        res+=ftR[i];
    }
    return res;
}

bool Solve()
{
    forinc(i,1,n)
    {
        l[i]=r[i]=0;
    }
    forinc(i,1,2*N-1)
    {
        ftL[i]=ftR[i]=0;
    }
    // sweep line a
    vector<Event> eventList;
    forinc(i,1,n)
    {
        eventList.pb({sa[i],0,i});
        eventList.pb({ea[i],1,i});
    }
    sort(all(eventList));
    foreach(event,eventList)
    {
        tme++;
        if(event.type==0)
        {
            l[event.id]=tme;
        }
        else
        {
            r[event.id]=tme;
        }
    }

    // sweep line b
    eventList.clear();
    forinc(i,1,n)
    {
        eventList.pb({sb[i],0,i});
        eventList.pb({eb[i],1,i});
    }
    sort(all(eventList));
    foreach(event,eventList)
    {
        if(event.type==0)
        {
            if(QueryL(l[event.id]+1)>0||QueryR(l[event.id]-1)>0)
            {
                return false;
            }
            UpdateL(l[event.id],1);
            UpdateR(r[event.id],1);
        }
        else
        {
            UpdateL(l[event.id],-1);
            UpdateR(r[event.id],-1);
        }
    }

    return true;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifndef ONLINE_JUDGE
	freopen(taskname".INP","r",stdin);
	#endif // ONLINE_JUDGE
	cin>>n;
	forinc(i,1,n)
	{
	    cin>>sa[i]>>ea[i]>>sb[i]>>eb[i];
	}
	bool res1=Solve();
	forinc(i,1,n)
	{
	    swap(sa[i],sb[i]);
	    swap(ea[i],eb[i]);
	}
	bool res2=Solve();
    if(res1&&res2)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define taskname "1284D"
#define forinc(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define fordec(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define foreach(i, x) for (auto &i : x)
#define ms(x, n) memset(x, n, sizeof(x))
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define fi first
#define se second
#define pb push_back
#define pf push_front

template<typename TH>
void _dbg(const char* sdbg, TH h)
{
	cerr << sdbg << " = " << h << "\n";
}

template<typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t)
{
	while (*sdbg != ',') cerr << *sdbg++;
	cerr << " = " << h << ",";
	_dbg(sdbg + 1, t...);
}

#define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define chkpt cerr << "--- Checkpoint here ---\n";

const int N=1e5+5;

int n,sa[N],ea[N],sb[N],eb[N];

int64_t Random(int64_t l, int64_t r) {
	return l + ((int64_t) rand() * (RAND_MAX + 1) * (RAND_MAX + 1) * (RAND_MAX + 1)
				+ (int64_t) rand() * (RAND_MAX + 1) * (RAND_MAX + 1)
				+ (int64_t) rand() * (RAND_MAX + 1)
				+ (int64_t) rand()) % (r - l + 1);
}

bool Solve()
{
    forinc(i,1,n-1)
    {
        if(n<=5000)
        {
            forinc(j,i+1,n)
            {
                if(max(sa[i],sa[j])<=min(ea[i],ea[j])&&max(sb[i],sb[j])>min(eb[i],eb[j]))
                {
                    return false;
                }
                if(max(sb[i],sb[j])<=min(eb[i],eb[j])&&max(sa[i],sa[j])>min(ea[i],ea[j]))
                {
                    return false;
                }
            }
        }
        else
        {
            srand(time(0));
            forinc(k,1,1e7/n)
            {
                int j=Random(i+1,n);
                if(max(sa[i],sa[j])<=min(ea[i],ea[j])&&max(sb[i],sb[j])>min(eb[i],eb[j]))
                {
                    return false;
                }
                if(max(sb[i],sb[j])<=min(eb[i],eb[j])&&max(sa[i],sa[j])>min(ea[i],ea[j]))
                {
                    return false;
                }
            }
        }
    }
    return true;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifndef ONLINE_JUDGE
	freopen(taskname".INP","r",stdin);
	#endif // ONLINE_JUDGE
	cin>>n;
	forinc(i,1,n)
	{
	    cin>>sa[i]>>ea[i]>>sb[i]>>eb[i];
	}
	cout<<(Solve()?"YES":"NO")<<'\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define taskname "1284D"
#define forinc(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define fordec(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define foreach(i, x) for (auto &i : x)
#define ms(x, n) memset(x, n, sizeof(x))
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define fi first
#define se second
#define pb push_back
#define pf push_front

template<typename TH>
void _dbg(const char* sdbg, TH h)
{
	cerr << sdbg << " = " << h << "\n";
}

template<typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t)
{
	while (*sdbg != ',') cerr << *sdbg++;
	cerr << " = " << h << ",";
	_dbg(sdbg + 1, t...);
}

#define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define chkpt cerr << "--- Checkpoint here ---\n";

const int N=1e5+5;

struct Event
{
    int val,type,id;

    bool operator<(const Event& other) const
    {
        if(val==other.val)
        {
            return type<other.type;
        }
        return val<other.val;
    }
};

int n,sa[N],ea[N],sb[N],eb[N];
int l[N],r[N],tme;
int ftL[2*N],ftR[2*N];

void UpdateL(int id,int delta)
{
    for(int i=id;i>0;i-=i&-i)
    {
        ftL[i]+=delta;
    }
}

int QueryL(int id)
{
    int res=0;
    for(int i=id;i<2*N;i+=i&-i)
    {
        res+=ftL[i];
    }
    return res;
}

void UpdateR(int id,int delta)
{
    for(int i=id;i<2*N;i+=i&-i)
    {
        ftR[i]+=delta;
    }
}

int QueryR(int id)
{
    int res=0;
    for(int i=id;i>0;i-=i&-i)
    {
        res+=ftR[i];
    }
    return res;
}

bool Solve()
{
    forinc(i,1,n)
    {
        l[i]=r[i]=0;
    }
    forinc(i,1,2*N-1)
    {
        ftL[i]=ftR[i]=0;
    }
    // sweep line a
    vector<Event> eventList;
    forinc(i,1,n)
    {
        eventList.pb({sa[i],0,i});
        eventList.pb({ea[i],1,i});
    }
    sort(all(eventList));
    tme=0;
    foreach(event,eventList)
    {
        tme++;
        if(event.type==0)
        {
            l[event.id]=tme;
        }
        else
        {
            r[event.id]=tme;
        }
    }

    // sweep line b
    eventList.clear();
    forinc(i,1,n)
    {
        eventList.pb({sb[i],0,i});
        eventList.pb({eb[i],1,i});
    }
    sort(all(eventList));
    foreach(event,eventList)
    {
        if(event.type==0)
        {
            if(QueryL(r[event.id]+1)>0||QueryR(l[event.id]-1)>0)
            {
                return false;
            }
            UpdateL(l[event.id],1);
            UpdateR(r[event.id],1);
        }
        else
        {
            UpdateL(l[event.id],-1);
            UpdateR(r[event.id],-1);
        }
    }

    return true;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifndef ONLINE_JUDGE
	freopen(taskname".INP","r",stdin);
	#endif // ONLINE_JUDGE
	cin>>n;
	forinc(i,1,n)
	{
	    cin>>sa[i]>>ea[i]>>sb[i]>>eb[i];
	}
	bool res1=Solve();
	forinc(i,1,n)
	{
	    swap(sa[i],sb[i]);
	    swap(ea[i],eb[i]);
	}
	bool res2=Solve();
    if(res1&&res2)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define taskname "1284D"
#define forinc(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define fordec(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define foreach(i, x) for (auto &i : x)
#define ms(x, n) memset(x, n, sizeof(x))
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define fi first
#define se second
#define pb push_back
#define pf push_front

template<typename TH>
void _dbg(const char* sdbg, TH h)
{
	cerr << sdbg << " = " << h << "\n";
}

template<typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t)
{
	while (*sdbg != ',') cerr << *sdbg++;
	cerr << " = " << h << ",";
	_dbg(sdbg + 1, t...);
}

#define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define chkpt cerr << "--- Checkpoint here ---\n";

const int N=1e5+5;

struct Event
{
    int val,type,id;

    bool operator<(const Event& other) const
    {
        if(val==other.val)
        {
            return type<other.type;
        }
        return val<other.val;
    }
};

int n,sa[N],ea[N],sb[N],eb[N];
int l[N],r[N],tme;
int ftL[2*N],ftR[2*N];

void UpdateL(int id,int delta)
{
    for(int i=id;i>0;i-=i&-i)
    {
        ftL[i]+=delta;
    }
}

int QueryL(int id)
{
    int res=0;
    for(int i=id;i<2*N;i+=i&-i)
    {
        res+=ftL[i];
    }
    return res;
}

void UpdateR(int id,int delta)
{
    for(int i=id;i<2*N;i+=i&-i)
    {
        ftR[i]+=delta;
    }
}

int QueryR(int id)
{
    int res=0;
    for(int i=id;i>0;i-=i&-i)
    {
        res+=ftR[i];
    }
    return res;
}

bool Solve()
{
    forinc(i,1,n)
    {
        l[i]=r[i]=0;
    }
    forinc(i,1,2*N-1)
    {
        ftL[i]=ftR[i]=0;
    }
    // sweep line a
    vector<Event> eventList;
    forinc(i,1,n)
    {
        eventList.pb({sa[i],0,i});
        eventList.pb({ea[i],1,i});
    }
    sort(all(eventList));
    tme=0;
    foreach(event,eventList)
    {
        tme++;
        if(event.type==0)
        {
            l[event.id]=tme;
        }
        else
        {
            r[event.id]=tme;
        }
    }

    // sweep line b
    eventList.clear();
    forinc(i,1,n)
    {
        eventList.pb({sb[i],0,i});
        eventList.pb({eb[i],1,i});
    }
    sort(all(eventList));
    foreach(event,eventList)
    {
        if(event.type==0)
        {
            if(QueryL(l[event.id]+1)>0||QueryR(l[event.id]-1)>0)
            {
                return false;
            }
            UpdateL(l[event.id],1);
            UpdateR(r[event.id],1);
        }
        else
        {
            UpdateL(l[event.id],-1);
            UpdateR(r[event.id],-1);
        }
    }

    return true;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifndef ONLINE_JUDGE
	freopen(taskname".INP","r",stdin);
	#endif // ONLINE_JUDGE
	cin>>n;
	forinc(i,1,n)
	{
	    cin>>sa[i]>>ea[i]>>sb[i]>>eb[i];
	}
	bool res1=Solve();
	forinc(i,1,n)
	{
	    swap(sa[i],sb[i]);
	    swap(ea[i],eb[i]);
	}
	bool res2=Solve();
    if(res1&&res2)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2e5 + 5;
const ll mod = 1e9 + 21;
const ll mod1 = 1e9 + 9;
const ll b = 1e6 + 3;
const ll b1 = 1e6 + 33;

ll b_pow[maxn], b1_pow[maxn];

pair<ll, ll> kill(vector<pair<int, pii>> &ev){

	pair<ll, ll> ans = {0, 0};
	pair<ll, ll> sum = {0, 0};

	for(auto &e : ev){
		int t = e.second.first;
		int idx = e.second.second;
		ll h1 = 1ll * b_pow[idx];
		ll h2 = 1ll * b1_pow[idx];

		if(t == -1){
			ans.first = (ans.first + h1 * sum.first % mod) % mod;
			ans.second = (ans.second + h2 * sum.second % mod1) % mod1;
			sum.first = (sum.first + h1) % mod;
			sum.second = (sum.second + h2) % mod1;
		}
		else{
			sum.first = (sum.first + mod - h1) % mod;
			sum.second = (sum.second + mod1 - h2) % mod1;
		}

	}

	return ans;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	b_pow[0] = b1_pow[0] = 1ll;
	for(int i = 1; i < maxn; i++){
		b_pow[i] = (b_pow[i - 1] * b) % mod;
		b1_pow[i] = (b1_pow[i - 1] * b1) % mod1;
	}

	int n;
	cin >> n;

	vector<pair<int, pii>> ev1, ev2;

	for(int i = 0; i < n; i++){
		int x, y, c, d;
		cin >> x >> y >> c >> d;

		ev1.push_back({x, {-1, i}});
		ev1.push_back({y, {+1, i}});

		ev2.push_back({c, {-1, i}});
		ev2.push_back({d, {+1, i}});
	}

	sort(ev1.begin(), ev1.end());
	sort(ev2.begin(), ev2.end());

	auto h1 = kill(ev1);
	auto h2 = kill(ev2);

	if(h1 == h2)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2e5 + 5;
const ll mod = 1e9 + 7;
const ll b = 331;

ll b_pow[maxn];

vector<ll> kill(vector<pair<int, pii>> &ev){

	vector<ll> ans;

	ll num = 0;

	ans.push_back(0);

	for(auto &e : ev){
		int t = e.second.first;
		int idx = e.second.second;

	//	cout << e.first << " " << t << " " << idx << endl;

		if(t == -1)
			num = (num + b_pow[idx]) % mod;
		else
			num = (num + mod - b_pow[idx]) % mod;
		ans.push_back(num);

	//	cout << num << endl;

	}

	//cout << "end" << endl;

	sort(ans.begin(), ans.end());
	return ans;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	b_pow[0] = 1ll;
	for(int i = 1; i < maxn; i++)
		b_pow[i] = (b_pow[i - 1] * b) % mod;

	int n;
	cin >> n;

	vector<pair<int, pii>> ev1, ev2;

	for(int i = 0; i < n; i++){
		int x, y, c, d;
		cin >> x >> y >> c >> d;

		ev1.push_back({x, {-1, i}});
		ev1.push_back({y, {+1, i}});

		ev2.push_back({c, {-1, i}});
		ev2.push_back({d, {+1, i}});
	}

	sort(ev1.begin(), ev1.end());
	sort(ev2.begin(), ev2.end());

	auto h1 = kill(ev1);
	auto h2 = kill(ev2);

	for(int i = 0; i < h1.size(); i++){
		if(h1[i] != h2[i]){
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;

	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<vector<int>> kill(vector<pair<pii, int>> &a, int n){

	vector<vector<int>> g(n);

	int last = a[0].second;
	int R = a[0].first.second;
	for(int i = 1; i < n; i++){
		int lo = a[i].first.first;
		int hi = a[i].first.second;
		int j = a[i].second;

		if(lo <= R){
			g[last].push_back(j);
			g[j].push_back(last);
		}
		else{
			R = hi;
			last = j;
		}
	}

	return g;
}

vector<int> bfs(int u, vector<vector<int>> &g, vector<bool> &f){
	f[u] = true;
	queue<int> Q;
	Q.push(u);
	vector<int> ans;

	while(!Q.empty()){
		u = Q.front();Q.pop();
		ans.push_back(u);

		for(auto &v : g[u]){
			if(!f[v]){
				f[v] = true;
				Q.push(v);
			}
		}
	}

	return ans;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n;
	cin >> n;

	vector<pair<pii, int>> a(n), b(n);

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

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	auto g1 = kill(a, n);
	auto g2 = kill(b, n);

	vector<bool> f1(n), f2(n);

	for(int i = 0; i < n; i++){
		if(f1[i] != f2[i]){
			cout << "NO" << endl;
			return 0;
		}

		if(!f1[i]){
			auto l1 = bfs(i, g1, f1);
			auto l2 = bfs(i, g2, f2);

			if(l1.size() != l2.size()){
				cout << "NO" << endl;
				return 0;
			}

			sort(l1.begin(), l1.end());
			sort(l2.begin(), l2.end());

			for(int j = 0; j < l1.size(); j++){
				if(l1[j] != l2[j]){
					cout << "NO" << endl;
					return 0;
				}
			}

		}
	}

	cout << "YES" << endl;

	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<vector<int>> kill(vector<pair<pii, int>> &a, int n){

	vector<vector<int>> g;

	vector<int> cur;
	cur.push_back(a[0].second);

	int last = a[0].second;
	int R = a[0].first.second;
	for(int i = 1; i < n; i++){
		int lo = a[i].first.first;
		int hi = a[i].first.second;
		int j = a[i].second;

		if(lo <= R){
			cur.push_back(j);
		}
		else{
			g.push_back(cur);
			cur.clear();
			cur.push_back(j);
			R = hi;
			last = j;
		}
	}

	g.push_back(cur);

	for(auto &el : g)
		sort(el.begin(), el.end());

	return g;
}

vector<int> bfs(int u, vector<vector<int>> &g, vector<bool> &f){
	f[u] = true;
	queue<int> Q;
	Q.push(u);
	vector<int> ans;

	while(!Q.empty()){
		u = Q.front();Q.pop();
		ans.push_back(u);

		for(auto &v : g[u]){
			if(!f[v]){
				f[v] = true;
				Q.push(v);
			}
		}
	}

	return ans;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n;
	cin >> n;

	vector<pair<pii, int>> a(n), b(n);

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

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	for(int i = 0; i < n; i++){
		swap(a[i].first.first, a[i].first.second);
		swap(b[i].first.first, b[i].first.second);
		a[i].second = b[i].second = i;
	}

	auto g1 = kill(a, n);
	auto g2 = kill(b, n);

	if(g1.size() != g2.size())
		cout << "NO" << endl;
	else{

		for(int i = 0; i < g2.size(); i++){
			if(g1[0] == g2[i]){

				p1 = 0, p2 = i, cnt = 0;
				while(cnt < g1.size()){
					if(g1[p1] != g2[p2]){
						cout << "NO" << endl;
						return 0;
					}
					p1 = (p1 + 1) % g1.size();
					p2 = (p2 + 1) % g2.size();
					cnt++;
				}
				break;
			}
		}

		if(cnt != n)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;
		return 0;
	}

	cout << "YES" << endl;

	return 0;
}

/*

3
1 4 1 4
2 7 2 5
5 8 3 6

*/


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2e5 + 5;
const ll mod = 1e9 + 7;
const ll mod1 = 1e9 + 9;
const ll b = 1e6 + 3;
const ll b1 = 1e6 + 33;

ll b_pow[maxn], b1_pow[maxn];

vector<ll> kill(vector<pair<int, pii>> &ev){

	vector<ll> ans;

	ll num = 0;

	ans.push_back(0);

	for(auto &e : ev){
		int t = e.second.first;
		int idx = e.second.second;

	//	cout << e.first << " " << t << " " << idx << endl;

		if(t == -1)
			num = (num + b_pow[idx]) % mod;
		else
			num = (num + mod - b_pow[idx]) % mod;
		ans.push_back(num);

	//	cout << num << endl;

	}

	//cout << "end" << endl;

	sort(ans.begin(), ans.end());
	return ans;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	b_pow[0] = 1ll;
	for(int i = 1; i < maxn; i++)
		b_pow[i] = (b_pow[i - 1] * b) % mod;

	int n;
	cin >> n;

	vector<pair<int, pii>> ev1, ev2;

	for(int i = 0; i < n; i++){
		int x, y, c, d;
		cin >> x >> y >> c >> d;

		ev1.push_back({x, {-1, i}});
		ev1.push_back({y, {+1, i}});

		ev2.push_back({c, {-1, i}});
		ev2.push_back({d, {+1, i}});
	}

	sort(ev1.begin(), ev1.end());
	sort(ev2.begin(), ev2.end());

	auto h1 = kill(ev1);
	auto h2 = kill(ev2);

	for(int i = 0; i < h1.size(); i++){
		if(h1[i] != h2[i]){
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;

	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<vector<int>> kill(vector<pair<pii, int>> &a, int n){

	vector<vector<int>> g(n);

	int last = 0;
	int R = a[0].first.second;
	for(int i = 1; i < n; i++){
		int lo = a[i].first.first;
		int hi = a[i].first.second;
		int j = a[i].second;

		if(lo <= R){
			g[last].push_back(j);
			g[j].push_back(last);
		}
		else{
			R = hi;
			last = j;
		}
	}

	return g;
}

vector<int> bfs(int u, vector<vector<int>> &g, vector<bool> &f){
	f[u] = true;
	queue<int> Q;
	Q.push(u);
	vector<int> ans;

	while(!Q.empty()){
		u = Q.front();Q.pop();
		ans.push_back(u);

		for(auto &v : g[u]){
			if(!f[v]){
				f[v] = true;
				Q.push(v);
			}
		}
	}

	return ans;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n;
	cin >> n;

	vector<pair<pii, int>> a(n), b(n);

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

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	auto g1 = kill(a, n);
	auto g2 = kill(b, n);

	vector<bool> f1(n), f2(n);

	for(int i = 0; i < n; i++){
		if(f1[i] != f2[i]){
			cout << "NO" << endl;
			return 0;
		}

		if(!f1[i]){
			auto l1 = bfs(i, g1, f1);
			auto l2 = bfs(i, g2, f2);

			if(l1.size() != l2.size()){
				cout << "NO" << endl;
				return 0;
			}

			sort(l1.begin(), l1.end());
			sort(l2.begin(), l2.end());

			for(int j = 0; j < l1.size(); j++){
				if(l1[j] != l2[j]){
					cout << "NO" << endl;
					return 0;
				}
			}

		}
	}

	cout << "YES" << endl;

	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<vector<int>> kill(vector<pair<pii, int>> &a, int n){

	vector<vector<int>> g(n);

	int last = a[0].second;
	int R = a[0].first.second;
	for(int i = 1; i < n; i++){
		int lo = a[i].first.first;
		int hi = a[i].first.second;
		int j = a[i].second;

		if(lo <= R){
			g[last].push_back(j);
			g[j].push_back(last);
		}
		else{
			R = hi;
			last = j;
		}
	}

	return g;
}

vector<int> bfs(int u, vector<vector<int>> &g, vector<bool> &f){
	f[u] = true;
	queue<int> Q;
	Q.push(u);
	vector<int> ans;

	while(!Q.empty()){
		u = Q.front();Q.pop();
		ans.push_back(u);

		for(auto &v : g[u]){
			if(!f[v]){
				f[v] = true;
				Q.push(v);
			}
		}
	}

	return ans;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n;
	cin >> n;

	vector<pair<pii, int>> a(n), b(n);

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

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	for(int i = 0; i < n; i++){
		swap(a[i].first.first, a[i].first.second);
		swap(b[i].first.first, b[i].first.second);
		a[i].second = b[i].second = i;
	}

	auto g1 = kill(a, n);
	auto g2 = kill(b, n);

	vector<bool> f1(n), f2(n);

	for(int i = 0; i < n; i++){
		if(f1[i] != f2[i]){
			cout << "NO" << endl;
			return 0;
		}

		if(!f1[i]){
			auto l1 = bfs(i, g1, f1);
			auto l2 = bfs(i, g2, f2);

			if(l1.size() != l2.size()){
				cout << "NO" << endl;
				return 0;
			}

			sort(l1.begin(), l1.end());
			sort(l2.begin(), l2.end());

			for(int j = 0; j < l1.size(); j++){
				if(l1[j] != l2[j]){
					cout << "NO" << endl;
					return 0;
				}
			}

		}
	}

	cout << "YES" << endl;

	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2e5 + 5;
const ll mod = 1e9 + 7;
const ll mod1 = 1e9 + 9;
const ll b = 1e6 + 3;
const ll b1 = 1e6 + 33;

ll b_pow[maxn], b1_pow[maxn];

vector<pair<ll, ll>> kill(vector<pair<int, pii>> &ev){

	vector<pair<ll, ll>> ans;

	ll num = 0, num1 = 0;

	ans.push_back({0, 0});

	for(auto &e : ev){
		int t = e.second.first;
		int idx = e.second.second;

	//	cout << e.first << " " << t << " " << idx << endl;

		if(t == -1){
			num = (num + b_pow[idx]) % mod;
			num1 = (num1 + b1_pow[idx]) % mod1;
		}
		else{
			num = (num + mod - b_pow[idx]) % mod;
			num1 = (num1 + mod1 - b1_pow[idx]) % mod1;
		}

		ans.push_back({num, num1});

	//	cout << num << endl;

	}

	//cout << "end" << endl;

	sort(ans.begin(), ans.end());
	return ans;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	b_pow[0] = b1_pow[0] = 1ll;
	for(int i = 1; i < maxn; i++){
		b_pow[i] = (b_pow[i - 1] * b) % mod;
		b1_pow[i] = (b1_pow[i - 1] * b1) % mod1;
	}

	int n;
	cin >> n;

	vector<pair<int, pii>> ev1, ev2;

	for(int i = 0; i < n; i++){
		int x, y, c, d;
		cin >> x >> y >> c >> d;

		ev1.push_back({x, {-1, i}});
		ev1.push_back({y, {+1, i}});

		ev2.push_back({c, {-1, i}});
		ev2.push_back({d, {+1, i}});
	}

	sort(ev1.begin(), ev1.end());
	sort(ev2.begin(), ev2.end());

	auto h1 = kill(ev1);
	auto h2 = kill(ev2);

	for(int i = 0; i < h1.size(); i++){
		if(h1[i] != h2[i]){
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;

	return 0;
}


#include<bits/stdc++.h>
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define mems(a,b) memset(a,b,sizeof(a))
#define mod 998244353
using namespace std;
typedef long long ll;
const double ep = 0.000000001;
const int N=1e4+50;
const double pi=acos(-1);
const int inf=0x3f3f3f3f;
char s[110];
int a[30];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        mems(a,0);
        scanf("%s",s);
        int len=strlen(s);
        if(len==1)
        {
            printf("%s\n",s);
            continue;
        }
        for(int i=0;i<len;i++)
        {
            if(i==0)
            {
                if(s[i]!=s[i+1])
                    a[s[i]-'a']=1;
            }
            else if(i==len-1)
            {

                if(s[i]!=s[i-1])
                {
//                    printf("%d^^\n",s[i]-'a');
                    a[s[i]-'a']=1;
                }

            }
            else
            {
                if(s[i]!=s[i-1]&&s[i]!=s[i+1])
                    a[s[i]-'a']=1;
            }
        }
        for(int i=0;i<=30;i++)
        {
            if(a[i])
                printf("%c",i+'a');
        }
        printf("\n");
    }
}


#include<bits/stdc++.h>
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define mems(a,b) memset(a,b,sizeof(a))
#define mod 998244353
using namespace std;
typedef long long ll;
const double ep = 0.000000001;
const int N=1e4+50;
const double pi=acos(-1);
const int inf=0x3f3f3f3f;
char s[550];
stack<char>st;
int a[38];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        mems(a,0);
        scanf("%s",s);
        int len=strlen(s);
        st.push(s[0]);
        for(int j=1;j<len;j++)
        {
            if(st.empty())
            {
                st.push(s[j]);
                continue;
            }
            if(s[j]!=st.top())
            {
                st.push(s[j]);
            }
            else
            {
                st.pop();
            }
        }
        while(!st.empty())
        {
            a[st.top()-'a']=1;
            st.pop();
        }
        for(int i=0;i<=30;i++)
        {
            if(a[i])
                printf("%c",i+'a');
        }

        printf("\n");
    }
}


#include<bits/stdc++.h>
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define mems(a,b) memset(a,b,sizeof(a))
#define mod 998244353
using namespace std;
typedef long long ll;
const double ep = 0.000000001;
const int N=1e4+50;
const double pi=acos(-1);
const int inf=0x3f3f3f3f;
char s[510];
int a[35];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        mems(a,0);
        scanf("%s",s);
        int len=strlen(s);
        if(len==1)
        {
            printf("%s\n",s);
            continue;
        }
        for(int i=0;i<len;i++)
        {
            if(i==0)
            {
                if(s[i]!=s[i+1])
                {
//                    printf("%d^\n",s[i]-'a');
                    a[s[i]-'a']=1;
                }

            }
            else if(i==len-1)
            {

                if(s[i]!=s[i-1])
                {
//                    printf("%d^^\n",s[i]-'a');
                    a[s[i]-'a']=1;
                }
            }
            else
            {
                if(s[i]!=s[i-1]&&s[i]!=s[i+1])
                {
//                    printf("%d^^^\n",s[i]-'a');
                    a[s[i]-'a']=1;
                }

            }
        }
        for(int i=0;i<=30;i++)
        {
            if(a[i])
                printf("%c",i+'a');
        }
        printf("\n");
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int i,j=0,y;
        string s;
        string s1;
        map<char, int>mp;
        cin>>s;
        y=s.size();
        s[y]='\0';
        for(i=y-1;i>=0;i--)
        {
            mp[s[i]]++;
        }
        for(i=y-1;i>=0;i--)
        {
            if(mp[s[i]]!=2 && mp[s[i]]!=0)
            {
                s1[j]=s[i];
                j++;
                mp[s[i]]=0;
            }
        }
        for(i=0;i<j;i++)
        {
            cout<<s1[i];
        }
        cout<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;

const int sz=2e5+10;
const int mod=998244353;

void solve()
{
    int cur=0,j,k;
    string s,ans;
    cin>>s;

    map<char, int>mp;

    for(int i=0;i<s.size();i++)
    {
        mp[s[i]]++;
    }

    for(char i='a';i<='z';i++)
    {
        bool flag=true;
        for(j=0;j<s.size();j++)
        {
            cur=0;
            if(s[j]==i)
            {
                k=j;

                while(k<s.size() && s[k]==i) k++, cur++;

                if(cur!=2)
                {
                    flag=false;
                    break;
                }
                j=k-1;
            }
        }
        if(flag==false && mp[i])
        {
            ans+=i;
        }
    }
    cout<<ans<<endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t=1;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
    int t;
    cin>>t;
    string s;
    while(t--)
    {
        cin>>s;
        char v[505]={};
        int i,j=0,y,x;
        y=s.size();
        s[y]='\0';
         map<char, int>mp;
        for(i=0;i<y;i++)
        {
            mp[s[i]]++;
        }
        for(i=y-1;i>=0;i--)
        {
            if(mp[s[i]]!=0)
            {
            if(mp[s[i]]!=2)
            {
                v[j]=s[i];
                j++;
                mp[s[i]]=0;
            }
            }
        }
        v[j]='\0';
        if(y==j)
        {
            for(i=y-1;i>=0;i--)
            {
                cout<<v[i];
            }
        }
        else{
        for(i=0;i<j;i++)
        {
            cout<<v[i];
        }
        }
        cout<<endl;
        s.clear();
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int i,j=0,y;
        string s;
        char s1[505];
        map<char, int>mp;
        cin>>s;
        y=s.size();
        s[y]='\0';
        for(i=0;i<y;i++)
        {
            mp[s[i]]++;
        }
        for(i=y-1;i>=0;i--)
        {
            if(mp[s[i]]==0)
            {
                continue;
            }
            else if(mp[s[i]]!=2)
            {
                s1[j]=s[i];
                j++;
                mp[s[i]]=0;
            }
        }
        for(i=0;i<j;i++)
        {
            cout<<s1[i];
        }
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int i,j=0;
        string s,s1;
        map<char, int>mp;
        cin>>s;
        int y=s.size();
        s[y]='\0';
        for(i=y-1;i>=0;i--)
        {
            mp[s[i]]++;
        }
        for(i=y-1;i>=0;i--)
        {
            if(mp[s[i]]!=2 && mp[s[i]]!=0)
            {
                s1[j++]=s[i];
                mp[s[i]]=0;
            }
        }
        for(i=0;i<j;i++)
        {
            cout<<s1[i];
        }
        cout<<endl;
    }
}


#include<bits/stdc++.h>
#include<stdlib.h>
#include<string>
#define ll long long int
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int i,z;
        string s,temp;
        cin>>s; z=s.size();
        map<int, int>mp;
        int ind[z+1];
        memset(ind, 0, sizeof ind);
        for(i=0;i<s.size();i++)
        {
            if(i>0 && s[i]==s[i-1] && ind[i-1]==1)
            {
                ind[i] = -1;
                ind[i-1] = -1;
            }
            else
            {
                ind[i] = 1;
            }
        }
        for(i=0;i<s.size();i++)
        {
            if(ind[i]==1)
            {
                mp[s[i]]++;
                if(mp[s[i]]==1)  temp+=s[i];
            }
        }
        sort(temp.begin(), temp.end());
        cout<<temp<<endl;
    }
}


#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
    int t;
    cin>>t;
    string s;
    while(t--)
    {
        cin>>s;
        char v[505]={};
        int i,j=0,y,x;
        y=s.size();
        s[y]='\0';
         map<char, int>mp;
        for(i=0;i<y;i++)
        {
            mp[s[i]]++;
        }
        for(i=y-1;i>=0;i--)
        {
            if(mp[s[i]]!=0)
            {
            if(mp[s[i]]%2!=0)
            {
                v[j]=s[i];
                j++;
                mp[s[i]]=0;
            }
            }
        }
        v[j]='\0';
        if(y==j)
        {
            for(i=y-1;i>=0;i--)
            {
                cout<<v[i];
            }
        }
        else{
        for(i=0;i<j;i++)
        {
            cout<<v[i];
        }
        }
        cout<<endl;
        s.clear();
    }
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;

const int sz=2e5+10;
const int mod=998244353;

void solve()
{
    int cur=0,j,k;
    string s,ans;
    cin>>s;

    map<char, int>mp;

    for(int i=0;i<s.size();i++)
    {
        mp[s[i]]++;
    }

    for(char i='a';i<='z';i++)
    {
        bool flag=true;
        for(j=0;j<s.size();j++)
        {
            cur=0;
            if(s[j]==i)
            {
                k=j;

                while(k<s.size() && s[k]==i) k++, cur++;

                if(cur%2!=0)
                {
                    flag=false;
                    break;
                }
                j=k-1;
            }
        }
        if(flag==false && mp[i])
        {
            ans+=i;
        }
    }
    cout<<ans<<endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t=1;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#include<string>
#include<algorithm>
#include<iterator>
using namespace std;
int main()
{
    int t;
    cin>>t;
    string s;
    while(t--)
    {
        cin>>s;
        set<char>v;
        set<char>::iterator it;
        int i,j=0,y,x;
        y=s.size();
        s[y]='\0';
        map<char, int>mp;
        for(i=0;i<y;i++)
        {
            mp[s[i]]++;
        }
        for(i=y-1;i>=0;i--)
        {
            if(mp[s[i]]!=0)
            {
                if(mp[s[i]]%2!=0)
                {
                    v.insert(s[i]);
                    mp[s[i]]=0;
                }
            }
        }

       for(it=v.begin(); it!=v.end(); it++)
       {
           cout<<*it;
       }
       cout<<endl;
       s.clear();
    }
}


#include <iostream>
#include <string>

using namespace std;

int main() {
    int t, q = 0, w, e, r;
    cin >> t;
    string s, d, f, g, h;
    getline(cin, s);
    for (int i = 0; i < t; i++) {
        getline(cin, s);
        for (int j = 0; j < s.size(); j++) {//беру исправные клавиши
            if (s[j] != s[j + 1] && s[j] != s[j - 1] && j != 0 && j != s.size() - 1) {
                d.push_back(s[j]);//1
            }
            if (j == s.size() - 1 && s.size() != 1) { // последний
                if (s[j] != s[j - 1]) {
                    d.push_back(s[j]);//2
                }
            }
            if (j == 0 && s.size() != 1) { // первый
                if (s[j] != s[j + 1]) {
                    d.push_back(s[j]);//2
                }
            }
            if (s.size() == 1) { // если 1
                d.push_back(s[j]);
            }
        }
        f[0] = d[0];
        for (int j = 0; j < d.size(); j++) {//удалил повторяющиеся элементы
            for(int k = 0; k < f.size(); k++) {
                if (d[j] == f[k]) {
                    q = 1;
                }
            }
            if (q == 0) {
                f.push_back(d[j]);
            }
            q = 0;
        }
        for (int j = 0; j < f.size(); j++) {// порядок
            e = j;
            w = f[j];
            for (int k = j; k < f.size(); k++) {
                if (w > f[k]) {
                    w = f[k];
                    e = k;
                }
            }
            r = f[j];
            f[j] = f[e];
            f[e] = r;
        }
        for (int j = 0; j < f.size(); j++) {//основной массив (строка)
            g.push_back(f[j]);
        }
        if (i != t - 1) {//пробелы !!!!!!!!!!!!!!!!!!!!!
            g.push_back(' ');
        }
        f.clear();
        d.clear();
    }
    for (int i = 0; i < g.size(); i++)  {
        if (g[i] != ' ') {
            cout << g[i];
        } else {
            cout << endl;
        }
    }
}


#include <iostream>
#include <string>

using namespace std;

int main() {
    int t, temp;
    cin >> t;
    string s, a;
    getline(cin, s);
    for (int i = 0; i < t; i++) {
        getline(cin, s);
        for (int j = 0; j < s.size(); j++) {
            if (j == 0 && s[j] != s[j + 1]) {
                a.push_back(s[j]);
            }
            if (s.size() - 1 != 0 && j == s.size() - 1 && s[j] != s[j - 1]) {
                a.push_back(s[j]);
            }
            if (j != 0 && j != s.size() - 1 && s[j] != s[j - 1] && s[j] != s[j + 1]) {
                a.push_back(s[j]);
            }
        }
        if (i != t - 1) {
            a.push_back(' ');
        }
    }
    for (int i = 0; i < a.size(); i++) {
        if (a[i] >= 'a' && a[i] <= 'z') {
            for (int j = 0; j < a.size(); j++) {
                if (a[i] == ' ') {
                    break;
                }
                if (i != 0 && a[i - 1] != ' ' && temp > a[i]) {
                    int tenp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tenp;
                }
                temp = a[i];
            }
        }
    }
    for (int i = 0; i < a.size(); i++)  {
        if (a[i] != ' ') {
            cout << a[i];
        } else {
            cout << endl;
        }
    }
}