#include <bits/stdc++.h>

#define task "D"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define db1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define db2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define db3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, n) { cerr << #A << " = "; rep(_, 1, n) cerr << A[_] << ' '; cerr << '\n'; }
#define SZ(x) ((int)(x).size())
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 1e5 + 1;
int n;
struct Event
{
    int sa, ea, sb, eb;
    Event() {}
    Event(int _sa, int _ea, int _sb, int _eb) : sa(_sa), ea(_ea), sb(_sb), eb(_eb) {}
    bool operator < (const Event &ot)
    {
        return sa < ot.sa;
    }
} evea[N], eveb[N];
ii A[N], B[N];
int mx[2][17][N], mn[2][17][N], lg[N];
int getmx(int id, int l, int r)
{
    int k = lg[r - l + 1];
    if (id == 0)
    {
        if (evea[mx[id][k][l]].sb > evea[mx[id][k][r - (1 << k) + 1]].sb) return mx[id][k][l];
        return mx[id][k][r - (1 << k) + 1];
    } else
    {
        if (eveb[mx[id][k][l]].sb > eveb[mx[id][k][r - (1 << k) + 1]].sb) return mx[id][k][l];
        return mx[id][k][r - (1 << k) + 1];
    }
}
int getmn(int id, int l, int r)
{
    int k = lg[r - l + 1];
    if (id == 0)
    {
        if (evea[mn[id][k][l]].eb < evea[mn[id][k][r - (1 << k) + 1]].eb) return mn[id][k][l];
        return mn[id][k][r - (1 << k) + 1];
    } else
    {
        if (eveb[mn[id][k][l]].eb < eveb[mn[id][k][r - (1 << k) + 1]].eb) return mn[id][k][l];
        return mn[id][k][r - (1 << k) + 1];
    }
}
int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> n;
	rep(i, 1, n)
	{
	    int sa, ea, sb, eb;
	    cin >> sa >> ea >> sb >> eb;
	    evea[i] = Event(sa, ea, sb, eb);
	    eveb[i] = Event(sb, eb, sa, ea);
	    A[i] = {sa, ea};
	    B[i] = {sb, eb};
	}
	sort(evea + 1, evea + 1 + n);
	sort(eveb + 1, eveb + 1 + n);
	sort(A + 1, A + 1 + n);
	sort(B + 1, B + 1 + n);
	lg[1] = 0;
	rep(i, 2, n) lg[i] = lg[i / 2] + 1;
	rep(i, 1, n) mx[0][0][i] = mx[1][0][i] = mn[0][0][i] = mn[1][0][i] = i;

	rep(i, 1, 16) for (int j = 1; j + (1 << i) - 1 <= n; j++)
	{
	    if (evea[mx[0][i - 1][j]].sb > evea[mx[0][i - 1][j + (1 << (i - 1))]].sb)
        {
            mx[0][i][j] = mx[0][i - 1][j];
        } else mx[0][i][j] = mx[0][i - 1][j + (1 << (i - 1))];
	    if (eveb[mx[1][i - 1][j]].sb > eveb[mx[1][i - 1][j + (1 << (i - 1))]].sb)
        {
            mx[1][i][j] = mx[1][i - 1][j];
        } else mx[1][i][j] = mx[1][i - 1][j + (1 << (i - 1))];

        if (evea[mn[0][i - 1][j]].eb < evea[mn[0][i - 1][j + (1 << (i - 1))]].eb)
        {
            mn[0][i][j] = mn[0][i - 1][j];
        } else mn[0][i][j] = mn[0][i - 1][j + (1 << (i - 1))];
	    if (eveb[mn[1][i - 1][j]].eb < eveb[mn[1][i - 1][j + (1 << (i - 1))]].eb)
        {
            mn[1][i][j] = mn[1][i - 1][j];
        } else mn[1][i][j] = mn[1][i - 1][j + (1 << (i - 1))];
	}
	rep(i, 1, n)
	{
	    int left = lower_bound(A + 1, A + 1 + n, ii(evea[i].sa, -1)) - A;
	    int right = upper_bound(A + 1, A + 1 + n, ii(evea[i].ea, 1e9 + 1)) - A - 1;
	    int mxL, mnR;
	    if (left <= right)
        {
            mxL = getmx(0, left, right);
            mnR = getmn(0, left, right);
            if (((evea[mnR].eb < evea[i].sb) && (mnR != i)) || ((evea[i].eb < evea[mxL].sb) && (mxL != i)))
            {
                cout << "NO";
                return 0;
            }
        }
        left = lower_bound(B + 1, B + 1 + n, ii(eveb[i].sa, -1)) - B;
        right = upper_bound(B + 1, B + 1 + n, ii(eveb[i].ea, 1e9 + 1)) - B - 1;
        if (left > right) continue;
	    mxL = getmx(1, left, right);
	    mnR = getmn(1, left, right);
	    if ((eveb[mnR].eb < eveb[i].sb && mnR != i) || (eveb[i].eb < eveb[mxL].sb && mxL != i))
        {
            cout << "NO";
            return 0;
        }
	}
	cout << "YES";
}


#include <bits/stdc++.h>

#define task "D"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define db1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define db2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define db3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, n) { cerr << #A << " = "; rep(_, 1, n) cerr << A[_] << ' '; cerr << '\n'; }
#define SZ(x) ((int)(x).size())
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 1e5 + 1;
int n;
struct Event
{
    int sa, ea, sb, eb;
    Event() {}
    Event(int _sa, int _ea, int _sb, int _eb) : sa(_sa), ea(_ea), sb(_sb), eb(_eb) {}
    bool operator < (const Event &ot)
    {
        return sa < ot.sa;
    }
} evea[N], eveb[N];
ii A[N], B[N];
int mx[2][17][N], mn[2][17][N], lg[N];
int getmx(int id, int l, int r)
{
    int k = lg[r - l + 1];
    if (mx[id][k][l] > mx[id][k][r - (1 << k) + 1]) return mx[id][k][l];
    return mx[id][k][r - (1 << k) + 1];
}
int getmn(int id, int l, int r)
{
    int k = lg[r - l + 1];
    if (mn[id][k][l] < mn[id][k][r - (1 << k) + 1]) return mn[id][k][l];
    return mn[id][k][r - (1 << k) + 1];
}
int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> n;
	rep(i, 1, n)
	{
	    int sa, ea, sb, eb;
	    cin >> sa >> ea >> sb >> eb;
	    evea[i] = Event(sa, ea, sb, eb);
	    eveb[i] = Event(sb, eb, sa, ea);
	    A[i] = {sa, ea};
	    B[i] = {sb, eb};
	}
	sort(evea + 1, evea + 1 + n);
	sort(eveb + 1, eveb + 1 + n);
	sort(A + 1, A + 1 + n);
	sort(B + 1, B + 1 + n);
	lg[1] = 0;
	rep(i, 2, n) lg[i] = lg[i / 2] + 1;
	rep(i, 1, n) mx[0][0][i] = mx[1][0][i] = mn[0][0][i] = mn[1][0][i] = i;

	rep(i, 1, 16) for (int j = 1; j + (1 << i) - 1 <= n; j++)
	{
	    if (evea[mx[0][i - 1][j]].sb > evea[mx[0][i - 1][j + (1 << (i - 1))]].sb)
        {
            mx[0][i][j] = mx[0][i - 1][j];
        } else mx[0][i][j] = mx[0][i - 1][j + (1 << (i - 1))];
	    if (eveb[mx[1][i - 1][j]].sb > eveb[mx[1][i - 1][j + (1 << (i - 1))]].sb)
        {
            mx[1][i][j] = mx[1][i - 1][j];
        } else mx[1][i][j] = mx[1][i - 1][j + (1 << (i - 1))];
        if (evea[mn[0][i - 1][j]].eb > evea[mn[0][i - 1][j + (1 << (i - 1))]].eb)
        {
            mn[0][i][j] = mn[0][i - 1][j];
        } else mn[0][i][j] = mn[0][i - 1][j + (1 << (i - 1))];
	    if (eveb[mn[1][i - 1][j]].eb > eveb[mn[1][i - 1][j + (1 << (i - 1))]].eb)
        {
            mn[1][i][j] = mn[1][i - 1][j];
        } else mn[1][i][j] = mn[1][i - 1][j + (1 << (i - 1))];
	}
	rep(i, 1, n)
	{
	    int left = lower_bound(A + 1, A + 1 + n, ii(evea[i].sa, -1)) - A;
	    int right = upper_bound(A + 1, A + 1 + n, ii(evea[i].ea, 1e9)) - A - 1;
	    int mxL, mnR;
	    if (left <= right)
        {
            mxL = getmx(0, left, right);
            mnR = getmn(0, left, right);
            if (((evea[mnR].eb < evea[i].sb) && (mnR != i)) || ((evea[i].eb < evea[mxL].sb) && (mxL != i)))
            {
                cout << "NO";
                return 0;
            }
        }
        left = lower_bound(B + 1, B + 1 + n, ii(eveb[i].sa, -1)) - B;
        right = upper_bound(B + 1, B + 1 + n, ii(eveb[i].ea, 1e9)) - B - 1;
        if (left > right) continue;
	    mxL = getmx(1, left, right);
	    mnR = getmn(1, left, right);
	    if ((eveb[mnR].eb < eveb[i].sb && mnR != i) || (eveb[i].eb < eveb[mxL].sb && mxL != i))
        {
            cout << "NO";
            return 0;
        }
	}
	cout << "YES";
}


#include <bits/stdc++.h>

#define task "D"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define db1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define db2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define db3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, n) { cerr << #A << " = "; rep(_, 1, n) cerr << A[_] << ' '; cerr << '\n'; }
#define SZ(x) ((int)(x).size())
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vl;
const int N = 1e5 + 5;
int n, sa[N], sb[N], ea[N], eb[N], lofr[N], rofl[N];
viii right, left;
struct ITmx
{
    vi it;
    ITmx(int n) {it.assign(4 * n, 0);}
    void build(int id, int l, int r, int idd)
    {
        if (l == r)
        {
            if (idd == 1) it[id] = ea[left[l].S];
            else it[id] = ea[right[l].S];
            return;
        }
        int m = (l + r) >> 1;
        build(id << 1, l, m, idd);
        build((id << 1) | 1, m + 1, r, idd);
        it[id] = max(it[id << 1], it[(id << 1) | 1]);
    }
    int get(int id, int l, int r, int L, int R)
    {
        if (l > R || r < L || L > R) return 0;
        if (L <= l && r <= R) return it[id];
        int m = (l + r) >> 1;
        return max(get(id << 1, l, m, L, R), get((id << 1) | 1, m + 1, r, L, R));
    }
};
struct ITmn
{
    vi it;
    ITmn(int n) {it.assign(4 * n, 0);}
    void build(int id, int l, int r, int idd)
    {
        if (l == r)
        {
            if (idd == 1) it[id] = eb[left[l].S];
            else it[id] = eb[right[l].S];
            return;
        }
        int m = (l + r) >> 1;
        build(id << 1, l, m, idd);
        build((id << 1) | 1, m + 1, r, idd);
        it[id] = min(it[id << 1], it[(id << 1) | 1]);
    }
    int get(int id, int l, int r, int L, int R)
    {
        if (l > R || r < L || L > R) return 1e9 + 1;
        if (L <= l && r <= R) return it[id];
        int m = (l + r) >> 1;
        return min(get(id << 1, l, m, L, R), get((id << 1) | 1, m + 1, r, L, R));
    }
};
bool check()
{
    right.clear();
    left.clear();
    right.pb({{-1, -1}, 0});
    left.pb({{-1, -1}, 0});
    rep(i, 1, n)
    {
        right.pb({{sb[i], sa[i]}, i});
        left.pb({{sa[i], sb[i]}, i});
    }
    sort(ALL(right));
    sort(ALL(left));
    ITmx stmx1(n), stmx2(n);
    ITmn stmn2(n), stmn1(n);
    stmx1.build(1, 1, n, 0);
    stmx2.build(1, 1, n, 1);
    stmn1.build(1, 1, n, 0);
    stmn2.build(1, 1, n, 1);
    int j = -1;
    for (auto i : right)
    {
        j++;
        if (j == 0) continue;
        //DB(i.S);
        int mnr1 = lower_bound(ALL(right), iii(ii(sa[i.S], 0), 0)) - right.begin();
        int mxr1 = upper_bound(ALL(right), iii(ii(sb[i.S], 1e9 + 1), 0)) - right.begin() - 1;
        int mnr2 = j + 1, mxr2 = mxr1;
        mxr1 = j - 1;
        int mxl = max(stmx1.get(1, 1, n, mnr1, mxr1), stmx1.get(1, 1, n, mnr2, mxr2));
        int mnr = min(stmn1.get(1, 1, n, mnr1, mxr1), stmn1.get(1, 1, n, mnr2, mxr2));
        if (((mnr < ea[i.S] && mnr1 <= mxr1) || (mxl > eb[i.S] && mnr2 <= mxr2)))
        {
            //DB(j);
            return 0;

        }

        int mnl1 = lower_bound(ALL(left), iii(ii(sa[i.S], 0), 0)) - left.begin();
        int mxl1 = upper_bound(ALL(left), iii(ii(sb[i.S], 1e9 + 1), 0)) - left.begin() - 1;
        int mnl2 = j + 1, mxl2 = mxl1;
        mxl1 = j - 1;
        mxl = max(stmx2.get(1, 1, n, mnl1, mxl1), stmx2.get(1, 1, n, mnl2, mxl2));
        mnr = min(stmn2.get(1, 1, n, mnl1, mxl1), stmn2.get(1, 1, n, mnl2, mxl2));
        if (((mnr < ea[i.S] && mnl1 <= mxl1) || (mxl > eb[i.S] && mnl2 <= mxl2)))
        {
            //cout << "Fcuk: " << j << '\n';
            return 0;

        }
    }
    return 1;
}
int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> n;
	rep(i, 1, n) cin >> sa[i] >> sb[i] >> ea[i] >> eb[i];
	//build_sort();
	if (!check())
    {
        cout << "NO";
        return 0;
    }
	rep(i, 1, n)
	{
	    int tema = ea[i], temb = eb[i];
	    ea[i] = sa[i], eb[i] = sb[i];
	    sa[i] = tema, sb[i] = temb;
	}
	//build_sort();
	if (check()) cout << "YES";
	else cout << "NO";
}


