Under construction

Still being built. Things may change

Frog Leaps

Interview

Time limit1sMemory limit128 MB

Summary
Simulate a circular arrangement where a proclaimed frog repeatedly swaps forward with its neighbor B times, then output the final order starting from frog 1.
Level

Easy3 of 10

Topics
Simulation, Array
Solved
No attempts yet

Problem

The Frog Regent has arranged his NN frog servants in a circle, each frog facing the back of the frog directly ahead of it. Every frog carries a unique integer ID from 11 to NN.

The arrangement is written as a sequence of IDs that always begins with the frog whose ID is 11, followed by the frog directly ahead of it, then the next frog ahead, and so on all the way around the circle, ending with the frog directly behind frog 11.

A frog performs one leap by jumping over the single frog directly ahead of it, swapping places with that frog. Because the frogs stand in a circle, the frog directly ahead of the last one in the written sequence is frog 11 again. When the Regent proclaims a number BB, the frog whose ID is BB performs exactly BB leaps, one after another.

For example, from the arrangement 1 5 4 3 2 6, proclaiming 22 makes frog 22 perform 22 leaps and the arrangement becomes 1 2 5 4 3 6. The arrangement is always rewritten so that it starts with frog 11.

The Regent will issue a list of proclamations, one after another. Given the starting arrangement and the whole list of proclamations, determine the final arrangement of the frogs once every proclamation has been carried out in order.

Input

The first line contains an integer NN, the number of frogs (3≤N≤1003 \le N \le 100).

The second line contains a permutation of the integers 11 through NN: the starting arrangement, beginning with frog 11.

The third line contains an integer QQ, the number of proclamations (0≤Q≤100 0000 \le Q \le 100\,000).

The fourth line contains QQ integers B1,B2,…,BQB_1, B_2, \dots, B_Q (1≤Bi≤N1 \le B_i \le N), the proclamations in the order the Regent issues them. If Q=0Q = 0, this line is empty.

Output

Output one line with the final arrangement after all proclamations have been applied: NN integers separated by single spaces, written so that the sequence begins with frog 11.

Examples4

  1. Example 1

    Input
    6
    1 5 4 3 2 6
    1
    2
    
    Expected output
    1 2 5 4 3 6
    
  2. Example 2

    Input
    5
    1 5 3 2 4
    4
    5 3 5 2
    
    Expected output
    1 5 4 2 3
    
  3. Example 3

    Input
    3
    1 2 3
    0
    
    
    Expected output
    1 2 3
    
  4. Example 4

    Input
    5
    1 2 3 4 5
    1
    4
    
    Expected output
    1 2 3 4 5