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 long long MOD = 1e9 + 7;
template <typename T>
void chmin(T& a, T b) {
  if (a > b) a = b;
}
template <typename T>
void chmax(T& a, T b) {
  if (a < b) a = b;
}
template <typename T>
void add(T& a, T b) {
  a += b;
  if (a < 0) a += MOD;
  if (a >= MOD) a -= MOD;
}
void FastIn(int& T) {
  char C;
  bool F = 0;
  for (; C = getchar(), C < '0' || C > '9';)
    if (C == '-') F = 1;
  for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')
    ;
  F && (T = -T);
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
double din() {
  double x;
  scanf("%lf", &x);
  return x;
}
long long p2[64];
void initP2() {
  p2[0] = 1;
  for (int i = (1); i <= (63); ++i) {
    p2[i] = p2[i - 1] * 2;
  }
}
int countBitsBaseB(long long n, long long b) {
  if (n == 0) return 1;
  int ret = 0;
  while (n) {
    ret++;
    n /= b;
  }
  return ret;
}
int count1(long long n) {
  int ret = 0;
  while (n) {
    ret += n & 1;
    n >>= 1;
  }
  return ret;
}
long long c[1024][1024] = {0};
void initC() {
  for (int i = 0; i < (1024); ++i) {
    for (int j = 0; j < (i + 1); ++j) {
      if (j == 0 || j == i) {
        c[i][j] = 1;
      } else {
        c[i][j] = c[i - 1][j - 1];
        add(c[i][j], c[i - 1][j]);
      }
    }
  }
}
bool IsPrime(int n) {
  if (n < 2) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
void init() {
  initP2();
  initC();
}
const long long INF = 1000000000;
struct Rect {
  int a, b, c, d;
  Rect(int a_, int b_, int c_, int d_) : a(a_), b(b_), c(c_), d(d_) {}
  bool operator<(const Rect& r) const {
    if (a != r.a) return a < r.a;
    if (b != r.b) return b < r.b;
    if (c != r.c) return c < r.c;
    return d < r.d;
  }
};
set<Rect> gL, gR, gU, gD;
void GenP(const vector<Rect>& r, set<Rect>& pL, set<Rect>& pR, set<Rect>& pU,
          set<Rect>& pD, set<Rect>& L, set<Rect>& R, set<Rect>& U,
          set<Rect>& D) {
  for (int i = 0; i < (r.size()); ++i) {
    int a = r[i].a, b = r[i].b, c = r[i].c, d = r[i].d;
    pL.insert(Rect(a, b, c, d));
    L.erase(Rect(a, b, c, d));
    pR.insert(Rect(-b, -a, c, d));
    R.erase(Rect(-b, -a, c, d));
    pD.insert(Rect(c, d, a, b));
    D.erase(Rect(c, d, a, b));
    pU.insert(Rect(-d, -c, a, b));
    U.erase(Rect(-d, -c, a, b));
  }
}
bool solve(set<Rect>& L, set<Rect>& R, set<Rect>& U, set<Rect>& D) {
  if (L.size() == 1) return true;
  vector<Rect> sL, sR, sU, sD;
  set<Rect> pL, pR, pU, pD;
  int maxL = L.begin()->b, maxR = R.begin()->b;
  int maxU = U.begin()->b, maxD = D.begin()->b;
  set<Rect>::iterator iL = L.begin(), iR = R.begin(), iD = D.begin(),
                      iU = U.begin();
  while (iL != L.end()) {
    if (iL->a >= maxL) {
      GenP(sL, pL, pR, pU, pD, L, R, U, D);
      return solve(pL, pR, pU, pD) && solve(L, R, U, D);
    } else if (iR->a >= maxR) {
      GenP(sR, pL, pR, pU, pD, L, R, U, D);
      return solve(pL, pR, pU, pD) && solve(L, R, U, D);
    } else if (iU->a >= maxU) {
      GenP(sU, pL, pR, pU, pD, L, R, U, D);
      return solve(pL, pR, pU, pD) && solve(L, R, U, D);
    } else if (iD->a == maxD) {
      GenP(sD, pL, pR, pU, pD, L, R, U, D);
      return solve(pL, pR, pU, pD) && solve(L, R, U, D);
    }
    chmax(maxL, iL->b);
    sL.push_back(Rect(iL->a, iL->b, iL->c, iL->d));
    iL++;
    chmax(maxR, iR->b);
    sR.push_back(Rect(-iR->b, -iR->a, iR->c, iR->d));
    iR++;
    chmax(maxD, iD->b);
    sD.push_back(Rect(iD->c, iD->d, iD->a, iD->b));
    iD++;
    chmax(maxU, iU->b);
    sU.push_back(Rect(iU->c, iU->d, -iU->b, -iU->a));
    iU++;
  }
  return false;
}
int main() {
  init();
  int n = in();
  for (int i = 0; i < (n); ++i) {
    long long a = in(), c = in(), b = in(), d = in();
    gL.insert(Rect(a, b, c, d));
    gR.insert(Rect(-b, -a, c, d));
    gD.insert(Rect(c, d, a, b));
    gU.insert(Rect(-d, -c, a, b));
  }
  if (solve(gL, gR, gU, gD)) {
    puts("YES");
  } else
    puts("NO");
  return 0;
}