#include <bits/stdc++.h>

#define task "D"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define db1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define db2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define db3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, n) { cerr << #A << " = "; rep(_, 1, n) cerr << A[_] << ' '; cerr << '\n'; }
#define SZ(x) ((int)(x).size())
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vl;
const int N = 1e5 + 5;
int n, sa[N], sb[N], ea[N], eb[N], lofr[N], rofl[N];
viii right, left;
struct ITmx
{
    vi it;
    ITmx(int n) {it.assign(4 * n, 0);}
    void build(int id, int l, int r, int idd)
    {
        if (l == r)
        {
            if (idd == 1) it[id] = ea[left[l].S];
            else it[id] = ea[right[l].S];
            return;
        }
        int m = (l + r) >> 1;
        build(id << 1, l, m, idd);
        build((id << 1) | 1, m + 1, r, idd);
        it[id] = max(it[id << 1], it[(id << 1) | 1]);
    }
    int get(int id, int l, int r, int L, int R)
    {
        if (l > R || r < L || L > R) return 0;
        if (L <= l && r <= R) return it[id];
        int m = (l + r) >> 1;
        return max(get(id << 1, l, m, L, R), get((id << 1) | 1, m + 1, r, L, R));
    }
};
struct ITmn
{
    vi it;
    ITmn(int n) {it.assign(4 * n, 0);}
    void build(int id, int l, int r, int idd)
    {
        if (l == r)
        {
            if (idd == 1) it[id] = eb[left[l].S];
            else it[id] = eb[right[l].S];
            return;
        }
        int m = (l + r) >> 1;
        build(id << 1, l, m, idd);
        build((id << 1) | 1, m + 1, r, idd);
        it[id] = min(it[id << 1], it[(id << 1) | 1]);
    }
    int get(int id, int l, int r, int L, int R)
    {
        if (l > R || r < L || L > R) return 1e9 + 1;
        if (L <= l && r <= R) return it[id];
        int m = (l + r) >> 1;
        return min(get(id << 1, l, m, L, R), get((id << 1) | 1, m + 1, r, L, R));
    }
};
bool check()
{
    right.clear();
    left.clear();
    right.pb({{-1, -1}, 0});
    left.pb({{-1, -1}, 0});
    rep(i, 1, n)
    {
        right.pb({{sb[i], sa[i]}, i});
        left.pb({{sa[i], sb[i]}, i});
    }
    sort(ALL(right));
    sort(ALL(left));
    ITmx stmx1(n), stmx2(n);
    ITmn stmn2(n), stmn1(n);
    stmx1.build(1, 1, n, 0);
    stmx2.build(1, 1, n, 1);
    stmn1.build(1, 1, n, 0);
    stmn2.build(1, 1, n, 1);
    int j = -1;
    for (auto i : right)
    {
        j++;
        if (j == 0) continue;
        //DB(i.S);
        int mnr1 = lower_bound(ALL(right), iii(ii(sa[i.S], 0), 0)) - right.begin();
        int mxr1 = upper_bound(ALL(right), iii(ii(sb[i.S], 1e9 + 1), 0)) - right.begin() - 1;
        int mnr2 = j + 1, mxr2 = mxr1;
        mxr1 = j - 1;
        int mxl = max(stmx1.get(1, 1, n, mnr1, mxr1), stmx1.get(1, 1, n, mnr2, mxr2));
        int mnr = max(stmn1.get(1, 1, n, mnr1, mxr1), stmn1.get(1, 1, n, mnr2, mxr2));
        if (mxl != 0 && ((mnr < ea[i.S] && mnr1 <= mxr1) || (mxl > eb[i.S] && mnr2 <= mxr2)))
        {
            //DB(j);
            return 0;

        }

        int mnl1 = lower_bound(ALL(left), iii(ii(sa[i.S], 0), 0)) - left.begin();
        int mxl1 = upper_bound(ALL(left), iii(ii(sb[i.S], 1e9 + 1), 0)) - left.begin() - 1;
        int mnl2 = j + 1, mxl2 = mxl1;
        mxl1 = j - 1;
        mxl = max(stmx2.get(1, 1, n, mnl1, mxl1), stmx2.get(1, 1, n, mnl2, mxl2));
        mnr = min(stmn2.get(1, 1, n, mnl1, mxl1), stmn2.get(1, 1, n, mnl2, mxl2));
        if (mnr != 1e9 + 1 && ((mnr < ea[i.S] && mnl1 <= mxl1) || (mxl > eb[i.S] && mnl2 <= mxl2)))
        {
            //cout << "Fcuk: " << j << '\n';
            return 0;

        }
    }
    return 1;
}
int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> n;
	rep(i, 1, n) cin >> sa[i] >> sb[i] >> ea[i] >> eb[i];
	//build_sort();
	if (!check())
    {
        cout << "NO";
        return 0;
    }
	rep(i, 1, n)
	{
	    int tema = ea[i], temb = eb[i];
	    ea[i] = sa[i], eb[i] = sb[i];
	    sa[i] = tema, sb[i] = temb;
	}
	//build_sort();
	if (check()) cout << "YES";
	else cout << "NO";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
