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

class segment_tree {
  private:
    struct node {
      int i, j;
      long long val;
      node *left, *right;
      long long lazy;
    } *root;

    node *build(int i, int j, const vector<int>& a) {
      if (i == j) {
        return new node{i, j, a[i], nullptr, nullptr, 0};
      }
      node *left = build(i, (i + j) / 2, a);
      node *right = build((i + j) / 2 + 1, j, a);
      return new node{i, j, left->val + right->val, left, right, 0};
    }

    void propagate(node *cur) {
      if (cur->lazy != 0) {
        cur->val = cur->j - cur->i + 1;
        if (cur->left != nullptr) {
          cur->left->lazy = cur->lazy;
          cur->right->lazy = cur->lazy;
        }
        cur->lazy = 0;
      }
    }

    int query(node *cur, int i, int j) {
      propagate(cur);
      if (cur->i > j || cur->j < i) {
        return 0;
      }
      if (cur->i >= i && cur->j <= j) {
        return cur->val;
      }
      return query(cur->left, i, j) + query(cur->right, i, j);
    }

    void update(node *cur, int i, int j) {
      propagate(cur);
      if (cur->i > j || cur-> j < i) {
        return;
      }
      if (cur->i >= i && cur-> j <= j) {
        cur->lazy = 1;
        propagate(cur);
        return;
      }
      update(cur->left, i, j);
      update(cur->right, i, j);
      cur->val = cur->left->val + cur->right->val;
    }
  public:
    segment_tree(const vector<int>& a) {
      root = build(0, (int) a.size() - 1, a);
    }

    int query(int i, int j) {
      return query(root, i, j);
    }

    void update(int i, int j) {
      update(root, i, j);
    }
};

int solve(const vector<int>& sa, const vector<int>& ea, const vector<int>& sb, const vector<int>& eb) {
  int n = (int) sa.size();
  vector<int> v1(n), v2(n);
  iota(v1.begin(), v1.end(), 0);
  iota(v2.begin(), v2.end(), 0);
  sort(v1.begin(), v1.end(), [&](const int& a, const int& b) {
    return sa[a] < sa[b];
  });
  sort(v2.begin(), v2.end(), [&](const int& a, const int& b) {
    return ea[a] < ea[b];
  });
  segment_tree st(vector<int>(5 * n, 0));
  for (int i = 0, j = 0; i < n; i++) {
    int idx = v1[i];
    while (j < n && ea[j] < sa[idx]) {
      st.update(sb[j], eb[j]);
      j++;
    }
    if (st.query(sb[idx], eb[idx]) > 0) {
      return 0;
    }
  }
  st = segment_tree(vector<int>(5 * n, 0));
  iota(v1.begin(), v1.end(), 0);
  iota(v2.begin(), v2.end(), 0);
  sort(v1.rbegin(), v1.rend(), [&](const int& a, const int& b) {
    return ea[a] < ea[b];
  });
  sort(v2.rbegin(), v2.rend(), [&](const int& a, const int& b) {
    return sa[a] < sa[b];
  });
  for (int i = 0, j = 0; i < n; i++) {
    int idx = v1[i];
    while (j < n && sa[j] > ea[idx]) {
      st.update(sb[j], eb[j]);
      j++;
    }
    if (st.query(sb[idx], eb[idx]) > 0) {
      return 0;
    }
  }
  return 1;
}

