You are very curious to know about the frequency of stocks. The stocks are represented as nodes of a tree with prices of the stocks as their value.
You are given a tree with N nodes (each node represents a stock) numbered from 1 to N (rooted at 1). Each stock has a value that is denoted by Pi. You are given queries of the form U L R. For each of the queries, you are required to determine the number of different stock prices or values that are available in the subtree of U for which frequency is between L and R (both inclusive).
Input format
Output format
Print Q lines containing the answer to each query.
Constraints
1≤N,Q,U≤1051≤L≤R≤1051≤Pi≤105
0 (1 has frequency 3 and 2 has frequency 1 in the subtree of 2)
2 (1 has freq 3 and 2 has freq 3)
1 (1 has freq 2 and 2 has freq 0)