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 JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.function.BiPredicate;
import java.util.List;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Rustam Musin (t.me/musin_acm)
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        E2IstoriyaOdnoiStraniSlozhnaya solver = new E2IstoriyaOdnoiStraniSlozhnaya();
        solver.solve(1, in, out);
        out.close();
    }

    static class E2IstoriyaOdnoiStraniSlozhnaya {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt();
            List<Rect> rectangles = new ArrayList<>(n);
            for (int i = 0; i < n; i++) {
                int x0 = in.readInt();
                int y0 = in.readInt();
                int x1 = in.readInt() - 1;
                int y1 = in.readInt() - 1;
                rectangles.add(new Rect(i, x0, x1, y0, y1));
            }

            Packs packs = new Packs(rectangles);
            boolean ok = packs.go();
            out.print(ok ? "YES" : "NO");
        }

        class Packs {
            Pack[] a;

            Packs(List<Rect> rectangles) {
                List<Rect> byX = new ArrayList<>(rectangles);
                List<Rect> byNX = new ArrayList<>(rectangles);
                List<Rect> byY = new ArrayList<>(rectangles);
                List<Rect> byNY = new ArrayList<>(rectangles);

                byX.sort(Comparator.comparingInt(r -> r.minX));
                byNX.sort(Comparator.comparingInt(r -> -r.maxX));
                byY.sort(Comparator.comparingInt(r -> r.minY));
                byNY.sort(Comparator.comparingInt(r -> -r.maxY));

                a = new Pack[]{
                        new Pack(new Node(byX), Rect::freeByX),
                        new Pack(new Node(byNX), Rect::freeByX),
                        new Pack(new Node(byY), Rect::freeByY),
                        new Pack(new Node(byNY), Rect::freeByY)
                };
            }

            boolean go() {
                for (Pack p : a) {
                    p.reset();
                }

                if (a[0].isSingle()) {
                    a[0].root.getNext().rect.isRemoved = true;
                    return true;
                }

                for (int size = 0; a[0].hasNext(); size++) {
                    for (Pack p : a) {
                        if (!p.tryNext()) {
                            continue;
                        }
                        if (size == 0) {
                            continue;
                        }
                        List<Rect> leftPart = p.buildLeftPart(p.last);
                        return new Packs(leftPart).go() && go();
                    }
                }

                return false;
            }

        }

        class Pack {
            Node root;
            Node last;
            Rect filled;
            BiPredicate<Rect, Rect> isGood;

            Pack(Node root, BiPredicate<Rect, Rect> isGood) {
                this.root = root;
                this.isGood = isGood;
                reset();
            }

            boolean tryNext() {
                last = last.getNext();
                boolean ok = isGood.test(filled, last.rect);
                filled = filled.combine(last.rect);
                return ok;
            }

            boolean hasNext() {
                return last.getNext() != null;
            }

            List<Rect> buildLeftPart(Node lastNode) {
                List<Rect> res = new ArrayList<>();
                for (Node cur = root.getNext(); cur != lastNode; cur = cur.getNext()) {
                    res.add(cur.rect);
                }
                return res;
            }

            void reset() {
                last = root;
                filled = new Rect(-1, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE);
            }

            boolean isSingle() {
                Node first = root.getNext();
                Node second = first.getNext();
                return second == null;
            }

        }

        class Rect {
            int index;
            int minX;
            int maxX;
            int minY;
            int maxY;
            boolean isRemoved;

            Rect(int index, int minX, int maxX, int minY, int maxY) {
                this.index = index;
                this.minX = minX;
                this.maxX = maxX;
                this.minY = minY;
                this.maxY = maxY;
            }

            Rect combine(Rect other) {
                return new Rect(
                        -1,
                        Math.min(minX, other.minX),
                        Math.max(maxX, other.maxX),
                        Math.min(minY, other.minY),
                        Math.max(maxY, other.maxY)
                );
            }

            boolean freeByX(Rect other) {
                return maxX < other.minX || other.maxX < minX;
            }

            boolean freeByY(Rect other) {
                return maxY < other.minY || other.maxY < minY;
            }

            public String toString() {
                return "Rect{" +
                        "index=" + index +
                        ", minX=" + minX +
                        ", maxX=" + maxX +
                        ", minY=" + minY +
                        ", maxY=" + maxY +
                        ", isRemoved=" + isRemoved +
                        '}';
            }

        }

        class Node {
            Rect rect;
            Node next;

            Node(Rect rect) {
                this.rect = rect;
            }

            Node(List<Rect> rectangles) {
                Node last = this;
                for (Rect r : rectangles) {
                    last.next = new Node(r);
                    last = last.next;
                }
            }

            Node getNext() {
                while (next != null && next.rect.isRemoved) {
                    next = next.next;
                }
                return next;
            }

            public String toString() {
                return "Node{" +
                        "rect=" + rect +
                        ", next=" + next +
                        '}';
            }

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}