int n;
int a[100100],b[100100],c[100100],d[100100];
//vector<int> x,y;
map<int,int>m;
vector<pair<pair<int,int>,int > > v;
int p[1000100];
int seg[100100*4];
int seg2[100100*4];
void build(int cr,int s,int e){
    if(s==e){
        seg[cr]=c[p[s]];
        seg2[cr]=d[p[s]];
        return;
    }
    build(cr*2,s,(s+e)/2);
    build(cr*2+1,(s+e)/2+1,e);
    seg[cr]=max(seg[cr*2],seg[cr*2+1]);
    seg2[cr]=min(seg2[cr*2],seg2[cr*2+1]);
    return;
}
int l,r;
int get1(int cr,int s,int e){
    if(l>e||r<s)return 0;
    if(l<=s&&e<=r){return seg[cr];}
    return max(
    get1(cr*2,s,(s+e)/2),
    get1(cr*2+1,(s+e)/2+1,e));
    //seg[cr]=max(seg[cr*2],seg[cr*2+1]);
    //seg2[cr]=min(seg2[cr*2],seg2[cr*2+1]);
    //return;
}
int get2(int cr,int s,int e){
    if(l>e||r<s)return 1e9+100;
    if(l<=s&&e<=r){return seg2[cr];}
    return max(
    get2(cr*2,s,(s+e)/2),
    get2(cr*2+1,(s+e)/2+1,e));
    //seg[cr]=max(seg[cr*2],seg[cr*2+1]);
    //seg2[cr]=min(seg2[cr*2],seg2[cr*2+1]);
    //return;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin>>n;v.pb(mp(mp(0,0),0));
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        v.pb(mp(mp(a[i],b[i]),i));
    }
    sort(v.begin(),v.end());
    for(int i=1;i<=n;i++){
        p[i]=v[i].ss;
    }
    build(1,1,n);
    bool ok=1;
    for(int i=1;i<n;i++){
        int hi=n,lo=i,best=i;
        while(hi>=lo){
            int mid=(hi+lo)/2;
            if(v[mid].ff.ff<=v[i].ff.ss){
                best=max(best,mid);
                lo=mid+1;

            }
            else
                hi=mid-1;
        }
        if(best==i)continue;
        l=i;
        r=best;
        int x=get1(1,1,n);
        int y=get2(1,1,n);
        if(x>d[v[i].ss]||y<c[v[i].ss]){ok=0;}
    }
    v.clear();
    v.pb(mp(mp(0,0),0));
    for(int i=1;i<=n;i++){
        swap(a[i],c[i]);
        swap(b[i],d[i]);
        v.pb(mp(mp(a[i],b[i]),i));
    }
    sort(v.begin(),v.end());
    for(int i=1;i<=n;i++){
        p[i]=v[i].ss;
    }
    build(1,1,n);

    for(int i=1;i<n;i++){
        int hi=n,lo=i,best=i;
        while(hi>=lo){
            int mid=(hi+lo)/2;
            if(v[mid].ff.ff<=v[i].ff.ss){
                best=max(best,mid);
                lo=mid+1;

            }
            else
                hi=mid-1;
        }
        if(best==i)continue;
        l=i;
        r=best;
        int x=get1(1,1,n);
        int y=get2(1,1,n);
        if(x>d[v[i].ss]||y<c[v[i].ss]){ok=0;}
    }
    if(ok)cout<<"YES";
    else
        cout<<"NO";
    return 0;
}
/*

1
6       2 3
32      2 2 2 2 2
180     2 2 3 3 5
1116    2 2 3 3 31
7728    2 2 2 2 3
59904
*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
int n;
int a[100100],b[100100],c[100100],d[100100];
//vector<int> x,y;
map<int,int>m;
vector<pair<pair<int,int>,int > > v;
int p[1000100];
int seg[100100*4];
int seg2[100100*4];
void build(int cr,int s,int e){
    if(s==e){
        seg[cr]=c[p[s]];
        seg2[cr]=d[p[s]];
        return;
    }
    build(cr*2,s,(s+e)/2);
    build(cr*2+1,(s+e)/2+1,e);
    seg[cr]=max(seg[cr*2],seg[cr*2+1]);
    seg2[cr]=min(seg2[cr*2],seg2[cr*2+1]);
    return;
}
int l,r;
ll mx=0;
int get1(int cr,int s,int e){
    if(l>e||r<s)return 0;
    if(l<=s&&e<=r){return seg[cr];}
    return max(
    get1(cr*2,s,(s+e)/2),
    get1(cr*2+1,(s+e)/2+1,e));
    //seg[cr]=max(seg[cr*2],seg[cr*2+1]);
    //seg2[cr]=min(seg2[cr*2],seg2[cr*2+1]);
    //return;
}
int get2(int cr,int s,int e){
    if(l>e||r<s)return mx;
    if(l<=s&&e<=r){return seg2[cr];}
    return max(
    get2(cr*2,s,(s+e)/2),
    get2(cr*2+1,(s+e)/2+1,e));
    //seg[cr]=max(seg[cr*2],seg[cr*2+1]);
    //seg2[cr]=min(seg2[cr*2],seg2[cr*2+1]);
    //return;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin>>n;v.pb(mp(mp(0,0),0));
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        v.pb(mp(mp(a[i],b[i]),i));
        mx=max(max(b[i],d[i]),mx);
    }
    mx++;
    sort(v.begin(),v.end());
    for(int i=1;i<=n;i++){
        p[i]=v[i].ss;
    }
    build(1,1,n);
    bool ok=1;
    for(int i=1;i<n;i++){
        int hi=n,lo=i,best=i;
        while(hi>=lo){
            int mid=(hi+lo)/2;
            if(v[mid].ff.ff<=v[i].ff.ss){
                best=max(best,mid);
                lo=mid+1;

            }
            else
                hi=mid-1;
        }
        if(best==i)continue;
        l=i;
        r=best;
        int x=get1(1,1,n);
        int y=get2(1,1,n);
        if(x>d[v[i].ss]||y<c[v[i].ss]){ok=0;}
    }
    v.clear();
    v.pb(mp(mp(0,0),0));
    for(int i=1;i<=n;i++){
        swap(a[i],c[i]);
        swap(b[i],d[i]);
        v.pb(mp(mp(a[i],b[i]),i));
    }
    sort(v.begin(),v.end());
    for(int i=1;i<=n;i++){
        p[i]=v[i].ss;
    }
    build(1,1,n);

    for(int i=1;i<n;i++){
        int hi=n,lo=i,best=i;
        while(hi>=lo){
            int mid=(hi+lo)/2;
            if(v[mid].ff.ff<=v[i].ff.ss){
                best=max(best,mid);
                lo=mid+1;

            }
            else
                hi=mid-1;
        }
        if(best==i)continue;
        l=i;
        r=best;
        int x=get1(1,1,n);
        int y=get2(1,1,n);
        if(x>d[v[i].ss]||y<c[v[i].ss]){ok=0;}
    }
    if(ok)cout<<"YES";
    else
        cout<<"NO";
    return 0;
}
/*

1
6       2 3
32      2 2 2 2 2
180     2 2 3 3 5
1116    2 2 3 3 31
7728    2 2 2 2 3
59904
*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
int n;
ll a[100100],b[100100],c[100100],d[100100];
int main(){
    ios_base::sync_with_stdio(0);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    bool ok=1;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ll x=max(a[i],a[j]),y=min(b[j],b[i]);
            ll x2=max(c[i],c[j]),yy=min(d[j],d[i]);
            if((y>=x)^(yy>=x2))ok=0;
        }
    }
    if(ok)cout<<"YES";
    else cout<<"NO";
    return 0;
}
/*

1
6       2 3
32      2 2 2 2 2
180     2 2 3 3 5
1116    2 2 3 3 31
7728    2 2 2 2 3
59904
*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
int n;
int a[100100],b[100100],c[100100],d[100100];
//vector<int> x,y;
map<int,int>m;
vector<pair<pair<int,int>,int > > v;
int p[1000100];
int seg[100100*4];
int seg2[100100*4];
void build(int cr,int s,int e){
    if(s==e){
        seg[cr]=c[p[s]];
        seg2[cr]=d[p[s]];
        return;
    }
    build(cr*2,s,(s+e)/2);
    build(cr*2+1,(s+e)/2+1,e);
    seg[cr]=max(seg[cr*2],seg[cr*2+1]);
    seg2[cr]=min(seg2[cr*2],seg2[cr*2+1]);
    return;
}
int l,r;
int mx=0;
int get1(int cr,int s,int e){
    if(l>e||r<s)return 0;
    if(l<=s&&e<=r){return seg[cr];}
    return max(
    get1(cr*2,s,(s+e)/2),
    get1(cr*2+1,(s+e)/2+1,e));
    //seg[cr]=max(seg[cr*2],seg[cr*2+1]);
    //seg2[cr]=min(seg2[cr*2],seg2[cr*2+1]);
    //return;
}
int get2(int cr,int s,int e){
    if(l>e||r<s)return mx;
    if(l<=s&&e<=r){return seg2[cr];}
    return min(
    get2(cr*2,s,(s+e)/2),
    get2(cr*2+1,(s+e)/2+1,e));
    //seg[cr]=max(seg[cr*2],seg[cr*2+1]);
    //seg2[cr]=min(seg2[cr*2],seg2[cr*2+1]);
    //return;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin>>n;v.pb(mp(mp(0,0),0));
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        v.pb(mp(mp(a[i],b[i]),i));
        mx=max(max(b[i],d[i]),mx);
    }
    mx++;
    sort(v.begin(),v.end());
    for(int i=1;i<=n;i++){
        p[i]=v[i].ss;
    }
    build(1,1,n);
    bool ok=1;
    for(int i=1;i<n;i++){
        int hi=n,lo=i,best=i;
        while(hi>=lo){
            int mid=(hi+lo)/2;
            if(v[mid].ff.ff<=v[i].ff.ss){
                best=max(best,mid);
                lo=mid+1;

            }
            else
                hi=mid-1;
        }
        if(best==i)continue;
        l=i;
        r=best;
        int x=get1(1,1,n);
        int y=get2(1,1,n);
        if(x>d[v[i].ss]||y<c[v[i].ss]){ok=0;}
    }
    v.clear();
    v.pb(mp(mp(0,0),0));
    for(int i=1;i<=n;i++){
        swap(a[i],c[i]);
        swap(b[i],d[i]);
        v.pb(mp(mp(a[i],b[i]),i));
    }
    sort(v.begin(),v.end());
    for(int i=1;i<=n;i++){
        p[i]=v[i].ss;
    }
    build(1,1,n);

    for(int i=1;i<n;i++){
        int hi=n,lo=i,best=i;
        while(hi>=lo){
            int mid=(hi+lo)/2;
            if(v[mid].ff.ff<=v[i].ff.ss){
                best=max(best,mid);
                lo=mid+1;

            }
            else
                hi=mid-1;
        }
        if(best==i)continue;
        l=i;
        r=best;
        int x=get1(1,1,n);
        int y=get2(1,1,n);
        if(x>d[v[i].ss]||y<c[v[i].ss]){ok=0;}
    }
    if(ok)cout<<"YES";
    else
        cout<<"NO";
    return 0;
}
/*

1
6       2 3
32      2 2 2 2 2
180     2 2 3 3 5
1116    2 2 3 3 31
7728    2 2 2 2 3
59904
*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
int n;
int a[100100],b[100100],c[100100],d[100100];
vector<int> x,y;
map<int,int>m;
vector<pair<int,int> > v,v2;
int main(){
    ios_base::sync_with_stdio(0);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        x.pb(a[i]);
        x.pb(b[i]);
        y.pb(c[i]);
        y.pb(d[i]);
    }
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    int cr=1;
    for(int i=0;i<x.size();i++){
        if(i>0&&x[i]!=x[i-1]){
            cr++;
        }
        if(i>0&&x[i]==x[i-1])continue;
        m[x[i]]=cr;
    }
    for(int i=0;i<n;i++){
        v.pb(mp(m[a[i]],m[b[i]]));
    }
    m.clear();
    cr=1;
    for(int i=0;i<x.size();i++){
        if(i>0&&y[i]!=y[i-1]){
            cr++;
        }
        if(i>0&&y[i]==y[i-1])continue;
        m[y[i]]=cr;
    }
    for(int i=0;i<n;i++){
        v2.pb(mp(m[c[i]],m[d[i]]));
    }
    sort(v.begin(),v.end());
    sort(v2.begin(),v2.end());

    bool ok=1;
    for(int i=0;i<v.size();i++){
        if(v[i].ff!=v2[i].ff||v[i].ss!=v2[i].ss)ok=0;
    }
    if(ok)cout<<"YES";
    else cout<<"NO";
    return 0;
}
/*

1
6       2 3
32      2 2 2 2 2
180     2 2 3 3 5
1116    2 2 3 3 31
7728    2 2 2 2 3
59904
*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
int n;
int a[100100],b[100100],c[100100],d[100100];
//vector<int> x,y;
map<int,int>m;
vector<pair<pair<int,int>,int > > v;
int p[1000100];
int seg[100100*4];
int seg2[100100*4];
void build(int cr,int s,int e){
    if(s==e){
        seg[cr]=c[p[s]];
        seg2[cr]=d[p[s]];
        return;
    }
    build(cr*2,s,(s+e)/2);
    build(cr*2+1,(s+e)/2+1,e);
    seg[cr]=max(seg[cr*2],seg[cr*2+1]);
    seg2[cr]=min(seg2[cr*2],seg2[cr*2+1]);
    return;
}
int l,r;
int mx=0;
int get1(int cr,int s,int e){
    if(l>e||r<s)return 0;
    if(l<=s&&e<=r){return seg[cr];}
    return max(
    get1(cr*2,s,(s+e)/2),
    get1(cr*2+1,(s+e)/2+1,e));
    //seg[cr]=max(seg[cr*2],seg[cr*2+1]);
    //seg2[cr]=min(seg2[cr*2],seg2[cr*2+1]);
    //return;
}
int get2(int cr,int s,int e){
    if(l>e||r<s)return mx;
    if(l<=s&&e<=r){return seg2[cr];}
    return max(
    get2(cr*2,s,(s+e)/2),
    get2(cr*2+1,(s+e)/2+1,e));
    //seg[cr]=max(seg[cr*2],seg[cr*2+1]);
    //seg2[cr]=min(seg2[cr*2],seg2[cr*2+1]);
    //return;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin>>n;v.pb(mp(mp(0,0),0));
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        v.pb(mp(mp(a[i],b[i]),i));
        mx=max(max(b[i],d[i]),mx);
    }
    mx++;
    sort(v.begin(),v.end());
    for(int i=1;i<=n;i++){
        p[i]=v[i].ss;
    }
    build(1,1,n);
    bool ok=1;
    for(int i=1;i<n;i++){
        int hi=n,lo=i,best=i;
        while(hi>=lo){
            int mid=(hi+lo)/2;
            if(v[mid].ff.ff<=v[i].ff.ss){
                best=max(best,mid);
                lo=mid+1;

            }
            else
                hi=mid-1;
        }
        if(best==i)continue;
        l=i;
        r=best;
        int x=get1(1,1,n);
        int y=get2(1,1,n);
        if(x>d[v[i].ss]||y<c[v[i].ss]){ok=0;}
    }
    v.clear();
    v.pb(mp(mp(0,0),0));
    for(int i=1;i<=n;i++){
        swap(a[i],c[i]);
        swap(b[i],d[i]);
        v.pb(mp(mp(a[i],b[i]),i));
    }
    sort(v.begin(),v.end());
    for(int i=1;i<=n;i++){
        p[i]=v[i].ss;
    }
    build(1,1,n);

    for(int i=1;i<n;i++){
        int hi=n,lo=i,best=i;
        while(hi>=lo){
            int mid=(hi+lo)/2;
            if(v[mid].ff.ff<=v[i].ff.ss){
                best=max(best,mid);
                lo=mid+1;

            }
            else
                hi=mid-1;
        }
        if(best==i)continue;
        l=i;
        r=best;
        int x=get1(1,1,n);
        int y=get2(1,1,n);
        if(x>d[v[i].ss]||y<c[v[i].ss]){ok=0;}
    }
    if(ok)cout<<"YES";
    else
        cout<<"NO";
    return 0;
}
/*

1
6       2 3
32      2 2 2 2 2
180     2 2 3 3 5
1116    2 2 3 3 31
7728    2 2 2 2 3
59904
*/


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

const int N = 510031;

int n;
int l1[N],r1[N],l2[N],r2[N];

multiset<int> right_ends;
multiset<int> left_ends;
multiset<int>::iterator it;

vector<pair<int,pair<int,int> > > events;

bool solver(){
	right_ends.clear();
	left_ends.clear();

	for (int i=0;i<events.size();i++){
		int id=events[i].second.second;
		if (events[i].second.first==-1) // start
		{
			right_ends.insert(r2[id]);
			left_ends.insert(l2[id]);
		}
		else // end
		{
			right_ends.erase(right_ends.find(r2[id]));
			left_ends.erase(left_ends.find(l2[id]));
		}
		if (left_ends.size()>0){
			it=left_ends.end();
			--it;
			int rmost_start=(*it);
			it=right_ends.begin();
			int lmost_end=(*it);
			if (lmost_end<rmost_start)
				return 1;
		}
	}
	return 0;
}

int main() {

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

   	cin>>n;
    for (int i=0;i<n;i++)
    {
    	cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
    	events.push_back(make_pair(l1[i],make_pair(-1,i)));
		events.push_back(make_pair(r1[i],make_pair(1,i)));
    }

    sort(events.begin(),events.end());

    int ans=solver();

    events.clear();

    for (int i=0;i<n;i++){
    	swap(l1[i],l2[i]);
    	swap(r1[i],r2[i]);
    	events.push_back(make_pair(l1[i],make_pair(-1,i)));
		events.push_back(make_pair(r1[i],make_pair(1,i)));
    }

    sort(events.begin(),events.end());

    ans=(ans|solver());

    if (ans)
    	cout<<"NO"<<endl;
    else
    	cout<<"YES"<<endl;

    return 0;
}


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

#define endl '\n'
// #define int long long

const int mod = 1e9+7;

const int N = 510031;

int n;

vector<int> l1(N),r1(N),l2(N),r2(N);

vector<pair<int,pair<int,int>>> v;

multiset<int> sst;
multiset<int> tts;

bool check() {

	v.clear();
	sst.clear();
	tts.clear();

	for(int i=0;i<n;i++) {
		v.push_back(make_pair(l1[i],make_pair(i,1)));
		v.push_back(make_pair(r1[i],make_pair(i,-1)));
	}

	sort(v.begin(), v.end());

	for(int i=0;i<v.size();i++) {

		int idx = v[i].second.first;

    	// Entry
    	if(v[i].second.second == 1) {
    		sst.insert(l2[idx]);
    		tts.insert(r2[idx]);
    	} else {
    		sst.erase(sst.find(l2[idx]));
    		tts.erase(tts.find(r2[idx]));
    	}

    	// Check

    	if(sst.size()>0) {

    		auto bb = sst.end();
    		bb--;
    		int bl = *bb;
    		int lb = *tts.begin();

    		if(bl>lb) {
    			cout<<"NO\n";
    			return 1;
    		}
    	}
    }

    return 0;
}

