You are given N (0 < N < 100) line segments on a line. Every segment is defined with its endpoints Ai and Bi (Ai ≠ Bi, 1 ≤ i ≤ N). The endpoints are integer coordinates in the interval [−999, 999]. Some of the segments probably intersect. Write a program, which removes minimum number of the given segments, so that none of the left segments have common interior point.
The first line of input contains the integer N. Each of the following N lines, contains two integers (Ai and Bi), separated with one space.
On the first line write the integer P, equal to the number of segments, which are left after your program removes the excess segments. The following P lines should contain the coordinates of the left and the right endpoints of the segments which are left. These coordinates must be separated with one space. Coordinates of the left endpoints must be written in their ascending order. If the problem has more the one solution, write only one of them no matter which.
Problem Source: Bulgarian National Olympiad Day #2