#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <iomanip>
#include <cmath>
#include <set>
#include <unordered_set>
#include <functional>
#include <map>
#include <unordered_map>
#include <string>
#include <tuple>
#include <deque>
using namespace std;
using ll = long long;
const int MOD=1e9+7;
const int MAX=100009;
ll fac[100009],finv[100009],inv[100009];

#define pi 3.14159265358979323846
#define ee 2.71828182845904523536
#define INF 1e18

ll gcd(ll x, ll y) { // 最大公約数
    if (y == 0)return x;
    else return gcd(y, x % y);
}

bool prime(ll x) { //素数判定
    if(x==1)return false;
    if (x!=2&&x % 2 == 0)return false;
    for (ll i = 3; i <= sqrt(x); i+=2) {
        if (x % i == 0)return false;
    }
    return true;
}

ll modinv(ll a, ll m) { //逆元
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll modpow(ll a, ll n, ll mod) { //二分累乗法
    ll res = 1;
    while (n) {
        if (n % 2)res = res * a % mod;
        a = a * a % mod;
        n /= 2;
    }
    return res;
}

void COMinit() { //二項係数計算の前処理
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k){ //二項係数計算
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {   // UnionFind
    vector<int> par;
    vector<int> siz;

    UnionFind(int N) : par(N), siz(N, 1) {
        for (int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (par[rx] > par[ry])swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int size(int x) {
        return siz[root(x)];
    }
};

int main() {
    int n;
    cin>>n;
    ll dp[100009][2]={};
    dp[0][0]=1;
    for(int i=0;i<n-1;i++){
        dp[i+1][0]+=dp[i][0]+dp[i][1];
        dp[i+1][0]%=MOD;
        dp[i+1][1]+=dp[i][0];
        dp[i+1][1]%=MOD;
    }
    ll a[100009];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll ans=a[0]*((dp[n-1][0]+dp[n-1][1])%MOD)%MOD;
    for(int i=1;i<n;i++){
        ans+=a[i]*((dp[i-1][0]+dp[i-1][1])%MOD*((dp[n-i-1][0]+dp[n-i-1][1])%MOD)%MOD-dp[i-1][0]*dp[n-i-1][0]%MOD);
        ans%=MOD;
        if(ans<0)ans+=MOD;
    }
    cout<<ans<<endl;
}
using namespace std;
#include <bits/stdc++.h>
#define N 100005
#define ll long long
#define mo 1000000007
int n;
ll a[N];
int main(){
	ll x;
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
		scanf("%lld",&a[i]);
	ll c0=1,s0=a[1],c1=0,s1=0;
	for (int i=2;i<=n;++i){
		ll _c0=c0+c1,_s0=s0+s1+_c0*a[i];
		ll _c1=c0,_s1=s0-_c1*a[i];
		c0=_c0%mo,s0=_s0%mo;
		c1=_c1%mo,s1=_s1%mo;
	}
	ll ans=((s0+s1)%mo+mo)%mo;
	printf("%lld\n",ans);
	return 0;
}