Apartment
InterviewTime limit1sMemory limit1024 MB
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 times. ANSI consists of a host, Kyoseon, and participants. Each participant is numbered from to , and each stacks their two hands on top of each other to build a hand apartment. The hand of participant sits at the -th position from the bottom. The -th game proceeds as follows.
- Kyoseon calls a positive integer .
- The participants count from to . Each time they count, they take the hand at the bottom of the hand apartment and place it on top.
- The participant whose hand is at the bottom when the count reaches loses. The losing participant leaves their hand in place and does not remove it.
For example, if there are hands and Kyoseon calls , the participant whose hand is th 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 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 .
The second line contains the number of apartment games .
The third line contains numbers separated by spaces, giving the positions of the hands in the hand apartment. is the number of the participant whose hand is at the -th position from the bottom. Each participant number appears exactly twice.
The fourth line contains positive integers separated by spaces. is the number Kyoseon called in the -th game.
Output
Print the numbers of the participants who lose, in order from the first game, separated by spaces.