Under construction

Still being built. Things may change

Apartment

Interview

Time limit1sMemory limit1024 MB

Summary
Rotate a circular stack of 2N hands by each game's count and report the participant at the bottom, keeping the arrangement between games.
Level

Easy2 of 10

Topics
Simulation, Array
Solved
No attempts yet

Problem

A~partment, apartment! A~partment, apartment! Which floor shall I live on?

To celebrate the end of the year, the algorithm club ANSI from the Department of Software Science at Ajou University plays the apartment game TT times. ANSI consists of a host, Kyoseon, and NN participants. Each participant is numbered from 11 to NN, and each stacks their two hands on top of each other to build a hand apartment. The hand of participant aia_i sits at the ii-th position from the bottom. The jj-th game proceeds as follows.

  1. Kyoseon calls a positive integer bjb_j.
  2. The participants count from 11 to bjb_j. Each time they count, they take the hand at the bottom of the hand apartment and place it on top.
  3. The participant whose hand is at the bottom when the count reaches bjb_j loses. The losing participant leaves their hand in place and does not remove it.

For example, if there are 66 hands and Kyoseon calls 44, the participant whose hand is 44th from the bottom loses. Note that Kyoseon can call a number larger than the total number of hands in the apartment.

To keep the games continuous, each new game starts from the state where the previous game ended, without changing the positions of the hands in the apartment. Over TT games, the participant who loses the most must receive a penalty, so find the loser of each game.

Input

The first line contains the number of participants NN. (1≤N≤40)(1 \leq N \leq 40)

The second line contains the number of apartment games TT. (1≤T≤5 000)(1 \leq T \leq 5\,000)

The third line contains 2N2N numbers separated by spaces, giving the positions of the hands in the hand apartment. aia_i is the number of the participant whose hand is at the ii-th position from the bottom. Each participant number appears exactly twice. (1≤ai≤N)(1 \leq a_i \leq N)

The fourth line contains TT positive integers bjb_j separated by spaces. bjb_j is the number Kyoseon called in the jj-th game. (1≤bj≤1 000)(1 \leq b_j \leq 1\,000)

Output

Print the numbers of the participants who lose, in order from the first game, separated by spaces.

Examples1

  1. Example 1

    Input
    4
    2
    2 4 4 3 3 1 2 1
    3 12
    
    Expected output
    4 1