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 static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {

	class Tuple implements Comparable<Tuple> {
		int a, b;
		int id;
		int type;

		public int compareTo(Tuple o) {
			if (a != o.a) return a < o.a ? -1 : 1;
			if (type != o.type) return type > o.type ? -1: 1;
			if (b != o.b) return b < o.b ? -o.type : o.type;
			return 0;
		}

		public Tuple(int a, int b, int id, int t) {
			this.a = a;
			this.b = b;
			this.id = id;
			this.type = t;
		}

		@Override
		public String toString() {
			return "(" + a + "," + b + ")";
		}
	}

	void solve() {
		int n = sc.nextInt();

		Tuple[] ts = new Tuple[n * 2];
		for (int i = 0; i < n; i++) {
			int h = sc.nextInt();
			int l = sc.nextInt();
			int r = sc.nextInt();
			ts[i * 2] = new Tuple(l, h, i, 1);
			ts[i * 2 + 1] = new Tuple(r, h,i,-1);
		}
		sort(ts);

		final Tuple BEGIN = new Tuple( -(1000 * 1000 * 1000 + 1), 0, n, 1);
		final Tuple END   = new Tuple(+(1000 * 1000 * 1000 + 1), 0, n, -1);

		boolean[] in = new boolean[n + 1];

//		tr(ts);

		PriorityQueue pq = new PriorityQueue();
		pq.add(BEGIN);
		in[n] = true;

		int sz = 0;
		int[] ans1 = new int[4 * n + 10];
		int[] ans2 = new int[4 * n + 10];

		int oldHeight = 0;
		for (int i = 0; i < ts.length; i++) {
			Tuple t = ts[i];

			if (t.type == 1) {
				pq.add(ts[i]);
				in[t.id] = true;
			} else {
				in[t.id] = false;
			}

			while (in[pq.top.val.id] == false) {
				pq.pop();
			}

			Tuple s = pq.top.val;

			int x = t.a;
			int newHeight = s.b;
			if (oldHeight != newHeight) {

				ans1[sz] = (x);
				ans2[sz] = (oldHeight);
				sz++;

				ans1[sz] = (x);
				ans2[sz] = (newHeight);
				sz++;

				oldHeight = newHeight;
			}
		}


		int nsz = 0;
		for (int i = 0; i < sz; i++) {
			if (nsz == 0) {
				nsz++;
			} else {
				boolean go = true;
				if (ans1[nsz-1] == ans1[i] && ans2[nsz-1] == ans2[i]) {
					go = false;
				}
				if (nsz >= 2 && ans1[nsz-2] == ans1[nsz-1] && ans1[nsz-1] == ans1[i]) {
					go = false;
				}
				if (nsz >= 2 && ans2[nsz-2] == ans2[nsz-1] && ans2[nsz-1] == ans2[i]) {
					go = false;
				}
				if (go) {
					ans1[nsz] = ans1[i];
					ans2[nsz] = ans2[i];
					nsz++;
				} else {
					ans1[nsz-1] = ans1[i];
					ans2[nsz-1] = ans2[i];
				}
			}
		}

		sz = nsz;
		out.println(sz);
		for (int i = 0; i < sz; i++) {
			out.println(ans1[i] + " " + ans2[i]);
		}

	}

	class PriorityQueue {

		class Heap {
			Heap l, r;
			Tuple val;
		}

		Heap meld(Heap a, Heap b) {
			if (a == null) return b;
			if (b == null) return a;
			if (a.val.b < b.val.b) {Heap t = a;a = b;b = t;} // large value become top
			a.r = meld(a.r, b);
			{Heap t = a.l;a.l = a.r;a.r = t;}
			return a;
		}

		Heap top;
		public PriorityQueue() {
			top = null;
		}
		void add(Tuple a) {
			Heap one = new Heap();
			one.val = a;
			top = meld(top, one);
		}
		Tuple peak() {
			return top.val;
		}
		void pop() {
			if (top != null) top = meld(top.l, top.r);
		}
	}

	void print(int[] a) {
		out.print(a[0]);
		for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
		out.println();
	}

	static void tr(Object... os) {
		System.err.println(deepToString(os));
	}

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

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
//		sc = new MyScanner(System.in);
//		out = new PrintWriter(System.out);
		sc = new MyScanner(new FileInputStream(new File("input.txt")));
		out = new PrintWriter(new File("output.txt"));
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}