MOD = 1_000_000_000 + 7

N = int(input())
A = list(map(int, input().split()))


dp = [
    [0 for _ in range(N + 1)],
    [0 for _ in range(N + 1)],
    [0 for _ in range(N + 1)],
    [0 for _ in range(N + 1)],
]
dp[0][1] = 1
for i in range(1, N):
    dp[0][i + 1] = dp[0][i] + dp[1][i]
    dp[0][i + 1] %= MOD
    dp[1][i + 1] = dp[0][i]

for i in range(N):
    dp[2][i + 1] = dp[2][i] + dp[3][i] + A[i] * dp[0][i + 1]
    dp[2][i + 1] %= MOD
    dp[3][i + 1] = dp[2][i] - A[i] * dp[1][i + 1]
    dp[3][i + 1] %= MOD

ans = dp[2][N] + dp[3][N]
ans %= MOD
print(ans)
