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