A number of hot dog vendors have started selling hot dogs at corners (intersections) along a very long east-west street. The problem is that multiple vendors might be selling at the same corner, and then they will take each other's business. All is not lost though! The hot dog vendors have a plan.
If there are ever two or more vendors at the same corner, then exactly two of the vendors can perform a move, which means:
- One vendor moves one corner further to the east along the street.
- The other vendor moves one corner further to the west along the street.
Remember that the street is really long, so there is no danger of running out of corners. Given the starting positions of all hot dog vendors, you should find the minimum number of moves they need to perform before the vendors are all separated (meaning they are all on different corners).
For example, suppose the street begins with the following number of hot dog vendors on each corner, listed in order from west to east:
Then the vendors can be separated in three moves, as shown below:
... 0 0 2 1 2 0 0 ...
|
+--- Do a move here
... 0 1 0 2 2 0 0 ...
|
+--- Do a move here
... 0 1 1 0 3 0 0 ...
|
+--- Do a move here
... 0 1 1 1 1 1 0 ...