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.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.TreeMap;
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author AlexFetisov
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream;
		try {
			inputStream = new FileInputStream("input.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		OutputStream outputStream;
		try {
			outputStream = new FileOutputStream("output.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskE solver = new TaskE();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskE {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        Event[] events = new Event[2 * n];
        for (int i = 0; i < n; ++i) {
            int height = in.nextInt();
            int left = in.nextInt();
            int right = in.nextInt();
            events[i * 2] = new Event(left, 1, height);
            events[i * 2 + 1] = new Event(right, 0, height);
        }

        Arrays.sort(events);
        TreeMap<Integer, Integer> dict = new TreeMap<Integer, Integer>();

        List<Point> points = new ArrayList<Point>();
        int curLevel = 0;

        for (Event e : events) {
            if (e.type == 1) {
                if (e.height > curLevel) {
                    if (points.size() > 0) {
                        if (points.get(points.size()-1).x == e.x) {
                            points.set(points.size()-1, new Point(e.x, e.height));
                        } else {
                            int lastY = points.get(points.size()-1).y;
                            points.add(new Point(e.x, lastY));
                            points.add(new Point(e.x, e.height));
                        }
                    } else {
                        points.add(new Point(e.x, 0));
                        points.add(new Point(e.x, e.height));
                    }
                    curLevel = e.height;
                }
                addToDict(dict, e.height);
            } else {
                removeFromDict(dict, e.height);
                if (e.height == curLevel) {
                    if (dict.size() == 0) {
                        points.add(new Point(e.x, curLevel));
                        points.add(new Point(e.x, 0));
                        curLevel = 0;
                    } else {
                        curLevel = dict.lastKey();
                        if (points.get(points.size() - 1).x == e.x) {
                            points.set(points.size() - 1, new Point(e.x, curLevel));
                        } else {
                            int lastY = points.get(points.size() - 1).y;
                            if (lastY != curLevel) {
                                points.add(new Point(e.x, lastY));
                                points.add(new Point(e.x, curLevel));
                            }
                        }
                    }
                }
            }
        }
        out.println(points.size());
        for (Point p : points) {
            out.println(p.x + " " + p.y);
        }
    }

    private void addToDict(TreeMap<Integer, Integer> dict, int x) {
        if (dict.containsKey(x)) {
            dict.put(x, dict.get(x) + 1);
        } else {
            dict.put(x, 1);
        }
    }

    private void removeFromDict(TreeMap<Integer, Integer> dict, int x) {
        if (dict.get(x) == 1) {
            dict.remove(x);
        } else {
            dict.put(x, dict.get(x) - 1);
        }
    }

    class Point {
        int x, y;

        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    class Event implements Comparable<Event> {
        int x;
        int type;
        int height;

        Event(int x, int type, int height) {
            this.x = x;
            this.type = type;
            this.height = height;
        }

        public int compareTo(Event o) {
            if (x != o.x) return x - o.x;
            if (type != o.type) return o.type - type;
            return height - o.height;
        }
    }

}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer stt;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
    }

    public String nextLine() {
        try {
            return reader.readLine().trim();
        } catch (IOException e) {
            return null;
        }
    }

    public String nextString() {
        while (stt == null || !stt.hasMoreTokens()) {
            stt = new StringTokenizer(nextLine());
        }
        return stt.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

}