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 {
  long long l, r, u, d;
  rect() { l = 0, r = 0, u = 0, d = 0; }
  rect(long long a, long long b, long long c, long long d1) {
    l = a, r = b, u = c, d = d1;
  }
};
long long n;
vector<pair<rect, long long>> a;
void read() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    rect help;
    long long a1, b1, c1, d1;
    cin >> a1 >> b1 >> c1 >> d1;
    help.l = a1;
    help.d = b1;
    help.r = c1;
    help.u = d1;
    a.push_back({help, i});
  }
}
bool cmp_l(pair<rect, long long> a, pair<rect, long long> b) {
  return a.first.l > b.first.l;
}
bool cmp_r(pair<rect, long long> a, pair<rect, long long> b) {
  return a.first.r < b.first.r;
}
bool cmp_d(pair<rect, long long> a, pair<rect, long long> b) {
  return a.first.d > b.first.d;
}
bool cmp_u(pair<rect, long long> a, pair<rect, long long> b) {
  return a.first.u < b.first.u;
}
vector<bool> used;
bool check_l(vector<pair<rect, long long>> &st1,
             vector<pair<rect, long long>> &st2, long long &maxR) {
  while (!st1.empty() && used[st1.back().second]) st1.pop_back();
  if (st1.empty()) return false;
  st2.push_back(st1.back());
  st1.pop_back();
  while (!st1.empty() && used[st1.back().second]) st1.pop_back();
  if (st1.empty()) return false;
  maxR = max(maxR, st2.back().first.r);
  return maxR <= st1.back().first.l;
}
bool check_r(vector<pair<rect, long long>> &st1,
             vector<pair<rect, long long>> &st2, long long &minL) {
  while (!st1.empty() && used[st1.back().second]) st1.pop_back();
  if (st1.empty()) return false;
  st2.push_back(st1.back());
  st1.pop_back();
  while (!st1.empty() && used[st1.back().second]) st1.pop_back();
  if (st1.empty()) return false;
  minL = min(minL, st2.back().first.l);
  return minL >= st1.back().first.r;
}
bool check_d(vector<pair<rect, long long>> &st1,
             vector<pair<rect, long long>> &st2, long long &maxU) {
  while (!st1.empty() && used[st1.back().second]) st1.pop_back();
  if (st1.empty()) return false;
  st2.push_back(st1.back());
  st1.pop_back();
  while (!st1.empty() && used[st1.back().second]) st1.pop_back();
  if (st1.empty()) return false;
  maxU = max(maxU, st2.back().first.u);
  return maxU <= st1.back().first.d;
}
bool check_u(vector<pair<rect, long long>> &st1,
             vector<pair<rect, long long>> &st2, long long &minD) {
  while (!st1.empty() && used[st1.back().second]) st1.pop_back();
  if (st1.empty()) return false;
  st2.push_back(st1.back());
  st1.pop_back();
  while (!st1.empty() && used[st1.back().second]) st1.pop_back();
  if (st1.empty()) return false;
  minD = min(minD, st2.back().first.d);
  return minD >= st1.back().first.u;
}
void make(vector<pair<rect, long long>> &st) {
  for (auto i : st) used[i.second] = true;
}
void make(vector<pair<rect, long long>> &st2, long long &cnt) {
  for (auto i : st2) {
    if (!used[i.second]) cnt--;
  }
}
void make(vector<pair<rect, long long>> &st1,
          vector<pair<rect, long long>> &st2) {
  while (!st2.empty()) {
    st1.push_back(st2.back());
    st2.pop_back();
  }
}
bool solve(vector<pair<rect, long long>> a) {
  long long cnt = 0;
  vector<pair<rect, long long>> st1[4], st2[4];
  for (auto i : a) {
    if (!used[i.second]) {
      cnt++;
      st1[0].push_back(i);
      st1[1].push_back(i);
      st1[2].push_back(i);
      st1[3].push_back(i);
    }
  }
  sort(st1[0].begin(), st1[0].end(), cmp_l);
  sort(st1[1].begin(), st1[1].end(), cmp_r);
  sort(st1[2].begin(), st1[2].end(), cmp_d);
  sort(st1[3].begin(), st1[3].end(), cmp_u);
  long long maxR, minL, maxU, minD;
  maxR = -1e18;
  minL = 1e18;
  maxU = -1e18;
  minD = 1e18;
  while (cnt > 3) {
    if (st1[0].empty() && st1[1].empty() && st1[2].empty() && st1[3].empty())
      return false;
    if (check_l(st1[0], st2[0], maxR)) {
      make(st2[0], cnt);
      if (!solve(st2[0])) return false;
      make(st2[0]);
      for (long long i = 0; i < 4; i++) make(st1[i], st2[i]);
      maxR = -1e18;
      minL = 1e18;
      maxU = -1e18;
      minD = 1e18;
      continue;
    }
    if (check_r(st1[1], st2[1], minL)) {
      make(st2[1], cnt);
      if (!solve(st2[1])) return false;
      make(st2[1]);
      for (long long i = 0; i < 4; i++) make(st1[i], st2[i]);
      maxR = -1e18;
      minL = 1e18;
      maxU = -1e18;
      minD = 1e18;
      continue;
    }
    if (check_d(st1[2], st2[2], maxU)) {
      make(st2[2], cnt);
      if (!solve(st2[2])) return false;
      make(st2[2]);
      for (long long i = 0; i < 4; i++) make(st1[i], st2[i]);
      maxR = -1e18;
      minL = 1e18;
      maxU = -1e18;
      minD = 1e18;
      continue;
    }
    if (check_u(st1[3], st2[3], minD)) {
      make(st2[3], cnt);
      if (!solve(st2[3])) return false;
      make(st2[3]);
      for (long long i = 0; i < 4; i++) make(st1[i], st2[i]);
      maxR = -1e18;
      minL = 1e18;
      maxU = -1e18;
      minD = 1e18;
      continue;
    }
  }
  return true;
}
string ans;
void run() {
  used.assign(n, false);
  if (solve(a)) {
    ans = "YES";
  } else {
    ans = "NO";
  }
}
void write() { cout << ans << endl; }
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  read();
  run();
  write();
  return 0;
}