Problem F
Galactic Warlords
Will the galaxy see peace at last? All the warlords have
gathered to divide all of space between themselves. The
negotiations have come quite far and the warlords have finally
agreed on a peaceful way of deciding who gets what. The
Different sets of lines have been suggested, and it is up to you to present these alternatives to the meeting. To make sure that there will be peace, you are ready to modify the suggestions slightly. You have some experience with warlords and know that no warlord will settle for less space than anyone else, so for there to be peace, all of them must get the exact same area on the map. Since space is infinite, so is the map. Some sectors therefore have infinite area, so that is the amount of space everyone wants. How many extra lines do you have to add to make sure each warlord can get at least one sector with infinite area?
Input
The first line of input contains two positive integers
Output
Output the number of lines you have to add to this suggestion to satisfy all warlords.
Sample Input 1 | Sample Output 1 |
---|---|
2 1 1 1 -2 0 |
0 |
Sample Input 2 | Sample Output 2 |
---|---|
5 3 0 5 5 5 0 0 1 1 2 2 3 3 |
1 |