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;
void canhazfast() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
  T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
  while (b) {
    T q = a / b;
    a %= b;
    swap(a, b);
    x0 -= q * x1;
    swap(x0, x1);
    y0 -= q * y1;
    swap(y0, y1);
  }
  x = x0;
  y = y0;
  return a;
}
int ctz(unsigned x) { return __builtin_ctz(x); }
int ctzll(unsigned long long x) { return __builtin_ctzll(x); }
int clz(unsigned x) { return __builtin_clz(x); }
int clzll(unsigned long long x) { return __builtin_clzll(x); }
int popcnt(unsigned x) { return __builtin_popcount(x); }
int popcntll(unsigned long long x) { return __builtin_popcountll(x); }
int bsr(unsigned x) { return 31 ^ clz(x); }
int bsrll(unsigned long long x) { return 63 ^ clzll(x); }
template <typename T>
void umin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void umax(T &a, T b) {
  a = max(a, b);
}
struct S {
  int l, r;
  int d, u;
};
struct Node {
  int pre, nxt;
};
void lnk(Node lst[], int x, int y) {
  lst[x].nxt = y;
  lst[y].pre = x;
}
void del(Node lst[], int x, int &h) {
  int pre = lst[x].pre, nxt = lst[x].nxt;
  if (pre >= 0)
    lst[pre].nxt = nxt;
  else
    h = nxt;
  if (nxt >= 0) lst[nxt].pre = pre;
  if (x == h) h = lst[h].nxt;
}
void pri(const Node lst[], int x) {
  while (x >= 0) {
    cerr << ' ' << x;
    x = lst[x].nxt;
  }
}
int lsz(const Node lst[], int x) {
  int res = 0;
  while (x >= 0) {
    ++res;
    x = lst[x].nxt;
  }
  return res;
}
Node llist[100016], rlist[100016], dlist[100016], ulist[100016];
int ids[100016];
S s[100016];
bool cmpl(int a, int b) { return s[a].l < s[b].l; }
bool cmpr(int a, int b) { return s[a].r > s[b].r; }
bool cmpd(int a, int b) { return s[a].d < s[b].d; }
bool cmpu(int a, int b) { return s[a].u > s[b].u; }
int init(int n, Node lst[]) {
  lst[ids[0]].pre = -1;
  for (int i = 1; i < n; ++i) lnk(lst, ids[i - 1], ids[i]);
  lst[ids[n - 1]].nxt = -1;
  return ids[0];
}
void del_all(int x, int &hl, int &hr, int &hd, int &hu) {
  del(llist, x, hl);
  del(rlist, x, hr);
  del(dlist, x, hd);
  del(ulist, x, hu);
}
void init_all(int n, int &hl, int &hr, int &hd, int &hu) {
  sort(ids, ids + n, cmpl);
  hl = init(n, llist);
  sort(ids, ids + n, cmpr);
  hr = init(n, rlist);
  sort(ids, ids + n, cmpd);
  hd = init(n, dlist);
  sort(ids, ids + n, cmpu);
  hu = init(n, ulist);
}
bool check(int n, int hl, int hr, int hd, int hu) {
  if (n < 4) return true;
  int xl = hl, xr = hr, xd = hd, xu = hu;
  int gl, gr, gd, gu;
  int llo = 1234567890, rhi = 0;
  int dlo = 1234567890, uhi = 0;
  for (int i = 1; i <= n / 2; ++i) {
    int yl = llist[xl].nxt;
    umax(rhi, s[xl].r);
    if (rhi <= s[yl].l) {
      for (int j = 0, v = hl; j < i; ++j, v = llist[v].nxt) {
        del_all(v, hl, hr, hd, hu);
        ids[j] = v;
      }
      init_all(i, gl, gr, gd, gu);
      return check(i, gl, gr, gd, gu) && check(n - i, hl, hr, hd, hu);
    }
    xl = yl;
    int yd = dlist[xd].nxt;
    umax(uhi, s[xd].u);
    if (uhi <= s[yd].d) {
      for (int j = 0, v = hd; j < i; ++j, v = dlist[v].nxt) {
        del_all(v, hl, hr, hd, hu);
        ids[j] = v;
      }
      init_all(i, gl, gr, gd, gu);
      return check(i, gl, gr, gd, gu) && check(n - i, hl, hr, hd, hu);
    }
    xd = yd;
    int yr = rlist[xr].nxt;
    umin(llo, s[xr].l);
    if (llo >= s[yr].r) {
      for (int j = 0, v = hr; j < i; ++j, v = rlist[v].nxt) {
        del_all(v, hl, hr, hd, hu);
        ids[j] = v;
      }
      init_all(i, gl, gr, gd, gu);
      return check(i, gl, gr, gd, gu) && check(n - i, hl, hr, hd, hu);
    }
    xr = yr;
    int yu = ulist[xu].nxt;
    umin(dlo, s[xu].d);
    if (dlo >= s[yu].u) {
      for (int j = 0, v = hu; j < i; ++j, v = ulist[v].nxt) {
        del_all(v, hl, hr, hd, hu);
        ids[j] = v;
      }
      init_all(i, gl, gr, gd, gu);
      return check(i, gl, gr, gd, gu) && check(n - i, hl, hr, hd, hu);
    }
    xu = yu;
  }
  return false;
}
int main() {
  int n;
  int hl, hr, hd, hu;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> s[i].l >> s[i].d >> s[i].r >> s[i].u;
  iota(ids, ids + n, 0);
  init_all(n, hl, hr, hd, hu);
  cout << (check(n, hl, hr, hd, hu) ? "YES\n" : "NO\n");
  return 0;
}