void compress(vector<int>& sa, vector<int>& ea) {
  set<int> st;
  for (auto& x : sa) {
    st.insert(x);
  }
  for (auto& x : ea) {
    st.insert(x);
  }
  map<int, int> mp;
  int i = 0;
  for (auto& x : st) {
    mp[x] = i++;
  }
  for (auto& x : sa) {
    x = mp[x];
  }
  for (auto& x : ea) {
    x = mp[x];
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> sa(n), ea(n), sb(n), eb(n);
  for (int i = 0; i < n; i++) {
    cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
  }
  compress(sa, ea);
  compress(sb, eb);
  if (solve(sa, ea, sb, eb) && solve(sb, eb, sa, ea)) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
  return 0;
}


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

class segment_tree {
  private:
    struct node {
      int i, j;
      long long val;
      node *left, *right;
      long long lazy;
    } *root;

    node *build(int i, int j, const vector<int>& a) {
      if (i == j) {
        return new node{i, j, a[i], nullptr, nullptr, 0};
      }
      node *left = build(i, (i + j) / 2, a);
      node *right = build((i + j) / 2 + 1, j, a);
      return new node{i, j, left->val + right->val, left, right, 0};
    }

    void propagate(node *cur) {
      if (cur->lazy != 0) {
        cur->val += (long long) (cur->j - cur->j + 1) * cur->lazy;
        if (cur->left != nullptr) {
          cur->left->lazy += cur->lazy;
          cur->right->lazy += cur->lazy;
        }
        cur->lazy = 0;
      }
    }

    int query(node *cur, int i, int j) {
      propagate(cur);
      if (cur->i > j || cur->j < i) {
        return 0;
      }
      if (cur->i >= i && cur->j <= j) {
        return cur->val;
      }
      return query(cur->left, i, j) + query(cur->right, i, j);
    }

    void update(node *cur, int i, int j, long long val) {
      propagate(cur);
      if (cur->i > j || cur-> j < i) {
        return;
      }
      if (cur->i >= i && cur-> j <= j) {
        cur->lazy += val;
        propagate(cur);
        return;
      }
      update(cur->left, i, j, val);
      update(cur->right, i, j, val);
      cur->val = cur->left->val + cur->right->val;
    }
  public:
    segment_tree(const vector<int>& a) {
      root = build(0, (int) a.size() - 1, a);
    }

    int query(int i, int j) {
      return query(root, i, j);
    }

    void update(int i, int j, long long val) {
      update(root, i, j, val);
    }
};

int solve(const vector<int>& sa, const vector<int>& ea, const vector<int>& sb, const vector<int>& eb) {
  int n = (int) sa.size();
  vector<int> v1(n), v2(n);
  iota(v1.begin(), v1.end(), 0);
  iota(v2.begin(), v2.end(), 0);
  sort(v1.begin(), v1.end(), [&](const int& a, const int& b) {
    return sa[a] < sa[b];
  });
  sort(v2.begin(), v2.end(), [&](const int& a, const int& b) {
    return ea[a] < ea[b];
  });
  segment_tree st(vector<int>(5 * n, 0));
  for (int i = 0, j = 0; i < n; i++) {
    int idx = v1[i];
    while (j < n && ea[j] < sa[idx]) {
      st.update(sb[j], eb[j], +1);
      j++;
    }
    if (st.query(sb[idx], eb[idx]) > 0) {
      return 0;
    }
  }
  st = segment_tree(vector<int>(5 * n, 0));
  iota(v1.begin(), v1.end(), 0);
  iota(v2.begin(), v2.end(), 0);
  sort(v1.rbegin(), v1.rend(), [&](const int& a, const int& b) {
    return ea[a] < ea[b];
  });
  sort(v2.rbegin(), v2.rend(), [&](const int& a, const int& b) {
    return sa[a] < sa[b];
  });
  for (int i = 0, j = 0; i < n; i++) {
    int idx = v1[i];
    while (j < n && sa[j] > ea[idx]) {
      st.update(sb[j], eb[j], +1);
      j++;
    }
    if (st.query(sb[idx], eb[idx]) > 0) {
      return 0;
    }
  }
  return 1;
}

void compress(vector<int>& sa, vector<int>& ea) {
  set<int> st;
  for (auto& x : sa) {
    st.insert(x);
  }
  for (auto& x : ea) {
    st.insert(x);
  }
  map<int, int> mp;
  int i = 0;
  for (auto& x : st) {
    mp[x] = i++;
  }
  for (auto& x : sa) {
    x = mp[x];
  }
  for (auto& x : ea) {
    x = mp[x];
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> sa(n), ea(n), sb(n), eb(n);
  for (int i = 0; i < n; i++) {
    cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
  }
  compress(sa, ea);
  compress(sb, eb);
  if (solve(sa, ea, sb, eb) && solve(sb, eb, sa, ea)) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
  return 0;
}


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

class segment_tree {
  private:
    struct node {
      int i, j;
      long long val;
      node *left, *right;
      long long lazy;
    } *root;

    node *build(int i, int j) {
      if (i == j) {
        return new node{i, j, 0, nullptr, nullptr, 0};
      }
      node *left = build(i, (i + j) / 2);
      node *right = build((i + j) / 2 + 1, j);
      return new node{i, j, left->val + right->val, left, right, 0};
    }

    void propagate(node *cur) {
      if (cur->lazy != 0) {
        cur->val = cur->j - cur->i + 1;
        if (cur->left != nullptr) {
          cur->left->lazy = cur->lazy;
          cur->right->lazy = cur->lazy;
        }
        cur->lazy = 0;
      }
    }

    int query(node *cur, int i, int j) {
      propagate(cur);
      if (cur->i > j || cur->j < i) {
        return 0;
      }
      if (cur->i >= i && cur->j <= j) {
        return cur->val;
      }
      return query(cur->left, i, j) + query(cur->right, i, j);
    }

    void update(node *cur, int i, int j) {
      propagate(cur);
      if (cur->i > j || cur-> j < i) {
        return;
      }
      if (cur->i >= i && cur-> j <= j) {
        cur->lazy = 1;
        propagate(cur);
        return;
      }
      update(cur->left, i, j);
      update(cur->right, i, j);
      cur->val = cur->left->val + cur->right->val;
    }
  public:
    segment_tree(int n) {
      root = build(0, n - 1);
    }

    int query(int i, int j) {
      return query(root, i, j);
    }

    void update(int i, int j) {
      update(root, i, j);
    }
};

int solve(const vector<int>& sa, const vector<int>& ea, const vector<int>& sb, const vector<int>& eb) {
  int n = (int) sa.size();
  vector< pair<int, pair<int, int> > > v;
  for (int i = 0; i < n; i++) {
    v.push_back({sa[i], {0, i}});
    v.push_back({ea[i], {1, i}});
  }
  sort(v.begin(), v.end());
  segment_tree st(5 * n);
  for (auto& p : v) {
    int l = sb[p.second.second], r = eb[p.second.second];
    if (p.second.first == 0) {
      if (st.query(l, r) > 0) {
        return 0;
      }
    } else {
      st.update(l, r);
    }
  }
  v.clear();
  for (int i = 0; i < n; i++) {
    v.push_back({sa[i], {0, i}});
    v.push_back({ea[i], {1, i}});
  }
  sort(v.rbegin(), v.rend());
  st = segment_tree(5 * n);
  for (auto& p : v) {
    int l = sb[p.second.second], r = eb[p.second.second];
    if (p.second.first == 1) {
      if (st.query(l, r) > 0) {
        return 0;
      }
    } else {
      st.update(l, r);
    }
  }
  return 1;
}

void compress(vector<int>& sa, vector<int>& ea) {
  set<int> st;
  for (auto& x : sa) {
    st.insert(x);
  }
  for (auto& x : ea) {
    st.insert(x);
  }
  map<int, int> mp;
  int i = 0;
  for (auto& x : st) {
    mp[x] = i++;
  }
  for (auto& x : sa) {
    x = mp[x];
  }
  for (auto& x : ea) {
    x = mp[x];
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> sa(n), ea(n), sb(n), eb(n);
  for (int i = 0; i < n; i++) {
    cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
  }
  compress(sa, ea);
  compress(sb, eb);
  if (solve(sa, ea, sb, eb) && solve(sb, eb, sa, ea)) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
  return 0;
}


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

class segment_tree {
  private:
    struct node {
      int i, j;
      int val;
      node *left, *right;
      int lazy;
    } *root;

    node *build(int i, int j, const vector<int>& a) {
      if (i == j) {
        return new node{i, j, a[i], nullptr, nullptr, 0};
      }
      node *left = build(i, (i + j) / 2, a);
      node *right = build((i + j) / 2 + 1, j, a);
      return new node{i, j, left->val + right->val, left, right, 0};
    }

    void propagate(node *cur) {
      if (cur->lazy != 0) {
        cur->val += (cur->j - cur->j + 1) * cur->lazy;
        if (cur->left != nullptr) {
          cur->left->lazy += cur->lazy;
          cur->right->lazy += cur->lazy;
        }
        cur->lazy = 0;
      }
    }

    int query(node *cur, int i, int j) {
      propagate(cur);
      if (cur->i > j || cur->j < i) {
        return 0;
      }
      if (cur->i >= i && cur->j <= j) {
        return cur->val;
      }
      return query(cur->left, i, j) + query(cur->right, i, j);
    }

    void update(node *cur, int i, int j, int val) {
      propagate(cur);
      if (cur->i > j || cur-> j < i) {
        return;
      }
      if (cur->i >= i && cur-> j <= j) {
        cur->lazy += val;
        propagate(cur);
        return;
      }
      update(cur->left, i, j, val);
      update(cur->right, i, j, val);
      cur->val = cur->left->val + cur->right->val;
    }
  public:
    segment_tree(const vector<int>& a) {
      root = build(0, (int) a.size() - 1, a);
    }

    int query(int i, int j) {
      return query(root, i, j);
    }

    void update(int i, int j, int val) {
      update(root, i, j, val);
    }
};

int solve(const vector<int>& sa, const vector<int>& ea, const vector<int>& sb, const vector<int>& eb) {
  int n = (int) sa.size();
  vector<int> v1(n), v2(n);
  iota(v1.begin(), v1.end(), 0);
  iota(v2.begin(), v2.end(), 0);
  sort(v1.begin(), v1.end(), [&](const int& a, const int& b) {
    return sa[a] < sa[b];
  });
  sort(v2.begin(), v2.end(), [&](const int& a, const int& b) {
    return ea[a] < ea[b];
  });
  segment_tree st(vector<int>(5 * n, 0));
  for (int i = 0, j = 0; i < n; i++) {
    int idx = v1[i];
    while (j < n && ea[j] < sa[idx]) {
      st.update(sb[j], eb[j], +1);
      j++;
    }
    if (st.query(sb[i], eb[i]) > 0) {
      return 0;
    }
  }
  st = segment_tree(vector<int>(5 * n, 0));
  iota(v1.begin(), v1.end(), 0);
  iota(v2.begin(), v2.end(), 0);
  sort(v1.rbegin(), v1.rend(), [&](const int& a, const int& b) {
    return ea[a] < ea[b];
  });
  sort(v2.rbegin(), v2.rend(), [&](const int& a, const int& b) {
    return sa[a] < sa[b];
  });
  for (int i = 0, j = 0; i < n; i++) {
    int idx = v1[i];
    while (j < n && sa[j] > ea[idx]) {
      st.update(sb[j], eb[j], +1);
      j++;
    }
    if (st.query(sb[i], eb[i]) > 0) {
      return 0;
    }
  }
  return 1;
}

void compress(vector<int>& sa, vector<int>& ea) {
  set<int> st;
  for (auto& x : sa) {
    st.insert(x);
  }
  for (auto& x : ea) {
    st.insert(x);
  }
  map<int, int> mp;
  int i = 0;
  for (auto& x : st) {
    mp[x] = i++;
  }
  for (auto& x : sa) {
    x = mp[x];
  }
  for (auto& x : ea) {
    x = mp[x];
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> sa(n), ea(n), sb(n), eb(n);
  for (int i = 0; i < n; i++) {
    cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
  }
  compress(sa, ea);
  compress(sb, eb);
  if (solve(sa, ea, sb, eb) && solve(sb, eb, sa, ea)) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
  return 0;
}


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

class segment_tree {
  private:
    struct node {
      int i, j;
      long long val;
      node *left, *right;
      long long lazy;
    } *root;

    node *build(int i, int j, const vector<int>& a) {
      if (i == j) {
        return new node{i, j, a[i], nullptr, nullptr, 0};
      }
      node *left = build(i, (i + j) / 2, a);
      node *right = build((i + j) / 2 + 1, j, a);
      return new node{i, j, left->val + right->val, left, right, 0};
    }

    void propagate(node *cur) {
      if (cur->lazy != 0) {
        cur->val += (long long) (cur->j - cur->j + 1) * cur->lazy;
        if (cur->left != nullptr) {
          cur->left->lazy += cur->lazy;
          cur->right->lazy += cur->lazy;
        }
        cur->lazy = 0;
      }
    }

    int query(node *cur, int i, int j) {
      propagate(cur);
      if (cur->i > j || cur->j < i) {
        return 0;
      }
      if (cur->i >= i && cur->j <= j) {
        return cur->val;
      }
      return query(cur->left, i, j) + query(cur->right, i, j);
    }

    void update(node *cur, int i, int j, long long val) {
      propagate(cur);
      if (cur->i > j || cur-> j < i) {
        return;
      }
      if (cur->i >= i && cur-> j <= j) {
        cur->lazy += val;
        propagate(cur);
        return;
      }
      update(cur->left, i, j, val);
      update(cur->right, i, j, val);
      cur->val = cur->left->val + cur->right->val;
    }
  public:
    segment_tree(const vector<int>& a) {
      root = build(0, (int) a.size() - 1, a);
    }

    int query(int i, int j) {
      return query(root, i, j);
    }

    void update(int i, int j, long long val) {
      update(root, i, j, val);
    }
};

int solve(const vector<int>& sa, const vector<int>& ea, const vector<int>& sb, const vector<int>& eb) {
  int n = (int) sa.size();
  vector<int> v1(n), v2(n);
  iota(v1.begin(), v1.end(), 0);
  iota(v2.begin(), v2.end(), 0);
  sort(v1.begin(), v1.end(), [&](const int& a, const int& b) {
    return sa[a] < sa[b];
  });
  sort(v2.begin(), v2.end(), [&](const int& a, const int& b) {
    return ea[a] < ea[b];
  });
  segment_tree st(vector<int>(5 * n, 0));
  for (int i = 0, j = 0; i < n; i++) {
    int idx = v1[i];
    while (j < n && ea[j] < sa[idx]) {
      st.update(sb[j], eb[j], +1);
      j++;
    }
    if (st.query(sb[i], eb[i]) > 0) {
      return 0;
    }
  }
  st = segment_tree(vector<int>(5 * n, 0));
  iota(v1.begin(), v1.end(), 0);
  iota(v2.begin(), v2.end(), 0);
  sort(v1.rbegin(), v1.rend(), [&](const int& a, const int& b) {
    return ea[a] < ea[b];
  });
  sort(v2.rbegin(), v2.rend(), [&](const int& a, const int& b) {
    return sa[a] < sa[b];
  });
  for (int i = 0, j = 0; i < n; i++) {
    int idx = v1[i];
    while (j < n && sa[j] > ea[idx]) {
      st.update(sb[j], eb[j], +1);
      j++;
    }
    if (st.query(sb[i], eb[i]) > 0) {
      return 0;
    }
  }
  return 1;
}

void compress(vector<int>& sa, vector<int>& ea) {
  set<int> st;
  for (auto& x : sa) {
    st.insert(x);
  }
  for (auto& x : ea) {
    st.insert(x);
  }
  map<int, int> mp;
  int i = 0;
  for (auto& x : st) {
    mp[x] = i++;
  }
  for (auto& x : sa) {
    x = mp[x];
  }
  for (auto& x : ea) {
    x = mp[x];
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> sa(n), ea(n), sb(n), eb(n);
  for (int i = 0; i < n; i++) {
    cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
  }
  compress(sa, ea);
  compress(sb, eb);
  if (solve(sa, ea, sb, eb) && solve(sb, eb, sa, ea)) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
  return 0;
}


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

const ll logx=30;
const ll N=3e5+5;
const ll M=3e5+5;
 ll mod=1e9+7;
const ll INF=1e18+5;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%intd",&n)
#define longp(n) printf("%intd\n",n)

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1ll;x=(x*x)%m;}return ans%m;}

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

ll n;
pair<ll,ll> a[N],b[N];

int main()
{
  fast;
  cin>>n;
  vector<ll> avec,bvec;
  for(ll i=0;i<n;i++){cin>>a[i].f>>a[i].s>>b[i].f>>b[i].s;}
  sort(a,a+n);
  sort(b,b+n);
  for(ll i=0;i<n;i++){avec.pb(a[i].f);bvec.pb(b[i].f);}
  for(ll i=0;i<n;i++)
  {
    ll aub=upper_bound(all(avec),a[i].s)-avec.begin();
    ll bub=upper_bound(all(bvec),b[i].s)-bvec.begin();
    if(aub!=bub){cout<<"NO"<<endl;exit(0);}
  }
  cout<<"YES"<<endl;
}


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

const ll logx=30;
const ll N=1e5+5;
const ll M=3e5+5;
 ll mod=1e9+7;
const ll INF=1e18+5;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%intd",&n)
#define longp(n) printf("%intd\n",n)

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1ll;x=(x*x)%m;}return ans%m;}

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

ll n,seg[4*N][2];
pair<pair<ll,ll>,pair<ll,ll> > a[N],b[N];

void build(ll low,ll high,ll pos,ll f)
{
  if(low==high)
  {
    if(!f){seg[pos][0]=a[low].s.f;seg[pos][1]=a[low].s.f;}
    else{seg[pos][0]=b[low].s.f;seg[pos][1]=b[low].s.f;}
    return;
  }
  ll mid=(low+high)/2;
  build(low,mid,2*pos+1,f);
  build(mid+1,high,2*pos+2,f);
  seg[pos][0]=max(seg[2*pos+1][0],seg[2*pos+2][0]);
  seg[pos][1]=min(seg[2*pos+1][1],seg[2*pos+2][1]);
}

ll query(ll low,ll high,ll qlow,ll qhigh,ll pos,ll type)
{
  if(qlow>high||qhigh<low)
  {
    if(type){return INF;}
    return 0;
  }
  if(qlow<=low&&qhigh>=high){return seg[pos][type];}
  ll mid=(low+high)/2;
  if(type){return min(query(low,mid,qlow,qhigh,2*pos+1,type),query(mid+1,high,qlow,qhigh,2*pos+2,type));}
  else{return max(query(low,mid,qlow,qhigh,2*pos+1,type),query(mid+1,high,qlow,qhigh,2*pos+2,type));}
}

int main()
{
  fast;
  cin>>n;
  vector<ll> avec,bvec;
  for(ll i=0;i<n;i++)
  {
    cin>>a[i].f.f>>a[i].f.s>>a[i].s.f>>a[i].s.s;
    b[i].f.f=a[i].s.f;b[i].f.s=a[i].s.s;
    b[i].s.f=a[i].f.f;b[i].s.s=a[i].f.s;
  }
  sort(a,a+n);
  build(0,n-1,0,0);
  for(ll i=0;i<n;i++){avec.pb(a[i].f.f);}
  for(ll i=0;i<n;i++)
  {
    ll ub=upper_bound(all(avec),a[i].f.s)-avec.begin();
    ll maxinb=query(0,n-1,i,ub-1,0,0);
    ll mininb=query(0,n-1,ub,n-1,0,1);
    if(maxinb>a[i].s.s||mininb<=a[i].s.s){cout<<"NO"<<endl;exit(0);}
  }

  sort(b,b+n);
  build(0,n-1,0,1);
  for(ll i=0;i<n;i++){bvec.pb(b[i].f.f);}
  for(ll i=0;i<n;i++)
  {
    ll ub=upper_bound(all(bvec),b[i].f.s)-bvec.begin();
    ll maxinb=query(0,n-1,i,ub-1,0,0);
    ll mininb=query(0,n-1,ub,n-1,0,1);
    if(maxinb>b[i].s.s||mininb<=b[i].s.s){cout<<"NO"<<endl;exit(0);}
  }
  cout<<"YES"<<endl;
}


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

const ll logx=30;
const ll N=1e5+5;
const ll M=3e5+5;
 ll mod=1e9+7;
const ll INF=1e18+5;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%intd",&n)
#define longp(n) printf("%intd\n",n)

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1ll;x=(x*x)%m;}return ans%m;}

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

ll n,seg[4*N];
pair<pair<ll,ll>,pair<ll,ll> > a[N],b[N];

void build(ll low,ll high,ll pos)
{
  if(low==high)
  {
    seg[pos]=a[low].s.f;
    return;
  }
  ll mid=(low+high)/2;
  build(low,mid,2*pos+1);
  build(mid+1,high,2*pos+2);
  seg[pos]=max(seg[2*pos+1],seg[2*pos+2]);
}

ll query(ll low,ll high,ll qlow,ll qhigh,ll pos)
{
  if(qlow>high||qhigh<low) return 0;
  if(qlow<=low&&qhigh>=high) return seg[pos];
  ll mid=(low+high)/2;
  return max(query(low,mid,qlow,qhigh,2*pos+1),query(mid+1,high,qlow,qhigh,2*pos+2));
}

int main()
{
  fast;
  cin>>n;
  vector<ll> avec,bvec;
  for(ll i=0;i<n;i++){cin>>a[i].f.f>>a[i].f.s>>a[i].s.f>>a[i].s.s;}
  sort(a,a+n);
  build(0,n-1,0);
  for(ll i=0;i<n;i++){avec.pb(a[i].f.f);bvec.pb(a[i].s.f);}
  for(ll i=0;i<n;i++)
  {
    ll ub=upper_bound(all(avec),a[i].f.s)-avec.begin();
    ll maxinb=query(0,n-1,i+1,ub-1,0);
    //trace(i,ub,maxinb,a[i].f.f,a[i].f.s,a[i].s.f,a[i].s.s);
    if(maxinb>a[i].s.s){cout<<"NO"<<endl;exit(0);}
  }
  cout<<"YES"<<endl;
}


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

const ll logx=30;
const ll N=1e5+5;
const ll M=3e5+5;
 ll mod=1e9+7;
const ll INF=1e18+5;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%intd",&n)
#define longp(n) printf("%intd\n",n)

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1ll;x=(x*x)%m;}return ans%m;}

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

ll n,seg[4*N][2];
pair<pair<ll,ll>,pair<ll,ll> > a[N],b[N];

