atcoder#ARC122A. [ARC122A] Many Formulae

[ARC122A] Many Formulae

Score : 400400 points

Problem Statement

You are given a sequence of NN non-negative integers: A1,A2,,ANA_1,A_2,\cdots,A_N.

Consider inserting a + or - between each pair of adjacent terms to make one formula.

There are 2N12^{N-1} 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 (109+7)(10^9+7).

Constraints

  • 1N1051 \leq N \leq 10^5
  • 1Ai1091 \leq A_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \cdots ANA_N

Output

Print the sum modulo (109+7)(10^9+7).

3
3 1 5
15

We have the following three good formulae:

  • 3+1+5=93+1+5=9
  • 3+15=13+1-5=-1
  • 31+5=73-1+5=7

Note that 3153-1-5 is not good since- occurs twice in a row in it. Thus, the answer is 9+(1)+7=159+(-1)+7=15.

4
1 1 1 1
10

We have the following five good formulae:

  • 1+1+1+1=41+1+1+1=4
  • 1+1+11=21+1+1-1=2
  • 1+11+1=21+1-1+1=2
  • 11+1+1=21-1+1+1=2
  • 11+11=01-1+1-1=0

Thus, the answer is 4+2+2+2+0=104+2+2+2+0=10.

10
866111664 178537096 844917655 218662351 383133839 231371336 353498483 865935868 472381277 579910117
279919144

Print the sum modulo (109+7)(10^9+7).