int32_t main() {

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

   	cin>>n;

	for(int i=0;i<n;i++)
		cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];

    bool ans = check();

    for(int i=0;i<n;i++) {
		swap(l1[i],l2[i]);
		swap(r1[i],r2[i]);
	}

    ans = ans|check();

    if(ans) cout<<"NO\n";
    else
    	cout<<"YES\n";

    return 0;
}


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

#define endl '\n'
// #define int long long

const int mod = 1e9+7;

const int N = 510031;

int n;

int l1[N],r1[N],l2[N],r2[N];

vector<pair<int,pair<int,int>>> v;

multiset<int> sst;
multiset<int> tts;
multiset<int>::iterator it;

bool check() {

	tts.clear();
	sst.clear();
	v.clear();

	for(int i=0;i<n;i++) {
		v.push_back(make_pair(l1[i],make_pair(-1,i)));
		v.push_back(make_pair(r1[i],make_pair(1,i)));
	}

    sort(v.begin(), v.end());

	for(int i=0;i<v.size();i++) {

		int idx = v[i].second.second;

    	// Entry
    	if(v[i].second.first == -1) {
    		sst.insert(l2[idx]);
    		tts.insert(r2[idx]);
    	} else {
    		sst.erase(sst.find(l2[idx]));
    		tts.erase(tts.find(r2[idx]));
    	}

    	// Check

    	if(sst.size()>0) {

    		it = sst.end();
    		it--;
    		int bl = *it;
    		it = tts.begin();
    		int lb = *it;
    		if(bl>lb) {
    			return 1;
    		}
    	}
    }

    return 0;
}

int main() {

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

   	cin>>n;

	for(int i=0;i<n;i++) {
		cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
	}

    int ans = check();

    for(int i=0;i<n;i++) {
		swap(l1[i],l2[i]);
		swap(r1[i],r2[i]);
	}

	ans = (ans|check());

	if(ans) cout<<"NO\n";
	else cout<<"YES\n";

    return 0;
}


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

const int N = 510031;

int n;
int l1[N],r1[N],l2[N],r2[N];

multiset<int> right_ends;
multiset<int> left_ends;
multiset<int>::iterator it;

vector<pair<int,pair<int,int> > > events;

bool solver(){
	right_ends.clear();
	left_ends.clear();
	events.clear();

	for (int i=1;i<=n;i++){
		events.push_back(make_pair(l1[i],make_pair(-1,i)));
		events.push_back(make_pair(r1[i],make_pair(1,i)));
	}
	sort(events.begin(),events.end());

	for (int i=0;i<events.size();i++){
		int id=events[i].second.second;
		if (events[i].second.first==-1) // start
		{
			right_ends.insert(r2[id]);
			left_ends.insert(l2[id]);
		}
		else // end
		{
			right_ends.erase(right_ends.find(r2[id]));
			left_ends.erase(left_ends.find(l2[id]));
		}
		if (left_ends.size()>0){
			it=left_ends.end();
			--it;
			int rmost_start=(*it);
			it=right_ends.begin();
			int lmost_end=(*it);
			if (lmost_end<rmost_start)
				return 1;
		}
	}
	return 0;
}

int main() {

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

   	cin>>n;
    for (int i=1;i<=n;i++)
    {
    	cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
    }

    int ans=solver();

    for (int i=1;i<=n;i++){
    	swap(l1[i],l2[i]);
    	swap(r1[i],r2[i]);
    }
    ans=(ans|solver());

    if (ans)
    	cout<<"NO"<<endl;
    else
    	cout<<"YES"<<endl;

    return 0;
}


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

const int N = 510031;

int n;
int l1[N],r1[N],l2[N],r2[N];

multiset<int> right_ends;
multiset<int> left_ends;;

vector<pair<int,pair<int,int> > > events;

bool solver(){
	right_ends.clear();
	left_ends.clear();

	for (int i=0;i<events.size();i++){
		int id=events[i].second.second;
		if (events[i].second.first==-1) // start
		{
			right_ends.insert(r2[id]);
			left_ends.insert(l2[id]);
		}
		else // end
		{
			right_ends.erase(right_ends.find(r2[id]));
			left_ends.erase(left_ends.find(l2[id]));
		}

		if (left_ends.size()>0){
			int lb=*left_ends.rbegin();
			int bl=*right_ends.begin();

			if (lb>bl)
				return 1;
		}
	}
	return 0;
}

int main() {

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

   	cin>>n;
    for (int i=0;i<n;i++)
    {
    	cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
    	events.push_back(make_pair(l1[i],make_pair(-1,i)));
		events.push_back(make_pair(r1[i],make_pair(1,i)));
    }

    sort(events.begin(),events.end());

    int ans=solver();

    events.clear();

    for (int i=0;i<n;i++){
    	swap(l1[i],l2[i]);
    	swap(r1[i],r2[i]);
    	events.push_back(make_pair(l1[i],make_pair(-1,i)));
		events.push_back(make_pair(r1[i],make_pair(1,i)));
    }

    sort(events.begin(),events.end());

    ans=(ans|solver());

    if (ans)
    	cout<<"NO"<<endl;
    else
    	cout<<"YES"<<endl;

    return 0;
}


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

#define endl '\n'
// #define int long long

const int mod = 1e9+7;

const int N = 510031;

int n;

vector<int> l1(N),r1(N),l2(N),r2(N);

vector<pair<int,pair<int,int>>> v;

multiset<int> sst;
multiset<int> tts;

void check() {

	for(int i=0;i<v.size();i++) {

		int idx = v[i].second.first;

    	// Entry
    	if(v[i].second.second == 1) {
    		sst.insert(l2[idx]);
    		tts.insert(r2[idx]);
    	} else {
    		sst.erase(sst.find(l2[idx]));
    		tts.erase(tts.find(r2[idx]));
    	}

    	// Check

    	if(sst.size()>0) {

    		auto bb = sst.end();
    		bb--;
    		int bl = *bb;
    		int lb = *tts.begin();

    		if(bl>lb) {
    			cout<<"NO\n";
    			exit(0);
    		}
    	}
    }
}

int main() {

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

   	cin>>n;

	for(int i=0;i<n;i++) {
		cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
		v.push_back(make_pair(l1[i],make_pair(i,1)));
		v.push_back(make_pair(r1[i],make_pair(i,-1)));
	}

    sort(v.begin(), v.end());

    check();
    v.clear();

    for(int i=0;i<n;i++) {
		// cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
		swap(l1[i],l2[i]);
		swap(r1[i],r2[i]);
		v.push_back(make_pair(l1[i],make_pair(i,1)));
		v.push_back(make_pair(r1[i],make_pair(i,-1)));
	}

    sort(v.begin(), v.end());

    check();

    cout<<"YES\n";

    return 0;
}


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

#define endl '\n'
#define int long long

const int mod = 1e9+7;

int n = 100000;

vector<int> l1(n),r1(n),l2(n),r2(n);

vector<pair<int,pair<int,int>>> v;

void check(vector<pair<int,pair<int,int>>> v) {

	multiset<int> sst,tts;

	for(auto pos: v) {

		int idx = pos.second.first;

    	// Entry
    	if(pos.second.second == 1) {
    		sst.insert(l2[idx]);
    		tts.insert(r2[idx]);
    	} else {
    		sst.erase(sst.find(l2[idx]));
    		tts.erase(tts.find(r2[idx]));
    	}

    	// Check

    	if(sst.size()) {

    		int bl = *sst.rbegin();
    		int lb = *tts.begin();

    		if(bl>lb) {
    			cout<<"NO\n";
    			exit(0);
    		}
    	}
    }
}

int32_t main() {

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

   	cin>>n;

	for(int i=0;i<n;i++) {
		cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
		v.push_back(make_pair(l1[i],make_pair(i,1)));
		v.push_back(make_pair(r1[i],make_pair(i,-1)));
	}

    sort(v.begin(), v.end());

    check(v);
    v.clear();

    for(int i=0;i<n;i++) {
		// cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
		swap(l1[i],l2[i]);
		swap(r1[i],r2[i]);
		v.push_back(make_pair(l1[i],make_pair(i,1)));
		v.push_back(make_pair(r1[i],make_pair(i,-1)));
	}

    sort(v.begin(), v.end());

    check(v);

    cout<<"YES\n";

    return 0;
}


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

#define endl '\n'
// #define int long long

const int mod = 1e9+7;

const int N = 510031;

int n;

vector<int> l1(N),r1(N),l2(N),r2(N);

vector<pair<int,pair<int,int>>> v;

multiset<int> sst;
multiset<int> tts;
multiset<int>::iterator it;

bool check() {

	tts.clear();
	sst.clear();
	v.clear();

	for(int i=0;i<n;i++) {
		v.push_back(make_pair(l1[i],make_pair(i,1)));
		v.push_back(make_pair(r1[i],make_pair(i,-1)));
	}

    sort(v.begin(), v.end());

	for(int i=0;i<v.size();i++) {

		int idx = v[i].second.first;

    	// Entry
    	if(v[i].second.second == 1) {
    		sst.insert(l2[idx]);
    		tts.insert(r2[idx]);
    	} else {
    		sst.erase(sst.find(l2[idx]));
    		tts.erase(tts.find(r2[idx]));
    	}

    	// Check

    	if(sst.size()>0) {

    		it = sst.end();
    		it--;
    		int bl = *it;
    		it = tts.begin();
    		int lb = *it;
    		if(bl>lb) {
    			return 1;
    		}
    	}
    }

    return 0;
}

int main() {

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

   	cin>>n;

	for(int i=0;i<n;i++) {
		cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
	}

    int ans = check();

    for(int i=0;i<n;i++) {
		swap(l1[i],l2[i]);
		swap(r1[i],r2[i]);
	}

	ans = (ans|check());

	if(ans) cout<<"NO\n";
	else cout<<"YES\n";

    return 0;
}


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

#define endl '\n'
#define int long long

const int mod = 1e9+7;

int n = 100000;

vector<int> l1(n),r1(n),l2(n),r2(n);

vector<pair<int,pair<int,int>>> v;

void check(vector<pair<int,pair<int,int>>> v) {

	multiset<int> sst,tts;

	for(int i=0;i<v.size();i++) {

		int idx = v[i].second.first;

    	// Entry
    	if(v[i].second.second == 1) {
    		sst.insert(l2[idx]);
    		tts.insert(r2[idx]);
    	} else {
    		sst.erase(sst.find(l2[idx]));
    		tts.erase(tts.find(r2[idx]));
    	}

    	// Check

    	if(sst.size()>0) {

    		int bl = *sst.rbegin();
    		int lb = *tts.begin();

    		if(bl>lb) {
    			cout<<"NO\n";
    			exit(0);
    		}
    	}
    }
}

int32_t main() {

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

   	cin>>n;

	for(int i=0;i<n;i++) {
		cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
		v.push_back(make_pair(l1[i],make_pair(i,1)));
		v.push_back(make_pair(r1[i],make_pair(i,-1)));
	}

    sort(v.begin(), v.end());

    check(v);
    v.clear();

    for(int i=0;i<n;i++) {
		// cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
		swap(l1[i],l2[i]);
		swap(r1[i],r2[i]);
		v.push_back(make_pair(l1[i],make_pair(i,1)));
		v.push_back(make_pair(r1[i],make_pair(i,-1)));
	}

    sort(v.begin(), v.end());

    check(v);

    cout<<"YES\n";

    return 0;
}


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

#define endl '\n'
// #define int long long

const int mod = 1e9+7;

const int N = 510031;

int n;

int l1[N],r1[N],l2[N],r2[N];

vector<pair<int,pair<int,int>>> v;

multiset<int> sst;
multiset<int> tts;
multiset<int>::iterator it;

bool check() {

	tts.clear();
	sst.clear();
	v.clear();

    sort(v.begin(), v.end());

	for(int i=0;i<v.size();i++) {

		int idx = v[i].second.second;

    	// Entry
    	if(v[i].second.first == 1) {
    		sst.insert(l2[idx]);
    		tts.insert(r2[idx]);
    	} else {
    		sst.erase(sst.find(l2[idx]));
    		tts.erase(tts.find(r2[idx]));
    	}

    	// Check

    	if(sst.size()>0) {

    		it = sst.end();
    		--it;
    		int bl = (*it);
    		it = tts.begin();
    		int lb = (*it);
    		if(bl>lb) {
    			return 1;
    		}
    	}
    }

    return 0;
}

int main() {

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

   	cin>>n;

	for(int i=0;i<n;i++) {
		cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
	}

    int ans = check();

    for(int i=0;i<n;i++) {
		swap(l1[i],l2[i]);
		swap(r1[i],r2[i]);

		v.push_back(make_pair(l1[i],make_pair(1,i)));
		v.push_back(make_pair(r1[i],make_pair(-1,i)));
	}

	ans = (ans|check());

	if(ans) cout<<"NO\n";
	else cout<<"YES\n";

    return 0;
}


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

#define endl '\n'
// #define int long long

const int mod = 1e9+7;

const int N = 510031;

int n;

int l1[N],r1[N],l2[N],r2[N];

vector<pair<int,pair<int,int>>> v;