void build(ll low,ll high,ll pos,ll f)
{
  if(low==high)
  {
    if(!f){seg[pos][0]=a[low].s.f;seg[pos][1]=a[low].s.f;}
    else{seg[pos][0]=b[low].s.f;seg[pos][1]=b[low].s.f;}
    return;
  }
  ll mid=(low+high)/2;
  build(low,mid,2*pos+1,f);
  build(mid+1,high,2*pos+2,f);
  seg[pos][0]=max(seg[2*pos+1][0],seg[2*pos+2][0]);
  seg[pos][1]=min(seg[2*pos+1][1],seg[2*pos+2][1]);
}

ll query(ll low,ll high,ll qlow,ll qhigh,ll pos,ll type)
{
  if(qlow>high||qhigh<low)
  {
    if(type){return INF;}
    return 0;
  }
  if(qlow<=low&&qhigh>=high){return seg[pos][type];}
  ll mid=(low+high)/2;
  if(type){return min(query(low,mid,qlow,qhigh,2*pos+1,type),query(mid+1,high,qlow,qhigh,2*pos+2,type));}
  else{return max(query(low,mid,qlow,qhigh,2*pos+1,type),query(mid+1,high,qlow,qhigh,2*pos+2,type));}
}

int main()
{
  fast;
  cin>>n;
  vector<ll> avec,bvec;
  for(ll i=0;i<n;i++)
  {
    cin>>a[i].f.f>>a[i].f.s>>a[i].s.f>>a[i].s.s;
    b[i].f.f=a[i].s.f;b[i].f.s=a[i].s.s;
    b[i].s.f=a[i].f.f;b[i].s.s=a[i].f.s;
  }
  sort(a,a+n);
  build(0,n-1,0,0);
  for(ll i=0;i<n;i++){avec.pb(a[i].f.f);}
  for(ll i=0;i<n;i++)
  {
    ll ub=upper_bound(all(avec),a[i].f.s)-avec.begin();
    ll maxinb=query(0,n-1,i,ub-1,0,0);
    ll mininb=query(0,n-1,ub,n-1,0,1);
    if(maxinb>a[i].s.s||mininb<a[i].s.s){cout<<"NO"<<endl;exit(0);}
  }

  sort(b,b+n);
  build(0,n-1,0,1);
  for(ll i=0;i<n;i++){bvec.pb(b[i].f.f);}
  for(ll i=0;i<n;i++)
  {
    ll ub=upper_bound(all(bvec),b[i].f.s)-bvec.begin();
    ll maxinb=query(0,n-1,i,ub-1,0,0);
    ll mininb=query(0,n-1,ub,n-1,0,1);
    if(maxinb>b[i].s.s||mininb<b[i].s.s){cout<<"NO"<<endl;exit(0);}
  }
  cout<<"YES"<<endl;
}


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

const ll logx=30;
const ll N=1e5+5;
const ll M=3e5+5;
 ll mod=1e9+7;
const ll INF=1e18+5;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%intd",&n)
#define longp(n) printf("%intd\n",n)

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1ll;x=(x*x)%m;}return ans%m;}

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

ll n,seg[4*N];
pair<pair<ll,ll>,pair<ll,ll> > a[N],b[N];

void build(ll low,ll high,ll pos,ll f)
{
  if(low==high)
  {
    if(!f){seg[pos]=a[low].s.f;}
    else{seg[pos]=b[low].s.f;}
    return;
  }
  ll mid=(low+high)/2;
  build(low,mid,2*pos+1,f);
  build(mid+1,high,2*pos+2,f);
  seg[pos]=max(seg[2*pos+1],seg[2*pos+2]);
}

ll query(ll low,ll high,ll qlow,ll qhigh,ll pos)
{
  if(qlow>high||qhigh<low) return 0;
  if(qlow<=low&&qhigh>=high) return seg[pos];
  ll mid=(low+high)/2;
  return max(query(low,mid,qlow,qhigh,2*pos+1),query(mid+1,high,qlow,qhigh,2*pos+2));
}

int main()
{
  fast;
  cin>>n;
  vector<ll> avec,bvec;
  for(ll i=0;i<n;i++)
  {
    cin>>a[i].f.f>>a[i].f.s>>a[i].s.f>>a[i].s.s;
    b[i].f.f=a[i].s.f;b[i].f.s=a[i].s.s;
    b[i].s.f=a[i].f.f;b[i].s.s=a[i].f.s;
  }
  sort(a,a+n);
  build(0,n-1,0,0);
  for(ll i=0;i<n;i++){avec.pb(a[i].f.f);}
  for(ll i=0;i<n;i++)
  {
    ll ub=upper_bound(all(avec),a[i].f.s)-avec.begin();
    ll maxinb=query(0,n-1,i+1,ub-1,0);
    if(maxinb>a[i].s.s){cout<<"NO"<<endl;exit(0);}
  }

  sort(b,b+n);
  build(0,n-1,0,1);
  for(ll i=0;i<n;i++){bvec.pb(b[i].f.f);}
  for(ll i=0;i<n;i++)
  {
    ll ub=upper_bound(all(bvec),b[i].f.s)-bvec.begin();
    ll maxinb=query(0,n-1,i+1,ub-1,0);
    if(maxinb>b[i].s.s){cout<<"NO"<<endl;exit(0);}
  }
  cout<<"YES"<<endl;
}


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

const ll logx=30;
const ll N=1e5+5;
const ll M=3e5+5;
 ll mod=1e9+7;
const ll INF=1e18+5;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%intd",&n)
#define longp(n) printf("%intd\n",n)

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1ll;x=(x*x)%m;}return ans%m;}

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

ll n,seg[4*N][2];
pair<pair<ll,ll>,pair<ll,ll> > a[N];

void build(ll low,ll high,ll pos)
{
  if(low==high)
  {
    seg[pos][0]=a[low].s.s;
    seg[pos][1]=a[low].s.f;
    return;
  }
  ll mid=(low+high)/2;
  build(low,mid,2*pos+1);
  build(mid+1,high,2*pos+2);
  seg[pos][0]=min(seg[2*pos+1][0],seg[2*pos+2][0]);
  seg[pos][1]=max(seg[2*pos+1][1],seg[2*pos+2][1]);
}

ll query(ll low,ll high,ll qlow,ll qhigh,ll pos,ll type)
{
  if(qlow>high||qhigh<low)
  {
    if(type){return 0;}
    return INF;
  }
  if(qlow<=low&&qhigh>=high) return seg[pos][type];
  ll mid=(low+high)/2;
  if(type){return max(query(low,mid,qlow,qhigh,2*pos+1,type),query(mid+1,high,qlow,qhigh,2*pos+2,type));}
  else{return min(query(low,mid,qlow,qhigh,2*pos+1,type),query(mid+1,high,qlow,qhigh,2*pos+2,type));}
}

void Solve()
{
  sort(a,a+n);
  build(0,n-1,0);
  vector<ll> vec;
  for(ll i=0;i<n;i++){vec.pb(a[i].f.f);}
  for(ll i=0;i<n;i++)
  {
    ll ub=upper_bound(all(vec),a[i].f.s)-vec.begin();
    ll l=i+1,r=ub-1;
    ll mini=query(0,n-1,l,r,0,0);
    ll maxi=query(0,n-1,l,r,0,1);
    if(maxi>a[i].s.s||mini<a[i].s.f){cout<<"NO"<<endl;exit(0);}
  }
}

int main()
{
  fast;
  cin>>n;
  vector<ll> avec;
  for(ll i=0;i<n;i++){cin>>a[i].f.f>>a[i].f.s>>a[i].s.f>>a[i].s.s;}
  Solve();
  for(ll i=0;i<n;i++)
  {
    swap(a[i].f.f,a[i].s.f);
    swap(a[i].f.s,a[i].s.s);
  }
  Solve();
  cout<<"YES"<<endl;
}


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

const ll logx=30;
const ll N=1e5+5;
const ll M=3e5+5;
 ll mod=1e9+7;
const ll INF=1e18+5;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%intd",&n)
#define longp(n) printf("%intd\n",n)

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1ll;x=(x*x)%m;}return ans%m;}

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

ll n,seg[4*N][2];
pair<pair<ll,ll>,pair<ll,ll> > a[N],b[N];

void build(ll low,ll high,ll pos,ll f)
{
  if(low==high)
  {
    if(!f){seg[pos][0]=a[low].s.f;seg[pos][1]=a[low].s.f;}
    else{seg[pos][0]=b[low].s.f;seg[pos][1]=b[low].s.f;}
    return;
  }
  ll mid=(low+high)/2;
  build(low,mid,2*pos+1,f);
  build(mid+1,high,2*pos+2,f);
  seg[pos][0]=max(seg[2*pos+1][0],seg[2*pos+2][0]);
  seg[pos][1]=min(seg[2*pos+1][1],seg[2*pos+2][1]);
}

ll query(ll low,ll high,ll qlow,ll qhigh,ll pos,ll type)
{
  if(qlow>high||qhigh<low)
  {
    if(type){return INF;}
    return 0;
  }
  if(qlow<=low&&qhigh>=high){return seg[pos][type];}
  ll mid=(low+high)/2;
  if(type){return min(query(low,mid,qlow,qhigh,2*pos+1,type),query(mid+1,high,qlow,qhigh,2*pos+2,type));}
  else{return max(query(low,mid,qlow,qhigh,2*pos+1,type),query(mid+1,high,qlow,qhigh,2*pos+2,type));}
}

int main()
{
  fast;
  cin>>n;
  vector<ll> avec,bvec;
  for(ll i=0;i<n;i++)
  {
    cin>>a[i].f.f>>a[i].f.s>>a[i].s.f>>a[i].s.s;
    b[i].f.f=a[i].s.f;b[i].f.s=a[i].s.s;
    b[i].s.f=a[i].f.f;b[i].s.s=a[i].f.s;
  }
  sort(a,a+n);
  build(0,n-1,0,0);
  for(ll i=0;i<n;i++){avec.pb(a[i].f.f);}
  for(ll i=0;i<n;i++)
  {
    ll ub=upper_bound(all(avec),a[i].f.s)-avec.begin();
    ll maxinb=query(0,n-1,i+1,ub-1,0,0);
    ll mininb=query(0,n-1,ub,n-1,0,1);
    if(maxinb>a[i].s.s||mininb<=a[i].s.s){cout<<"NO"<<endl;exit(0);}
  }

  sort(b,b+n);
  build(0,n-1,0,1);
  for(ll i=0;i<n;i++){bvec.pb(b[i].f.f);}
  for(ll i=0;i<n;i++)
  {
    ll ub=upper_bound(all(bvec),b[i].f.s)-bvec.begin();
    ll maxinb=query(0,n-1,i+1,ub-1,0,0);
    ll mininb=query(0,n-1,ub,n-1,0,1);
    if(maxinb>b[i].s.s||mininb<=b[i].s.s){cout<<"NO"<<endl;exit(0);}
  }
  cout<<"YES"<<endl;
}


#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXN 1000005
#define X first
#define Y second
#define mod 1000000007
#define inf 1e10
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

bool check(ll n,vector<ll > sa,vector<ll > ea,vector<ll > sb,vector<ll > eb){
    vector<pair<ll,ll > > v;
    for(int i=1;i<=n;i++){
        v.pb({sa[i],i});
        v.pb({ea[i]+1,-i});
    }
    sort(v.begin(),v.end());
    multiset<ll > l,r;
    l.insert(-inf);
    r.insert(inf);
    for(auto i:v){
        if(i.Y>0){
            ll ind=i.Y;
            ll lt=max(*l.rbegin(),sb[ind]);
            ll rt=min(*r.begin(),eb[ind]);
            if(lt>rt) return false;
            l.insert(sb[ind]);
            r.insert(eb[ind]);
        }
        else{
            ll ind=-i.Y;
            l.erase(l.find(sb[ind]));
            r.erase(r.find(eb[ind]));
        }
    }
    return true;
}

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


#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXN 1000005
#define X first
#define Y second
#define mod 1000000007
#define inf 1e10
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

