#P4622. [COCI 2012/2013 #6] JEDAN
[COCI 2012/2013 #6] JEDAN
Description
There are numbers in a row (their values represent heights). Initially, all numbers are zero. You may choose a continuous segment of numbers with the same height, and increase all of them by (except the first and last numbers of the segment). The figure below shows two operations:

Now, some numbers cannot be seen clearly, and we use to represent them. Based on the remaining numbers, determine how many possible valid arrays there are such that the visible numbers fit exactly the operation rules above.
Input Format
The first line contains a positive integer , the number of numbers.
The next line contains integers, representing the height of each number in order. A value of means it cannot be seen clearly; you may replace it with any number that satisfies the conditions. Let the -th number be .
Output Format
Output one integer: the number of all possible valid arrays modulo .
3
-1 2 -1
0
3
-1 -1 -1
2
6
-1 -1 -1 2 -1 -1
3
Hint
- .
- .
Translated by ChatGPT 5
京公网安备 11011102002149号