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 maxn = 1e5 + 5;
int n, a[maxn], b[maxn], c[maxn], d[maxn];
bool cut[maxn];
bool cmp0(int x, int y) { return a[x] < a[y]; }
bool cmp1(int x, int y) { return c[x] > c[y]; }
bool cmp2(int x, int y) { return b[x] < b[y]; }
bool cmp3(int x, int y) { return d[x] > d[y]; }
struct Node {
  int id;
  Node *nxt;
  Node() : nxt(0) {}
};
bool chk(vector<int> v) {
  for (int i : v) cut[i] = false;
  Node *h[4], *pre;
  for (int i = 0; i <= 3; i++) {
    if (i == 0) sort(v.begin(), v.end(), cmp0);
    if (i == 1) sort(v.begin(), v.end(), cmp1);
    if (i == 2) sort(v.begin(), v.end(), cmp2);
    if (i == 3) sort(v.begin(), v.end(), cmp3);
    h[i] = new Node;
    pre = h[i];
    for (int i : v) {
      Node *tmp = new Node;
      tmp->id = i;
      pre->nxt = tmp;
      pre = tmp;
    }
  }
  while (true) {
    Node *pt[4];
    for (int w = 0; w <= 3; w++) {
      pt[w] = h[w];
      while (cut[pt[w]->nxt->id]) pt[w]->nxt = pt[w]->nxt->nxt;
      pt[w] = pt[w]->nxt;
    }
    while (pt[0]->nxt && cut[pt[0]->nxt->id]) pt[0]->nxt = pt[0]->nxt->nxt;
    if (!pt[0]->nxt) {
      for (int i : v) cut[i] = true;
      return true;
    }
    int p0 = c[pt[0]->id], p1 = a[pt[1]->id], p2 = d[pt[2]->id],
        p3 = b[pt[3]->id];
    bool flg = false;
    while (true) {
      for (int w = 0; w <= 3; w++) {
        while (pt[w]->nxt && cut[pt[w]->nxt->id]) pt[w]->nxt = pt[w]->nxt->nxt;
        pt[w] = pt[w]->nxt;
      }
      if (!pt[0]) break;
      if (a[pt[0]->id] >= p0) {
        vector<int> tmp;
        Node *p;
        for (p = h[0]->nxt; p != pt[0]; p = p->nxt)
          tmp.push_back(p->id), cut[p->id] = true;
        if (!chk(tmp)) return false;
        flg = true;
        break;
      } else
        p0 = max(p0, c[pt[0]->id]);
      if (c[pt[1]->id] <= p1) {
        vector<int> tmp;
        Node *p;
        for (p = h[1]->nxt; p != pt[1]; p = p->nxt)
          tmp.push_back(p->id), cut[p->id] = true;
        if (!chk(tmp)) return false;
        flg = true;
        break;
      } else
        p1 = min(p1, a[pt[1]->id]);
      if (b[pt[2]->id] >= p2) {
        vector<int> tmp;
        Node *p;
        for (p = h[2]->nxt; p != pt[2]; p = p->nxt)
          tmp.push_back(p->id), cut[p->id] = true;
        if (!chk(tmp)) return false;
        flg = true;
        break;
      } else
        p2 = max(p2, d[pt[2]->id]);
      if (d[pt[3]->id] <= p3) {
        vector<int> tmp;
        Node *p;
        for (p = h[3]->nxt; p != pt[3]; p = p->nxt)
          tmp.push_back(p->id), cut[p->id] = true;
        if (!chk(tmp)) return false;
        flg = true;
        break;
      } else
        p3 = min(p3, b[pt[3]->id]);
    }
    if (!flg) return false;
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
  vector<int> whole;
  for (int i = 1; i <= n; i++) whole.push_back(i);
  cout << (chk(whole) ? "YES" : "NO") << '\n';
  return 0;
}