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;
struct Rect {
  int x0, y0, x1, y1;
};
bool operator<(const Rect& a, const Rect& b) {
  return make_pair(a.x0, a.y0) < make_pair(b.x0, b.y0);
}
struct Segtree {
  static const int n = 1 << 18;
  int mi[n * 2], lazy[n * 2];
  long long sum = 0;
  int query() {
    int i = 1, acc = 0;
    while (i < n) {
      i *= 2;
      if (mi[i] + lazy[i] + acc > 0) i++;
      acc += lazy[i];
    }
    return i - n;
  }
  void add(int i, int v) {
    sum += 1ll * i * v;
    for (i += n; i > 1; i >>= 1) {
      if (i & 1) lazy[i - 1] += v;
      mi[i >> 1] = min(mi[i] + lazy[i], mi[i ^ 1] + lazy[i ^ 1]);
    }
  }
  void add(int a, int b, int v) {
    assert(a <= b);
    add(a, -v);
    add(b, v);
  }
  void print() {
    for (int i = 0; i < 10; i++) {
      int r = 0;
      for (int j = i + n; j; j >>= 1) r += lazy[j];
      cout << r << ' ';
    }
    cout << endl;
  }
};
void solve(set<Rect>& sx, set<Rect>& sy, Segtree& treex, Segtree& treey, int x1,
           int y1, int flips = 0) {
  if (sx.size() <= 1) {
    for (const Rect& r : sx) {
      treex.add(r.x0, r.x1, -1);
      treey.add(r.y0, r.y1, -1);
    }
    return;
  }
  treex.add(sx.begin()->x0, 1);
  int x = treex.query();
  treex.add(sx.begin()->x0, -1);
  if (x < x1) {
    set<Rect> sx_, sy_;
    auto sit = sx.begin(), eit = prev(sx.end());
    int nx1, nx1_;
    while (1) {
      if (sit->x0 > x) {
        eit = sit;
        sit = sx.begin();
        nx1_ = x;
        nx1 = x1;
        break;
      }
      if (eit->x0 <= x) {
        sit = next(eit);
        eit = sx.end();
        nx1 = x;
        nx1_ = x1;
        break;
      }
      ++sit;
      --eit;
    }
    for (auto it = sit; it != eit; ++it) {
      sx_.insert(*it);
      auto yit = sy.find({it->y0, it->x0, it->y1, it->x1});
      sy_.insert(*yit);
    }
    for (const Rect& r : sx_) sx.erase(r);
    for (const Rect& r : sy_) sy.erase(r);
    for (const Rect& r : sx_) {
      treex.add(r.x0, r.x1, -1);
      treey.add(r.y0, r.y1, -1);
    }
    solve(sx, sy, treex, treey, nx1, y1);
    assert(treex.sum == 0 && treey.sum == 0);
    for (const Rect& r : sx_) {
      treex.add(r.x0, r.x1, 1);
      treey.add(r.y0, r.y1, 1);
    }
    solve(sx_, sy_, treex, treey, nx1_, y1);
    assert(treex.sum == 0 && treey.sum == 0);
    return;
  }
  if (!flips) {
    solve(sy, sx, treey, treex, y1, x1, flips + 1);
    assert(treex.sum == 0 && treey.sum == 0);
  } else {
    cout << "NO" << endl;
    exit(0);
  }
}
Segtree treex, treey;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  set<Rect> sx, sy;
  map<int, int> mx, my;
  vector<Rect> rects;
  for (int i = 0; i < n; i++) {
    Rect r;
    cin >> r.x0 >> r.y0 >> r.x1 >> r.y1;
    r.x0++, r.y0++;
    rects.push_back(r);
    mx[r.x0], mx[r.x1], my[r.y0], my[r.y1];
  }
  int c = 1;
  for (auto& p : mx) p.second = c++;
  c = 1;
  for (auto& p : my) p.second = c++;
  for (Rect r : rects) {
    r = {mx[r.x0], my[r.y0], mx[r.x1], my[r.y1]};
    sx.insert(r);
    sy.insert({r.y0, r.x0, r.y1, r.x1});
    treex.add(r.x0, r.x1, 1);
    treey.add(r.y0, r.y1, 1);
  }
  assert(sx.size() == n && sy.size() == n);
  solve(sx, sy, treex, treey, 2e5 + 10, 2e5 + 10);
  assert(treex.sum == 0 && treey.sum == 0);
  cout << "YES" << endl;
}