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;
int N;
int X1[101010], X2[101010], Y1[101010], Y2[101010];
int dfs(set<pair<int, int>>& L, set<pair<int, int>>& R, set<pair<int, int>>& U,
        set<pair<int, int>>& D) {
  if (L.size() <= 1) return 1;
  auto Lit = L.begin();
  auto Rit = R.begin();
  auto Dit = D.begin();
  auto Uit = U.begin();
  int Llim = X2[Lit->second];
  int Rlim = X1[Rit->second];
  int Dlim = Y2[Dit->second];
  int Ulim = Y1[Uit->second];
  set<pair<int, int>> L2, R2, U2, D2;
  while (1) {
    Lit++;
    Rit++;
    Dit++;
    Uit++;
    if (Lit == L.end()) break;
    if (Lit->first >= Llim) {
      auto p = *Lit;
      while (*L.begin() != p) {
        int x = L.begin()->second;
        L2.insert({X1[x], x});
        R2.insert({-X2[x], x});
        D2.insert({Y1[x], x});
        U2.insert({-Y2[x], x});
        L.erase({X1[x], x});
        R.erase({-X2[x], x});
        D.erase({Y1[x], x});
        U.erase({-Y2[x], x});
      }
      return dfs(L, R, U, D) && dfs(L2, R2, U2, D2);
    }
    if (Dit->first >= Dlim) {
      auto p = *Dit;
      while (*D.begin() != p) {
        int x = D.begin()->second;
        L2.insert({X1[x], x});
        R2.insert({-X2[x], x});
        D2.insert({Y1[x], x});
        U2.insert({-Y2[x], x});
        L.erase({X1[x], x});
        R.erase({-X2[x], x});
        D.erase({Y1[x], x});
        U.erase({-Y2[x], x});
      }
      return dfs(L, R, U, D) && dfs(L2, R2, U2, D2);
    }
    if (-Rit->first <= Rlim) {
      auto p = *Rit;
      while (*R.begin() != p) {
        int x = R.begin()->second;
        L2.insert({X1[x], x});
        R2.insert({-X2[x], x});
        D2.insert({Y1[x], x});
        U2.insert({-Y2[x], x});
        L.erase({X1[x], x});
        R.erase({-X2[x], x});
        D.erase({Y1[x], x});
        U.erase({-Y2[x], x});
      }
      return dfs(L, R, U, D) && dfs(L2, R2, U2, D2);
    }
    if (-Uit->first <= Ulim) {
      auto p = *Uit;
      while (*U.begin() != p) {
        int x = U.begin()->second;
        L2.insert({X1[x], x});
        R2.insert({-X2[x], x});
        D2.insert({Y1[x], x});
        U2.insert({-Y2[x], x});
        L.erase({X1[x], x});
        R.erase({-X2[x], x});
        D.erase({Y1[x], x});
        U.erase({-Y2[x], x});
      }
      return dfs(L, R, U, D) && dfs(L2, R2, U2, D2);
    }
    Llim = max(Llim, X2[Lit->second]);
    Rlim = min(Rlim, X1[Rit->second]);
    Dlim = max(Dlim, Y2[Dit->second]);
    Ulim = min(Ulim, Y1[Uit->second]);
  }
  return 0;
}
int dfs(vector<int>& A) {
  if (A.size() <= 1) return 1;
  int i, R;
  vector<pair<int, int>> C;
  for (auto& a : A) C.push_back({X1[a], X2[a]});
  sort((C.begin()), (C.end()));
  R = C[0].second;
  for (i = 1; i < C.size(); i++) {
    if (C[i].first >= R) {
      vector<int> S, T;
      for (auto& a : A) {
        if (X2[a] <= C[i].first)
          S.push_back(a);
        else
          T.push_back(a);
      }
      return dfs(S) & dfs(T);
    } else {
      R = max(R, C[i].second);
    }
  }
  C.clear();
  for (auto& a : A) C.push_back({Y1[a], Y2[a]});
  sort((C.begin()), (C.end()));
  R = C[0].second;
  for (i = 1; i < C.size(); i++) {
    if (C[i].first >= R) {
      vector<int> S, T;
      for (auto& a : A) {
        if (Y2[a] <= C[i].first)
          S.push_back(a);
        else
          T.push_back(a);
      }
      return dfs(S) & dfs(T);
    } else {
      R = max(R, C[i].second);
    }
  }
  return 0;
}
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N;
  set<pair<int, int>> L, R, U, D;
  for (i = 0; i < (N); i++) {
    cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
    L.insert({X1[i], i});
    R.insert({-X2[i], i});
    D.insert({Y1[i], i});
    U.insert({-Y2[i], i});
  }
  if (dfs(L, R, U, D))
    (void)printf("YES\n");
  else
    (void)printf("NO\n");
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}