int main()
{
    fastio;
    ll n,u,v;
    cin>>n;
    vector<pair<ll,pair<ll,ll > > > sa,sb;
    for(int i=0;i<n;i++){
        cin>>u>>v; sa.pb({u,{v,i}});
        cin>>u>>v; sb.pb({u,{v,i}});
    }
    sort(sa.begin(),sa.end());
    sort(sb.begin(),sb.end());
    vector<ll > overa(n),overb(n);
    for(int i=0;i<n;i++){
        overa[i]=i; overb[i]=i;
    }
    for(int i=0;i<n;i++){
        ll lo=i,hi=n-1;
        while(lo<=hi){
            ll mid=((hi-lo)/2)+lo;
            if(sa[mid].X<=sa[i].Y.X){
                overa[mid]=min(overa[mid],(ll)i);
                lo=mid+1;
            }
            else hi=mid-1;
        }
    }
    for(int i=0;i<n;i++){
        ll lo=i,hi=n-1;
        while(lo<=hi){
            ll mid=((hi-lo)/2)+lo;
            if(sb[mid].X<=sb[i].Y.X){
                overb[mid]=min(overb[mid],(ll)i);
                lo=mid+1;
            }
            else hi=mid-1;
        }
    }
    vector<vector<ll > > adja(n,vector<ll >()),adjb(n,vector<ll >());
    for(int i=1;i<n;i++){
        for(int j=overa[i];j<i;j++) adja[sa[i].Y.Y].pb(sa[j].Y.Y);
        for(int j=overb[i];j<i;j++) adjb[sb[i].Y.Y].pb(sb[j].Y.Y);
    }
    for(int i=0;i<n;i++){
        sort(adja[i].begin(),adja[i].end());
        sort(adjb[i].begin(),adjb[i].end());
    }
    bool ok=true;
    for(int i=0;i<n;i++){
        if(adja[i]!=adjb[i]) ok=false;
    }
    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXN 1000005
#define X first
#define Y second
#define mod 1000000007
#define inf 1e10
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

int main()
{
    fastio;
    ll n,u,v;
    cin>>n;
    vector<pair<ll,ll > > a,b;
    vector<pair<ll,pair<ll,ll > > > sa,sb;
    for(int i=0;i<n;i++){
        cin>>u>>v; a.pb({u,v}); sa.pb({u,{v,i}});
        cin>>u>>v; b.pb({u,v}); sb.pb({u,{v,i}});
    }
    sort(sa.begin(),sa.end());
    sort(sb.begin(),sb.end());
    vector<ll > overa(n),overb(n);
    for(int i=0;i<n;i++){
        overa[i]=i; overb[i]=i;
    }
    for(int i=0;i<n;i++){
        ll lo=i,hi=n-1;
        while(lo<=hi){
            ll mid=((hi-lo)/2)+lo;
            if(sa[mid].X<=sa[i].Y.X){
                overa[mid]=min(overa[mid],(ll)i);
                lo=mid+1;
            }
            else hi=mid-1;
        }
    }
    for(int i=0;i<n;i++){
        ll lo=i,hi=n-1;
        while(lo<=hi){
            ll mid=((hi-lo)/2)+lo;
            if(sb[mid].X<=sb[i].Y.X){
                overb[mid]=min(overb[mid],(ll)i);
                lo=mid+1;
            }
            else hi=mid-1;
        }
    }
    vector<vector<ll > > adja(n,vector<ll >()),adjb(n,vector<ll >());
    for(int i=0;i<n;i++){
        for(int j=overa[i];i>j;j++) adja[sa[i].Y.Y].pb(sa[j].Y.Y);
        for(int j=overb[i];i>j;j++) adjb[sb[i].Y.Y].pb(sb[j].Y.Y);
    }
    for(int i=0;i<n;i++){
        sort(adja[i].begin(),adja[i].end());
        sort(adjb[i].begin(),adjb[i].end());
    }
    bool ok=true;
    for(int i=0;i<n;i++){
        if(adja[i]!=adjb[i]) ok=false;
    }
    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXN 1000005
#define X first
#define Y second
#define mod 1000000007
#define inf 1e10
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

int main()
{
    fastio;
    ll n,u,v;
    cin>>n;
    vector<pair<ll,ll > > a,b;
    vector<pair<ll,pair<ll,ll > > > sa,sb;
    for(int i=0;i<n;i++){
        cin>>u>>v; a.pb({u,v}); sa.pb({u,{v,i}});
        cin>>u>>v; b.pb({u,v}); sb.pb({u,{v,i}});
    }
    sort(sa.begin(),sa.end());
    sort(sb.begin(),sb.end());
    for(int i=1;i<n;i++){
        if(sa[i].X<=sa[i-1].Y.X){
            ll ind1=sa[i-1].Y.Y;
            ll ind2=sa[i].Y.Y;
            if(max(b[ind1].X,b[ind2].X)>min(b[ind1].Y,b[ind2].Y)){
                cout<<"NO"<<endl;
                exit(0);
            }
        }
    }
    for(int i=1;i<n;i++){
        if(sb[i].X<=sb[i-1].Y.X){
            ll ind1=sb[i-1].Y.Y;
            ll ind2=sb[i].Y.Y;
            if(max(a[ind1].X,a[ind2].X)>min(a[ind1].Y,a[ind2].Y)){
                cout<<"NO"<<endl;
                exit(0);
            }
        }
    }
    cout<<"YES"<<endl;
}


#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXN 1000005
#define X first
#define Y second
#define mod 1000000007
#define inf 1e10
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

int main()
{
    fastio;
    ll n,u,v;
    cin>>n;
    vector<pair<ll,ll > > a,b;
    vector<pair<ll,pair<ll,ll > > > sa,sb;
    for(int i=0;i<n;i++){
        cin>>u>>v; a.pb({u,v}); sa.pb({u,{v,i}});
        cin>>u>>v; b.pb({u,v}); sb.pb({u,{v,i}});
    }
    sort(sa.begin(),sa.end());
    sort(sb.begin(),sb.end());
    vector<ll > overa(n),overb(n);
    for(int i=0;i<n;i++){
        overa[i]=i; overb[i]=i;
    }
    for(int i=0;i<n;i++){
        ll lo=i,hi=n-1;
        while(lo<=hi){
            ll mid=((hi-lo)/2)+lo;
            if(sa[mid].X<=sa[i].Y.X){
                overa[mid]=min(overa[mid],(ll)i);
                lo=mid+1;
            }
            else hi=mid-1;
        }
    }
    for(int i=0;i<n;i++){
        ll lo=i,hi=n-1;
        while(lo<=hi){
            ll mid=((hi-lo)/2)+lo;
            if(sb[mid].X<=sb[i].Y.X){
                overb[mid]=min(overb[mid],(ll)i);
                lo=mid+1;
            }
            else hi=mid-1;
        }
    }
    bool ok=true;
    for(int i=1;i<n;i++){
        if(overa[i]!=overb[i]) ok=false;
    }
    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXN 1000005
#define X first
#define Y second
#define mod 1000000007
#define inf 1e10
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

int main()
{
    fastio;
    ll n,u,v;
    cin>>n;
    vector<pair<ll,ll > > a,b;
    vector<pair<ll,pair<ll,ll > > > sa,sb;
    for(int i=0;i<n;i++){
        cin>>u>>v; a.pb({u,v}); sa.pb({u,{v,i}});
        cin>>u>>v; b.pb({u,v}); sb.pb({u,{v,i}});
    }
    sort(sa.begin(),sa.end());
    sort(sb.begin(),sb.end());
    for(int i=1;i<n;i++){
        ll k=1;
        while(i-k>=0 && sa[i].X<=sa[i-k].Y.X){
            ll ind1=sa[i-k].Y.Y;
            ll ind2=sa[i].Y.Y;
            if(max(b[ind1].X,b[ind2].X)>min(b[ind1].Y,b[ind2].Y)){
                cout<<"NO"<<endl;
                exit(0);
            }
            k++;
        }
    }
    for(int i=1;i<n;i++){
        ll k=1;
        while(i-k>=0 && sb[i].X<=sb[i-k].Y.X){
            ll ind1=sb[i-1].Y.Y;
            ll ind2=sb[i].Y.Y;
            if(max(a[ind1].X,a[ind2].X)>min(a[ind1].Y,a[ind2].Y)){
                cout<<"NO"<<endl;
                exit(0);
            }
            k++;
        }
    }
    cout<<"YES"<<endl;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define pb push_back
#define ll long long
#define ld long double
#define mp make_pair
#define ull unsigned long long
#define all(s) s.begin(), s.end()
#define sz(a) (int)a.size()

const int INF = (int)1e9 + 7;
const int N = (int)7070 + 7;
const int MAXN = (int)4e5 + 228;
const double eps = (double)1e-8;

using namespace std;

double f[3][MAXN];
double calc(int x, int type) {
  if (!type)
    return sqrt(x);
  else if (type == 1)
    return x;
  else
    return x * 1.0 * x;
}

void add(int r, int x) {
  for (; r < MAXN; r += (r & -r))
    for (int type = 0; type < 3; ++type) {
      int sign = 1;
      if (x < 0) sign = -1;
      f[type][r] += sign * calc(sign * x, type);
    }
}
double get(int r, int type) {
  double res = 0.0;
  for (; r > 0; r -= (r & -r)) res += f[type][r];
  return res;
}
int n, sa[MAXN], sta[MAXN], sb[MAXN], stb[MAXN];
double value[MAXN][3];

void operate(int sign = 1) {
  for (int i = 1; i <= n; ++i) add(sa[i], i);
  for (int i = 1; i <= n; ++i) {
    add(sa[i], -i);
    for (int type = 0; type < 3; ++type)
      value[i][type] += sign * (get(sta[i], type) - get(sa[i], type));
    add(sa[i], i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], i);
    add(sa[i], -i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], -i);
    for (int type = 0; type < 3; ++type)
      value[i][type] += sign * (get(sta[i], type) - get(sa[i], type));
    add(sta[i], i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], -i);
  }
}
void compress() {
  vector<int> comp;
  for (int i = 1; i <= n; ++i) {
    comp.push_back(sta[i]);
    comp.push_back(sa[i]);
    comp.push_back(stb[i]);
    comp.push_back(sb[i]);
  }
  sort(all(comp));
  comp.resize(unique(all(comp)) - comp.begin());
  for (int i = 1; i <= n; ++i) {
    sta[i] = upper_bound(all(comp), sta[i]) - comp.begin();
    sa[i] = upper_bound(all(comp), sa[i]) - comp.begin();
    stb[i] = upper_bound(all(comp), stb[i]) - comp.begin();
    sb[i] = upper_bound(all(comp), sb[i]) - comp.begin();
  }
}

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

#ifdef Local
  freopen(".in", "r", stdin);
#else
  // freopen("sum.in", "r", stdin);
  // freopen("sum.out", "w", stdout);
#endif
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> sa[i] >> sta[i] >> sb[i] >> stb[i];
  }
  compress();
  operate();
  for (int i = 1; i <= n; ++i) {
    swap(sa[i], sb[i]);
    swap(sta[i], stb[i]);
  }
  operate(-1);
  for (int i = 1; i <= n; ++i) {
    for (int type = 0; type < 3; ++type) {
      if (value[i][type] > eps || value[i][type] < -eps) {
        puts("NO");
        exit(0);
      }
    }
  }
  puts("YES");

  return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define pb push_back
#define ll long long
#define ld long double
#define mp make_pair
#define ull unsigned long long
#define all(s) s.begin(), s.end()
#define sz(a) (int)a.size()

const int INF = (int)1e9 + 7;
const int N = (int)7070 + 7;
const int MAXN = (int)4e5 + 228;
const double eps = (double)1e-8;

using namespace std;

ll f[3][MAXN];
ll calc(int x, int type) {
  if (!type)
    return __builtin_popcount(x);
  else if (type == 1)
    return x;
  else
    return x * 1ll * x;
}

void add(int r, int x) {
  for (; r < MAXN; r += (r & -r))
    for (int type = 0; type < 3; ++type) {
      int sign = 1;
      if (x < 0) sign = -1;
      f[type][r] += sign * calc(sign * x, type);
    }
}
ll get(int r, int type) {
  ll res = 0;
  for (; r > 0; r -= (r & -r)) res += f[type][r];
  return res;
}
int n, sa[MAXN], sta[MAXN], sb[MAXN], stb[MAXN];
ll value[MAXN][3];
vector<int> comp;
vector<pair<int, int> > cur[MAXN];

void operate(int sign = 1) {
  for (int i = 1; i <= n; ++i) add(sa[i], i);
  for (int i = 1; i <= n; ++i) {
    add(sa[i], -i);
    for (int type = 0; type < 3; ++type)
      value[i][type] += sign * (get(sta[i], type) - get(sa[i] - 1, type));
    add(sa[i], i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], i);
    add(sa[i], -i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], -i);
    for (int type = 0; type < 3; ++type)
      value[i][type] += sign * (get(sta[i], type) - get(sa[i] - 1, type));
    add(sta[i], i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], -i);
  }

  for (int i = 1; i <= n; ++i) cur[sa[i]].push_back(make_pair(sta[i], i));
  for (int i = comp.size(); i >= 1; --i) {
    for (auto &to : cur[i]) add(to.first, to.second);
    for (auto &to : cur[i]) {
      add(to.first, -to.second);
      for (int type = 0; type < 3; ++type)
        value[to.second][type] -=
            sign * (get(to.first, type) - get(i - 1, type));
      add(to.first, to.second);
    }
  }
  for (int i = comp.size(); i >= 1; --i) {
    for (auto &to : cur[i]) add(to.first, -to.second);
    cur[i].clear();
  }
}
void compress() {
  for (int i = 1; i <= n; ++i) {
    comp.push_back(sta[i]);
    comp.push_back(sa[i]);
    comp.push_back(stb[i]);
    comp.push_back(sb[i]);
  }
  sort(all(comp));
  comp.resize(unique(all(comp)) - comp.begin());
  for (int i = 1; i <= n; ++i) {
    sta[i] = upper_bound(all(comp), sta[i]) - comp.begin();
    sa[i] = upper_bound(all(comp), sa[i]) - comp.begin();
    stb[i] = upper_bound(all(comp), stb[i]) - comp.begin();
    sb[i] = upper_bound(all(comp), sb[i]) - comp.begin();
  }
}

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

