A permutation with values is written on rows with two elements each, thus forming two columns.
Task
Choose a maximum number of rows on which, if we write the elements one beneath the other and read them from top to bottom, the elements of the column on the left form an ascending sequence, and the elements of the column on the right form a descending sequence.
Input data
The first line contains the natural number . Each of the following lines contains two natural numbers separated by a space. All the elements are distinct natural numbers from the set .
Output data
The first line will contain the maximum number of rows , followed by pairs of numbers from the input, which form an ascending sequence on the first column, respectively a descending sequence on the second column.
Constraints and clarifications
- ().
- There can be several solutions for the problem.
- If you print only the correct number of rows, you get of the score.
- The test cases are not the same as the ones used in the contest, so the scores might be slightly different from these obtained in the real contest.
# | Points | Constraints |
---|---|---|
0 | 0 | Examples. |
1 | 70 | |
2 | 30 |
Example
stdin
8
7 3
12 10
11 16
4 2
9 8
14 5
1 15
6 13
stdout
4
1 15
6 13
9 8
14 5
Explanation
We have a permutation with elements arranged on rows out of which the maximum number of rows that satisfy the task of the problem is .
The pairs of numbers can be found in the rows of the permutation which is given in the input file. The first numbers on the row form the ascending sequence , and the other numbers form the descending sequence .
Another possible solution can be