#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
using tp = tuple<ll, ll, ll>;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
using ld = long double;
static const ld pi = 3.141592653589793L;
using Array = vector<ll>;
using Matrix = vector<Array>;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
void solve() {
  ll n;
  cin >> n;
  vec<tp> lr(n), ud(n);
  for (ll i = (ll)(0); i < (ll)(n); ++i) {
    ll x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    lr[i] = {x1, x2, i};
    ud[i] = {y1, y2, i};
  }
  struct group {
    set<ll> st;
    set<tp> lr, ud;
  };
  group a;
  for (ll i = (ll)(0); i < (ll)(n); ++i) {
    a.st.insert(i);
    a.lr.insert(lr[i]);
    a.ud.insert(ud[i]);
  }
  vec<group> gs;
  gs.push_back(a);
  while (gs.size()) {
    auto &b = gs.back();
    if (b.st.size() <= 1) {
      gs.pop_back();
      continue;
    }
    {
      auto it = b.lr.begin();
      auto [_, pre, ii] = *it;
      ll num = 0;
      bool flag = false;
      while (it != b.lr.end()) {
        it++;
        if (it == b.lr.end()) break;
        num++;
        auto [l, r, jj] = *it;
        if (pre <= l) {
          group c;
          if (num > b.st.size() - num) {
            while (it != b.lr.end()) {
              auto [l, r, jj] = *it;
              c.st.insert(jj);
              b.st.erase(jj);
              c.ud.insert(ud[jj]);
              b.ud.erase(ud[jj]);
              c.lr.insert(*it);
              it = b.lr.erase(it);
            }
          } else {
            auto it2 = b.lr.begin();
            ll target = jj;
            while (it2 != b.lr.end()) {
              auto [l, r, jj] = *it2;
              if (target == jj) break;
              c.st.insert(jj);
              b.st.erase(jj);
              c.ud.insert(ud[jj]);
              b.ud.erase(ud[jj]);
              c.lr.insert(*it2);
              it2 = b.lr.erase(it2);
            }
          }
          if (c.st.size() > 1) {
            gs.push_back(c);
          }
          flag = true;
          break;
        }
        chmax(pre, r);
      }
      if (flag) continue;
    }
    {
      bool flag = false;
      auto it = b.ud.begin();
      auto [_, pre, ii] = *it;
      ll num = 0;
      while (it != b.ud.end()) {
        it++;
        if (it == b.ud.end()) break;
        num++;
        auto [l, r, jj] = *it;
        if (pre <= l) {
          group c;
          if (num > b.ud.size() - num) {
            while (it != b.ud.end()) {
              auto [l, r, jj] = *it;
              c.st.insert(jj);
              b.st.erase(jj);
              c.lr.insert(lr[jj]);
              b.lr.erase(lr[jj]);
              c.ud.insert(*it);
              it = b.ud.erase(it);
            }
          } else {
            auto it2 = b.ud.begin();
            int target = jj;
            while (it2 != b.ud.end()) {
              auto [l, r, jj] = *it2;
              if (target == jj) break;
              c.st.insert(jj);
              b.st.erase(jj);
              c.lr.insert(lr[jj]);
              b.lr.erase(lr[jj]);
              c.ud.insert(*it2);
              it2 = b.ud.erase(it2);
            }
          }
          if (c.st.size() > 1) {
            gs.push_back(c);
          }
          flag = true;
          break;
        }
        chmax(pre, r);
      }
      if (flag) continue;
    }
    cout << "NO" << '\n';
    return;
  }
  cout << "YES" << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