multiset<int> sst;
multiset<int> tts;
multiset<int>::iterator it;

bool check() {

	tts.clear();
	sst.clear();
	v.clear();

	for(int i=0;i<n;i++) {
		v.push_back(make_pair(l1[i],make_pair(-1,i)));
		v.push_back(make_pair(r1[i],make_pair(1,i)));
	}

    sort(v.begin(), v.end());

	for(int i=0;i<v.size();i++) {

		int idx = v[i].second.second;

    	// Entry
    	if(v[i].second.first == -1) {
    		sst.insert(l2[idx]);
    		tts.insert(r2[idx]);
    	} else {
    		sst.erase(sst.find(l2[idx]));
    		tts.erase(tts.find(r2[idx]));
    	}

    	if(sst.size()>0) {

    		it = sst.end();
    		it--;
    		int bl = *it;
    		it = tts.begin();
    		int lb = *it;
    		if(bl>lb) {
    			return 1;
    		}
    	}
    }

    return 0;
}

int main() {

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

   	cin>>n;

	for(int i=0;i<n;i++) {
		cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
	}

    int ans = check();

    for(int i=0;i<n;i++) {
		swap(l1[i],l2[i]);
		swap(r1[i],r2[i]);
	}

	ans = (ans|check());

	if(ans) cout<<"NO\n";
	else cout<<"YES\n";

    return 0;
}


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

#define endl '\n'
#define int long long

const int mod = 1e9+7;

const int N = 510031;

int n;

vector<int> l1(N),r1(N),l2(N),r2(N);

vector<pair<int,pair<int,int>>> v;

multiset<int> sst;
multiset<int> tts;

void check() {

	for(int i=0;i<v.size();i++) {

		int idx = v[i].second.first;

    	// Entry
    	if(v[i].second.second == 1) {
    		sst.insert(l2[idx]);
    		tts.insert(r2[idx]);
    	} else {
    		sst.erase(sst.find(l2[idx]));
    		tts.erase(tts.find(r2[idx]));
    	}

    	// Check

    	if(sst.size()>0) {

    		auto bb = sst.end();
    		bb--;
    		int bl = *bb;
    		int lb = *tts.begin();

    		if(bl>lb) {
    			cout<<"NO\n";
    			exit(0);
    		}
    	}
    }
}

int32_t main() {

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

   	cin>>n;

	for(int i=0;i<n;i++) {
		cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
		v.push_back(make_pair(l1[i],make_pair(i,1)));
		v.push_back(make_pair(r1[i],make_pair(i,-1)));
	}

    sort(v.begin(), v.end());

    check();
    v.clear();

    for(int i=0;i<n;i++) {
		// cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
		swap(l1[i],l2[i]);
		swap(r1[i],r2[i]);
		v.push_back(make_pair(l1[i],make_pair(i,1)));
		v.push_back(make_pair(r1[i],make_pair(i,-1)));
	}

    sort(v.begin(), v.end());

    check();

    cout<<"YES\n";

    return 0;
}


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

#define endl '\n'
// #define int long long

const int mod = 1e9+7;

const int N = 510031;

int n;

int l1[N],r1[N],l2[N],r2[N];

vector<pair<int,pair<int,int>>> v;

multiset<int> sst;
multiset<int> tts;
multiset<int>::iterator it;

bool check() {

	tts.clear();
	sst.clear();
	v.clear();

	for(int i=0;i<n;i++) {
		v.push_back(make_pair(l1[i],make_pair(1,i)));
		v.push_back(make_pair(r1[i],make_pair(-1,i)));
	}

    sort(v.begin(), v.end());

	for(int i=0;i<v.size();i++) {

		int idx = v[i].second.second;

    	// Entry
    	if(v[i].second.first == 1) {
    		sst.insert(l2[idx]);
    		tts.insert(r2[idx]);
    	} else {
    		sst.erase(sst.find(l2[idx]));
    		tts.erase(tts.find(r2[idx]));
    	}

    	// Check

    	if(sst.size()>0) {

    		it = sst.end();
    		it--;
    		int bl = *it;
    		it = tts.begin();
    		int lb = *it;
    		if(bl>lb) {
    			return 1;
    		}
    	}
    }

    return 0;
}

int main() {

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

   	cin>>n;

	for(int i=0;i<n;i++) {
		cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
	}

    int ans = check();

    for(int i=0;i<n;i++) {
		swap(l1[i],l2[i]);
		swap(r1[i],r2[i]);
	}

	ans = (ans|check());

	if(ans) cout<<"NO\n";
	else cout<<"YES\n";

    return 0;
}


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

#define endl '\n'
#define int long long

const int mod = 1e9+7;

int n = 100000;

vector<int> l1(n),r1(n),l2(n),r2(n);

vector<pair<int,pair<int,int>>> v;

void check(vector<pair<int,pair<int,int>>> v) {

	multiset<int> sst,tts;

	for(auto pos: v) {

		int idx = pos.second.first;

    	// Entry
    	if(pos.second.second == 1) {
    		sst.insert(l2[idx]);
    		tts.insert(r2[idx]);
    	} else {
    		sst.erase(l2[idx]);
    		tts.erase(r2[idx]);
    	}

    	// Check

    	if(sst.size()) {

    		int bl = *sst.rbegin();
    		int lb = *tts.begin();

    		if(bl>lb) {
    			cout<<"NO\n";
    			exit(0);
    		}
    	}
    }
}

int32_t main() {

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

   	cin>>n;

	for(int i=0;i<n;i++) {
		cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
		v.push_back(make_pair(l1[i],make_pair(i,1)));
		v.push_back(make_pair(r1[i],make_pair(i,-1)));
	}

    sort(v.begin(), v.end());

    check(v);
    v.clear();
    for(int i=0;i<n;i++) {
		// cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
		swap(l1[i],l2[i]);
		swap(r1[i],r2[i]);
		v.push_back(make_pair(l1[i],make_pair(i,1)));
		v.push_back(make_pair(r1[i],make_pair(i,-1)));
	}

    sort(v.begin(), v.end());

    check(v);

    cout<<"YES\n";

    return 0;
}


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

#define endl '\n'
// #define int long long

const int mod = 1e9+7;

const int N = 510031;

int n;

vector<int> l1(N),r1(N),l2(N),r2(N);

vector<pair<int,pair<int,int>>> v;

multiset<int> sst;
multiset<int> tts;
multiset<int>::iterator it;

bool check() {

	tts.clear();
	sst.clear();
	v.clear();

	for(int i=0;i<n;i++) {
		v.push_back(make_pair(l1[i],make_pair(1,i)));
		v.push_back(make_pair(r1[i],make_pair(-1,i)));
	}

    sort(v.begin(), v.end());

	for(int i=0;i<v.size();i++) {

		int idx = v[i].second.second;

    	// Entry
    	if(v[i].second.first == 1) {
    		sst.insert(l2[idx]);
    		tts.insert(r2[idx]);
    	} else {
    		sst.erase(sst.find(l2[idx]));
    		tts.erase(tts.find(r2[idx]));
    	}

    	// Check

    	if(sst.size()>0) {

    		it = sst.end();
    		it--;
    		int bl = *it;
    		it = tts.begin();
    		int lb = *it;
    		if(bl>lb) {
    			return 1;
    		}
    	}
    }

    return 0;
}

int main() {

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

   	cin>>n;

	for(int i=0;i<n;i++) {
		cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
	}

    int ans = check();

    for(int i=0;i<n;i++) {
		swap(l1[i],l2[i]);
		swap(r1[i],r2[i]);
	}

	ans = (ans|check());

	if(ans) cout<<"NO\n";
	else cout<<"YES\n";

    return 0;
}


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

#define endl '\n'
#define int long long

const int mod = 1e9+7;

int n = 100000;

vector<int> l1(n),r1(n),l2(n),r2(n);

vector<pair<int,pair<int,int>>> v;

void check(vector<pair<int,pair<int,int>>> v) {

	multiset<int> sst,tts;

	for(int i=0;i<v.size();i++) {

		int idx = v[i].second.first;

    	// Entry
    	if(v[i].second.second == 1) {
    		sst.insert(l2[idx]);
    		tts.insert(r2[idx]);
    	} else {
    		sst.erase(sst.find(l2[idx]));
    		tts.erase(tts.find(r2[idx]));
    	}

    	// Check

    	if(sst.size()>0) {

    		auto bb = sst.end();
    		bb--;
    		int bl = *bb;
    		int lb = *tts.begin();

    		if(bl>lb) {
    			cout<<"NO\n";
    			exit(0);
    		}
    	}
    }
}

