Average Value Sequence
Time limit5sMemory limit256 MB
Given a non-decreasing average sequence m of length n, count the integer sequences s of length n+1 whose adjacent averages equal m.
- Level
Medium6 of 10
- Topics
- Math, Combinatorics, Dynamic programming, Implementation
- Solved
- No attempts yet
Problem
Consider a non-decreasing integer sequence of length (that is, for every ).
Define the average sequence of as follows: for ,
For example, if then its average sequence is . The elements of an average sequence need not be integers, but in this problem we only consider cases where every element of the average sequence is an integer.
You are given a non-decreasing average sequence of length . Count the number of integer sequences whose average sequence equals it.
Input
The first line contains the length of the average sequence. ()
Each of the next lines contains one element of the average sequence, in order. (; the sequence is non-decreasing.)
Output
Print the number of integer sequences whose average sequence equals the given one.
Hint
For the first example (), exactly the following four sequences exist: