#arc122a. [arc122_a]Many Formulae
[arc122_a]Many Formulae
Problem Statement
You are given a sequence of non-negative integers: .
Consider inserting a +
or -
between each pair of adjacent terms to make one formula.
There are such ways to make a formula. Such a formula is called good when the following condition is satisfied:
-
does not occur twice or more in a row.
Find the sum of the evaluations of all good formulae. We can prove that this sum is always a non-negative integer, so print it modulo .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the sum modulo .
Sample Input 1
3
3 1 5
Sample Output 1
15
We have the following three good formulae:
Note that is not good since-
occurs twice in a row in it. Thus, the answer is .
Sample Input 2
4
1 1 1 1
Sample Output 2
10
We have the following five good formulae:
Thus, the answer is .
Sample Input 3
10
866111664 178537096 844917655 218662351 383133839 231371336 353498483 865935868 472381277 579910117
Sample Output 3
279919144
Print the sum modulo .