13632 - DS_2022_Quiz1_LinkedList   

Description

You are asked to implement a game about passing a bomb with rotation.

  1. N people are playing this game.
    • That is, players are called a1, a2, …, aN.
  2. When the game starts, a1 holds the bomb.
  3. In each round afterwards, we have an input number j ≥ 0.
    The bomb is passed from its current holder to the next jth person, and the bomb will explode after the passing completes.
  4. After passing, people who passed the bomb in this round need to rotate once.
    • For example, in the beginning, if j=3:
      Player a1 (the current bomb holder) passes the bomb to player a4, and the bomb explodes.
    • Next, a1, a2 and a3 change their positions.

Figure: bomb passing sequence

  1. If the bomb explodes at player ay’s hand, ay dies and is removed from the passing sequence. At the same time, the next player of ay gets another bomb immediately.
    • For example, if the bomb explodes at the kth player (ak)’s hand, then ak dies and ak is removed from the sequence. At the same time, ak+1 obtains another bomb. The new passing sequence starting at the next round would be ak-1, ak-2, …, a1, ak+1, …, aN.
  2. If input j = -1 or only one person remains in the sequence, the game stops.
  3. Please print the indices of the remaining players in the sequence, starting at the person who has the bomb. Note when the game stops, there may be one or more players.

Input

The first line has one number, N.

The second line has N numbers, denoting the indices of the players.

For the remaining lines, players pass the bomb based on the rules mentioned above.

  • 2 ≤ N ≤ 10,000
  • 1 ≤ Player index ≤ 1,000,000
  • 1 ≤ number of remaining lines ≤ 1,000,000
  • 1 ≤ j ≤ 264-1

Output

Please print the indices of the remaining players in the sequence, starting at the person who has the bomb.

Print ' ' between two numbers and '\n' after the last number.

Sample Input  Download

Sample Output  Download

Tags




Discuss