Problem: This problem differs from the previous problem only in constraints.

Petya decided to visit Byteland during the summer holidays. It turned out that the history of this country is quite unusual.

Initially, there were n different countries on the land that is now Berland. Each country had its own territory that was represented as a rectangle on the map. The sides of the rectangle were parallel to the axes, and the corners were located at points with integer coordinates. Territories of no two countries intersected, but it was possible that some territories touched each other. As time passed, sometimes two countries merged into one. It only happened if the union of their territories was also a rectangle. In the end only one country remained — Byteland.

Initially, each country had a rectangular castle inside its territory. Its sides were parallel to the axes and its corners had integer coordinates. Some castles might touch the border of the corresponding country and sides or other castles. Miraculously, after all the unions the castles are still intact. Unfortunately, their locations are the only information we have to restore the initial territories of the countries.

<image> The possible formation of Byteland. The castles are shown in blue. 

Petya wonders why no information about the initial countries remained. He suspected that the whole story is a fake. You were recommended to him as a smart person. Please check whether or not there exists a possible set of initial territories that could make the story true.

Input

The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of countries and castles.

Each of the next n lines contains four integers a_i, b_i, c_i, d_i (0 ≤ a_i < c_i ≤ 10^9, 0 ≤ b_i < d_i ≤ 10^9) — the coordinates of the i-th castle, where (a_i, b_i) are the coordinates of the lower left corner and (c_i, d_i) are the coordinates of the upper right corner.

It is guaranteed that no two castles intersect, however, they may touch.

Output

If there exists a possible set of territories that satisfies the story, print "YES", otherwise print "NO".

You can print each letter in any case (upper or lower).

Examples

Input


4
0 0 1 2
0 2 1 3
1 0 2 1
1 1 2 3


Output


YES


Input


4
0 0 2 1
1 2 3 3
2 0 3 2
0 1 1 3


Output


NO

Note

The castles in the first and second examples are shown on the pictures below. 

<image> <image>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) {
  return os << '(' << pai.first << ' ' << pai.second << ')';
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
  cout << '[';
  for (int i = 0, _i = (((int)(v).size())); i < _i; i++) cout << v[i] << ",";
  cout << "]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> v) {
  cout << "{";
  for (auto p : v) cout << p << ",";
  cout << "}";
  return os;
}
template <typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
  cout << "{";
  for (auto p : v) cout << p << ",";
  cout << "}";
  return os;
}
template <typename T>
void get_max(T &a, T b) {
  a = max(a, b);
}
template <typename T>
void get_min(T &a, T b) {
  a = min(a, b);
}
int N;
struct Block {
  int l, r, d, u;
  bool operator<(Block t) const {
    if (l != t.l) return l < t.l;
    if (r != t.r) return r < t.r;
    if (d != t.d) return d < t.d;
    if (u != t.u) return u < t.u;
    return false;
  }
};
ostream &operator<<(ostream &os, Block t) {
  cout << (vector<int>({t.l, t.r, t.d, t.u}));
  return os;
}
bool test(set<pair<int, Block>> &sl, set<pair<int, Block>> &sr,
          set<pair<int, Block>> &sd, set<pair<int, Block>> &su) {
  0;
  0;
  0;
  0;
  0;
  int N = ((int)(sl).size());
  assert(((int)(sr).size()) == N);
  assert(((int)(sd).size()) == N);
  assert(((int)(su).size()) == N);
  if (N <= 2) return true;
  int ml = 0, mr = (1 << 30), md = 0, mu = (1 << 30);
  set<pair<int, Block>> nl, nr, nd, nu;
  auto pl = sl.begin(), pr = sr.begin(), pd = sd.begin(), pu = su.begin();
  for (int i = 0, _i = (N * 2); i < _i; i++) {
    set<pair<int, Block>>::iterator px;
    set<pair<int, Block>> *s = nullptr;
    set<pair<int, Block>> *o = nullptr;
    switch (i % 4) {
      case 0:
        get_max(ml, (pl++)->second.r);
        if (ml <= pl->second.l) {
          s = &sl;
          o = &nl;
          px = pl;
        }
        break;
      case 1:
        get_max(md, (pd++)->second.u);
        if (md <= pd->second.d) {
          s = &sd;
          o = &nd;
          px = pd;
        }
        break;
      case 2:
        get_min(mr, (pr++)->second.l);
        if (mr >= pr->second.r) {
          s = &sr;
          o = &nr;
          px = pr;
        }
        break;
      case 3:
        get_min(mu, (pu++)->second.d);
        if (mu >= pu->second.u) {
          s = &su;
          o = &nu;
          px = pu;
        }
        break;
    }
    if (s != nullptr) {
      for (auto p = s->begin(); p != px; s->erase(p++)) {
        if (s != &sl)
          sl.erase({p->second.l, p->second}),
              nl.insert({p->second.l, p->second});
        if (s != &sr)
          sr.erase({-p->second.r, p->second}),
              nr.insert({-p->second.r, p->second});
        if (s != &sd)
          sd.erase({p->second.d, p->second}),
              nd.insert({p->second.d, p->second});
        if (s != &su)
          su.erase({-p->second.u, p->second}),
              nu.insert({-p->second.u, p->second});
        o->insert(*p);
      }
      return test(sl, sr, sd, su) and test(nl, nr, nd, nu);
    }
  }
  return false;
}
int main(void) {
  iostream::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cin >> N;
  set<pair<int, Block>> sl, sr, sd, su;
  for (int i = 0, _i = (N); i < _i; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    Block t = {a, c, b, d};
    sl.insert({a, t});
    sr.insert({-c, t});
    sd.insert({b, t});
    su.insert({-d, t});
  }
  cout << (test(sl, sr, sd, su) ? "YES" : "NO") << '\n';
}