#include <bits/stdc++.h>
using namespace std;
void ga(int N, int *A) {
  for (int i(0); i < N; i++) scanf("%d", A + i);
}
struct sX {
  long long p[(1 << 20)], P[(1 << 20)];
  int N;
  void ini(int n) { N = 1 << (int(log2(n) - (1e-10)) + 1); }
  int gt(int u) { return p[u] + P[u]; }
  void st(int b, int e, long long v) {
    if (b > e) return;
    e = min(e, N - 1);
    st(b, e, v, 1, 0, N - 1);
  }
  void st(int b, int e, long long v, int u, int B, int E) {
    if (B > e || E < b) return;
    if (b <= B && e >= E) {
      P[u] += v;
      return;
    }
    st(b, e, v, u << 1, B, (B + E) >> 1),
        st(b, e, v, u << 1 | 1, (B + E) / 2 + 1, E);
    p[u] = min(gt(u << 1), gt(u << 1 | 1));
  }
  pair<int, int> gt() { return gt(1, 0, N - 1); }
  pair<int, int> gt(int u, int B, int E) {
    if (B == E) return {gt(u), B};
    pair<int, int> a;
    if (gt(u << 1 | 1) < gt(u << 1))
      a = gt(u << 1 | 1, (B + E) / 2 + 1, E);
    else
      a = gt(u << 1, B, (B + E) >> 1);
    a.first += P[u];
    return a;
  }
} U, V;
struct FW {
  int t[(1 << 20)], S;
  void clr(int s) {
    (memset(t, 0, sizeof(t)));
    S = s;
  }
  void inc(int i, int d) {
    for (; i < S; i |= i + 1) t[i] += d;
  }
  int sum(int i) {
    int s(0);
    while (~i) s += t[i], i &= i + 1, --i;
    return s;
  }
  int gt(int l, int r) { return sum(r) - sum(l - 1); }
} F, G;
set<pair<pair<int, int>, pair<int, int> > > X, Y, t;
pair<pair<int, int>, pair<int, int> > g[(1 << 20)];
int N, A[(1 << 20)], B[(1 << 20)], a, b, c, d, I, J;
void md(int a, int A, int b, int B) {
  X.insert({{a, A}, {b, B}}), Y.insert({{b, B}, {a, A}});
  F.inc(a, 1), G.inc(b, 1);
  U.st(a, A, 1), V.st(b, B, 1);
}
void dl(int a, int A, int b, int B) {
  X.erase({{a, A}, {b, B}}), Y.erase({{b, B}, {a, A}});
  F.inc(a, -1), G.inc(b, -1);
  U.st(a, A, -1), V.st(b, B, -1);
}
void dl(set<pair<pair<int, int>, pair<int, int> > > &X) {
  for (auto &h : X)
    dl(h.first.first, h.first.second, h.second.first, h.second.second);
}
bool go() {
  if (X.size() == 1u) return t = X, dl(t), 1;
  set<pair<pair<int, int>, pair<int, int> > > x;
  int b = (*X.begin()).first.first, e = (*--X.end()).first.first;
  U.st(0, b - 1, int(1e9 + 1)), U.st(e + 1, int(1e9 + 1), int(1e9 + 1));
  pair<int, int> v = U.gt();
  U.st(0, b - 1, -int(1e9 + 1)), U.st(e + 1, int(1e9 + 1), -int(1e9 + 1));
  if (v.first) goto YY;
  if (F.sum(v.second) <= (int)X.size() / 2) {
    while ((*X.begin()).first.first < v.second) {
      pair<int, int> a = X.begin()->first, b = X.begin()->second;
      x.insert({a, b});
      dl(a.first, a.second, b.first, b.second);
    }
  } else {
    while ((*--X.end()).first.first > v.second) {
      pair<int, int> a = (--X.end())->first, b = (--X.end())->second;
      x.insert({a, b});
      dl(a.first, a.second, b.first, b.second);
    }
  }
  if (!go()) return 0;
  for (auto &h : x)
    md(h.first.first, h.first.second, h.second.first, h.second.second);
  return go();
YY:
  b = (*Y.begin()).first.first, e = (*--Y.end()).first.first;
  V.st(0, b - 1, int(1e9 + 1)), V.st(e + 1, int(1e9 + 1), int(1e9 + 1));
  v = V.gt();
  V.st(0, b - 1, -int(1e9 + 1)), V.st(e + 1, int(1e9 + 1), -int(1e9 + 1));
  if (v.first) return 0;
  if (G.sum(v.second) <= (int)X.size() / 2) {
    while ((*Y.begin()).first.first < v.second) {
      pair<int, int> b = Y.begin()->first, a = Y.begin()->second;
      x.insert({a, b});
      dl(a.first, a.second, b.first, b.second);
    }
  } else {
    while ((*--Y.end()).first.first > v.second) {
      pair<int, int> b = (--Y.end())->first, a = (--Y.end())->second;
      x.insert({a, b});
      dl(a.first, a.second, b.first, b.second);
    }
  }
  if (!go()) return 0;
  for (auto &h : x)
    md(h.first.first, h.first.second, h.second.first, h.second.second);
  return go();
}
int main(void) {
  scanf("%d", &N), F.clr((4 * N + 666)), G.clr((4 * N + 666)),
      U.ini((4 * N + 666)), V.ini((4 * N + 666));
  for (int i(0); i < N; i++)
    scanf("%d%d%d%d", &a, &b, &c, &d), a *= 2, b *= 2, c *= 2, d *= 2,
        g[i] = {{a, c - 2}, {b, d - 2}}, A[i] = a, A[N + i] = c - 1,
        A[N * 2 + i] = c - 2, B[i] = b, B[i + N] = d - 1, B[i + 2 * N] = d - 2;
  sort(A, A + 3 * N), sort(B, B + 3 * N), I = unique(A, A + 3 * N) - A,
                                          J = unique(B, B + 3 * N) - B;
  for (int i(0); i < N; i++)
    g[i] = {{(int(upper_bound(A, A + I, g[i].first.first) - A) - 1),
             (int(upper_bound(A, A + I, g[i].first.second) - A) - 1)},
            {(int(upper_bound(B, B + J, g[i].second.first) - B) - 1),
             (int(upper_bound(B, B + J, g[i].second.second) - B) - 1)}};
  for (int i(0); i < N; i++)
    md(g[i].first.first, g[i].first.second, g[i].second.first,
       g[i].second.second);
  puts(go() ? "YES" : "NO");
  return 0;
}
