atcoder#ARC122A. [ARC122A] Many Formulae
[ARC122A] Many Formulae
Score : points
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 .
3
3 1 5
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 .
4
1 1 1 1
10
We have the following five good formulae:
Thus, the answer is .
10
866111664 178537096 844917655 218662351 383133839 231371336 353498483 865935868 472381277 579910117
279919144
Print the sum modulo .