Problem hidden
This problem was hidden by Editorial Board member probably because it has incorrect language version or invalid test data, or description of the problem is not clear.

IOI05MEA - IOI05 Mean Sequence

Consider a nondecreasing sequence of integers s1, . . . ,sn+1 (si ≤ si+1 for 1 ≤ i ≤ n). The sequence m1, . . . ,mn defined by mi = 1/2 (si+si+1), for 1 ≤ i ≤ n, 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 (2 ≤ n ≤ 5 000 000 ). The remaining n lines contain the sequence m1, . . . ,mn. Line i+ 1 contains a single integer mi (0 ≤ mi ≤ 1 000 000 000 ). You can assume that in 50% of the test cases n ≤ 1 000 and 0 ≤ mi 6 20 000 .

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.

Example

For the input data:
3
2
5
9
the correct result is:
4

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 .

Note: For now there are only 17 not very big test cases, remaining ones will be added in a month, all submissions will be rejudged.


Added by:Ivan Katanic
Date:2009-08-16
Time limit:0.200s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 SCM qobi VB.NET
Resource:IOI 2005 - Poland

hide comments
2012-04-10 16:54:55 Dulguun Batmunkh
nondecreasing integer sequences
2011-06-18 06:37:04 Vivek
The output could be infinite in above problem........Some of the outputs are:
-7 11 -1 19
-6 10 0 18
-5 9 1 17
-4 8 2 16
-3 7 3 15
-2 6 4 14
-1 5 5 13
0 4 6 12
1 3 7 11
2 2 8 10
.................


Last edit: 2011-06-18 06:38:37
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.