Football#333

Football

2 seconds
1,024 megabytes
Very hard

There are players in a football team, numbered with integers from to . The skill level of player with number is described by the integer c_i.

The players are arranged in a circle in such a way that the player with number has the player with number i+1 on their right side (for 1 \le i < n), and for the player with number , the next player is the one with number .

Let's define the strength of a game combination, characterized by an array of integers k=[k_0, k_1, k_2, \ldots, k_{m-1}], as follows:

An array of integers a_0,a_1,\ldots,a_{q-1} is given. For each from to (q-1), find the strength of the game combination characterized by the array [a_0,a_1,\ldots,a_i].

Input

The first line contains two integers and (1 \leq n, q \leq 3\cdot{10}^5) — the number of players and the length of the array .

The second line contains integers c_1, c_2, \dots, c_n (1 \leq c_i \leq n) — the skill levels of the players.

The third line contains integers a_0, a_1, \dots, a_{q-1} (1 \leq a_i \leq n-1) — the elements of the array .

Output

Output integers — the sought values of the strengths of game combinations.

Examples

Example 1

Loading
Loading

Note

In the example of passing the ball for game combinations, it looks as follows:

k=[3]

k=[3,1]

k=[3,1,2]

Scoring

  1. ( points): n, q \leq 100;

  2. ( points): all values of a_i are the same;

  3. ( points): is a prime number;

  4. ( points): n, q \leq 1000;

  5. ( points): n, q \leq 1.5\cdot{10}^5, n = 2^k for some integer ;

  6. ( points): n, q \leq {10}^5;

  7. ( points): without additional constraints.