Count Descendants

easy
<a href="https://atcoder.jp/contests/abc202/tasks/abc202_e">https://atcoder.jp/contests/abc202/tasks/abc202_e</a>

Input Format

.

Output Format

.

Constraints

.

Notice

.

Example

Input
7
1 1 2 2 4 2
4
1 2
7 2
4 1
5 5
Output
3
1
0
0
Previous
Similar String Groups
Next
Rectangle Puzzle 2

Related Questions