CSES - Aalto Competitive Programming 2024 - wk6 - Mon - Terrible security
  • Time limit: 1.00 s
  • Memory limit: 512 MB

Syrjälä's prison has nn inmates numbered 1,2,,n1,2,\dots,n. 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 ii-th locker can be opened with the key to cell kik_i. No two lockers can be opened with the same cell key. You will be given qq queries numbered 1,2,,q1,2,\dots,q. The ii-th query asks the number of inmates that can escape if they get a hold of the key to cell xix_i.

Input

The first line contains two integers nn and qq. The second line contains nn integers k1,k2,knk_1,\,k_2,\dots\,k_n, and the third line contains qq integers x1,x2,,xqx_1,\,x_2,\,\dots,\,x_q

Output

Print the answers to the queries on a single line.

Constraints

  • 1n,q1051 \leq n, q \leq 10^5
  • 1kin1 \leq k_i \leq n
  • 1xin1 \leq x_i \leq n
  • kikjk_i \neq k_j if iji \neq j

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