#ifdef Local
  freopen(".in", "r", stdin);
#else
  // freopen("sum.in", "r", stdin);
  // freopen("sum.out", "w", stdout);
#endif
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> sa[i] >> sta[i] >> sb[i] >> stb[i];
  }
  compress();
  operate();
  for (int i = 1; i <= n; ++i) {
    swap(sa[i], sb[i]);
    swap(sta[i], stb[i]);
  }
  operate(-1);
  for (int i = 1; i <= n; ++i) {
    for (int type = 0; type < 3; ++type) {
      if (value[i][type] != 0) {
        puts("NO");
        exit(0);
      }
    }
  }
  puts("YES");

  return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define pb push_back
#define ll long long
#define ld long double
#define mp make_pair
#define ull unsigned long long
#define all(s) s.begin(), s.end()
#define sz(a) (int)a.size()

const int INF = (int)1e9 + 7;
const int N = (int)7070 + 7;
const int MAXN = (int)4e5 + 228;
const double eps = (double)1e-8;

using namespace std;

ll f[3][MAXN];
ll calc(int x, int type) {
  if (!type)
    return __builtin_popcount(x);
  else if (type == 1)
    return x;
  else
    return x * 1ll * x;
}

void add(int r, int x) {
  for (; r < MAXN; r += (r & -r))
    for (int type = 0; type < 3; ++type) {
      int sign = 1;
      if (x < 0) sign = -1;
      f[type][r] += sign * calc(sign * x, type);
    }
}
ll get(int r, int type) {
  ll res = 0;
  for (; r > 0; r -= (r & -r)) res += f[type][r];
  return res;
}
int n, sa[MAXN], sta[MAXN], sb[MAXN], stb[MAXN];
ll value[MAXN][3];

void operate(int sign = 1) {
  for (int i = 1; i <= n; ++i) add(sa[i], i);
  for (int i = 1; i <= n; ++i) {
    add(sa[i], -i);
    for (int type = 0; type < 3; ++type)
      value[i][type] += sign * (get(sta[i], type) - get(sa[i], type));
    add(sa[i], i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], i);
    add(sa[i], -i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], -i);
    for (int type = 0; type < 3; ++type)
      value[i][type] += sign * (get(sta[i], type) - get(sa[i], type));
    add(sta[i], i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], -i);
  }
}
void compress() {
  vector<int> comp;
  for (int i = 1; i <= n; ++i) {
    comp.push_back(sta[i]);
    comp.push_back(sa[i]);
    comp.push_back(stb[i]);
    comp.push_back(sb[i]);
  }
  sort(all(comp));
  comp.resize(unique(all(comp)) - comp.begin());
  for (int i = 1; i <= n; ++i) {
    sta[i] = upper_bound(all(comp), sta[i]) - comp.begin();
    sa[i] = upper_bound(all(comp), sa[i]) - comp.begin();
    stb[i] = upper_bound(all(comp), stb[i]) - comp.begin();
    sb[i] = upper_bound(all(comp), sb[i]) - comp.begin();
  }
}

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

#ifdef Local
  freopen(".in", "r", stdin);
#else
  // freopen("sum.in", "r", stdin);
  // freopen("sum.out", "w", stdout);
#endif
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> sa[i] >> sta[i] >> sb[i] >> stb[i];
  }
  compress();
  operate();
  for (int i = 1; i <= n; ++i) {
    swap(sa[i], sb[i]);
    swap(sta[i], stb[i]);
  }
  operate(-1);
  for (int i = 1; i <= n; ++i) {
    for (int type = 0; type < 3; ++type) {
      if (value[i][type] != 0) {
        puts("NO");
        exit(0);
      }
    }
  }
  puts("YES");

  return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define pb push_back
#define ll long long
#define ld long double
#define mp make_pair
#define ull unsigned long long
#define all(s) s.begin(), s.end()
#define sz(a) (int)a.size()

const int INF = (int)1e9 + 7;
const int N = (int)7070 + 7;
const int MAXN = (int)4e5 + 228;
const double eps = (double)1e-8;

using namespace std;

ll f[3][MAXN];
ll calc(int x, int type) {
  if (!type)
    return __builtin_popcount(x);
  else if (type == 1)
    return x;
  else
    return x * 1ll * x;
}

void add(int r, int x) {
  for (; r < MAXN; r += (r & -r))
    for (int type = 0; type < 3; ++type) {
      int sign = 1;
      if (x < 0) sign = -1;
      f[type][r] += sign * calc(sign * x, type);
    }
}
ll get(int r, int type) {
  ll res = 0;
  for (; r > 0; r -= (r & -r)) res += f[type][r];
  return res;
}
int n, sa[MAXN], sta[MAXN], sb[MAXN], stb[MAXN];
ll value[MAXN][3];
vector<int> comp;
vector<pair<int, int> > cur[MAXN];

void operate(int sign = 1) {
  for (int i = 1; i <= n; ++i) add(sa[i], i);
  for (int i = 1; i <= n; ++i) {
    add(sa[i], -i);
    for (int type = 0; type < 3; ++type)
      value[i][type] += sign * (get(sta[i], type) - get(sa[i] - 1, type));
    add(sa[i], i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], i);
    add(sa[i], -i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], -i);
    for (int type = 0; type < 3; ++type)
      value[i][type] += sign * (get(sta[i], type) - get(sa[i] - 1, type));
    add(sta[i], i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], -i);
  }

  for (int i = 1; i <= n; ++i) cur[sa[i]].push_back(make_pair(sta[i], i));
  for (int i = comp.size(); i >= 1; --i) {
    for (auto &to : cur[i]) add(to.first, to.second);
    for (auto &to : cur[i]) {
      add(to.first, -to.second);
      for (int type = 0; type < 3; ++type)
        value[to.second][type] -=
            sign * (get(to.first, type) - get(i - 1, type));
      add(to.first, to.second);
    }
  }
  for (int i = comp.size(); i >= 1; --i) {
    for (auto &to : cur[i]) add(to.first, -to.second);
  }
  for (int i = 1; i <= comp.size(); ++i) {
    for (auto &to : cur[i]) add(to.first, to.second);
    for (auto &to : cur[i]) {
      add(to.first, -to.second);
      for (int type = 0; type < 3; ++type) {
        value[to.second][type] +=
            sign * (get(comp.size(), type) - get(to.first, type));
      }
      add(to.first, to.second);
    }
  }
  for (int i = comp.size(); i >= 1; --i) {
    for (auto &to : cur[i]) add(to.first, -to.second);
    cur[i].clear();
  }
}
void compress() {
  for (int i = 1; i <= n; ++i) {
    comp.push_back(sta[i]);
    comp.push_back(sa[i]);
    comp.push_back(stb[i]);
    comp.push_back(sb[i]);
  }
  sort(all(comp));
  comp.resize(unique(all(comp)) - comp.begin());
  for (int i = 1; i <= n; ++i) {
    sta[i] = upper_bound(all(comp), sta[i]) - comp.begin();
    sa[i] = upper_bound(all(comp), sa[i]) - comp.begin();
    stb[i] = upper_bound(all(comp), stb[i]) - comp.begin();
    sb[i] = upper_bound(all(comp), sb[i]) - comp.begin();
  }
}

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

#ifdef Local
  freopen(".in", "r", stdin);
#else
  // freopen("sum.in", "r", stdin);
  // freopen("sum.out", "w", stdout);
#endif
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> sa[i] >> sta[i] >> sb[i] >> stb[i];
  }
  compress();
  operate();
  // cerr << value[1][1] << ' ' << value[2][1] << endl;
  for (int i = 1; i <= n; ++i) {
    swap(sa[i], sb[i]);
    swap(sta[i], stb[i]);
  }
  operate(-1);
  // cerr << value[1][1] << ' ' << value[2][1] << endl;
  for (int i = 1; i <= n; ++i) {
    for (int type = 0; type < 3; ++type) {
      if (value[i][type] != 0) {
        puts("NO");
        exit(0);
      }
    }
  }
  puts("YES");

  return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define pb push_back
#define ll long long
#define ld long double
#define mp make_pair
#define ull unsigned long long
#define all(s) s.begin(), s.end()
#define sz(a) (int)a.size()

const int INF = (int)1e9 + 7;
const int N = (int)7070 + 7;
const int MAXN = (int)3e5 + 228;
const double eps = (double)1e-8;

using namespace std;

map<int, double> f[3];

double calc(int x, int type) {
  if (!type)
    return sqrt(x);
  else if (type == 1)
    return x;
  else
    return x * 1.0 * x;
}

void add(int r, int x) {
  for (; r <= (int)1e9; r += (r & -r))
    for (int type = 0; type < 3; ++type) {
      int sign = 1;
      if (x < 0) sign = -1;
      f[type][r] += sign * calc(sign * x, type);
    }
}
double get(int r, int type) {
  double res = 0.0;
  for (; r > 0; r -= (r & -r)) res += f[type][r];
  return res;
}
int n, sa[MAXN], sta[MAXN], sb[MAXN], stb[MAXN];
double value[MAXN][3];

void operate(int sign = 1) {
  for (int i = 1; i <= n; ++i) add(sa[i], i);
  for (int i = 1; i <= n; ++i) {
    add(sa[i], -i);
    for (int type = 0; type < 3; ++type)
      value[i][type] += sign * (get(sta[i], type) - get(sa[i], type));
    add(sa[i], i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], i);
    add(sa[i], -i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], -i);
    for (int type = 0; type < 3; ++type)
      value[i][type] += sign * (get(sta[i], type) - get(sa[i], type));
    add(sta[i], i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], -i);
  }
}

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

#ifdef Local
  freopen(".in", "r", stdin);
#else
  // freopen("sum.in", "r", stdin);
  // freopen("sum.out", "w", stdout);
#endif
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> sa[i] >> sta[i] >> sb[i] >> stb[i];
  }
  operate();
  for (int i = 1; i <= n; ++i) {
    swap(sa[i], sb[i]);
    swap(sta[i], stb[i]);
  }
  operate(-1);
  for (int i = 1; i <= n; ++i) {
    for (int type = 0; type < 3; ++type) {
      if (value[i][type] > eps || value[i][type] < -eps) {
        cerr << i << ' ' << value[i][type] << ' ' << type << endl;
        puts("NO");
        exit(0);
      }
    }
  }
  puts("YES");

  return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define pb push_back
#define ll long long
#define ld long double
#define mp make_pair
#define ull unsigned long long
#define all(s) s.begin(), s.end()
#define sz(a) (int)a.size()

const int INF = (int)1e9 + 7;
const int N = (int)7070 + 7;
const int MAXN = (int)4e5 + 228;
const double eps = (double)1e-8;

using namespace std;

ll f[3][MAXN];
ll calc(int x, int type) {
  if (!type)
    return __builtin_popcount(x);
  else if (type == 1)
    return x;
  else
    return x * 1ll * x;
}

void add(int r, int x) {
  for (; r < MAXN; r += (r & -r))
    for (int type = 0; type < 3; ++type) {
      int sign = 1;
      if (x < 0) sign = -1;
      f[type][r] += sign * calc(sign * x, type);
    }
}
ll get(int r, int type) {
  ll res = 0;
  for (; r > 0; r -= (r & -r)) res += f[type][r];
  return res;
}
int n, sa[MAXN], sta[MAXN], sb[MAXN], stb[MAXN];
ll value[MAXN][3];
vector<int> comp;
vector<pair<int, int> > cur[MAXN];

void operate(int sign = 1) {
  for (int i = 1; i <= n; ++i) add(sa[i], i);
  for (int i = 1; i <= n; ++i) {
    add(sa[i], -i);
    for (int type = 0; type < 3; ++type)
      value[i][type] += sign * (get(sta[i], type) - get(sa[i] - 1, type));
    add(sa[i], i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], i);
    add(sa[i], -i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], -i);
    for (int type = 0; type < 3; ++type)
      value[i][type] += sign * (get(sta[i], type) - get(sa[i] - 1, type));
    add(sta[i], i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], -i);
  }
  for (int i = 1; i <= n; ++i) cur[sa[i]].push_back(make_pair(sta[i], i));
  for (int i = comp.size(); i >= 1; --i) {
    for (auto &to : cur[i]) add(to.first, to.second);
    for (auto &to : cur[i]) {
      add(to.first, -to.second);
      for (int type = 0; type < 3; ++type)
        value[to.second][type] -=
            sign * (get(to.first, type) - get(i - 1, type));
      add(to.first, to.second);
    }
  }
  for (int i = comp.size(); i >= 1; --i) {
    for (auto &to : cur[i]) add(to.first, -to.second);
  }
  for (int i = 1; i <= comp.size(); ++i) {
    for (auto &to : cur[i]) {
      add(to.first, -to.second);
      for (int type = 0; type < 3; ++type) {
        value[to.second][type] +=
            sign * (get(comp.size(), type) - get(to.first, type));
      }
      add(to.first, to.second);
    }
    for (auto &to : cur[i]) {
      add(to.first, to.second);
    }
  }
  for (int i = comp.size(); i >= 1; --i) {
    for (auto &to : cur[i]) add(to.first, -to.second);
    cur[i].clear();
  }
}
void compress() {
  for (int i = 1; i <= n; ++i) {
    comp.push_back(sta[i]);
    comp.push_back(sa[i]);
    comp.push_back(stb[i]);
    comp.push_back(sb[i]);
  }
  sort(all(comp));
  comp.resize(unique(all(comp)) - comp.begin());
  for (int i = 1; i <= n; ++i) {
    sta[i] = upper_bound(all(comp), sta[i]) - comp.begin();
    sa[i] = upper_bound(all(comp), sa[i]) - comp.begin();
    stb[i] = upper_bound(all(comp), stb[i]) - comp.begin();
    sb[i] = upper_bound(all(comp), sb[i]) - comp.begin();
  }
}

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

