- Time limit: 1.00 s
- Memory limit: 512 MB
Syrjälä's prison has inmates numbered . Each of the inmates has their own cell and each of the cells has a unique key. The guards have invented a neat convenience feature: the keys to the cells are stored in an array of tiny lockers. The lockers can be opened with a master key or with one of the other cell keys in case the master key gets lost. This is obviously terrible for security. The -th locker can be opened with the key to cell . No two lockers can be opened with the same cell key. You will be given queries numbered . The -th query asks the number of inmates that can escape if they get a hold of the key to cell .
Input
The first line contains two integers and . The second line contains integers , and the third line contains integers
Output
Print the answers to the queries on a single line.
Constraints
- if
Example 1
Input:
5 5 1 3 2 4 5 3 5 3 4 4
Output:
2 1 2 1 1
Example 2
Input:
10 6 8 6 3 10 1 5 7 2 4 9 9 3 5 1 7 5
Output:
3 1 5 5 1 5
Example 3
Input:
1 1 1 1
Output:
1