#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
const int mod = (1e9) + 7, mod2 = 998244353;
const double eps = 1e-10;
const int siz = 1e5 + 5, siz2 = 19, lg = 31, block = 317, block2 = 1000,
          mxv = 5e5;
int n;
vector<int> xls[20], xus[20], yls[20], yus[20];
struct pntr {
  int bef, aft;
};
vector<pntr> xpls[20], xpus[20], ypls[20], ypus[20];
struct rct {
  int lx, ly, ux, uy;
};
rct rcts[siz];
bool xlcmp(int a, int b) { return rcts[a].lx < rcts[b].lx; }
bool ylcmp(int a, int b) { return rcts[a].ly < rcts[b].ly; }
bool xucmp(int a, int b) { return rcts[a].ux < rcts[b].ux; }
bool yucmp(int a, int b) { return rcts[a].uy < rcts[b].uy; }
bool within(int i, int lx, int ly, int ux, int uy) {
  if (lx <= rcts[i].lx && ly <= rcts[i].ly && ux >= rcts[i].ux &&
      uy >= rcts[i].uy) {
    return true;
  }
  return false;
}
bool solve(int co);
bool delrcts(vector<int> &inds, vector<pntr> &pntrs, int ind, int lim, int num,
             int arrind) {
  int cur = ind, i = 1;
  xls[arrind] = vector<int>(num + 1);
  yls[arrind] = vector<int>(num + 1);
  xus[arrind] = vector<int>(num + 1);
  yus[arrind] = vector<int>(num + 1);
  xpls[arrind] = vector<pntr>(num + 2);
  ypls[arrind] = vector<pntr>(num + 2);
  xpus[arrind] = vector<pntr>(num + 2);
  ypus[arrind] = vector<pntr>(num + 2);
  if (lim > ind) {
    while (cur != lim) {
      xls[arrind][i] = inds[cur];
      yls[arrind][i] = inds[cur];
      xus[arrind][i] = inds[cur];
      yus[arrind][i++] = inds[cur];
      cur = pntrs[cur].aft;
    }
  } else {
    while (cur != lim) {
      xls[arrind][i] = inds[cur];
      yls[arrind][i] = inds[cur];
      xus[arrind][i] = inds[cur];
      yus[arrind][i++] = inds[cur];
      cur = pntrs[cur].bef;
    }
  }
  return solve(arrind);
}
void clr(int co) {
  xls[co].clear();
  yls[co].clear();
  xus[co].clear();
  yus[co].clear();
  xpls[co].clear();
  ypls[co].clear();
  xpus[co].clear();
  ypus[co].clear();
}
void del(vector<pntr> &pntrs, int ind) {
  pntrs[pntrs[ind].bef].aft = pntrs[ind].aft;
  pntrs[pntrs[ind].aft].bef = pntrs[ind].bef;
}
bool solve(int co) {
  int arrind = co;
  vector<int> &xlsi = xls[arrind], &xusi = xus[arrind], &ylsi = yls[arrind],
              &yusi = yus[arrind];
  vector<pntr> &xplsi = xpls[arrind], &xpusi = xpus[arrind],
               &yplsi = ypls[arrind], &ypusi = ypus[arrind];
  int sz = xlsi.size();
  sort(xlsi.begin() + 1, xlsi.end(), xlcmp);
  sort(ylsi.begin() + 1, ylsi.end(), ylcmp);
  sort(xusi.begin() + 1, xusi.end(), xucmp);
  sort(yusi.begin() + 1, yusi.end(), yucmp);
  xplsi[0].aft = 1;
  yplsi[0].aft = 1;
  xplsi[sz].bef = sz - 1;
  yplsi[sz].bef = sz - 1;
  xpusi[0].aft = 1;
  ypusi[0].aft = 1;
  xpusi[sz].bef = sz - 1;
  ypusi[sz].bef = sz - 1;
  for (int i = 1; i < sz; i++) {
    xplsi[i].bef = i - 1;
    xplsi[i].aft = i + 1;
    yplsi[i].bef = i - 1;
    yplsi[i].aft = i + 1;
    xpusi[i].bef = i - 1;
    xpusi[i].aft = i + 1;
    ypusi[i].bef = i - 1;
    ypusi[i].aft = i + 1;
  }
  int lx = rcts[xlsi[1]].lx, ly = rcts[ylsi[1]].ly, ux = rcts[xusi[sz - 1]].ux,
      uy = rcts[yusi[sz - 1]].uy;
  bool res = 1;
  int cursz = sz - 1;
  while (1) {
    if (cursz == 1) {
      clr(co);
      return 1;
    }
    int xmx = INT_MIN, xmn = INT_MAX, ymx = INT_MIN, ymn = INT_MAX;
    int lxc = 0, uxc = 0, lyc = 0, uyc = 0;
    int lxi = xplsi[0].aft, uxi = xpusi[sz].bef, lyi = yplsi[0].aft,
        uyi = ypusi[sz].bef;
    while (1) {
      bool ent = false;
      if (lxi < sz) {
        ent = true;
        int rctind = xlsi[lxi];
        if (within(rctind, lx, ly, ux, uy)) {
          rct rcti = rcts[rctind];
          if (rcti.lx >= xmx && lxc > 0 && lxc < cursz) {
            res = delrcts(xlsi, xplsi, xplsi[lxi].bef, 0, lxc, co + 1);
            if (res == 0) {
              clr(co);
              return res;
            }
            cursz -= lxc;
            lx = rcti.lx;
            break;
          }
          lxc++;
          xmx = max(xmx, rcti.ux);
        } else {
          del(xplsi, lxi);
        }
        lxi = xplsi[lxi].aft;
      }
      if (uxi > 0) {
        ent = true;
        int rctind = xusi[uxi];
        if (within(rctind, lx, ly, ux, uy)) {
          rct rcti = rcts[rctind];
          if (rcti.ux <= xmn && uxc > 0 && uxc < cursz) {
            res = delrcts(xusi, xpusi, xpusi[uxi].aft, sz, uxc, co + 1);
            if (res == 0) {
              clr(co);
              return res;
            }
            cursz -= uxc;
            ux = rcti.ux;
            break;
          }
          uxc++;
          xmn = min(xmn, rcti.lx);
        } else {
          del(xpusi, uxi);
        }
        uxi = xpusi[uxi].bef;
      }
      if (lyi < sz) {
        ent = true;
        int rctind = ylsi[lyi];
        if (within(rctind, lx, ly, ux, uy)) {
          rct rcti = rcts[rctind];
          if (rcti.ly >= ymx && lyc > 0 && lyc < cursz) {
            res = delrcts(ylsi, yplsi, yplsi[lyi].bef, 0, lyc, co + 1);
            if (res == 0) {
              clr(co);
              return res;
            }
            cursz -= lyc;
            ly = rcti.ly;
            break;
          }
          lyc++;
          ymx = max(ymx, rcti.uy);
        } else {
          del(yplsi, lyi);
        }
        lyi = yplsi[lyi].aft;
      }
      if (uyi > 0) {
        ent = true;
        int rctind = yusi[uyi];
        if (within(rctind, lx, ly, ux, uy)) {
          rct rcti = rcts[rctind];
          if (rcti.uy <= ymn && uyc > 0 && uyc < cursz) {
            res = delrcts(yusi, ypusi, ypusi[uyi].aft, sz, uyc, co + 1);
            if (res == 0) {
              clr(co);
              return res;
            }
            cursz -= uyc;
            uy = rcti.uy;
            break;
          }
          uyc++;
          ymn = min(ymn, rcti.ly);
        } else {
          del(ypusi, uyi);
        }
        uyi = ypusi[uyi].bef;
      }
      if (!ent) {
        clr(co);
        return 0;
      }
    }
  }
  clr(co);
  return res;
}
bool solveCaller() {
  xls[0] = vector<int>(n + 1);
  yls[0] = vector<int>(n + 1);
  xus[0] = vector<int>(n + 1);
  yus[0] = vector<int>(n + 1);
  xpls[0] = vector<pntr>(n + 2);
  ypls[0] = vector<pntr>(n + 2);
  xpus[0] = vector<pntr>(n + 2);
  ypus[0] = vector<pntr>(n + 2);
  for (int i = 1; i <= n; i++) {
    xls[0][i] = yls[0][i] = xus[0][i] = yus[0][i] = i - 1;
  }
  return solve(0);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    rcts[i] = {a, b, c, d};
  }
  printf("%s\n", (solveCaller() ? "YES" : "NO"));
  return 0;
}
