#include<algorithm>
#include<cstdio>
typedef long long ll;
const int maxn=1e5+5;
const int mod=1e9+7;
int n;
int val[maxn];
ll sum[maxn][2];
ll cn[maxn][2];
signed main(){
	scanf("%d",&n);
	if(n==1){
		int x;
		scanf("%d",&x);
		printf("%d",x);
		return 0;
	}
	for(int i=1;i<=n;i++)scanf("%d",val+i);
	sum[2][0]=1ll*(val[1]+val[2])%mod;
	sum[2][1]=1ll*(val[1]-val[2]+mod)%mod;
	cn[2][0]=cn[2][1]=1;
	for(int i=3;i<=n;i++){
		cn[i][0]=(cn[i-1][0]+cn[i-1][1])%mod;
		cn[i][1]=(cn[i-1][0])%mod;
		sum[i][0]=(sum[i-1][0]+sum[i-1][1]+1ll*cn[i][0]*val[i])%mod;
		sum[i][1]=((sum[i-1][0]-1ll*cn[i][1]*val[i]+mod)%mod+mod)%mod;
//		printf("cn[%d][0]=%lld,[1]=%lld\n",i,cn[i][0],cn[i][1]);
	}
//	for(int i=2;i<=n;i++)printf("sum[%d][0]=%lld,sum[%d][1]=%lld\n",i,sum[i][0],i,sum[i][1]);
	printf("%lld",(sum[n][0]+sum[n][1])%mod);
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr int INF = (int)1e9;
constexpr long long LINF = (long long)1e18;
constexpr long long MOD = 1e9 + 7;
//constexpr long long MOD = 998244353;
constexpr double pi = 3.141592653589793238;
 
int main() {
    int n;
    cin >> n;
 
    vector<ll> a(n);
    vector<vector<ll>> dp(n, vector<ll>(3));
    for (int i = 0; i < n; ++i) {
        if (i == 0) {
            dp.at(0).at(0) = 1;
            dp.at(0).at(1) = 0;
            dp.at(0).at(2) = 1;
        }
        else {
            dp.at(i).at(0) = (dp.at(i - 1).at(0) + dp.at(i - 1).at(1)) % MOD;
            dp.at(i).at(1) = dp.at(i - 1).at(0);
            dp.at(i).at(2) = (dp.at(i).at(0) + dp.at(i).at(1)) % MOD;
        }
 
        ll ai;
        cin >> ai;
        a.at(i) = ai;
    }
 
    ll ans = 0;
    ans += (dp.at(n - 1).at(2) * a.at(0)) % MOD;
    if (n <= 2) {
        cout << ans << endl;
        return 0;
    }
    ans = (ans + dp.at(n - 2).at(2) * a.at(1)) % MOD;
    ans = ans - dp.at(n - 3).at(2) * a.at(1);
    if (ans < 0) ans += MOD;
 
    ans += dp.at(n - 2).at(2) * a.at(n - 1) % MOD;
    ans %= MOD;
    ans -= dp.at(n - 3).at(2) * a.at(n - 1) % MOD;
    if (ans < 0) ans += MOD;
    
    for (int i = 2; i < n - 1; ++i) {
        ans += dp.at(i - 1).at(2) * dp.at(n - 1 - i).at(2) % MOD * a.at(i) % MOD;
        ans %= MOD;
        ans -= dp.at(i - 2).at(2) * dp.at(n - 2 - i).at(2) % MOD * a.at(i) % MOD;
        if (ans < 0) ans += MOD;
    }
 
    cout << ans << endl;
 
    return 0;
}