#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const ll mod = 1000000007;

int f[100000][2] = {0}, times[100000][2] = {0};

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n >> f[0][0];
    times[0][0] = 1;
    for (int i = 1; i < n; ++i) {
        times[i][0] = (times[i - 1][0] + times[i - 1][1]) % mod;
        times[i][1] = times[i - 1][0];
        cin >> f[i][1];
        f[i][0] = ((f[i - 1][0] + f[i - 1][1]) % mod + (ll)f[i][1] * times[i][0] % mod) % mod;
        f[i][1] = (f[i - 1][0] - (ll)f[i][1] * times[i][1]) % mod;
        if (f[i][1] < 0) f[i][1] += mod;
    }
    cout << (f[n - 1][0] + f[n - 1][1]) % mod;
}
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define tc int t;cin>>t;while(t--)
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define pb push_back
#define pi pair<int,int>
#define pll pair<lli,lli>
#define vi vector<int>
#define vll vector<lli>
#define vpi vector<pair<int,int> > 
#define vpll vector<pair<lli,lli> > 
#define vvi vector<vector<int> >
#define vvll vector<vector<lli> >
#define vvpi vector<vector<pair<int,int> > >
#define vvpll vector<vector<pair<lli,lli> > >
#define inf 1000000000
#define maxn 100005
lli mod=1e9+7;

int main(){
    fastio;
    int n;
    cin>>n;
    vll a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    if(n==1){
        cout<<a[0]<<"\n";
        return 0;
    }
    if(n==2){
        lli tot = (2*a[0])%mod;
        cout<<tot<<"\n";
        return 0;
    }
    lli dp[n][2];
    dp[0][1]=dp[0][0]=1;
    for(int i=1;i<n;i++){
        dp[i][0]=(dp[i-1][0]+dp[i-1][1])%mod;
        dp[i][1]=dp[i-1][0];
        //cout<<dp[i][0]<<" "<<dp[i][1]<<"\n";
    }
    lli ans=0;
    for(int i=0;i<n;i++){
        int nl = i;
        int nr = n-1-i;
        if(i==0){
            ans+= ( a[i]*(dp[nr-1][0]+dp[nr-1][1]) )%mod;
            ans%=mod;
            continue;
        }
        nl--;
        if(nl and nr){
            ans+=(a[i]*( ((dp[nl-1][0]+dp[nl-1][1])*(dp[nr-1][0]+dp[nr-1][1]))%mod ) )%mod;
            ans%=mod;
            ans-=( a[i]*((dp[nl-1][0]*dp[nr-1][0])%mod) )%mod;
            ans=(ans+mod)%mod;
        }
        else{
            int cr = max(nl,nr);
            ans+=(a[i]*(dp[cr-1][0]+dp[cr-1][1]))%mod;
            ans%=mod;
            ans-= ( a[i]*dp[cr-1][0] )%mod;
            ans=(ans+mod)%mod;
        }
    }
    cout<<ans<<"\n";
	return 0;
}