Rotate

Time limit1sMemory limit128 MB

Summary
Reverse a sequence of operations: first undo a rotation of each block of K, then undo a rotation of the whole sequence, recovering the original array.
Level

Medium4 of 10

Topics
Implementation, Simulation, Array
Solved
No attempts yet

Problem

Sang-geun and Jeong-in invented a new game called Rotate.

First, Jeong-in thinks of a sequence of length NN. He then splits the sequence into sections that each hold KK numbers (KK divides NN). The first section holds the first KK numbers of the sequence, the second section holds the next KK numbers, and the remaining sections are filled the same way.

Jeong-in may apply the following two operations to the sequence.

  1. Rotate every section to the left or right by XX positions.
  2. Rotate the entire sequence to the left or right by XX positions.

Because operation 2 acts on the whole sequence, it may change which numbers belong to each section.

Jeong-in applies these operations to his sequence in order and then shows the final sequence to Sang-geun. Given the final sequence and the operations Jeong-in applied, in order, write a program that recovers the sequence Jeong-in originally thought of.

Input

The first line contains the length of the sequence NN, the section size KK, and the number of operations Jeong-in applied QQ (1≤N,K,Q≤100,0001 \le N, K, Q \le 100{,}000, and KK divides NN).

Each of the next QQ lines describes one operation, in order. Each line contains an integer AA (1≤A≤21 \le A \le 2) indicating the operation type, followed by an integer XX (−100,000≤X≤100,000-100{,}000 \le X \le 100{,}000) indicating how far to rotate. A negative XX rotates to the left and a positive XX rotates to the right.

The last line contains the final sequence after all operations have been applied, separated by spaces.

Output

Print the sequence Jeong-in originally thought of on the first line, separated by spaces.

Examples3

  1. Example 1

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

    Input
    8 4 4
    1 3
    1 15
    1 -5
    2 -1
    6 10 14 19 2 16 17 1
    
    Expected output
    6 10 14 1 2 16 17 19
    
  3. Example 3

    Input
    9 3 5
    1 1
    2 -8
    2 9
    1 1
    2 -4
    3 1 8 7 4 5 2 6 9
    
    Expected output
    5 3 6 9 7 1 8 2 4