#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    long long a;
    long long s[n+1];
    long long d;
    int i;
    s[0]=1;
    s[1]=1;
    for(i=2;i<=n;i++){
        s[i]=(s[i-2]+s[i-1])%1000000007;
    }
    cin >> a;
    long long sum=(s[n]*a)%1000000007;
    for(i=1;i<n;i++){
        cin>>a;
        d = s[i]*s[n-i]-s[i-1]*s[n-i-1];
        if(d<0)d+=1000000007;
        d=d%1000000007;
        sum+=(a*d)%1000000007;
        sum=sum%1000000007;
    }
    cout << sum << endl;
    return 0;
}
#include <bits/stdc++.h>          
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
template<class in_chmax> void chmax(in_chmax &x, in_chmax y) {x = max(x,y);}
template<class in_chmin> void chmin(in_chmin &x, in_chmin y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

const ll inf = 1e18;
const ll mod = 1e9 + 7;

ll powmodp(ll x, ll n) {
    if (n<0) return 0;
    if (n==0) return 1;
    if (n%2) return x * powmodp(x,n-1) % mod;
    ll res = powmodp(x,n/2);
    return res * res % mod;
}

void addmodp(ll &x, ll y) {x = (x + y) % mod;}

int main() {
    ll N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    vector<vector<ll>> L(N,vector<ll>(2)), R(N,vector<ll>(2));
    L[0][0] = 1;
    repp(i,1,N) {
        L[i][0] = (L[i-1][0] + L[i-1][1]) % mod;
        L[i][1] = L[i-1][0];
    }
    R[N-1][0] = 1;
    repm(i,N-2,0) {
        R[i][0] = (R[i+1][0] + R[i+1][1]) % mod;
        R[i][1] = R[i+1][0];
    }

    ll ans = 0;
    rep(i,N) {
        ll x = L[i][0] * ((R[i][0] + R[i][1])%mod) % mod;
        ll y = L[i][1] * R[i][0] % mod;
        addmodp(ans,A[i]*x%mod);
        addmodp(ans,(mod-A[i])*y%mod);
    }

    Cout(ans);
}