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;
const int MX = 100005;
struct List {
  List *nex, *pre;
  int i;
  List(int i) : nex(0), pre(0), i(i) {}
};
int n, a[MX], b[MX], c[MX], d[MX], q[MX];
List *la[MX], *lb[MX], *lc[MX], *ld[MX];
List *makeList(List *l[MX]) {
  List *r = new List(-1), *ant = r;
  for (int i = 0; i < n; i++) {
    List *act = new List(q[i]);
    ant->nex = act;
    act->pre = ant;
    ant = act;
    l[q[i]] = act;
  }
  return r;
}
vector<int> makeSmall(List *r, List *t) {
  vector<int> v;
  r = r->nex;
  while (r != t) {
    v.emplace_back(r->i);
    r = r->nex;
  }
  return v;
}
bool go(List *ra, List *rb, List *rc, List *rd, int n);
void reloc(List *l[MX], List *nl, int x) {
  List *elem = l[x];
  List *pre = elem->pre;
  List *nex = elem->nex;
  pre->nex = nex;
  if (nex) nex->pre = pre;
  elem->pre = nl;
  elem->nex = 0;
  nl->nex = elem;
}
bool trans(List *ra, List *rb, List *rc, List *rd, int n, vector<int> &v) {
  List *na = new List(-1), *ta = na;
  List *nb = new List(-1), *tb = nb;
  List *nc = new List(-1), *tc = nc;
  List *nd = new List(-1), *td = nd;
  sort(v.begin(), v.end(), [&](int i, int j) { return a[i] < a[j]; });
  for (int x : v) {
    reloc(la, ta, x);
    ta = ta->nex;
  }
  sort(v.begin(), v.end(), [&](int i, int j) { return b[i] < b[j]; });
  for (int x : v) {
    reloc(lb, tb, x);
    tb = tb->nex;
  }
  sort(v.begin(), v.end(), [&](int i, int j) { return c[i] > c[j]; });
  for (int x : v) {
    reloc(lc, tc, x);
    tc = tc->nex;
  }
  sort(v.begin(), v.end(), [&](int i, int j) { return d[i] > d[j]; });
  for (int x : v) {
    reloc(ld, td, x);
    td = td->nex;
  }
  return go(na, nb, nc, nd, v.size()) && go(ra, rb, rc, rd, n - v.size());
}
bool go(List *ra, List *rb, List *rc, List *rd, int n) {
  if (n < 2) return 1;
  List *ta = ra->nex;
  int ma = 0;
  List *tb = rb->nex;
  int mb = 0;
  List *tc = rc->nex;
  int mc = 1e9;
  List *td = rd->nex;
  int md = 1e9;
  for (int i = 0; i < n; i++) {
    if (i && ma <= a[ta->i]) {
      vector<int> v = makeSmall(ra, ta);
      return trans(ra, rb, rc, rd, n, v);
    }
    if (i && mb <= b[tb->i]) {
      vector<int> v = makeSmall(rb, tb);
      return trans(ra, rb, rc, rd, n, v);
    }
    if (i && mc >= c[tc->i]) {
      vector<int> v = makeSmall(rc, tc);
      return trans(ra, rb, rc, rd, n, v);
    }
    if (i && md >= d[td->i]) {
      vector<int> v = makeSmall(rd, td);
      return trans(ra, rb, rc, rd, n, v);
    }
    ma = max(ma, c[ta->i]);
    ta = ta->nex;
    mb = max(mb, d[tb->i]);
    tb = tb->nex;
    mc = min(mc, a[tc->i]);
    tc = tc->nex;
    md = min(md, b[td->i]);
    td = td->nex;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
  iota(q, q + n, 0);
  sort(q, q + n, [&](int i, int j) { return a[i] < a[j]; });
  List *ra = makeList(la);
  sort(q, q + n, [&](int i, int j) { return b[i] < b[j]; });
  List *rb = makeList(lb);
  sort(q, q + n, [&](int i, int j) { return c[i] > c[j]; });
  List *rc = makeList(lc);
  sort(q, q + n, [&](int i, int j) { return d[i] > d[j]; });
  List *rd = makeList(ld);
  if (go(ra, rb, rc, rd, n))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}