Cartesian tree#5293

Cartesian tree

2 seconds
64 megabytes
Easy

You are given a set of pairs (a_i, b_i), and your task is to construct a Cartesian tree where the -th node has keys (a_i, b_i). The nodes with key a_i should form a binary search tree, while the nodes with key b_i should form a heap.

Input

The first line contains the integer , representing the number of pairs. This is followed by pairs (a_i, b_i), where 1 \leq N \leq 50000. Each pair satisfies |a_i|, |b_i| \leq 30000. Additionally, a_i \neq a_j and b_i \neq b_j for all i \neq j.

Output

If it is possible to construct a Cartesian tree with these keys, print **YES** on the first line. Otherwise, print **NO**. If the answer is **YES**, follow it with lines, each describing a node. Each node's description consists of three numbers: the index of the parent, the index of the left child, and the index of the right child. Use to indicate the absence of a parent or child. If multiple valid trees exist, you may output any one of them.

Examples

Example 1

Loading
Loading