#P5847. [IOI 2005] mea

[IOI 2005] mea

Description

Consider a non-decreasing integer sequence S1,,Sn+1S_1,\cdots,S_{n+1} (SiSi+1S_i \le S_{i+1}, 1in1 \le i \le n). A sequence M1MnM_1 \cdots M_n is defined based on the sequence SS by the relation Mi=Si+Si+12M_i = \frac{S_i + S_{i+1}}{2} (1in1 \le i \le n). The sequence MM is called the mean sequence of SS.

For example, the mean sequence of 1,2,2,41,2,2,4 is 1.5,2,31.5,2,3. Note that elements in the mean sequence may be decimals. However, in this problem, you only need to handle the case where all elements of the mean sequence are integers.

You are given a non-decreasing integer sequence M1,M2,,MnM_1,M_2,\cdots,M_n of length nn. Please compute the total number of sequences S1,,Sn+1S_1,\cdots,S_{n+1} such that the mean sequence of SS is exactly M1,,MnM_1,\cdots,M_n.

Task: Read a non-decreasing integer sequence from standard input. Compute the number of integer sequences whose mean sequence equals the given integer sequence. Write the result to standard output.

Input Format

The first line contains an integer nn (2n5×1062 \le n \le 5 \times 10^6).

The next nn lines contain the given integer sequence M1,,MnM_1,\cdots,M_n. The (i+1)(i+1)-th line contains an integer MiM_i (1Mi1091 \le M_i \le 10^9).

Output Format

Output only one line, which is the required answer.

3
2
5
9

4

Hint

Sample Explanation

There are 44 sequences in total whose mean sequence is 2,5,92,5,9. These four sequences are:

  • 2,2,8,102,2,8,10
  • 1,3,7,111,3,7,11
  • 0,4,6,120,4,6,12
  • 1,5,5,13-1,5,5,13

Constraints

For 50%50\% of the testdata, 2n10002 \le n \le 1000, 1Mi2×1041 \le M_i \le 2 \times 10^4.

For 100%100\% of the testdata, 2n5×1062 \le n \le 5 \times 10^6, 1Mi1091 \le M_i \le 10^9.

Translated by ChatGPT 5