Problem: No Great Victory anniversary in Berland has ever passed without the war parade. This year is not an exception. That’s why the preparations are on in full strength. Tanks are building a line, artillery mounts are ready to fire, soldiers are marching on the main square... And the air forces general Mr. Generalov is in trouble again. This year a lot of sky-scrapers have been built which makes it difficult for the airplanes to fly above the city. It was decided that the planes should fly strictly from south to north. Moreover, there must be no sky scraper on a plane’s route, otherwise the anniversary will become a tragedy. The Ministry of Building gave the data on n sky scrapers (the rest of the buildings are rather small and will not be a problem to the planes). When looking at the city from south to north as a geometrical plane, the i-th building is a rectangle of height hi. Its westernmost point has the x-coordinate of li and the easternmost — of ri. The terrain of the area is plain so that all the buildings stand on one level. Your task as the Ministry of Defence’s head programmer is to find an enveloping polyline using the data on the sky-scrapers. The polyline’s properties are as follows:

  * If you look at the city from south to north as a plane, then any part of any building will be inside or on the boarder of the area that the polyline encloses together with the land surface. 
  * The polyline starts and ends on the land level, i.e. at the height equal to 0. 
  * The segments of the polyline are parallel to the coordinate axes, i.e. they can only be vertical or horizontal. 
  * The polyline’s vertices should have integer coordinates. 
  * If you look at the city from south to north the polyline (together with the land surface) must enclose the minimum possible area. 
  * The polyline must have the smallest length among all the polylines, enclosing the minimum possible area with the land. 
  * The consecutive segments of the polyline must be perpendicular. 

<image> Picture to the second sample test (the enveloping polyline is marked on the right). 

Input

The first input line contains integer n (1 ≤ n ≤ 100000). Then follow n lines, each containing three integers hi, li, ri (1 ≤ hi ≤ 109, - 109 ≤ li < ri ≤ 109).

Output

In the first line output integer m — amount of vertices of the enveloping polyline. The next m lines should contain 2 integers each — the position and the height of the polyline’s vertex. Output the coordinates of each vertex in the order of traversing the polyline from west to east. Remember that the first and the last vertices of the polyline should have the height of 0.

Examples

Input

2
3 0 2
4 1 3


Output

6
0 0
0 3
1 3
1 4
3 4
3 0


Input

5
3 -3 0
2 -1 1
4 2 4
2 3 7
3 6 8


Output

14
-3 0
-3 3
0 3
0 2
1 2
1 0
2 0
2 4
4 4
4 2
6 2
6 3
8 3
8 0

Solution (in JAVA):

Solution:
import java.util.*;
import java.io.*;

import static java.lang.Math.*;

public class Main {

    BufferedReader in;
    StringTokenizer st;
    PrintWriter out;

    static class Pair implements Comparable<Pair> {
        int h, id;

        public Pair(int h, int id) {
            this.h = h;
            this.id = id;
        }

        @Override
        public int compareTo(Pair o) {
            if (h != o.h)
                return o.h - h;
            return id - o.id;
        }

    }

    static class Event implements Comparable<Event> {
        int x, h;
        boolean open;
        int id;

        public Event(int x, int h, boolean open, int id) {
            this.x = x;
            this.h = h;
            this.open = open;
            this.id = id;
        }

        @Override
        public String toString() {
            return "Event [x=" + x + ", h=" + h + ", open=" + open + ", id="
                    + id + "]";
        }

        @Override
        public int compareTo(Event o) {
            if (h != o.h)
                return o.h - h;
            return id - o.id;
        }
    }

    static class Cmp implements Comparator<Event> {

        @Override
        public int compare(Event o1, Event o2) {
            if (o1.x != o2.x)
                return o1.x - o2.x;
            if (o1.open != o2.open)
                if (o2.open == false)
                    return -1;
                else
                    return 1;
            return o1.h - o2.h;
        }

    }

    int n;
    Event[] events;