#ifdef Local
  freopen(".in", "r", stdin);
#else
  // freopen("sum.in", "r", stdin);
  // freopen("sum.out", "w", stdout);
#endif
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> sa[i] >> sta[i] >> sb[i] >> stb[i];
  }
  compress();
  operate();
  cerr << value[1][1] << ' ' << value[2][1] << endl;
  for (int i = 1; i <= n; ++i) {
    swap(sa[i], sb[i]);
    swap(sta[i], stb[i]);
  }
  operate(-1);
  cerr << value[1][1] << ' ' << value[2][1] << endl;
  for (int i = 1; i <= n; ++i) {
    for (int type = 0; type < 3; ++type) {
      if (value[i][type] != 0) {
        puts("NO");
        exit(0);
      }
    }
  }
  puts("YES");

  return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define pb push_back
#define ll long long
#define ld long double
#define mp make_pair
#define ull unsigned long long
#define all(s) s.begin(), s.end()
#define sz(a) (int)a.size()

const int INF = (int)1e9 + 7;
const int N = (int)7070 + 7;
const int MAXN = (int)4e5 + 228;
const double eps = (double)1e-8;

using namespace std;

ll f[3][MAXN];
ll calc(int x, int type) {
  if (!type)
    return __builtin_popcount(x);
  else if (type == 1)
    return x;
  else
    return x * 1ll * x;
}

void add(int r, int x) {
  for (; r < MAXN; r += (r & -r))
    for (int type = 0; type < 3; ++type) {
      int sign = 1;
      if (x < 0) sign = -1;
      f[type][r] += sign * calc(sign * x, type);
    }
}
ll get(int r, int type) {
  ll res = 0;
  for (; r > 0; r -= (r & -r)) res += f[type][r];
  return res;
}
int n, sa[MAXN], sta[MAXN], sb[MAXN], stb[MAXN];
ll value[MAXN][3];
vector<int> comp;
vector<pair<int, int> > cur[MAXN];

void operate(int sign = 1) {
  for (int i = 1; i <= n; ++i) add(sa[i], i);
  for (int i = 1; i <= n; ++i) {
    add(sa[i], -i);
    for (int type = 0; type < 3; ++type)
      value[i][type] += sign * (get(sta[i], type) - get(sa[i] - 1, type));
    add(sa[i], i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], i);
    add(sa[i], -i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], -i);
    for (int type = 0; type < 3; ++type)
      value[i][type] += sign * (get(sta[i], type) - get(sa[i] - 1, type));
    add(sta[i], i);
  }
  for (int i = 1; i <= n; ++i) {
    add(sta[i], -i);
  }

  for (int i = 1; i <= n; ++i) cur[sa[i]].push_back(make_pair(sta[i], i));
  for (int i = comp.size(); i >= 1; --i) {
    for (auto &to : cur[i]) add(to.first, to.second);
    for (auto &to : cur[i]) {
      add(to.first, -to.second);
      for (int type = 0; type < 3; ++type)
        value[to.second][type] -=
            sign * (get(to.second, type) - get(to.first - 1, type));
      add(to.first, to.second);
    }
  }
  for (int i = comp.size(); i >= 1; --i) {
    for (auto &to : cur[i]) add(to.first, -to.second);
    cur[i].clear();
  }
}
void compress() {
  for (int i = 1; i <= n; ++i) {
    comp.push_back(sta[i]);
    comp.push_back(sa[i]);
    comp.push_back(stb[i]);
    comp.push_back(sb[i]);
  }
  sort(all(comp));
  comp.resize(unique(all(comp)) - comp.begin());
  for (int i = 1; i <= n; ++i) {
    sta[i] = upper_bound(all(comp), sta[i]) - comp.begin();
    sa[i] = upper_bound(all(comp), sa[i]) - comp.begin();
    stb[i] = upper_bound(all(comp), stb[i]) - comp.begin();
    sb[i] = upper_bound(all(comp), sb[i]) - comp.begin();
  }
}

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

#ifdef Local
  freopen(".in", "r", stdin);
#else
  // freopen("sum.in", "r", stdin);
  // freopen("sum.out", "w", stdout);
