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.io.*;
import java.util.*;
import java.math.*;

public class E implements Runnable {
	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;
	Random rnd;

	class SegmentTree {
		int[] values;

		public SegmentTree(int size) {
			values = new int[4 * size];
		}

		private final int middle(int l, int r) {
			return (l + r) >> 1;
		}

		private final int left(int v) {
			return (v << 1);
		}

		private final int right(int v) {
			return (v << 1) + 1;
		}

		public void push(int v) {
			// if(push[v]) {
			// push[left(v)] = push[right(v)] = true;
			values[left(v)] = Math.max(values[left(v)], values[v]);
			values[right(v)] = Math.max(values[right(v)], values[v]);
			// push[v] = false;
			// }
		}

		public void set(int v, int l, int r, int tl, int tr, int value) {
			if (l != r) {
				push(v);
			}

			if (l == tl && r == tr) {
				// push[v] = true;
				values[v] = Math.max(values[v], value);
				return;
			}

			int m = middle(l, r);

			if (tl <= m) {
				set(left(v), l, m, tl, Math.min(m, tr), value);
			}

			if (tr > m) {
				set(right(v), m + 1, r, Math.max(m + 1, tl), tr, value);
			}
		}

		public int get(int v, int l, int r, int tl, int tr) {
			if (l != r) {
				push(v);
			}

			if (l == tl && r == tr) {
				return values[v];
			}

			int m = middle(l, r), res = 0;

			if (tl <= m) {
				res = get(left(v), l, m, tl, Math.min(m, tr));
			}

			if (tr > m) {
				res = Math.max(
						get(right(v), m + 1, r, Math.max(m + 1, tl), tr), res);
			}

			return res;
		}
	}

	int[] hs, ls, rs, all;
	ArrayList<Point> res;

	class Point {
		final int x, y;

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

		public String toString() {
			return (x) + " " + (y);
		}

		public boolean equals(Point p) {
			return x == p.x && y == p.y;
		}
	}

	final int lowerBound(int[] arr, int value) {
		int l = -1, r = arr.length;

		while (r - l > 1) {
			int m = (l + r) / 2;

			if (arr[m] >= value) {
				r = m;
			} else {
				l = m;
			}
		}

		return r;
	}

	final int upperBound(int[] arr, int value) {
		int l = -1, r = arr.length;

		while (r - l > 1) {
			int m = (l + r) / 2;

			if (arr[m] <= value) {
				l = m;
			} else {
				r = m;
			}
		}

		return l;
	}
	
	private int readInt() throws IOException {
		int res = 0;
		boolean flag = false;
		
		while(true) {
			int cur = in.read();
			
			if(cur == '-') {
				flag = true;
				break;
			} else if(Character.isDigit(cur)) {
				res = cur - '0';
				break;
			}
		}
		
		while(true) {
			int cur = in.read();
			
			if(!Character.isDigit(cur)) {
				break;
			}
			
			res = 10 * res + (cur - '0');
		}
		
		if(flag) {
			res = -res;
		}
		
		return res;
	}

	void solve() throws IOException {
		int n = readInt();

		hs = new int[n];
		ls = new int[n];
		rs = new int[n];
		all = new int[2 * n];
		SegmentTree t = new SegmentTree(2 * n), needBefore = new SegmentTree(
				2 * n);

		for (int i = 0; i < n; i++) {
			hs[i] = readInt();
			ls[i] = all[2 * i] = readInt();
			rs[i] = all[2 * i + 1] = readInt();
		}
		
		Arrays.sort(all);

		for (int i = 0; i < n; i++) {
			ls[i] = lowerBound(all, ls[i]);
			rs[i] = upperBound(all, rs[i]);
			t.set(1, 0, 2 * n - 1, ls[i], rs[i], hs[i]);
			needBefore.set(1, 0, 2 * n - 1, ls[i], rs[i] - 1, hs[i]);
		}

		res = new ArrayList<E.Point>(2 * n);
		res.add(new Point(all[0], 0));
		res.add(new Point(all[0], t.get(1, 0, 2 * n - 1, 0, 0)));

		for (int i = 1; i < 2 * n; i++) {
			if (all[i] == all[i - 1]) {
				continue;
			}

			Point last = res.get(res.size() - 1);
			Point cur = new Point(all[i], t.get(1, 0, 2 * n - 1, i, i));
			int minNeed = needBefore.get(1, 0, 2 * n - 1, i - 1, i - 1);

			if (minNeed != cur.y) {
				res.add(new Point(last.x, minNeed));
				res.add(new Point(cur.x, minNeed));
			} else if (last.y > cur.y) {
				res.add(new Point(last.x, cur.y));
			} else if (last.y < cur.y) {
				res.add(new Point(cur.x, last.y));
			}

			res.add(cur);
		}

		res.add(new Point(all[2 * n - 1], t.get(1, 0, 2 * n - 1, 2 * n - 1,
				2 * n - 1)));
		res.add(new Point(all[2 * n - 1], 0));

		ArrayList<Point> rightRes = new ArrayList<E.Point>(res.size());

		for (int i = 0; i < res.size(); i++) {
			Point cur = res.get(i);

			if (rightRes.size() > 0
					&& rightRes.get(rightRes.size() - 1).equals(cur)) {
				continue;
			} else if (rightRes.size() >= 2) {
				Point prelast = rightRes.get(rightRes.size() - 2);
				Point last = rightRes.get(rightRes.size() - 1);

				if (prelast.y == last.y && last.y == cur.y) {
					rightRes.remove(rightRes.size() - 1);
				}
			}

			rightRes.add(cur);
		}

		res = rightRes;
		
		out.println(res.size());

		for (Point p : res) {
			out.println(p);
		}

	}

	public static void main(String[] args) {
		final boolean oldChecker = false;

		if (oldChecker) {
			new Thread(null, new E(), "yarrr", 1 << 24).start();
		} else {
			new E().run();
		}
	}

	public void run() {
		try {
			try {
				in = new BufferedReader(new FileReader("input.txt"));
				out = new PrintWriter(new FileWriter("output.txt"));
			} catch (FileNotFoundException e) {
				in = new BufferedReader(new InputStreamReader(System.in));
				out = new PrintWriter(System.out);
			}

			rnd = new Random();

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(42);
		}
	}

	String nextToken() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String line = in.readLine();

			if (line == null) {
				return null;
			}

			st = new StringTokenizer(line);
		}

		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}