Balanced tree#2950

Balanced tree

0.5 seconds
256 megabytes
Medium

Given a tree rooted at vertex with vertices, where the vertices are numbered from to and are colored either red or black.

A tree is called a red-black tree if it satisfies the following conditions:

Your task is to check whether the given tree is a red-black tree. If it is, construct an isomorphic -- tree.

Input

The first line contains (1 \leq n \leq 10^5). Each of the next pairs represents the parent of the -th vertex and its color (letter for red or for black). The parent of the root is the vertex numbered .

Output

Output YES or NO. If the answer is YES, also output the isomorphic -- tree in the following format: the number of edges, followed by the edges. The vertices must be numbered as in the original tree.

Examples

Example 1

Loading
Loading