#endif
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> sa[i] >> sta[i] >> sb[i] >> stb[i];
  }
  compress();
  operate();
  for (int i = 1; i <= n; ++i) {
    swap(sa[i], sb[i]);
    swap(sta[i], stb[i]);
  }
  operate(-1);
  for (int i = 1; i <= n; ++i) {
    for (int type = 0; type < 3; ++type) {
      if (value[i][type] != 0) {
        puts("NO");
        exit(0);
      }
    }
  }
  puts("YES");

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll n;
const ll L = 1e5 + 5;
ll sa[L];
ll ea[L];
ll sb[L];
ll eb[L];
ll answer(ll check) {
	vector <pair<pll,ll>> vec;
 	map <ll, pll> eds;
 	if (check == 0) {
	 	for (ll i = 0; i < n; i++) {
	 		vec.pb({{sa[i], 1}, i});
	 		vec.pb({{ea[i] + 1, -1}, i});
	 		eds[i] = {sb[i], eb[i]};
	 	}
 	}
 	else {
 		for (ll i = 0; i < n; i++) {
	 		vec.pb({{sb[i], 1}, i});
	 		vec.pb({{eb[i] + 1, -1}, i});
	 		eds[i] = {sa[i], ea[i]};
	 	}
 	}
 	sort(all(vec));
 	ll f = 0;
 	n = sz(vec);
 	multiset <pll> as;
 	ll l, r;
 	l = 1e18;
 	r = -1e18;
 	for (ll i = 0; i < n; i++) {
 		if (vec[i].fi.se == -1) {
 			pll ed = eds[vec[i].se];
 			l = min(l, ed.fi);
 			r = max(r, ed.se);
 		}
 		else {
 			pll ed = eds[vec[i].se];
 			if (!(ed.se < l || ed.fi > r)) {
 				f = 1;
 			}
 		}
 	}
 	l = 1e18;
 	r = -1e18;
 	as.clear();
 	for (ll i = n - 1; i >= 0; i--) {
 		if (vec[i].fi.se == 1) {
 			pll ed = eds[vec[i].se];
 			l = min(l, ed.fi);
 			r = max(r, ed.se);
 		}
 		else {
 			pll ed = eds[vec[i].se];
 			if (!(ed.se < l || ed.fi > r)) {
 				f = 1;
 			}
 		}
 	}
 	return f;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	cin >> n;
 	for (ll i = 0; i < n; i++) {
 		cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
 	}
 	if (answer(0) == 0 && answer(1) == 0) {
 		cout << "YES" << endl;
 	}
 	else {
 		cout << "NO" << endl;
 	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll n;
const ll L = 1e5 + 5;
ll sa[L];
ll ea[L];
ll sb[L];
ll eb[L];
ll answer(ll check) {
	vector <pair<pll,ll>> vec;
 	map <ll, pll> eds;
 	if (check == 0) {
	 	for (ll i = 0; i < n; i++) {
	 		vec.pb({{sa[i], 1}, i});
	 		vec.pb({{ea[i] + 1, -1}, i});
	 		eds[i] = {sb[i], eb[i]};
	 	}
 	}
 	else {
 		for (ll i = 0; i < n; i++) {
	 		vec.pb({{sb[i], 1}, i});
	 		vec.pb({{eb[i] + 1, -1}, i});
	 		eds[i] = {sa[i], ea[i]};
	 	}
 	}
 	sort(all(vec));
 	ll f = 0;
 	ll tempn = n;
 	n = sz(vec);
 	multiset <pll> as;
 	ll l, r;
 	l = 1e18;
 	r = -1e18;
 	for (ll i = 0; i < n; i++) {
 		if (vec[i].fi.se == -1) {
 			pll ed = eds[vec[i].se];
 			l = min(l, ed.fi);
 			r = max(r, ed.se);
 		}
 		else {
 			pll ed = eds[vec[i].se];
 			if (!(ed.se < l || ed.fi > r)) {
 				f = 1;
 			}
 		}
 	}
 	l = 1e18;
 	r = -1e18;
 	as.clear();
 	for (ll i = n - 1; i >= 0; i--) {
 		if (vec[i].fi.se == 1) {
 			pll ed = eds[vec[i].se];
 			l = min(l, ed.fi);
 			r = max(r, ed.se);
 		}
 		else {
 			pll ed = eds[vec[i].se];
 			if (!(ed.se < l || ed.fi > r)) {
 				f = 1;
 			}
 		}
 	}
 	n = tempn;
 	return f;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	cin >> n;
 	for (ll i = 0; i < n; i++) {
 		cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
 	}
 	if (answer(0) == 0 && answer(1) == 0) {
 		cout << "YES" << endl;
 	}
 	else {
 		cout << "NO" << endl;
 	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    ll sa, ea, sb, eb;
    cin >> n;
    vector <pair<pll,ll>> vec;
    map <ll, pll> ends;
    for (ll i = 0; i < n; i++) {
    	cin >> sa >> ea >> sb >> eb;
    	vec.pb({{sa, i}, 1});
    	vec.pb({{ea, i}, -1});
    	ends[i] = {sb, eb};
    }
    sort(all(vec));
    multiset <ll> st;
    multiset <ll> en;
    ll f = 0;
   	for (ll i = 0; i < 2 * n; i++) {
   		ll ind = vec[i].fi.se;
   		ll brac = vec[i].se;
   		if (brac == 1) {
   			st.insert(ends[ind].fi);
   			en.insert(ends[ind].se);
   		}
   		else {
   			ll y = *st.rbegin();
   			ll x = *en.begin();
   			if (!(ends[ind].fi <= x && ends[ind].se >= y)) {
   				f = 1;
   			}
   			st.erase(st.find(ends[ind].fi));
   			en.erase(en.find(ends[ind].se));
   		}
   	}
   	if (f == 0) {
   		cout << "YES" << endl;
   	}
   	else {
   		cout << "NO" << endl;
   	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    ll sa, ea, sb, eb;
    cin >> n;
    vector <pair<pll,ll>> vec;
    vector <pair<pll,ll>> vec2;
    map <ll, pll> ends;
    map <ll, pll> ends2;
    for (ll i = 0; i < n; i++) {
    	cin >> sa >> ea >> sb >> eb;
    	vec.pb({{sa, i}, 1});
    	vec.pb({{ea, i}, 2});
    	vec2.pb({{sb, i}, 1});
    	vec2.pb({{eb, i}, 2});
    	ends[i] = {sb, eb};
    	ends2[i] = {sa, ea};
    }
    sort(all(vec));
    multiset <ll> st;
    multiset <ll> en;
    ll f = 0;
   	for (ll i = 0; i < 2 * n; i++) {
   		ll ind = vec[i].fi.se;
   		ll brac = vec[i].se;
   		if (brac == 1) {
   			st.insert(ends[ind].fi);
   			en.insert(ends[ind].se);
   		}
   		else {
   			ll y = *st.rbegin();
   			ll x = *en.begin();
   			if (!(ends[ind].fi <= x && ends[ind].se >= y)) {
   				f = 1;
   			}
   			st.erase(st.find(ends[ind].fi));
   			en.erase(en.find(ends[ind].se));
   		}
   	}
   	st.clear();
   	en.clear();
   	for (ll i = 0; i < 2 * n; i++) {
   		ll ind = vec2[i].fi.se;
   		ll brac = vec2[i].se;
   		if (brac == 1) {
   			st.insert(ends2[ind].fi);
   			en.insert(ends2[ind].se);
   		}
   		else {
   			ll y = *st.rbegin();
   			ll x = *en.begin();
   			if (!(ends2[ind].fi <= x && ends2[ind].se >= y)) {
   				f = 1;
   			}
   			st.erase(st.find(ends2[ind].fi));
   			en.erase(en.find(ends2[ind].se));
   		}
   	}
   	if (f == 0) {
   		cout << "YES" << endl;
   	}
   	else {
   		cout << "NO" << endl;
   	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll n;
const ll L = 1e5 + 5;
ll sa[L];
ll ea[L];
ll sb[L];
ll eb[L];
ll answer(ll check) {
	vector <pair<pll,ll>> vec;
 	map <ll, pll> eds;
 	if (check == 0) {
	 	for (ll i = 0; i < n; i++) {
	 		vec.pb({{sa[i], 1}, i});
	 		vec.pb({{ea[i], 2}, i});
	 		eds[i] = {sb[i], eb[i]};
	 	}
 	}
 	else {
 		for (ll i = 0; i < n; i++) {
	 		vec.pb({{sb[i], 1}, i});
	 		vec.pb({{eb[i], 2}, i});
	 		eds[i] = {sa[i], ea[i]};
	 	}
 	}
 	sort(all(vec));
 	ll f = 0;
 	n = sz(vec);
 	multiset <pll> as;
 	ll l, r;
 	l = 1e18;
 	r = -1e18;
 	for (ll i = 0; i < n; i++) {
 		if (vec[i].fi.se == 2) {
 			as.insert({vec[i].fi.fi, vec[i].se});
 		}
 		else {
 			while (sz(as) > 0) {
 				pll temp = *as.begin();
 				if (temp.fi < vec[i].fi.fi) {
 					l = min(l, eds[temp.se].fi);
 					r = max(r, eds[temp.se].se);
 					as.erase(as.begin());
 				}
 				else
 					break;
 			}
 			pll ed = eds[vec[i].se];
 			if (!(ed.se < l || ed.fi > r)) {
 				f = 1;
 			}
 		}
 	}
 	l = 1e18;
 	r = -1e18;
 	as.clear();
 	for (ll i = n - 1; i >= 0; i--) {
 		if (vec[i].fi.se == 1) {
 			as.insert({vec[i].fi.fi, vec[i].se});
 		}
 		else {
 			while (sz(as) > 0) {
 				pll temp = *as.begin();
 				if (temp.fi > vec[i].fi.fi) {
 					l = min(l, eds[temp.se].fi);
 					r = max(r, eds[temp.se].se);
 					as.erase(as.begin());
 				}
 				else
 					break;
 			}
 			pll ed = eds[vec[i].se];
 			if (!(ed.se < l || ed.fi > r)) {
 				f = 1;
 			}
 		}
 	}
 	return f;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	cin >> n;
 	for (ll i = 0; i < n; i++) {
 		cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
 	}
 	if (answer(0) == 0 && answer(1) == 0) {
 		cout << "YES" << endl;
 	}
 	else {
 		cout << "NO" << endl;
 	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll n;
const ll L = 1e5 + 5;
ll sa[L];
ll ea[L];
ll sb[L];
ll eb[L];
ll answer(ll check) {
	vector <pair<pll,ll>> vec(2 * n);
 	map <ll, pll> eds;
 	ll c = 0;
 	if (check == 0) {
	 	for (ll i = 0; i < n; i++) {
	 		vec[c++] = {{sa[i], 1}, i};
	 		vec[c++] = {{ea[i], 2}, i};
	 		eds[i] = {sb[i], eb[i]};
	 	}
 	}
 	else {
 		for (ll i = 0; i < n; i++) {
	 		vec[c++] = {{sb[i], 1}, i};
	 		vec[c++] = {{eb[i], 2}, i};
	 		eds[i] = {sa[i], ea[i]};
	 	}
 	}
 	sort(all(vec));
 	ll f = 0;
 	n *= 2;
 	multiset <pll> as;
 	ll l, r;
 	l = 1e18;
 	r = -1e18;
 	for (ll i = 0; i < n; i++) {
 		if (vec[i].fi.se == 2) {
 			as.insert({vec[i].fi.fi, vec[i].se});
 		}
 		else {
 			while (sz(as) > 0) {
 				pll temp = *as.begin();
 				if (temp.fi < vec[i].fi.fi) {
 					l = min(l, eds[temp.se].fi);
 					r = max(r, eds[temp.se].se);
 					as.erase(as.begin());
 				}
 				else
 					break;
 			}
 			pll ed = eds[vec[i].se];
 			if (!(ed.se < l || ed.fi > r)) {
 				f = 1;
 			}
 		}
 	}
 	l = 1e18;
 	r = -1e18;
 	as.clear();
 	for (ll i = n - 1; i >= 0; i--) {
 		if (vec[i].fi.se == 1) {
 			as.insert({vec[i].fi.fi, vec[i].se});
 		}
 		else {
 			while (sz(as) > 0) {
 				pll temp = *as.begin();
 				if (temp.fi > vec[i].fi.fi) {
 					l = min(l, eds[temp.se].fi);
 					r = max(r, eds[temp.se].se);
 					as.erase(as.begin());
 				}
 				else
 					break;
 			}
 			pll ed = eds[vec[i].se];
 			if (!(ed.se < l || ed.fi > r)) {
 				f = 1;
 			}
 		}
 	}
 	return f;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	cin >> n;
 	for (ll i = 0; i < n; i++) {
 		cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
 	}
 	if (answer(0) == 0 && answer(1) == 0) {
 		cout << "YES" << endl;
 	}
 	else {
 		cout << "NO" << endl;
 	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll n;
const ll L = 1e5 + 5;
ll sa[L];
ll ea[L];
ll sb[L];
ll eb[L];
ll answer(ll check) {
	vector <pair<pll,ll>> vec;
 	map <ll, pll> eds;
 	if (check == 0) {
	 	for (ll i = 0; i < n; i++) {
	 		vec.pb({{sa[i], 1}, i});
	 		vec.pb({{ea[i], 2}, i});
	 		eds[i] = {sb[i], eb[i]};
	 	}
 	}
 	else {
 		for (ll i = 0; i < n; i++) {
	 		vec.pb({{sb[i], 1}, i});
	 		vec.pb({{eb[i], 2}, i});
	 		eds[i] = {sa[i], ea[i]};
	 	}
 	}
 	sort(all(vec));
 	ll f = 0;
 	ll tempn = n;
 	n = sz(vec);
 	multiset <pll> as;
 	ll l, r;
 	l = 1e18;
 	r = -1e18;
 	for (ll i = 0; i < n; i++) {
 		if (vec[i].fi.se == 2) {
 			as.insert({vec[i].fi.fi, vec[i].se});
 		}
 		else {
 			while (sz(as) > 0) {
 				pll temp = *as.begin();
 				if (temp.fi < vec[i].fi.fi) {
 					l = min(l, eds[temp.se].fi);
 					r = max(r, eds[temp.se].se);
 					as.erase(as.begin());
 				}
 				else
 					break;
 			}
 			pll ed = eds[vec[i].se];
 			if (!(ed.se < l || ed.fi > r)) {
 				f = 1;
 			}
 		}
 	}
 	l = 1e18;
 	r = -1e18;
 	as.clear();
 	for (ll i = n - 1; i >= 0; i--) {
 		if (vec[i].fi.se == 1) {
 			as.insert({vec[i].fi.fi, vec[i].se});
 		}
 		else {
 			while (sz(as) > 0) {
 				pll temp = *as.begin();
 				if (temp.fi > vec[i].fi.fi) {
 					l = min(l, eds[temp.se].fi);
 					r = max(r, eds[temp.se].se);
 					as.erase(as.begin());
 				}
 				else
 					break;
 			}
 			pll ed = eds[vec[i].se];
 			if (!(ed.se < l || ed.fi > r)) {
 				f = 1;
 			}
 		}
 	}
 	n = tempn;
 	return f;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	cin >> n;
 	for (ll i = 0; i < n; i++) {
 		cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
 	}
 	if (answer(0) == 0 && answer(1) == 0) {
 		cout << "YES" << endl;
 	}
 	else {
 		cout << "NO" << endl;
 	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll n;
const ll L = 1e5 + 5;
ll sa[L];
ll ea[L];
ll sb[L];
ll eb[L];
vector <pair<pll,ll>> vec;
map <ll, pll> eds;
ll answer(ll check) {
	vec.clear();
	eds.clear();
 	if (check == 0) {
	 	for (ll i = 0; i < n; i++) {
	 		vec.pb({{sa[i], 1}, i});
	 		vec.pb({{ea[i], 2}, i});
	 		eds[i] = {sb[i], eb[i]};
	 	}
 	}
 	else {
 		for (ll i = 0; i < n; i++) {
	 		vec.pb({{sb[i], 1}, i});
	 		vec.pb({{eb[i], 2}, i});
	 		eds[i] = {sa[i], ea[i]};
	 	}
 	}
 	sort(all(vec));
 	ll f = 0;
 	n = sz(vec);
 	multiset <pll> as;
 	ll l, r;
 	l = 1e18;
 	r = -1e18;
 	for (ll i = 0; i < n; i++) {
 		if (vec[i].fi.se == 2) {
 			as.insert({vec[i].fi.fi, vec[i].se});
 		}
 		else {
 			while (sz(as) > 0) {
 				pll temp = *as.begin();
 				if (temp.fi < vec[i].fi.fi) {
 					l = min(l, eds[temp.se].fi);
 					r = max(r, eds[temp.se].se);
 					as.erase(as.begin());
 				}
 				else
 					break;
 			}
 			pll ed = eds[vec[i].se];
 			if (!(ed.se < l || ed.fi > r)) {
 				f = 1;
 			}
 		}
 	}
 	l = 1e18;
 	r = -1e18;
 	as.clear();
 	for (ll i = n - 1; i >= 0; i--) {
 		if (vec[i].fi.se == 1) {
 			as.insert({vec[i].fi.fi, vec[i].se});
 		}
 		else {
 			while (sz(as) > 0) {
 				pll temp = *as.begin();
 				if (temp.fi > vec[i].fi.fi) {
 					l = min(l, eds[temp.se].fi);
 					r = max(r, eds[temp.se].se);
 					as.erase(as.begin());
 				}
 				else
 					break;
 			}
 			pll ed = eds[vec[i].se];
 			if (!(ed.se < l || ed.fi > r)) {
 				f = 1;
 			}
 		}
 	}
 	return f;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	cin >> n;
 	for (ll i = 0; i < n; i++) {
 		cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
 	}
 	if (answer(0) == 0 && answer(1) == 0) {
 		cout << "YES" << endl;
 	}
 	else {
 		cout << "NO" << endl;
 	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    ll sa, ea, sb, eb;
    cin >> n;
    vector <pair<pll,ll>> vec;
    vector <pair<pll,ll>> vec2;
    map <ll, pll> ends;
    map <ll, pll> ends2;
    for (ll i = 0; i < n; i++) {
    	cin >> sa >> ea >> sb >> eb;
    	vec.pb({{sa, i}, 1});
    	vec.pb({{ea + 1, i}, 2});
    	vec2.pb({{sb, i}, 1});
    	vec2.pb({{eb + 1, i}, 2});
    	ends[i] = {sb, eb};
    	ends2[i] = {sa, ea};
    }
    sort(all(vec));
    multiset <ll> st;
    multiset <ll> en;
    ll f = 0;
   	for (ll i = 0; i < 2 * n; i++) {
   		ll ind = vec[i].fi.se;
   		ll brac = vec[i].se;
   		if (brac == 1) {
   			st.insert(ends[ind].fi);
   			en.insert(ends[ind].se);
   		}
   		else {
   			ll y = *st.rbegin();
   			ll x = *en.begin();
   			if (!(ends[ind].fi <= x && ends[ind].se >= y)) {
   				f = 1;
   			}
   			st.erase(st.find(ends[ind].fi));
   			en.erase(en.find(ends[ind].se));
   		}
   	}
   	st.clear();
   	en.clear();
   	for (ll i = 0; i < 2 * n; i++) {
   		ll ind = vec2[i].fi.se;
   		ll brac = vec2[i].se;
   		if (brac == 1) {
   			st.insert(ends2[ind].fi);
   			en.insert(ends2[ind].se);
   		}
   		else {
   			ll y = *st.rbegin();
   			ll x = *en.begin();
   			if (!(ends2[ind].fi <= x && ends2[ind].se >= y)) {
   				f = 1;
   			}
   			st.erase(st.find(ends2[ind].fi));
   			en.erase(en.find(ends2[ind].se));
   		}
   	}
   	if (f == 0) {
   		cout << "YES" << endl;
   	}
   	else {
   		cout << "NO" << endl;
   	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    ll sa, ea, sb, eb;
    cin >> n;
    vector <pair<pll,ll>> vec;
    map <ll, pll> ends;
    for (ll i = 0; i < n; i++) {
    	cin >> sa >> ea >> sb >> eb;
    	vec.pb({{sa, i}, 1});
    	vec.pb({{ea, i}, 2});
    	ends[i] = {sb, eb};
    }
    sort(all(vec));
    multiset <ll> st;
    multiset <ll> en;
    ll f = 0;
   	for (ll i = 0; i < 2 * n; i++) {
   		ll ind = vec[i].fi.se;
   		ll brac = vec[i].se;
   		if (brac == 1) {
   			st.insert(ends[ind].fi);
   			en.insert(ends[ind].se);
   		}
   		else {
   			ll y = *st.rbegin();
   			ll x = *en.begin();
   			if (!(ends[ind].fi <= x && ends[ind].se >= y)) {
   				f = 1;
   			}
   			st.erase(st.find(ends[ind].fi));
   			en.erase(en.find(ends[ind].se));
   		}
   	}
   	if (f == 0) {
   		cout << "YES" << endl;
   	}
   	else {
   		cout << "NO" << endl;
   	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll n;
const ll L = 1e5 + 5;
ll sa[L];
ll ea[L];
ll sb[L];
ll eb[L];
ll answer() {
	vector <pll> vec;
	for (ll i = 1; i <= n; i++) {
		vec.pb({sa[i], i});
		vec.pb({ea[i] + 1, -i});
	}
	sort(all(vec));
	multiset <ll> ls;
	multiset <ll> rs;
	for (ll i = 0; i < 2 * n; i++) {
		ll ind = abs(vec[i].se);
		if (vec[i].se > 0) {
			if (sz(ls) != 0) {
				if (!(eb[ind] >= *ls.rbegin() && sb[ind] <= *rs.begin())) return 0;
			}
			ls.insert(sb[ind]);
			rs.insert(eb[ind]);
		}
		else {
			ls.erase(ls.find(sb[ind]));
			rs.erase(rs.find(eb[ind]));
		}
	}
	return 1;
}
int main()
{
	ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);
 	cin >> n;
 	for (ll i = 1; i <= n; i++) {
 		cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
 	}
 	if (!answer()) {
 		cout << "NO" << endl;
 		return 0;
 	}
 	for (ll i = 1; i <= n; i++) {
 		swap(sa[i], sb[i]);
 		swap(ea[i], eb[i]);
 	}
 	if (!answer()) {
 		cout << "NO" << endl;
 		return 0;
 	}
 	cout << "YES" << endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define mp make_pair
#define f first
#define s second
ll n;
map<ll,ll>mpa, mpb;
ll mod = 1000000007;
ll N = 100005;
vector<ll> p2(N);
void calc()
{
	p2[0]=1;
	for(int i =1; i<N; i++)p2[i] = (2*p2[i-1])%mod;
}

map<ll,ll> fun2(vector<pair<ll,pair<ll,ll> > >  a)
{
	sort(a.begin(), a.end());

    vector<ll> hsh(N);
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}

	map<ll,ll> m1;
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;

        ll smeq = lower_bound(a.begin(), a.end(), mp(r+(ll)1,mp((ll)-1,(ll)-1))) - a.begin();
        if(smeq == n)continue;
        smeq = hsh[smeq] ;

        m1[a[i].s.s] = (smeq) ;
    }
    return m1;
}

map<ll,ll> fun1(vector<pair<ll,pair<ll,ll> > >  a)
{
	map<ll,ll> mp1 = fun2(a), mp2;

    for(int i=0; i<n; i++)
    {
        swap(a[i].f, a[i].s.f);
        a[i].f =  1e9-a[i].f;
        a[i].s.f =  1e9-a[i].s.f;
    }

    mp2 = fun2(a);
    map<ll,ll> resultant;
    for(int i=0; i<=N; i++)
    {
    	resultant[i] = (mp1[i]+mp2[i])%mod;
	}
	return resultant;
}

int main(){
	calc();

    cin >> n;
    vector<pair<ll,pair<ll,ll> > > a(n), b(n);

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

    map<ll,ll> aa = fun1(a), bb = fun1(b);

    if(aa == bb)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define mp make_pair
#define f first
#define s second
ll n;
map<ll,ll>mpa, mpb;
ll mod = 1000000007;
ll N = 2000005;
vector<ll> p2(N);
void calc()
{
	p2[0]=1;
	for(int i =0; i<N; i++)p2[i] = (2*p2[i-1])%mod;
}
void khurapat(vector<pair<ll,pair<ll,ll> > >  &a, bool k)
{

    sort(a.begin(), a.end());
    vector<ll> hsh(N);
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;
        ll dd = lower_bound(a.begin(), a.end(), mp(a[i].f,mp((ll)-1,(ll)-1))) - a.begin();
        ll smeq = lower_bound(a.begin(), a.end(), mp(r+1,mp((ll)-1,(ll)-1))) - a.begin();

        smeq = hsh[smeq] - p2[dd];
        if(!k)
            mpa[a[i].s.s] += smeq ;
        else
            mpb[a[i].s.s] += smeq ;
    }
    for(int i=0; i<n; i++)
    {
        swap(a[i].f, a[i].s.f);
        a[i].f =  1e9-a[i].f;
        a[i].s.f =  1e9-a[i].s.f;
    }

    sort(a.begin(), a.end());
	hsh[n]=0;
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;
        ll dd = lower_bound(a.begin(), a.end(), mp(a[i].f,mp((ll)-1,(ll)-1))) - a.begin();
        ll smeq = lower_bound(a.begin(), a.end(), mp(r+1,mp((ll)-1,(ll)-1))) - a.begin();

        smeq = hsh[smeq] - p2[dd];
        if(!k)
            mpa[a[i].s.s] += smeq ;
        else
            mpb[a[i].s.s] += smeq ;
    }
}

int main(){
	calc();

    cin >> n;
    vector<pair<ll,pair<ll,ll> > > a(n), b(n);

    for(int i=0; i<n; i++)
    {
        cin>>a[i].f>>a[i].s.f>>b[i].f>>b[i].s.f;
        a[i].s.s = i;
        b[i].s.s = i;
    }
    khurapat(a,0);
    khurapat(b,1);
    if(mpa == mpb)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define mp make_pair
#define f first
#define s second
ll n;
map<ll,ll>mpa, mpb;
ll mod = 1000000007;
ll N = 2000005;
vector<ll> p2(N);
void calc()
{
	p2[0]=1;
	for(int i =0; i<N; i++)p2[i] = (p2[i]+p2[i-1])%mod;
}
void khurapat(vector<pair<ll,pair<ll,ll> > >  &a, bool k)
{

    sort(a.begin(), a.end());
    vector<ll> hsh(N);
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;
        ll dd = lower_bound(a.begin(), a.end(), mp(a[i].f,mp((ll)-1,(ll)-1))) - a.begin();
        ll smeq = lower_bound(a.begin(), a.end(), mp(r+1,mp((ll)-1,(ll)-1))) - a.begin();

        smeq = hsh[smeq] - p2[dd];
        if(!k)
            mpa[a[i].s.s] += smeq ;
        else
            mpb[a[i].s.s] += smeq ;
    }
    for(int i=0; i<n; i++)
    {
        swap(a[i].f, a[i].s.f);
        a[i].f =  1e9-a[i].f;
        a[i].s.f =  1e9-a[i].s.f;
    }

    sort(a.begin(), a.end());
	hsh[n]=0;
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;
        ll dd = lower_bound(a.begin(), a.end(), mp(a[i].f,mp((ll)-1,(ll)-1))) - a.begin();
        ll smeq = lower_bound(a.begin(), a.end(), mp(r+1,mp((ll)-1,(ll)-1))) - a.begin();

        smeq = hsh[smeq] - p2[dd];
        if(!k)
            mpa[a[i].s.s] += smeq ;
        else
            mpb[a[i].s.s] += smeq ;
    }
}

int main(){
	calc();

    cin >> n;
    vector<pair<ll,pair<ll,ll> > > a(n), b(n);

    for(int i=0; i<n; i++)
    {
        cin>>a[i].f>>a[i].s.f>>b[i].f>>b[i].s.f;
        a[i].s.s = i;
        b[i].s.s = i;
    }
    khurapat(a,0);
    khurapat(b,1);
    if(mpa == mpb)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define mp make_pair
#define f first
#define s second
ll n;
map<ll,ll>mpa, mpb;
ll mod = 1000000007;
ll N = 2000005;
vector<ll> p2(N);
void calc()
{
	p2[0]=1;
	for(int i =0; i<N; i++)p2[i] = (p2[i]+p2[i-1])%mod;
}
void khurapat(vector<pair<ll,pair<ll,ll> > >  a, bool k)
{

    sort(a.begin(), a.end());
    vector<ll> hsh(N);
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;
        ll dd = lower_bound(a.begin(), a.end(), mp(a[i].f,mp((ll)-1,(ll)-1))) - a.begin();
        ll smeq = lower_bound(a.begin(), a.end(), mp(r+1,mp((ll)-1,(ll)-1))) - a.begin();
        if(smeq == n)continue;
        smeq = hsh[smeq] - p2[dd];
        if(!k)
            mpa[a[i].s.s] += smeq ;
        else
            mpb[a[i].s.s] += smeq ;
    }
    for(int i=0; i<n; i++)
    {
        swap(a[i].f, a[i].s.f);
        a[i].f =  -a[i].f;
        a[i].s.f =  -a[i].s.f;
    }

    sort(a.begin(), a.end());
	hsh[n]=0;
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;
        ll dd = lower_bound(a.begin(), a.end(), mp(a[i].f,mp((ll)-1,(ll)-1))) - a.begin();
        ll smeq = lower_bound(a.begin(), a.end(), mp(r+1,mp((ll)-1,(ll)-1))) - a.begin();
        if(smeq == n)continue;
        smeq = hsh[smeq] - p2[dd];
        if(!k)
            mpa[a[i].s.s] += smeq ;
        else
            mpb[a[i].s.s] += smeq ;
    }
}

int main(){
	calc();

    cin >> n;
    vector<pair<ll,pair<ll,ll> > > a(n), b(n);

    for(int i=0; i<n; i++)
    {
        cin>>a[i].f>>a[i].s.f>>b[i].f>>b[i].s.f;
        a[i].s.s = i;
        b[i].s.s = i;
    }
    khurapat(a,0);
    khurapat(b,1);
    if(mpa == mpb)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define mp make_pair
#define f first
#define s second
ll n;
map<ll,ll>mpa, mpb;
ll mod = 1000000007;
ll N = 2000005;
vector<ll> p2(N);
void calc()
{
	p2[0]=1;
	for(int i =1; i<N; i++)p2[i] = (2*p2[i-1])%mod;
}
void khurapat(vector<pair<ll,pair<ll,ll> > >  a, bool k)
{

    sort(a.begin(), a.end());
    vector<ll> hsh(N);
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;
        //ll dd = lower_bound(a.begin(), a.end(), mp(a[i].f,mp((ll)-1,(ll)-1))) - a.begin();
        ll smeq = lower_bound(a.begin(), a.end(), mp(r+1,mp((ll)-1,(ll)-1))) - a.begin();
        if(smeq == n)continue;
        smeq = hsh[smeq] ;//- p2[dd];
        if(!k)
            mpa[a[i].s.s] += smeq ;
        else
            mpb[a[i].s.s] += smeq ;
    }
    for(int i=0; i<n; i++)
    {
        swap(a[i].f, a[i].s.f);
        a[i].f =  1e9-a[i].f;
        a[i].s.f =  1e9-a[i].s.f;
    }

    sort(a.begin(), a.end());
	hsh[n]=0;
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;
       // ll dd = lower_bound(a.begin(), a.end(), mp(a[i].f,mp((ll)-1,(ll)-1))) - a.begin();
        ll smeq = lower_bound(a.begin(), a.end(), mp(r+1,mp((ll)-1,(ll)-1))) - a.begin();
        if(smeq == n)continue;
        smeq = hsh[smeq];// - p2[dd];
        if(!k)
            mpa[a[i].s.s] += smeq ;
        else
            mpb[a[i].s.s] += smeq ;
    }
}

int main(){
	calc();

    cin >> n;
    vector<pair<ll,pair<ll,ll> > > a(n), b(n);

    for(int i=0; i<n; i++)
    {
        cin>>a[i].f>>a[i].s.f>>b[i].f>>b[i].s.f;
        a[i].s.s = i;
        b[i].s.s = i;
    }
    khurapat(a,0);
    khurapat(b,1);
    if(mpa == mpb)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define mp make_pair
#define f first
#define s second
ll n;
map<ll,ll>mpa, mpb;
ll mod = 1000000007;
ll N = 100005;
vector<ll> p2(N);
void calc()
{
	p2[0]=1;
	for(int i =1; i<N; i++)p2[i] = (2*p2[i-1])%mod;
}

map<ll,ll> fun2(vector<pair<ll,pair<ll,ll> > >  a)
{
	sort(a.begin(), a.end());

    vector<ll> hsh(N);
    for(int i=n-1; i>=0; i--)
    {
    	hsh[i]=(hsh[i+1]+p2[a[i].s.s])%mod;
	}

	map<ll,ll> m1;
    for(int i=0; i<n; i++)
    {
        ll r = a[i].s.f;

        ll smeq = lower_bound(a.begin(), a.end(), mp(r+(ll)1,mp((ll)-1,(ll)-1))) - a.begin();
        if(smeq == n)continue;
        smeq = hsh[smeq] ;

        m1[a[i].s.s] = (smeq) ;
    }
    return m1;
}

map<ll,ll> fun1(vector<pair<ll,pair<ll,ll> > >  a)
{
	map<ll,ll> mp1 = fun2(a), mp2;

    for(int i=0; i<n; i++)
    {
        swap(a[i].f, a[i].s.f);
        a[i].f =  -a[i].f;
        a[i].s.f =  -a[i].s.f;
    }

    mp2 = fun2(a);
    map<ll,ll> resultant;
    for(int i=0; i<n; i++)
    {
    	resultant[i] = (mp1[i]+mp2[i])%mod;
	}
	return resultant;
}

int main(){
	calc();

    cin >> n;
    vector<pair<ll,pair<ll,ll> > > a(n), b(n);

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

    map<ll,ll> aa = fun1(a), bb = fun1(b);

    if(aa == bb)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}