IOI '05 P3 - Mean Sequence

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 2.5s
Memory limit: 16M

Problem type

Consider a nondecreasing sequence of integers s1,,sn+1 (sisi+1 for 1in). The sequence m1,,mn defined by mi=12(si+si+1), for 1in, is called the mean sequence of sequence s1,,sn+1. For example, the mean sequence of sequence 1,2,2,4 is the sequence 1.5,2,3. Note that elements of the mean sequence can be fractions. However, this task deals with mean sequences whose elements are integers only.

Given a nondecreasing sequence of n integers m1,,mn, compute the number of nondecreasing sequences of n+1 integers s1,,sn+1 that have the given sequence m1,,mn as mean sequence.

Task

Write a program that:

  • reads from the standard input a nondecreasing sequence of integers,
  • calculates the number of nondecreasing sequences, for which the given sequence is mean sequence,
  • writes the answer to the standard output.

Input

The first line of the standard input contains one integer n (2n5000000). The remaining n lines contain the sequence m1,,mn. Line i+1 contains a single integer mi (0mi1000000000). You can assume that in 50% of the test cases n1000 and 0mi20000.

Output

Your program should write to the standard output exactly one integer — the number of nondecreasing integer sequences, that have the input sequence as the mean sequence.

Sample Input

Copy
3
2
5
9

Sample Output

Copy
4

Explanation for Sample Output

Indeed, there are four nondecreasing integer sequences for which 2,5,9 is the mean sequence. These sequences are:

  • 2,2,8,10,
  • 1,3,7,11,
  • 0,4,6,12,
  • 1,5,5,13.

Comments

There are no comments at the moment.