eolymp
bolt
Try our new interface for solving problems
Problems

Down the Pyramid

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 $[1, 2, 3]$, the sequence directly above it would be $[3, 5]$, and the top of the pyramid would be $[8]$: \includegraphics{https://eolympusercontent.com/images/ad4jmgkj6542hd02a0njd9hisc.gif} However, I am not interested in completing the pyramid --- instead, I would much rather go underground. Thus, for a sequence of $n$ non-negative integers, I will write down a sequence of $n + 1$ 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? \InputFile The first line contains the length $n (1 \le n \le 10^6)$ of the base sequence. The next line with $n$ integers $a_1, ..., a_n~(0 \le a_i \le 10^8$ for each $i$) forms the base sequence. \OutputFile Output the number of non-negative integer sequences that would have the input sequence as the next level in a number pyramid.
Time limit 1 second
Memory limit 128 MiB
Input example #1
6
12 5 7 7 8 4
Output example #1
2
Input example #2
3
10 1000 100
Output example #2
0
Source 2018 ICPC German Collegiate Programming Contest (GCPC), Problem D