Cats And Tree

hard
<a href="https://www.codechef.com/problems/CATS">https://www.codechef.com/problems/CATS</a>

Input Format

.

Output Format

.

Constraints

.

Notice

.

Example

Input
10
0 1 2 3 3 1 6 6 6 1
5 6 3 4 2 1 7 8 9 10
Output
4
1
2
2
0
0
1
1
1
1
Previous
Lca - Lowest Common Ancestor
Next
Learning Dishes

Related Questions