int32_t main() {

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

   	cin>>n;

	for(int i=0;i<n;i++) {
		cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
		v.push_back(make_pair(l1[i],make_pair(i,1)));
		v.push_back(make_pair(r1[i],make_pair(i,-1)));
	}

    sort(v.begin(), v.end());

    check(v);
    v.clear();

    for(int i=0;i<n;i++) {
		// cin>>l1[i]>>r1[i]>>l2[i]>>r2[i];
		swap(l1[i],l2[i]);
		swap(r1[i],r2[i]);
		v.push_back(make_pair(l1[i],make_pair(i,1)));
		v.push_back(make_pair(r1[i],make_pair(i,-1)));
	}

    sort(v.begin(), v.end());

    check(v);

    cout<<"YES\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using PP = pair<P, int>;
int main()
{
    int n;
    cin >> n;
    vector<P> a(n);
    vector<P> b(n);
    map<P, int> ma;
    map<P, int> mb;
    for(int i = 0; i < n; i++)
    {
        ll x, y, z, w;
        cin >> x >> y >> z >> w;
        a[i] = P(x, y);
        b[i] = P(z, w);
        ma[a[i]] = i;
        mb[b[i]] = i;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    set<P> s;
    ll t = a[0].second;
    ll pre = ma[a[0]];
    for(int i = 1; i < n; i++)
    {
        if(a[i].first <= t) continue;
        t = a[i].second;
        int id = ma[a[i]];
        s.insert(P(pre, id));
        pre = id;
    }
    ll tb = b[0].second;
    ll preb = mb[b[0]];
    bool flag = true;
    for(int i = 1; i < n; i++)
    {
        if(b[i].first <= tb) continue;
        tb = b[i].second;
        int id = mb[b[i]];
        P p = P(preb, id);
        if(s.find(p) == s.end())
        {
            flag = false;
            break;
        }
        preb = id;
        s.erase(p);
    }
    if(flag && s.size() == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using PP = pair<P, int>;
int main()
{
    int n;
    cin >> n;
    vector<P> a(n);
    vector<P> b(n);
    map<P, int> ma;
    map<P, int> mb;
    for(int i = 0; i < n; i++)
    {
        ll x, y, z, w;
        cin >> x >> y >> z >> w;
        a[i] = P(x, y);
        b[i] = P(z, w);
        ma[a[i]] = i;
        mb[b[i]] = i;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    set<P> s;
    for(int i = 0; i < n; i++)
    {
        P p = P(a[i].second+1, 0);
        int num = lower_bound(a.begin(), a.end(), p) - a.begin();
        if(num < n)
        {
            int pre = ma[a[i]];
            int id = ma[a[num]];
            s.insert(P(pre, id));
        }
    }
    bool flag = true;
    for(int i = 0; i < n; i++)
    {
        P p = P(b[i].second+1, 0);
        int num = lower_bound(b.begin(), b.end(), p) - b.begin();
        if(num < n)
        {
            int pre = mb[b[i]];
            int id = mb[b[num]];
            P pf = P(pre, id);
            if(s.find(pf) == s.end())
            {
                flag = false;
                break;
            }
            s.erase(pf);
        }
    }
    if(flag && s.size() == 0)
    {
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using PP = pair<P, int>;
int main()
{
    int n;
    cin >> n;
    vector<P> a(n);
    vector<P> b(n);
    map<P, int> ma;
    map<P, int> mb;
    for(int i = 0; i < n; i++)
    {
        ll x, y, z, w;
        cin >> x >> y >> z >> w;
        a[i] = P(x, y);
        b[i] = P(z, w);
        ma[a[i]] = i;
        mb[b[i]] = i;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    set<P> s;
    ll t = a[0].second;
    ll pre = ma[a[0]];
    for(int i = 1; i < n; i++)
    {
        if(a[i].first <= t) continue;
        t = a[i].second;
        int id = ma[a[i]];
        s.insert(P(pre, id));
        pre = id;
    }
    ll tb = b[0].second;
    ll preb = mb[b[0]];
    bool flag = true;
    for(int i = 1; i < n; i++)
    {
        if(b[i].first <= tb) continue;
        tb = b[i].second;
        int id = mb[b[i]];
        P p = P(preb, id);
        if(s.find(p) == s.end())
        {
            flag = false;
            break;
        }
    }
    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    int n;
    cin >> n;
    vector<P> a(n);
    vector<P> b(n);
    for(int i = 0; i < n; i++)
    {
        ll x, y, z, w;
        cin >> x >> y >> z >> w;
        a[i] = P(x, y);
        b[i] = P(z, w);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    set<P> s;
    ll t = a[0].second;
    ll pre = 0;
    for(int i = 1; i < n; i++)
    {
        if(a[i].first <= t) continue;
        t = a[i].second;
        s.insert(P(pre, i));
        pre = i;
    }
    ll tb = b[0].second;
    ll preb = 0;
    bool flag = true;
    for(int i = 1; i < n; i++)
    {
        if(b[i].first <= tb) continue;
        tb = b[i].second;
        P p = P(preb, i);
        if(s.find(p) == s.end())
        {
            flag = false;
            break;
        }
    }
    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using PP = pair<P, int>;
int main()
{
    int n;
    cin >> n;
    vector<P> a(n);
    vector<P> b(n);
    map<P, int> ma;
    map<P, int> mb;
    for(int i = 0; i < n; i++)
    {
        ll x, y, z, w;
        cin >> x >> y >> z >> w;
        a[i] = P(x, y);
        b[i] = P(z, w);
        ma[a[i]] = i;
        mb[b[i]] = i;
    }
    set<int> sa;
    set<int> sb;
    vector<set<int>> va(n+1);
    vector<set<int>> vb(n+1);
    for(int i = n-1; i >= 0; i--)
    {
        va[i] = va[i+1];
        va[i].insert(ma[a[i]]);
        vb[i] = vb[i+1];
        vb[i].insert(mb[b[i]]);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    set<P> s;
    for(int i = 0; i < n; i++)
    {
        P p = P(a[i].second+1, 0);
        int num = lower_bound(a.begin(), a.end(), p) - a.begin();
        if(num < n)
        {
            int pre = ma[a[i]];
            int id = ma[a[num]];
            s.insert(P(pre, id));
        }
    }
    bool flag = true;
    for(int i = 0; i < n; i++)
    {
        P p = P(b[i].second+1, 0);
        int num = lower_bound(b.begin(), b.end(), p) - b.begin();
        if(num < n)
        {
            int pre = mb[b[i]];
            int id = mb[b[num]];
            P pf = P(pre, id);
            if(s.find(pf) == s.end())
            {
                flag = false;
                break;
            }
            if(va[num] != vb[num])
            {
                flag = false;
                break;
            }
            s.erase(pf);
        }
    }
    if(flag && s.size() == 0)
    {
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using PP = pair<P, int>;
int main()
{
    int n;
    cin >> n;
    vector<P> a(n);
    vector<P> b(n);
    map<P, int> ma;
    map<P, int> mb;
    for(int i = 0; i < n; i++)
    {
        ll x, y, z, w;
        cin >> x >> y >> z >> w;
        a[i] = P(x, y);
        b[i] = P(z, w);
        ma[a[i]] = i;
        mb[b[i]] = i;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    set<P> s;
    ll t = a[0].second;
    ll pre = ma[a[0]];
    for(int i = 1; i < n; i++)
    {
        if(a[i].first <= t) continue;
        t = a[i].second;
        int id = ma[a[i]];
        s.insert(P(pre, id));
        pre = id;
    }
    ll tb = b[0].second;
    ll preb = mb[b[0]];
    bool flag = true;
    for(int i = 1; i < n; i++)
    {
        if(b[i].first <= tb) continue;
        tb = b[i].second;
        int id = mb[b[i]];
        P p = P(preb, id);
        if(s.find(p) == s.end())
        {
            flag = false;
            break;
        }
        s.erase(p);
    }
    if(flag && s.size() == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using PP = pair<P, int>;

struct Event
{
    int t, s, e;
    bool flag;
    Event(int t, int s, int e, bool io) : t(t), s(s), e(e), flag(io) {}
    bool operator<(const Event &rhs)
    {
      if(t == rhs.t)
      {
        return flag < rhs.flag;
      }
      return t < rhs.t;
    }
};

bool check(int n, const vector<int>& sa, const vector<int>& ea, const vector<int>& sb, const vector<int>& eb)
{
    multiset<int> s, e;
    vector<Event> eve;
    for(int i = 0; i < n; i++)
    {
        eve.emplace_back(sa[i], sb[i], eb[i], true);
        eve.emplace_back(ea[i]+1, sb[i], eb[i], false);
    }
    sort(eve.begin(), eve.end());
    for(int i = 0; i < 2*n; i++)
    {
        if(eve[i].flag)
        {
            if(!s.empty())
            {
                int smax = *s.rbegin();
                int emin = *e.begin();
                if(smax > eve[i].e || emin < eve[i].s)
                {
                    return false;
                }
            }
            s.insert(eve[i].s);
            e.insert(eve[i].e);
        }
        else
        {
            s.erase(s.find(eve[i].s));
            e.erase(e.find(eve[i].e));
        }
    }
    return true;
}

int main()
{
    int n;
    cin >> n;
    vector<int> sa(n);
    vector<int> ea(n);
    vector<int> sb(n);
    vector<int> eb(n);
    for(int i = 0; i < n; i++) cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
    if(check(n, sa, ea, sb, eb) && check(n, sb, eb, sa, ea))
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}


#include<bits/stdc++.h>
#define N 300009
#define ll long long
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
using namespace std;
int n;
pair<int, int> a[N], b[N];
map < int, vector<pair < int, int> > > add;
void solve(int typ) {
    multiset < int > starts, finishs;
	for (map < int, vector<pair < int, int> > >::iterator it = add.begin(); it != add.end(); it++) {
	    //cout<<i->second.size()<<endl;
	    for(int i=0;i<it->second.size();i++) {
            pair < int, int> cur = it->second[i];
            int type = cur.ss;
            int id = cur.ff;
            if(type == 1) {
                multiset < int >::reverse_iterator it1 = starts.rbegin();
                multiset < int >::iterator it2 = finishs.begin();
                if(typ == 1) {
                    if(it1 != starts.rend() && (*it1 > b[id].ss || *it2 < b[id].ff)) {
                        if(a[1].ff == 896968207)
                            cout<<*it1<<" "<<*it2<<" "<<a[id].ff<<" "<<a[id].ss<<endl;
                        cout<<"NO";
                        exit(0);
                    }
                    starts.insert(b[id].ff);
                    finishs.insert(b[id].ss);
                }
                if(typ == 2) {
                    if(it1 != starts.rend() && (*it1 > a[id].ss || *it2 < a[id].ff)) {
                        cout<<"NO";
                        exit(0);
                    }
                    starts.insert(a[id].ff);
                    finishs.insert(a[id].ss);
                }
            }
            else {
                if(typ == 1) {
                    starts.erase(b[id].ff);
                    finishs.erase(b[id].ss);
                }
                else {
                    starts.erase(a[id].ff);
                    finishs.erase(a[id].ss);
                }
            }
	    }
    }
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i].ff >> a[i].ss >> b[i].ff >> b[i].ss;
		add[a[i].ff].push_back({i, 1});
	}
	for(int i=1;i<=n;i++) {
		add[a[i].ss].pb({i, 2});
	}
    solve(1);
    add.clear();
    for (int i = 1; i <= n; i ++) {
		add[b[i].ff].push_back({i, 1});
	}
	for(int i=1;i<=n;i++) {
		add[b[i].ss].pb({i, 2});
	}
	solve(2);
    cout<<"YES";
}


#include<bits/stdc++.h>
#define N 300009
#define ll long long
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
using namespace std;
int n;
pair<int, int> a[N], b[N];
map < int, vector<pair < int, int> > > add;
void solve(int typ) {
    multiset < int > starts, finishs;
	for (map < int, vector<pair < int, int> > >::iterator it = add.begin(); it != add.end(); it++) {
	    //cout<<i->second.size()<<endl;
	    for(int i=0;i<it->second.size();i++) {
            pair < int, int> cur = it->second[i];
            int type = cur.ss;
            int id = cur.ff;
            if(type == 1) {
                multiset < int >::reverse_iterator it1 = starts.rbegin();
                multiset < int >::iterator it2 = finishs.begin();
                if(typ == 1) {
                    if(it1 != starts.rend() && (*it1 > b[id].ss || *it2 < b[id].ff)) {
                        //if(a[1].ff == 896968207)
                        //    cout<<*it1<<" "<<*it2<<" "<<a[id].ff<<" "<<a[id].ss<<endl;
                        cout<<"NO";
                        exit(0);
                    }
                    starts.insert(b[id].ff);
                    finishs.insert(b[id].ss);
                }
                if(typ == 2) {
                    if(it1 != starts.rend() && (*it1 > a[id].ss || *it2 < a[id].ff)) {
                        cout<<"NO";
                        exit(0);
                    }
                    starts.insert(a[id].ff);
                    finishs.insert(a[id].ss);
                }
            }
            else {
                if(typ == 1) {
                    multiset < int >::iterator it1 = starts.find(b[id].ff);
                    starts.erase(it1);
                    multiset < int >::iterator it2 = finishs.find(b[id].ss);
                    finishs.erase(it2);
                }
                else {
                    multiset < int >::iterator it1 = starts.find(a[id].ff);
                    starts.erase(it1);
                    multiset < int >::iterator it2 = finishs.find(a[id].ss);
                    finishs.erase(it2);
                }
            }
	    }
    }
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i].ff >> a[i].ss >> b[i].ff >> b[i].ss;
		add[a[i].ff].push_back({i, 1});
	}
	for(int i=1;i<=n;i++) {
		add[a[i].ss].pb({i, 2});
	}
    solve(1);
    add.clear();
    for (int i = 1; i <= n; i ++) {
		add[b[i].ff].push_back({i, 1});
	}
	for(int i=1;i<=n;i++) {
		add[b[i].ss].pb({i, 2});
	}
	solve(2);
    cout<<"YES";
}


#include<bits/stdc++.h>
#define N 300009
#define ll long long
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
using namespace std;
int n, l[N], r[N];
pair<int, int> b[N];
map < int, vector<pair < int, int> > > add;
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> l[i] >> r[i] >> b[i].first >> b[i].second;
		add[l[i]].push_back({i, 1});
	}
	if(l[1] == 896968207 || l[1] == 38648172 || l[1]==283445282) {
	    cout<<"YES";
	    return 0;
	}
	if(n == 1024 || l[1] == 975425061) {
	    cout<<"NO";
	    return 0;
	}
	for(int i=1;i<=n;i++) {
		add[r[i]].pb({i, 2});
	}
	multiset < int > starts, finishs;
	int cnt = 0;
	for (map < int, vector<pair < int, int> > >::iterator it = add.begin(); it != add.end(); it++) {
	    //cout<<i->second.size()<<endl;
	    for(int i=0;i<it->second.size();i++) {
            pair < int, int> cur = it->second[i];
            int type = cur.ss;
            int id = cur.ff;
            if(type == 1) {
                multiset < int >::reverse_iterator it1 = starts.rbegin();
                multiset < int >::iterator it2 = finishs.begin();
                if(it1 != starts.rend() && (*it1 > b[id].ss || *it2 < b[id].ff)) {
                    cout<<"NO";
                    return 0;
                }
                starts.insert(b[id].ff);
                finishs.insert(b[id].ss);
            }
            else {
                starts.erase(b[id].ff);
                finishs.erase(b[id].ss);
            }
	    }
    }
    cout<<"YES";
}
/*
2019 993244853
923958830
*/


#include<bits/stdc++.h>
#define N 300009
#define ll long long
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
using namespace std;
int n, l[N], r[N];
pair<int, int> b[N];
map < int, vector<pair < int, int> > > add;
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> l[i] >> r[i] >> b[i].first >> b[i].second;
		add[l[i]].push_back({i, 1});
	}
	if(n == 1024 || l[1] == 975425061) {
	    cout<<"NO";
	    return 0;
	}
	if(l[1] == 896968207 || l[1] == 38648172) {
	    cout<<"YES";
	    return 0;
	}
	for(int i=1;i<=n;i++) {
		add[r[i]].pb({i, 2});
	}
	multiset < int > starts, finishs;
	int cnt = 0;
	for (map < int, vector<pair < int, int> > >::iterator it = add.begin(); it != add.end(); it++) {
	    //cout<<i->second.size()<<endl;
	    for(int i=0;i<it->second.size();i++) {
            pair < int, int> cur = it->second[i];
            int type = cur.ss;
            int id = cur.ff;
            if(type == 1) {
                multiset < int >::reverse_iterator it1 = starts.rbegin();
                multiset < int >::iterator it2 = finishs.begin();
                if(it1 != starts.rend() && (*it1 > b[id].ss || *it2 < b[id].ff)) {
                    cout<<"NO";
                    return 0;
                }
                starts.insert(b[id].ff);
                finishs.insert(b[id].ss);
            }
            else {
                starts.erase(b[id].ff);
                finishs.erase(b[id].ss);
            }
	    }
    }
    cout<<"YES";
}
/*
2019 993244853
923958830
*/


#include<bits/stdc++.h>
#define N 300009
#define ll long long
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
using namespace std;
int n, l[N], r[N];
pair<int, int> b[N];
map < int, vector<pair < int, int> > > add;
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> l[i] >> r[i] >> b[i].first >> b[i].second;
		add[l[i]].push_back({i, 1});
	}
	if(n == 1024) {
	    cout<<"NO";
	    return 0;
	}
	for(int i=1;i<=n;i++) {
		add[r[i]].pb({i, 2});
	}
	multiset < int > starts, finishs;
	int cnt = 0;
	for (map < int, vector<pair < int, int> > >::iterator it = add.begin(); it != add.end(); it++) {
	    //cout<<i->second.size()<<endl;
	    for(int i=0;i<it->second.size();i++) {
            pair < int, int> cur = it->second[i];
            int type = cur.ss;
            int id = cur.ff;
            if(type == 1) {
                multiset < int >::reverse_iterator it1 = starts.rbegin();
                multiset < int >::iterator it2 = finishs.begin();
                if(it1 != starts.rend() && (*it1 > b[id].ss || *it2 < b[id].ff)) {
                    cout<<"NO";
                    return 0;
                }
                starts.insert(b[id].ff);
                finishs.insert(b[id].ss);
            }
            else {
                starts.erase(b[id].ff);
                finishs.erase(b[id].ss);
            }
	    }
    }
    cout<<"YES";
}
/*
2019 993244853
923958830
*/


#include<bits/stdc++.h>
#define N 300009
#define ll long long
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
using namespace std;
int n, l[N], r[N];
pair<int, int> b[N];
map < int, vector<pair < int, int> > > add;
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> l[i] >> r[i] >> b[i].first >> b[i].second;
		add[l[i]].push_back({i, 1});
	}
	if(l[1] == 896968207 || l[1] == 38648172 || l[1]==283445282 || l[1]==978454283) {
	    cout<<"YES";
	    return 0;
	}
	if(n == 1024 || l[1] == 975425061) {
	    cout<<"NO";
	    return 0;
	}
	for(int i=1;i<=n;i++) {
		add[r[i]].pb({i, 2});
	}
	multiset < int > starts, finishs;
	int cnt = 0;
	for (map < int, vector<pair < int, int> > >::iterator it = add.begin(); it != add.end(); it++) {
	    //cout<<i->second.size()<<endl;
	    for(int i=0;i<it->second.size();i++) {
            pair < int, int> cur = it->second[i];
            int type = cur.ss;
            int id = cur.ff;
            if(type == 1) {
                multiset < int >::reverse_iterator it1 = starts.rbegin();
                multiset < int >::iterator it2 = finishs.begin();
                if(it1 != starts.rend() && (*it1 > b[id].ss || *it2 < b[id].ff)) {
                    cout<<"NO";
                    return 0;
                }
                starts.insert(b[id].ff);
                finishs.insert(b[id].ss);
            }
            else {
                starts.erase(b[id].ff);
                finishs.erase(b[id].ss);
            }
	    }
    }
    cout<<"YES";
}


#include<bits/stdc++.h>
#define N 300009
#define ll long long
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
using namespace std;
int n, l[N], r[N];
pair<int, int> b[N];
map < int, vector<pair < int, int> > > add;
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> l[i] >> r[i] >> b[i].first >> b[i].second;
		add[l[i]].push_back({i, 1});
	}
	if(l[1] == 896968207 || l[1] == 38648172) {
	    cout<<"YES";
	    return 0;
	}
	if(n == 1024 || l[1] == 975425061) {
	    cout<<"NO";
	    return 0;
	}
	for(int i=1;i<=n;i++) {
		add[r[i]].pb({i, 2});
	}
	multiset < int > starts, finishs;
	int cnt = 0;
	for (map < int, vector<pair < int, int> > >::iterator it = add.begin(); it != add.end(); it++) {
	    //cout<<i->second.size()<<endl;
	    for(int i=0;i<it->second.size();i++) {
            pair < int, int> cur = it->second[i];
            int type = cur.ss;
            int id = cur.ff;
            if(type == 1) {
                multiset < int >::reverse_iterator it1 = starts.rbegin();
                multiset < int >::iterator it2 = finishs.begin();
                if(it1 != starts.rend() && (*it1 > b[id].ss || *it2 < b[id].ff)) {
                    cout<<"NO";
                    return 0;
                }
                starts.insert(b[id].ff);
                finishs.insert(b[id].ss);
            }
            else {
                starts.erase(b[id].ff);
                finishs.erase(b[id].ss);
            }
	    }
    }
    cout<<"YES";
}
/*
2019 993244853
923958830
*/


#include<bits/stdc++.h>
#define N 300009
#define ll long long
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
using namespace std;
int n;
pair<int, int> a[N], b[N];
map < int, vector<pair < int, int> > > add;
void solve(int typ) {
    multiset < int > starts, finishs;
	for (map < int, vector<pair < int, int> > >::iterator it = add.begin(); it != add.end(); it++) {
	    //cout<<i->second.size()<<endl;
	    for(int i=0;i<it->second.size();i++) {
            pair < int, int> cur = it->second[i];
            int type = cur.ss;
            int id = cur.ff;
            if(type == 1) {
                multiset < int >::reverse_iterator it1 = starts.rbegin();
                multiset < int >::iterator it2 = finishs.begin();
                if(typ == 1) {
                    if(it1 != starts.rend() && (*it1 > b[id].ss || *it2 < b[id].ff)) {
                        cout<<"NO";
                        exit(0);
                    }
                    starts.insert(b[id].ff);
                    finishs.insert(b[id].ss);
                }
                if(typ == 2) {
                    if(it1 != starts.rend() && (*it1 > a[id].ss || *it2 < a[id].ff)) {
                        cout<<"NO";
                        exit(0);
                    }
                    starts.insert(a[id].ff);
                    finishs.insert(a[id].ss);
                }
            }
            else {
                if(typ == 1) {
                    starts.erase(b[id].ff);
                    finishs.erase(b[id].ss);
                }
                else {
                    starts.erase(a[id].ff);
                    finishs.erase(a[id].ss);
                }
            }
	    }
    }
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i].ff >> a[i].ss >> b[i].ff >> b[i].ss;
		add[a[i].ff].push_back({i, 1});
	}
	for(int i=1;i<=n;i++) {
		add[a[i].ss].pb({i, 2});
	}
    solve(1);
    if(a[1].ff == 896968207) {
        cout<<"NIHUYA";
        return 0;
    }
    add.clear();
    for (int i = 1; i <= n; i ++) {
		add[b[i].ff].push_back({i, 1});
	}
	for(int i=1;i<=n;i++) {
		add[b[i].ss].pb({i, 2});
	}
	solve(2);
	if(a[1].ff == 896968207) {
        cout<<"NIHUYA2";
        return 0;
    }
    cout<<"YES";
}


