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.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class A {

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner("input.txt");
		PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
//		Scanner sc = new Scanner(System.in);
//		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt();
		Compressor c = new Compressor();
		Event[] ev = new Event[n << 1];
		for(int i = 0; i < n; ++i)
		{
			int h = sc.nextInt(), l = sc.nextInt(), r = sc.nextInt();
			ev[i << 1] = new Event(l, h, 1);
			ev[i << 1 | 1] = new Event(r, h, 0);
			c.add(l);
			c.add(r);
		}
		Arrays.sort(ev);
		c.fix();
		int k = c.map.size();
		int[] h = new int[k + 1];
		HashMap<Integer, Integer> cnt = new HashMap<>();
		PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
		for(int i = 0, j = 0; i < k + 1; ++i)
		{
			while(j < n << 1 && c.get(ev[j].end) == i)
			{
				if(ev[j].start == 1)
				{
					pq.add(ev[j].height);
					add(cnt, ev[j].height, 1);
				}
				else
					add(cnt, ev[j].height, -1);
				++j;
			}
			while(!pq.isEmpty() && add(cnt, pq.peek(), 0) == 0)
				pq.remove();
			if(!pq.isEmpty())
				h[i] = pq.peek();
		}
		int[] x = new int[k + 1 << 1], y = new int[k + 1 << 1];
		int m = 0, lstH = 0;
		for(int i = 0; i < k + 1; ++i)
			if(h[i] != lstH)
			{
				x[m] = x[m + 1] = c.getBack(i);
				y[m] = lstH;
				lstH = y[m + 1] = h[i];
				m += 2;
			}
		
		out.println(m);
		for(int i = 0; i < m; ++i)
			out.println(x[i] + " " + y[i]);
		
		out.close();
	}
	
	static int add(HashMap<Integer, Integer> map, int x, int val)
	{
		Integer f = map.get(x);
		if(f == null)
			f = 0;
		map.put(x, f + val);
		return f + val;
	}
	
	
	static class Event implements Comparable<Event>
	{
		int end, height, start;
		
		Event(int a, int b, int c) { end = a; height = b; start = c; }
		
		public int compareTo(Event e) { return end - e.end; }
	}
	
	static class Compressor
	{
		TreeSet<Integer> set = new TreeSet<>();
		HashMap<Integer, Integer> map = new HashMap<>();
		int[] mapBack = new int[200000];
		
		void add(int x) { set.add(x); }
		
		void fix() { for(int x: set) map.put(mapBack[map.size()] = x, map.size());  }
		
		int get(int x) { return map.get(x); }
		
		int getBack(int x) { return mapBack[x]; }
	}
	

	static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
		
		public Scanner(String s) throws FileNotFoundException{	br = new BufferedReader(new FileReader(s));}

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

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

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

		public String nextLine() throws IOException {return br.readLine();}

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

		public boolean ready() throws IOException {return br.ready();} 
	}
}