| Laser Sculpture |
The image above shows a diagram of an equipment to sculpt, with a laser, a block of some solid material. In the figure we can see a laser emitter that moves horizontally to the right and left with a constant speed. When the emitter is turned on when moving, a layer a specific width is removed from the block, being vaporized by the laser.
The image below illustrates the process of sculpting with a laser, showing an example of (a) a block, with a height of 5 mm and a length of 8 mm, at the start of the process, (b) the format that we want the sculpted block to be, and (c) the sequence of layer removals during the process, considering that in each step, a layer with 1 mm of width is removed. In the first step, the piece numbered 1 is removed; in the second, the one numbered with 2; and so it goes on. During the process of sculpting, the laser was turned on 7 times, in total, once for each removed piece of the block.
Write a program that, given the height and the length of the block, and its final format, find out the total number of times the laser must be turned on.
The end of the input is indicated by a line that contains only two zeros, separated by a blank space.
5 8 1 2 3 2 0 3 4 5 3 3 1 0 2 4 3 4 4 1 0
7 3 3