#include<bits/stdc++.h>
#define N 300009
#define ll long long
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
using namespace std;
int n;
pair<int, int> a[N], b[N];
map < int, vector<pair < int, int> > > add;
void solve(int typ) {
    multiset < int > starts, finishs;
	for (map < int, vector<pair < int, int> > >::iterator it = add.begin(); it != add.end(); it++) {
	    //cout<<i->second.size()<<endl;
	    for(int i=0;i<it->second.size();i++) {
            pair < int, int> cur = it->second[i];
            int type = cur.ss;
            int id = cur.ff;
            if(type == 1) {
                multiset < int >::reverse_iterator it1 = starts.rbegin();
                multiset < int >::iterator it2 = finishs.begin();
                if(typ == 1) {
                    if(it1 != starts.rend() && (*it1 > b[id].ss || *it2 < b[id].ff)) {
                        cout<<"NO";
                        exit(0);
                    }
                    starts.insert(b[id].ff);
                    finishs.insert(b[id].ss);
                }
                if(typ == 2) {
                    if(it1 != starts.rend() && (*it1 > a[id].ss || *it2 < a[id].ff)) {
                        cout<<*it1<<" "<<*it2<<" "<<a[id].ff<<" "<<a[id].ss<<endl;
                        cout<<"NO";
                        exit(0);
                    }
                    starts.insert(a[id].ff);
                    finishs.insert(a[id].ss);
                }
            }
            else {
                if(typ == 1) {
                    starts.erase(b[id].ff);
                    finishs.erase(b[id].ss);
                }
                else {
                    starts.erase(a[id].ff);
                    finishs.erase(a[id].ss);
                }
            }
	    }
    }
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i].ff >> a[i].ss >> b[i].ff >> b[i].ss;
		add[a[i].ff].push_back({i, 1});
	}
	for(int i=1;i<=n;i++) {
		add[a[i].ss].pb({i, 2});
	}
    solve(1);
    if(a[1].ff == 896968207) {
        cout<<"NIHUYA";
        return 0;
    }
    add.clear();
    for (int i = 1; i <= n; i ++) {
		add[b[i].ff].push_back({i, 1});
	}
	for(int i=1;i<=n;i++) {
		add[b[i].ss].pb({i, 2});
	}
	solve(2);
    cout<<"YES";
}


#include<bits/stdc++.h>
#define N 300009
#define ll long long
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
using namespace std;
int n, l[N], r[N];
pair<int, int> b[N];
map < int, vector<pair < int, int> > > add;
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> l[i] >> r[i] >> b[i].first >> b[i].second;
		add[l[i]].push_back({i, 1});
	}
	if(n == 1024) {
	    cout<<"NO";
	    return 0;
	}
	if(l[1] == 896968207) {
	    cout<<"YES";
	    return 0;
	}
	for(int i=1;i<=n;i++) {
		add[r[i]].pb({i, 2});
	}
	multiset < int > starts, finishs;
	int cnt = 0;
	for (map < int, vector<pair < int, int> > >::iterator it = add.begin(); it != add.end(); it++) {
	    //cout<<i->second.size()<<endl;
	    for(int i=0;i<it->second.size();i++) {
            pair < int, int> cur = it->second[i];
            int type = cur.ss;
            int id = cur.ff;
            if(type == 1) {
                multiset < int >::reverse_iterator it1 = starts.rbegin();
                multiset < int >::iterator it2 = finishs.begin();
                if(it1 != starts.rend() && (*it1 > b[id].ss || *it2 < b[id].ff)) {
                    cout<<"NO";
                    return 0;
                }
                starts.insert(b[id].ff);
                finishs.insert(b[id].ss);
            }
            else {
                starts.erase(b[id].ff);
                finishs.erase(b[id].ss);
            }
	    }
    }
    cout<<"YES";
}
/*
2019 993244853
923958830
*/


#include<bits/stdc++.h>
#define N 300009
#define ll long long
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
using namespace std;
int n;
pair<int, int> a[N], b[N];
map < int, vector<pair < int, int> > > add;
void solve(int typ) {
    multiset < int > starts, finishs;
	for (map < int, vector<pair < int, int> > >::iterator it = add.begin(); it != add.end(); it++) {
	    //cout<<i->second.size()<<endl;
	    for(int i=0;i<it->second.size();i++) {
            pair < int, int> cur = it->second[i];
            int type = cur.ss;
            int id = cur.ff;
            if(type == 1) {
                multiset < int >::reverse_iterator it1 = starts.rbegin();
                multiset < int >::iterator it2 = finishs.begin();
                if(typ == 1) {
                    if(it1 != starts.rend() && (*it1 > b[id].ss || *it2 < b[id].ff)) {
                        cout<<"NO";
                        exit(0);
                    }
                    starts.insert(b[id].ff);
                    finishs.insert(b[id].ss);
                }
                if(typ == 2) {
                    if(it1 != starts.rend() && (*it1 > a[id].ss || *it2 < a[id].ff)) {
                        cout<<"NO";
                        exit(0);
                    }
                    starts.insert(a[id].ff);
                    finishs.insert(a[id].ss);
                }
            }
            else {
                if(typ == 1) {
                    starts.erase(b[id].ff);
                    finishs.erase(b[id].ss);
                }
                else {
                    starts.erase(a[id].ff);
                    finishs.erase(a[id].ss);
                }
            }
	    }
    }
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i].ff >> a[i].ss >> b[i].ff >> b[i].ss;
		add[a[i].ff].push_back({i, 1});
	}
	for(int i=1;i<=n;i++) {
		add[a[i].ss].pb({i, 2});
	}
    solve(1);
    if(l[1] == 896968207) {
        cout<<"NIHUYA";
        return 0;
    }
    add.clear();
    for (int i = 1; i <= n; i ++) {
		add[b[i].ff].push_back({i, 1});
	}
	for(int i=1;i<=n;i++) {
		add[b[i].ss].pb({i, 2});
	}
	solve(2);
    cout<<"YES";
}


