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 InputReader {
  char buf[1048576];
  int p;
  inline InputReader() { p = 1048576; }
  inline void Flush() {
    p = 0;
    fread(buf, 1, 1048576, stdin);
  }
  inline char C() {
    if (p >= 1048576) Flush();
    return buf[p++];
  }
  inline char Readnum() {
    char ch = C();
    while (!isdigit(ch) && ch != '-') ch = C();
    return ch;
  }
  inline void Readalpha(char &c) {
    c = C();
    while (!isalpha(c)) c = C();
  }
  int operator()() {
    int ans = 0, fu = 1;
    char ch = Readnum();
    if (ch == '-') fu = -1, ch = C();
    while (ch >= '0' && ch <= '9') {
      ans = ans * 10 + ch - '0';
      ch = C();
    }
    return ans * fu;
  }
  long long Readll() {
    long long ans = 0LL, fu = 1LL;
    char ch = Readnum();
    if (ch == '-') fu = -1LL, ch = C();
    while (ch >= '0' && ch <= '9') {
      ans = ans * 10LL + ch - '0';
      ch = C();
    }
    return ans * fu;
  }
  inline void Readstring(string &x) {
    x.clear();
    char ch = C();
    while (!isdigit(ch) && !isalpha(ch) && ch != '#' && ch != '.') ch = C();
    while (isdigit(ch) || isalpha(ch) || ch == '#' || ch == '.') {
      x += ch;
      ch = C();
    }
  }
  inline void Readchstring(char s[]) {
    int len = 0;
    char ch = C();
    while (!isdigit(ch) && !isalpha(ch)) ch = C();
    while (isdigit(ch) || isalpha(ch)) {
      s[len++] = ch;
      ch = C();
    }
    s[len] = '\0';
  }
  inline void Specialread(char &c) {
    c = C();
    while (!isdigit(c) && !isalpha(c) && c != '#' && c != '.' && c != '=' &&
           c != 'B')
      c = C();
  }
} In;
inline void Read(int &x) { x = In(); }
inline void Read(int &x, int &y) {
  x = In();
  y = In();
}
inline void Read(int &x1, int &x2, int &x3) {
  x1 = In();
  x2 = In();
  x3 = In();
}
inline void Read(int &x1, int &x2, int &x3, int &x4) {
  x1 = In();
  x2 = In();
  x3 = In();
  x4 = In();
}
inline void Read(long long &x) { x = In.Readll(); }
inline void Read(long long &x, long long &y) {
  x = In.Readll();
  y = In.Readll();
}
inline void Read(long long &x1, long long &x2, long long &x3) {
  x1 = In.Readll();
  x2 = In.Readll();
  x3 = In.Readll();
}
inline void Read(long long &x1, long long &x2, long long &x3, long long &x4) {
  x1 = In.Readll();
  x2 = In.Readll();
  x3 = In.Readll();
  x4 = In.Readll();
}
template <typename T>
void Read(T a[], int st, int ed) {
  for (int(i) = (st); (i) <= (ed); ++(i)) Read(a[i]);
}
inline void FILEIO() {}
inline void FILEIO(string pname) {
  freopen((pname + ".in").c_str(), "r", stdin);
  freopen((pname + ".out").c_str(), "w", stdout);
}
inline void FILEIO_OICONTEST(string pname) {
  freopen((pname + ".in").c_str(), "r", stdin);
  freopen((pname + ".out").c_str(), "w", stdout);
}
void Printtime() {}
void END() {
  Printtime();
  exit(0);
}
template <typename T>
void END(T mes) {
  cout << mes << endl;
  END();
}
template <typename T>
void Print(T a[], int s, int t, char sp = ' ', char ed = '\n') {
  if (s > t) return;
  for (int i = s; i < t; i++) cout << a[i] << sp;
  cout << a[t] << ed;
  cout.flush();
}
template <typename T>
void Print(T a, int s = 0, int t = -1, char sp = ' ', char ed = '\n') {
  if (t == -1) t = a.size() - 1;
  for (int i = s; i <= t; i++) cout << a[i] << sp;
  cout << ed;
  cout.flush();
}
vector<int> Range(int l, int r) {
  vector<int> ret{};
  for (int(i) = (l); (i) <= (r); ++(i)) ret.push_back(i);
  return ret;
}
int n;
int ix1[131072], iy1[131072];
int ix2[131072], iy2[131072];
struct PU {
  int pos, add, id;
  inline bool operator==(const PU &y) {
    return pos == y.pos and add == y.add and id == y.id;
  }
  inline bool operator!=(const PU &y) {
    return pos != y.pos or add != y.add or id != y.id;
  }
  inline bool operator<(const PU &y) const {
    return pos != y.pos ? pos < y.pos : add != y.add ? add > y.add : id > y.id;
  }
};
struct PD {
  int pos, add, id;
  inline bool operator==(const PD &y) {
    return pos == y.pos and add == y.add and id == y.id;
  }
  inline bool operator!=(const PD &y) {
    return pos != y.pos or add != y.add or id != y.id;
  }
  inline bool operator<(const PD &y) const {
    return pos != y.pos ? pos > y.pos : add != y.add ? add > y.add : id > y.id;
  }
};
bool Solve(set<int> &ids, bool reb = 0) {
  if (ids.size() <= 2) return 1;
  static set<PU> xs1, ys1;
  static set<PD> xs2, ys2;
  if (reb) {
    xs1.clear();
    ys1.clear();
    xs2.clear();
    ys2.clear();
    for (auto id : ids) {
      xs1.insert({ix1[id], 1, id});
      xs2.insert({ix1[id], -1, id});
      ys1.insert({iy1[id], 1, id});
      ys2.insert({iy1[id], -1, id});
      xs1.insert({ix2[id], -1, id});
      xs2.insert({ix2[id], 1, id});
      ys1.insert({iy2[id], -1, id});
      ys2.insert({iy2[id], 1, id});
    }
  }
  int tadd[4] = {0, 0, 0, 0};
  static set<int> l[4];
  for (int(i) = 0; (i) < (4); ++(i)) l[i].clear();
  auto p1 = xs1.begin();
  auto p2 = xs2.begin();
  auto p3 = ys1.begin();
  auto p4 = ys2.begin();
  for (int(i) = 0; (i) < (xs1.size() - 1); ++(i)) {
    {
      PU up = *p1;
      tadd[0] += up.add;
      if (up.add == 1) l[0].insert(up.id);
      ++p1;
    }
    {
      PD up = *p2;
      tadd[1] += up.add;
      if (up.add == 1) l[1].insert(up.id);
      ++p2;
    }
    {
      PU up = *p3;
      tadd[2] += up.add;
      if (up.add == 1) l[2].insert(up.id);
      ++p3;
    }
    {
      PD up = *p4;
      tadd[3] += up.add;
      if (up.add == 1) l[3].insert(up.id);
      ++p4;
    }
    auto Try = [&](int i) -> bool {
      for (auto id : l[i]) {
        ids.erase(id);
        xs1.erase({ix1[id], 1, id});
        xs2.erase({ix1[id], -1, id});
        ys1.erase({iy1[id], 1, id});
        ys2.erase({iy1[id], -1, id});
        xs1.erase({ix2[id], -1, id});
        xs2.erase({ix2[id], 1, id});
        ys1.erase({iy2[id], -1, id});
        ys2.erase({iy2[id], 1, id});
      }
      bool t2 = Solve(ids);
      if (!t2) return 0;
      bool t1 = Solve(l[i], 1);
      if (!t1) return 0;
      return 1;
    };
    if (!tadd[0]) return Try(0);
    if (!tadd[1]) return Try(1);
    if (!tadd[2]) return Try(2);
    if (!tadd[3]) return Try(3);
  }
  return 0;
}
int main() {
  FILEIO();
  Read(n);
  for (int(i) = 1; (i) <= (n); ++(i)) {
    Read(ix1[i], iy1[i]);
    Read(ix2[i], iy2[i]);
    --ix2[i];
    --iy2[i];
  }
  static set<int> init;
  for (int(i) = 1; (i) <= (n); ++(i)) init.insert(i);
  bool ans = Solve(init, 1);
  if (ans)
    puts("YES");
  else
    puts("NO");
  END();
}