Down the Pyramid
Do you like number pyramids? Given a number sequence that represents the base, you are usually supposed to build the rest of the “pyramid” bottom-up: For each pair of adjacent numbers, you would compute their sum and write it down above them. For example, given the base sequence , the sequence directly above it would be , and the top of the pyramid would be :
However, I am not interested in completing the pyramid — instead, I would much rather go underground. Thus, for a sequence of non-negative integers, I will write down a sequence of non-negative integers below it such that each number in the original sequence is the sum of the two numbers I put below it. However, there may be several possible sequences or perhaps even none at all satisfying this condition. So, could you please tell me how many sequences there are for me to choose from?
Input
The first line contains the length of the base sequence.
The next line with integers for each ) forms the base sequence.
Output
Output the number of non-negative integer sequences that would have the input sequence as the next level in a number pyramid.