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 = 100003, INF = 1050000000;
struct T {
  int l, d, r, u;
  T() {}
  T(int _l, int _d, int _r, int _u) : l(_l), d(_d), r(_r), u(_u) {}
} b[maxn];
struct node {
  int x, y, num;
  node() {}
  node(int _x, int _y, int _n) : x(_x), y(_y), num(_n) {}
  bool operator<(node t) const { return x != t.x ? x < t.x : y < t.y; }
} a[4][maxn];
int n, tmp[maxn], j;
bool cmp(int x, int y) { return a[j][x] < a[j][y]; }
struct list {
  int pre, nxt;
} lst[4][maxn];
bool solve() {
  if (lst[0][lst[0][0].nxt].nxt == 0) return 1;
  int mx[4] = {-INF, -INF, -INF, -INF}, q = -1, tmphead[4], now[4], now1[4];
  for (j = 0; j <= 3; j++) now[j] = lst[j][0].nxt, now1[j] = lst[j][now[j]].nxt;
  while (1) {
    if (now1[0] == 0) break;
    for (j = 0; j <= 3; j++) {
      mx[j] = max(mx[j], a[j][now[j]].y);
      if (mx[j] <= a[j][now1[j]].x) {
        q = j;
        tmphead[q] = now1[j];
        lst[j][now[j]].nxt = lst[j][now1[j]].pre = 0;
        break;
      }
      now[j] = now1[j], now1[j] = lst[j][now1[j]].nxt;
    }
    if (~q) break;
  }
  if (q == -1) return 0;
  for (j = 0; j <= 3; j++) {
    if (j != q) {
      int cnt = 0;
      for (int i = lst[q][0].nxt; i; i = lst[q][i].nxt) {
        lst[j][lst[j][i].pre].nxt = lst[j][i].nxt;
        if (lst[j][i].nxt) lst[j][lst[j][i].nxt].pre = lst[j][i].pre;
        lst[j][i].pre = lst[j][i].nxt = 0;
        tmp[++cnt] = i;
      }
      tmphead[j] = lst[j][0].nxt;
      sort(tmp + 1, tmp + cnt + 1, cmp);
      for (int i = 0; i < cnt; i++)
        lst[j][tmp[i]].nxt = tmp[i + 1], lst[j][tmp[i + 1]].pre = tmp[i];
    }
  }
  bool ret = solve();
  if (!ret) return 0;
  for (int j = 0; j <= 3; j++) {
    lst[j][0].nxt = tmphead[j];
    lst[j][tmphead[j]].pre = 0;
  }
  ret = solve();
  if (!ret) return 0;
  return 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int l, d, r, u;
    scanf("%d%d%d%d", &l, &d, &r, &u);
    b[i] = T(l, d, r, u);
    a[0][i] = node(l, r, i);
    a[1][i] = node(-r, -l, i);
    a[2][i] = node(d, u, i);
    a[3][i] = node(-u, -d, i);
  }
  for (j = 0; j <= 3; j++) {
    for (int i = 1; i <= n; i++) tmp[i] = i;
    sort(tmp + 1, tmp + n + 1, cmp);
    for (int i = 0; i < n; i++)
      lst[j][tmp[i]].nxt = tmp[i + 1], lst[j][tmp[i + 1]].pre = tmp[i];
  }
  puts(solve() ? "YES" : "NO");
  return 0;
}