Denis received a set of dominoes as a birthday present and soon he invented a new game: he takes n dominoes from the set and makes the rectangle from them so that one domino piece forms one horizontal row.
The goal of the game is to swap and turn over some of the dominoes so that the numbers
in the left column would be sorted upside down in nondecreasing order and numbers
in the right column would be sorted in nonincreasing order. Denis called this game
However, this game takes a lot of time… Now Denis wants to write a program that will sort any suggested set of dominoes. But Denis is not a programmer yet, so he asked you to help him.
The first line contains an integer n (1 ≤ n ≤ 105).
The i-th of the following n lines contains two space-separated
integers ai and bi (0 ≤ ai, bi ≤ 106). They correspond to the numbers on the i-th domino.
Output “YES” if the given set of dominoes can be sorted as explained. Next n lines should describe the dominoes in the sorted order, two space-separated numbers in each line. Numbers in the first column should be nondecreasing and numbers in
the second column should be nonincreasing. If there is more than one solution, you may output any of them. In case there is no solution, output “NO”.
Problem Author: Artyom Ripatti, Petr Lezhankin
Problem Source: Ufa SATU Contest. Petrozavodsk Summer Session, August 2009