    void solve() throws IOException {
        long mem0 = Runtime.getRuntime().totalMemory()
                - Runtime.getRuntime().freeMemory();
        n = ni();
        events = new Event[2 * n];
        for (int i = 0; i < n; ++i) {
            int h = ni();
            int l = ni();
            int r = ni();
            events[i * 2] = new Event(l, h, true, 2 * i);
            events[i * 2 + 1] = new Event(r, h, false, 2 * i);
        }
        Arrays.sort(events, new Cmp());
        TreeSet<Pair> set = new TreeSet<Pair>();
        // ArrayList<Integer> x = new ArrayList<Integer>(400000), y = new
        // ArrayList<Integer>(
        // 400000);
        int[] x = new int[400000];
        int[] y = new int[400000];
        int size = 0;
        int curY = 0, curX = 0;
        for (int i = 0; i < events.length; ++i) {
            if (events[i].open) {
                set.add(new Pair(events[i].h, events[i].id));
                Pair e = set.first();
                if (events[i].h > curY) {
                    x[size] = events[i].x;
                    y[size++] = curY;
                    x[size] = events[i].x;
                    y[size++] = e.h;
                    curY = e.h;
                    curX = events[i].x;
                }
            } else {
                set.remove(new Pair(events[i].h, events[i].id));
                if (set.size() == 0) {
                    x[size] = events[i].x;
                    y[size++] = curY;
                    x[size] = events[i].x;
                    y[size++] = 0;
                    curX = events[i].x;
                    curY = 0;
                } else if (events[i].h >= curY && curX != events[i].x) {
                    Pair e = set.first();
                    x[size] = events[i].x;
                    y[size++] = curY;
                    x[size] = events[i].x;
                    y[size++] = e.h;
                    curX = events[i].x;
                    curY = e.h;
                }
            }
        }

        /*
         * ArrayList<Integer> ax = new ArrayList<Integer>(500000), ay = new
         * ArrayList<Integer>( 500000);
         */
        int i1 = 0;
        int cnt = 0;
        for (i1 = 1; i1 < size; ++i1) {
            if (x[i1] == x[i1 - 1] && y[i1] == y[i1 - 1])
                ++i1;
            else {
                ++cnt;
                // out.println(x.get(i1-1) +" " + y.get(i1-1));
                /*
                 * ax.add(x.get(i1 - 1)); ay.add(y.get(i1 - 1));
                 */
            }
        }
        if (i1 == size) {
            ++cnt;
            // out.println(x.get(i1-1) +" " + y.get(i1-1));
            /*
             * ax.add(x.get(i1 - 1)); ay.add(y.get(i1 - 1));
             */
        }
        out.println(cnt);
        for (i1 = 1; i1 < size; ++i1) {
            if (x[i1] == x[i1 - 1] && y[i1] == y[i1 - 1])
                ++i1;
            else {
                // ++cnt;
                out.println(x[i1 - 1] + " " + y[i1 - 1]);
                /*
                 * ax.add(x.get(i1 - 1)); ay.add(y.get(i1 - 1));
                 */
            }
        }
        if (i1 == size) {
            // ++cnt;
            out.println(x[i1 - 1] + " " + y[i1 - 1]);
            /*
             * ax.add(x.get(i1 - 1)); ay.add(y.get(i1 - 1));
             */
        }
        /*
         * out.println(ax.size()); for (int j = 0; j < ax.size(); ++j) {
         * out.println(ax.get(j) + " " + ay.get(j)); }
         */
        // System.err.println(mem0 / 1024 / 1024);
        // System.err.println(mem1 / 1024 / 1024);
    }

    void test() throws FileNotFoundException {
        PrintWriter out = new PrintWriter("test");
        out.println("100000");
        int x = -1000000000;
        int y = 1000000000;
        int h = 1;
        for (int i = 0; i < 100000; ++i) {
            out.println(h + " " + x + " " + y);
            ++h;
            ++x;
            --y;
        }
        out.close();

    }

    public Main() throws IOException {
        // test();
        in = new BufferedReader(new FileReader("input.txt"));
        out = new PrintWriter("output.txt");
        solve();
        in.close();
        out.close();
    }

    String ns() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    int ni() throws IOException {
        return Integer.valueOf(ns());
    }

    long nl() throws IOException {
        return Long.valueOf(ns());
    }

    double nd() throws IOException {
        return Double.valueOf(ns());
    }

    public static void main(String[] args) throws IOException {
        new Main();
    }
}