Cartesian Tree

No attempts yetTime limit2sMemory limit64 MB

Problem

Consider a special kind of binary search tree called a Cartesian tree. A binary search tree is a rooted ordered binary tree in which every node xx satisfies one condition: every node in its left subtree has a key smaller than the key of xx, and every node in its right subtree has a key larger than the key of xx.

Write L(x)L(x) for the left subtree of node xx, R(x)R(x) for its right subtree, and kxk_x for its key. Then every node xx satisfies

  • if yL(x)y \in L(x) then ky<kxk_y < k_x
  • if zR(x)z \in R(x) then kz>kxk_z > k_x

A binary search tree is Cartesian when every node xx also carries an auxiliary key axa_x and those auxiliary keys satisfy the heap condition, that is,

  • if yy is the parent of xx then ay<axa_y < a_x

So a Cartesian tree is a rooted ordered binary tree in which every node carries a pair of keys (k,a)(k, a) and all three conditions above hold.

You are given a set of pairs. Build a Cartesian tree out of them, or decide that it is impossible.

Input

The first line contains an integer NN, the number of pairs to build the Cartesian tree from (1N500001 \le N \le 50000). Each of the next NN lines contains two integers kik_i and aia_i. Every pair satisfies ki30000|k_i| \le 30000 and ai30000|a_i| \le 30000. All main keys are distinct and all auxiliary keys are distinct, that is, kikjk_i \ne k_j and aiaja_i \ne a_j for iji \ne j.

Output

On the first line print YES if a Cartesian tree can be built out of the given pairs, or NO if it cannot. If it can, print the tree on the next NN lines. Nodes are numbered from 1 to NN in the order their pairs appear in the input. For each node print three numbers on one line: its parent, its left child and its right child. Print 0 when the node has no parent or no such child.

Only one tree can be built from the given input.