eolymp
bolt
Try our new interface for solving problems
Problems

Domino sorting

Domino sorting

Denis, a young programmer, received a set of dominoes as a birthday present. As Denis was a programmer he didn’t know how to play domino. That’s why he invented a new game: he took n dominoes from the set and made the rectangle 2 * n from them so that one domino piece makes one horizontal row. Then he swapped and turned over some of them in order to make numbers in the left column be sorted upside down in nondecreasing order and numbers in the right column be sorted in nonincreasing order. Denis called this game “domino sorting”.

However, this game takes a lot of time... Now Denis wants to write a program that will sort any suggested set of dominoes. But as Denis is a young programmer he got stuck with this problem. So he asked you to help him.

Input

First line contains an integer n (1n105). The following n lines describe dominoes. The i–th of these lines contains two integers ai and bi (0ai, bi106). They correspond to numbers on the i-th domino.

Output

First line should contain YES if the given set of dominoes can be sorted as explained. Next n lines should describe the dominoes in the sorted order - two numbers separated by space in each line. Numbers in the first column should be nondecreasing and from the second column nonincreasing. If there is more than one solution you may output any of them. In case there is no solution you should a output single line NO.

Time limit 1 second
Memory limit 128 MiB
Input example #1
3
5 2
6 1
3 4
Output example #1
YES
1 6
2 5
3 4
Input example #2
4
1 5
7 1
3 8
5 6
Output example #2
YES
3 8
5 6
5 1
7 1
Input example #3
2
1 2
3 4
Output example #3
NO
Source 2009 Petrozavodsk, Ufa SATU Contest, August 31, Problem B