#include <bits/stdc++.h>
using namespace std;
// vtqi6hy80o@email.edu.pl
#define rep(i, a, b) for(lli i = a; i < b; i++)
#define lli long long int
#define ld long double
#define all(v) v.begin(), v.end()
#define hell 1000000000000000
#define pb push_back
#define pf push_front
#define vi vector<lli>
#define vip vector<pair<lli, lli>>
#define F first
#define S second
#define pi 2*acos(0.0)
#define sz(s) s.size()
#define atmod (1000000000+7)
#define mod 998244353
// auto _C=clock();
// lli n = 10000000;
// int dx[]={1,-1,0,0};
// int dy[]={0,0,1,-1};
/*vector<bool> p(n + 1, true);
void sieve()
{
    for (long long int i = 2; i * i <= n; i++)
    {
        if (p[i])
        {
            for (long long int j = i + i; j <= n; j = j + i)
            {
                p[j] = false;
            }
        }
    }
}
*/
/*
WINNERS NEVER QUIT AND QUITTERS NEVER WIN!!
Falling down is an accident, Staying down is a choice.
*/
/*lli binpow(lli a, lli n,lli m)
{
    lli r = 1;
    a %=m ;
    while (n > 0)
    {
        if (n & 1)
        {
            r = (r * a)%m ;
        }
        a = (a * a)%m ;
        n = n / 2;
    }
    return r;
}*/
/*bool cmp(pair<lli,lli> a,pair<lli,lli> b)
{
    if(a.F<b.F) return 1;
    else if(a.F==b.F) return(a.S>b.S);
    else return 0;
}*/
/*lli ncr(lli n,lli r)
{
    lli res = 1;
    rep(i,1,r+1)
    {
        res = (res%atmod*(n-r+i)%atmod)%atmod;
        res = (res%atmod * binpow(i,atmod-2,atmod)%atmod)%atmod;
    }
    return res;
}*/
void solve() 
{
    lli n;
    cin>>n;
    lli a[n];
    rep(i,0,n)cin>>a[i];
    if(n==1)
    {
        cout<<a[0];
        return;
    }
    lli dp[n][2];
    lli f[n][2];
    f[1][1]=f[1][0]=1;
    rep(i,2,n)
    {
        f[i][1] = f[i-1][0];
        f[i][0] = (f[i-1][1]%atmod+f[i-1][0]%atmod)%atmod;
    }
    dp[1][0] = (a[1]+a[0])%atmod;
    dp[1][1] = (a[0]-a[1])%atmod;
    rep(i,2,n)
    {
        dp[i][0] = (dp[i-1][1]%atmod+dp[i-1][0]%atmod + ((f[i-1][1]+f[i-1][0])%atmod)*a[i])%atmod;
        dp[i][1] = (dp[i-1][0]%atmod - (f[i-1][0])%atmod*a[i]%atmod+(lli)atmod*atmod)%atmod;
    }
    cout<<(dp[n-1][1]%atmod+dp[n-1][0]%atmod)%atmod;
    // cout<<endl;
    // rep(i,1,n)
    // {
    //     rep(j,0,2)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
}   
int main()  
{ 
    // ios_base::sync_with_stdio(false);
    // cin.tie(0);
    // cout.tie(0); 
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout); 
    // sieve();
    lli t = 1;  
    // cin >> t;
    rep(i,1,t+1)
    {   
        solve();
    }
    // cerr<<"\n\n\nTime elapsed: ";
    // cout<<"\n"<<(double)(clock()-_C)*1000.0/CLOCKS_PER_SEC<<"ms\n";      
}
#include <bits/stdc++.h>
using namespace std;
const int maxn=112345;
const long long mod=1000000007;
int n;
long long res,dp[maxn];
inline long long go(int x) {
    if (x<=0) return 1;
    return dp[x];
}
int main()
{
    dp[0]=1;
    dp[1]=2;
    for (int i=2;i<maxn;++i)
        dp[i]=(dp[i-1]+dp[i-2])%mod;
    scanf("%d",&n);
    for (int i=1;i<=n;++i) {
        int x;scanf("%d",&x);
        if (i==1) res+=go(n-1)*x%mod;
        else res+=(go(i-2)*go(n-i)%mod-go(i-3)*go(n-i-1)%mod)*x%mod;
        res=(res+mod)%mod;
    }
    cout<<res<<endl;
    return 0;
}
