#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=1e5+5;
ll f[maxn][2],g[maxn];
int main()
{

    ll ans=0,x;
    int n;
    scanf("%d",&n);
    ll tot=2*n-3+(n-3)*(n-4)/2;
    tot%=mod;
    // 0 -  1 +
    f[0][1]=1; g[0]=1;
    for(int i=1;i<=n;i++)
    {
        f[i][0]=f[i-1][1];
        f[i][1]=(f[i-1][0]+f[i-1][1])%mod;
        g[i]=(f[i][0]+f[i][1])%mod;
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&x);
        x%=mod;
        ll plus=0,multi=0;
        plus=g[n-i];
        if(i>=2) plus=g[i-2]*plus%mod;
        if(i!=1) multi=1;
        if(i>=3) multi=g[i-3];
        if(i!=n) multi=g[n-i-1]*multi%mod;
        ans=(ans+1LL*x*(plus-multi+mod)%mod)%mod;
    }
    printf("%lld",(ans+mod)%mod);
    return 0;
}
#pragma GCC optimize("Ofast")
 #include <bits/stdc++.h>
#define ll         long long int
#define umap       unordered_map
#define mod        1000000007ll
#define pb         push_back
#define all(x)     (x).begin(), (x).end()
#define rall(x)    (x).rbegin(), (x).rend()
#define MN(a,b,c)  min(a,min(b,c))
#define MX(a,b,c)  max(a,max(b,c))
#define pr1         pair<ll,ll>
#define F          first
#define S          second
#define mP         make_pair
#define f(i,n)     for(ll i=0;i<n;i++)
#define f1(i,x,y)  for(ll i=x;i<=y;i++)
#define f2(i,x,y)  for(ll i=x;i>=y;i--)
#define yes        cout<<"YES"<<"\n"
#define no         cout<<"NO"<<"\n"
#define modsum(a,b)  ((a%mod)+(b%mod))%mod
#define modpro(a,b)  ((a%mod)*(b%mod))%mod
#define moddif(a,b)  ((a%mod)-(b%mod)+mod)%mod
#define modsumt(a,b,c) modsum(a,modsum(b,c))
//__builtin_popcount(x)
//__builtin_parity(x)   =(number of set bits)%2
//__builtin_clz(x)      to count the number of leading  zeroes 
//__builtin_ctz(x)      to count the number of trailing zeroes 
//__gcd(a,b)
// Binary Search 
// TO AVOID GETTING INFINITE LOOP
// mid = (l+r)/2      l=mid+1   r=mid
// mid = (l+r+1)/2    l=mid     r=mid-1
using namespace std;
ll fac[200005];
/*void calc_pow2()
{
    pow2[0]=1;
    for(ll i=1;i<63;i++) pow2[i]=2*pow2[i-1];
}*/
ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=modpro(result,x);
        x=modpro(x,x);
        n=n/2;
    }
    return result;
}
ll binaryExponentiation(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=result * x;
        x=x*x;
        n=n/2;
    }
    return result;
}
ll pow1(ll x,ll y)
{
    ll z=1;
    while(y--){z=z*x;}
    return z;
}
/*bool isprime(ll n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
 
    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;
 
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
 
    return true;
}*/
// Returns n^(-1) mod p 
ll  modInverse(ll n, ll p) 
{ 
    return modularExponentiation(n, p - 2, p); 
} 
// Returns nCr % p using Fermat's little 
// theorem. 
unsigned long long nCrModPFermat(unsigned long long n, 
                                 ll r, ll p) 
{ 
    // Base case 
    if (r == 0) 
        return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
}
ll check(ll x,ll y)
{
    ll z=1;
    ll ans=0;
    while(z<x){ans++;z*=y;}
    return ans;
}

ll countbits(ll n)
{
    ll x=0;
    while(n>0)
    {
        x++;
        n=(n&(n-1));
    }
    return x;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;cin>>n;
    vector <ll> a(n);
    f(i,n) cin>>a[i];
    if(n==1) cout<<a[0];
    else
    {
    ll dp[n][2];
    ll countp[n];
    ll countn[n];
    countp[1]=countn[1]=1;
    dp[1][0]=a[1];
    dp[1][1]=-1*a[1];
    ll sum=0;
    for(ll i=2;i<n;i++)
    {
        countp[i]=modsum(countp[i-1],countn[i-1]);
        countn[i]=countp[i-1];
        dp[i][0]=modsum(sum,modpro(countp[i],a[i]));
        dp[i][1]=moddif(dp[i-1][0],modpro(countn[i],a[i]));
        sum=modsum(dp[i][0],dp[i][1]);
        //cout<<dp[i][0]<<' '<<dp[i][1]<<' '<<sum<<"\n";
    }
    ll num=modsum(countp[n-1],countn[n-1]);
    num=modpro(num,a[0]);
    sum=modsum(sum,num);
    cout<<sum;
    }
}