Tree#635

Tree

2 seconds
256 megabytes
Hard (≈1650)

The hanging tree contains n\:(1 \le n \le 10^6) vertices. Each vertex is colored in one of colors. For each vertex find the number of different colors, occurring in the subtree with root .

Input

The first line contains the number . The next lines describe the vertices. The description of the vertex has the form p_i\:c_i, where p_i is the parent number of the vertex , and c_i is the color of the vertex i\:(1 \le c_i \le n). For the root of the tree p_i = 0.

Output

Print numbers, denoting the number of different colors in the subtrees rooted at the vertices 1, 2, ..., n.

Examples

Example 1

Loading
Loading