You are playing a video game in which several stacks of boxes are lined up on the floor, with a crane on top to rearrange the boxes, as shown in the picture below.
The crane supports the following commands:
Move one position left (does nothing if already at the leftmost position)
Move one position right (does nothing if already at the rightmost position)
Pick up a box from the current stack (does nothing if the crane already has a box)
Drop a box on the current stack (does nothing if the crane doesn't already have a box)
Further, there is a limit H on the number of boxes on each stack. If a 'drop' command would result in a stack having more than H boxes, the crane ignores this drop command. If the current stack has no boxes, a 'pick up' command is ignored.
You are given the initial number of boxes in each stack and the sequence of operations performed by the crane. You have to compute the final number of boxes in each stack.
For example, suppose the initial configuration of the game is as shown in the figure above, with 7 stacks and H=4. Then, after the following sequence of instructions,
The number of boxes in each stack from left to right would be 2,1,3,1,4,0,1.
A single line with N integers, the number of boxes in each stack, from left to right.
> 7 4 3 1 2 1 4 0 1 3 2 2 2 2 4 1 3 1 4 0
> 2 1 3 1 4 0 1
> 3 5 2 5 2 3 2 4 2 2 2 1 4 1 1 1 1 0
> 1 5 2
There is only one subtask worth 100 marks. In all inputs:
There are 18 test inputs on the server during the exam.
Time limit : 1s
Memory limit: 32 MB