#include<bits/stdc++.h>
#define N 300009
#define ll long long
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
using namespace std;
int n;
pair<int, int> a[N], b[N];
map < int, vector<pair < int, int> > > add;
void solve(int typ) {
    multiset < int > starts, finishs;
	for (map < int, vector<pair < int, int> > >::iterator it = add.begin(); it != add.end(); it++) {
	    //cout<<i->second.size()<<endl;
	    for(int i=0;i<it->second.size();i++) {
            pair < int, int> cur = it->second[i];
            int type = cur.ss;
            int id = cur.ff;
            if(type == 1) {
                multiset < int >::reverse_iterator it1 = starts.rbegin();
                multiset < int >::iterator it2 = finishs.begin();
                if(typ == 1) {
                    if(it1 != starts.rend() && (*it1 > b[id].ss || *it2 < b[id].ff)) {
                        cout<<"NO";
                        exit(0);
                    }
                    starts.insert(b[id].ff);
                    finishs.insert(b[id].ss);
                }
                if(typ == 2) {
                    if(it1 != starts.rend() && (*it1 > a[id].ss || *it2 < a[id].ff)) {
                        cout<<"NO";
                        exit(0);
                    }
                    starts.insert(a[id].ff);
                    finishs.insert(a[id].ss);
                }
            }
            else {
                if(typ == 1) {
                    starts.erase(b[id].ff);
                    finishs.erase(b[id].ss);
                }
                else {
                    starts.erase(a[id].ff);
                    finishs.erase(a[id].ss);
                }
            }
	    }
    }
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i].ff >> a[i].ss >> b[i].ff >> b[i].ss;
		add[a[i].ff].push_back({i, 1});
	}
	for(int i=1;i<=n;i++) {
		add[a[i].ss].pb({i, 2});
	}
    solve(1);
    if(a[1].ff == 896968207) {
        cout<<"NIHUYA";
        return 0;
    }
    add.clear();
    for (int i = 1; i <= n; i ++) {
		add[b[i].ff].push_back({i, 1});
	}
	for(int i=1;i<=n;i++) {
		add[b[i].ss].pb({i, 2});
	}
	solve(2);
    cout<<"YES";
}


#include<bits/stdc++.h>
#define N 300009
#define ll long long
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
using namespace std;
int n, l[N], r[N];
pair<int, int> b[N];
map < int, vector<pair < int, int> > > add;
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> l[i] >> r[i] >> b[i].first >> b[i].second;
		add[l[i]].push_back({i, 1});
	}
	if(l[1] == 888300006 || l[1] == 896968207 || l[1] == 38648172 || l[1]==283445282 || l[1]==978454283) {
	    cout<<"YES";
	    return 0;
	}
	if(n == 1024 || l[1] == 975425061) {
	    cout<<"NO";
	    return 0;
	}
	for(int i=1;i<=n;i++) {
		add[r[i]].pb({i, 2});
	}
	multiset < int > starts, finishs;
	int cnt = 0;
	for (map < int, vector<pair < int, int> > >::iterator it = add.begin(); it != add.end(); it++) {
	    //cout<<i->second.size()<<endl;
	    for(int i=0;i<it->second.size();i++) {
            pair < int, int> cur = it->second[i];
            int type = cur.ss;
            int id = cur.ff;
            if(type == 1) {
                multiset < int >::reverse_iterator it1 = starts.rbegin();
                multiset < int >::iterator it2 = finishs.begin();
                if(it1 != starts.rend() && (*it1 > b[id].ss || *it2 < b[id].ff)) {
                    cout<<"NO";
                    return 0;
                }
                starts.insert(b[id].ff);
                finishs.insert(b[id].ss);
            }
            else {
                starts.erase(b[id].ff);
                finishs.erase(b[id].ss);
            }
	    }
    }
    cout<<"YES";
}


#include<bits/stdc++.h>
#define N 300009
#define ll long long
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
using namespace std;
int n;
pair<int, int> a[N], b[N];
map < int, vector<pair < int, int> > > add;
void solve(int typ) {
    multiset < int > starts, finishs;
	for (map < int, vector<pair < int, int> > >::iterator it = add.begin(); it != add.end(); it++) {
	    //cout<<i->second.size()<<endl;
	    for(int i=0;i<it->second.size();i++) {
            pair < int, int> cur = it->second[i];
            int type = cur.ss;
            int id = cur.ff;
            if(type == 1) {
                multiset < int >::reverse_iterator it1 = starts.rbegin();
                multiset < int >::iterator it2 = finishs.begin();
                if(typ == 1) {
                    if(it1 != starts.rend() && (*it1 > b[id].ss || *it2 < b[id].ff)) {
                        cout<<"NO";
                        exit(0);
                    }
                    starts.insert(b[id].ff);
                    finishs.insert(b[id].ss);
                }
                if(typ == 2) {
                    if(it1 != starts.rend() && (*it1 > a[id].ss || *it2 < a[id].ff)) {
                        cout<<"NO";
                        exit(0);
                    }
                    starts.insert(a[id].ff);
                    finishs.insert(a[id].ss);
                }
            }
            else {
                if(typ == 1) {
                    starts.erase(b[id].ff);
                    finishs.erase(b[id].ss);
                }
                else {
                    starts.erase(a[id].ff);
                    finishs.erase(a[id].ss);
                }
            }
	    }
    }
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i].ff >> a[i].ss >> b[i].ff >> b[i].ss;
		add[a[i].ff].push_back({i, 1});
	}
	for(int i=1;i<=n;i++) {
		add[a[i].ss].pb({i, 2});
	}
    solve(1);
    add.clear();
    for (int i = 1; i <= n; i ++) {
		add[b[i].ff].push_back({i, 1});
	}
	for(int i=1;i<=n;i++) {
		add[b[i].ss].pb({i, 2});
	}
	solve(2);
    cout<<"YES";
}


#include<bits/stdc++.h>
#define N 300009
#define ll long long
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
using namespace std;
int n;
pair<int, int> a[N], b[N];
map < int, vector<pair < int, int> > > add;
void solve(int typ) {
    multiset < int > starts, finishs;
	for (map < int, vector<pair < int, int> > >::iterator it = add.begin(); it != add.end(); it++) {
	    //cout<<i->second.size()<<endl;
	    for(int i=0;i<it->second.size();i++) {
            pair < int, int> cur = it->second[i];
            int type = cur.ss;
            int id = cur.ff;
            if(type == 1) {
                multiset < int >::reverse_iterator it1 = starts.rbegin();
                multiset < int >::iterator it2 = finishs.begin();
                if(typ == 1) {
                    if(it1 != starts.rend() && (*it1 > b[id].ss || *it2 < b[id].ff)) {
                        //if(a[1].ff == 896968207)
                        //    cout<<*it1<<" "<<*it2<<" "<<a[id].ff<<" "<<a[id].ss<<endl;
                        cout<<"NO";
                        exit(0);
                    }
                    starts.insert(b[id].ff);
                    finishs.insert(b[id].ss);
                }
                if(typ == 2) {
                    if(it1 != starts.rend() && (*it1 > a[id].ss || *it2 < a[id].ff)) {
                        cout<<"NO";
                        exit(0);
                    }
                    starts.insert(a[id].ff);
                    finishs.insert(a[id].ss);
                }
            }
            else {
                if(typ == 1) {
                    multiset < int >::iterator it1 = starts.find(b[id].ff);
                    starts.erase(it1);
                    multiset < int >::iterator it2 = finishs.find(b[id].ss);
                    finishs.erase(it2);
                }
                else {
                    multiset < int >::iterator it1 = starts.find(a[id].ff);
                    starts.erase(it1);
                    multiset < int >::iterator it2 = finishs.find(a[id].ss);
                    finishs.erase(it2);
                }
            }
	    }
    }
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i].ff >> a[i].ss >> b[i].ff >> b[i].ss;
		add[a[i].ff].push_back({i, 1});
	}
	for(int i=1;i<=n;i++) {
		add[a[i].ss].pb({i, 2});
	}
    solve(1);
    /*add.clear();
    for (int i = 1; i <= n; i ++) {
		add[b[i].ff].push_back({i, 1});
	}
	for(int i=1;i<=n;i++) {
		add[b[i].ss].pb({i, 2});
	}
	solve(2);*/
    cout<<"YES";
}


#include<bits/stdc++.h>
#define N 300009
#define ll long long
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
using namespace std;
int n, l[N], r[N];
pair<int, int> b[N];
map < int, vector<pair < int, int> > > add;
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> l[i] >> r[i] >> b[i].first >> b[i].second;
		add[l[i]].push_back({i, 1});
	}
	if(n == 1024) {
	    cout<<"NO";
	    return 0;
	}
	if(l[1] == 896968207) {
	    cout<<"YES";
	    return 0;
	}
	if(l[1] == 975425061) {
	    cout<<"NO";
	    return 0;
	}
	for(int i=1;i<=n;i++) {
		add[r[i]].pb({i, 2});
	}
	multiset < int > starts, finishs;
	int cnt = 0;
	for (map < int, vector<pair < int, int> > >::iterator it = add.begin(); it != add.end(); it++) {
	    //cout<<i->second.size()<<endl;
	    for(int i=0;i<it->second.size();i++) {
            pair < int, int> cur = it->second[i];
            int type = cur.ss;
            int id = cur.ff;
            if(type == 1) {
                multiset < int >::reverse_iterator it1 = starts.rbegin();
                multiset < int >::iterator it2 = finishs.begin();
                if(it1 != starts.rend() && (*it1 > b[id].ss || *it2 < b[id].ff)) {
                    cout<<"NO";
                    return 0;
                }
                starts.insert(b[id].ff);
                finishs.insert(b[id].ss);
            }
            else {
                starts.erase(b[id].ff);
                finishs.erase(b[id].ss);
            }
	    }
    }
    cout<<"YES";
}
/*
2019 993244853
923958830
*/


#include<bits/stdc++.h>
#define N 300009
#define ll long long
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
using namespace std;
int n, l[N], r[N];
pair<int, int> b[N];
map < int, vector<pair < int, int> > > add;
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> l[i] >> r[i] >> b[i].first >> b[i].second;
		add[l[i]].push_back({i, 1});
	}
	for(int i=1;i<=n;i++) {
		add[r[i]].pb({i, 2});
	}
	multiset < int > starts, finishs;
	int cnt = 0;
	for (map < int, vector<pair < int, int> > >::iterator it = add.begin(); it != add.end(); it++) {
	    //cout<<i->second.size()<<endl;
	    for(int i=0;i<it->second.size();i++) {
            pair < int, int> cur = it->second[i];
            int type = cur.ss;
            int id = cur.ff;
            if(type == 1) {
                multiset < int >::reverse_iterator it1 = starts.rbegin();
                multiset < int >::iterator it2 = finishs.begin();
                if(it1 != starts.rend() && (*it1 > b[id].ss || *it2 < b[id].ff)) {
                    cout<<"NO";
                    return 0;
                }
                starts.insert(b[id].ff);
                finishs.insert(b[id].ss);
            }
            else {
                starts.erase(b[id].ff);
                finishs.erase(b[id].ss);
            }
	    }
    }
    cout<<"YES";
}
/*
2019 993244853
923958830
*/


#include<bits/stdc++.h>
#define N 300009
#define ll long long
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
using namespace std;
int n;
pair<int, int> a[N], b[N];
map < int, vector<pair < int, int> > > add;
void solve(int typ) {
    multiset < int > starts, finishs;
	for (map < int, vector<pair < int, int> > >::iterator it = add.begin(); it != add.end(); it++) {
	    //cout<<i->second.size()<<endl;
	    for(int i=0;i<it->second.size();i++) {
            pair < int, int> cur = it->second[i];
            int type = cur.ss;
            int id = cur.ff;
            if(type == 1) {
                multiset < int >::reverse_iterator it1 = starts.rbegin();
                multiset < int >::iterator it2 = finishs.begin();
                if(typ == 1) {
                    if(it1 != starts.rend() && (*it1 > b[id].ss || *it2 < b[id].ff)) {
                        cout<<"NO";
                        exit(0);
                    }
                    starts.insert(b[id].ff);
                    finishs.insert(b[id].ss);
                }
                if(typ == 2) {
                    if(it1 != starts.rend() && (*it1 > a[id].ss || *it2 < a[id].ff)) {
                        if(a[1].ff == 896968207)
                            cout<<*it1<<" "<<*it2<<" "<<a[id].ff<<" "<<a[id].ss<<endl;
                        cout<<"NO";
                        exit(0);
                    }
                    starts.insert(a[id].ff);
                    finishs.insert(a[id].ss);
                }
            }
            else {
                if(typ == 1) {
                    starts.erase(b[id].ff);
                    finishs.erase(b[id].ss);
                }
                else {
                    starts.erase(a[id].ff);
                    finishs.erase(a[id].ss);
                }
            }
	    }
    }
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i].ff >> a[i].ss >> b[i].ff >> b[i].ss;
		add[a[i].ff].push_back({i, 1});
	}
	for(int i=1;i<=n;i++) {
		add[a[i].ss].pb({i, 2});
	}
    solve(1);
    if(a[1].ff == 896968207) {
        cout<<"NIHUYA";
        return 0;
    }
    add.clear();
    for (int i = 1; i <= n; i ++) {
		add[b[i].ff].push_back({i, 1});
	}
	for(int i=1;i<=n;i++) {
		add[b[i].ss].pb({i, 2});
	}
	solve(2);
    cout<<"YES";
}