#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusive
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long;
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

long long LLINF = 1e18;
int INF = 1e9+1e6;
#define MAXN (100006)
ll n, A[MAXN], ans, mod=1e9+7, p2[MAXN], dp[MAXN][2];
ll mult(ll x,ll y) {
	x %= mod, y %= mod;
	return x * y % mod;
}
int main() {
	FAST
	cin>>n;
	FOR(i,1,n) cin>>A[i];
	if(n==1) {
		cout<<A[1]<<'\n';
		return 0;
	} else if(n==2) {
		cout<<A[1] * 2 % mod<<'\n';
		return 0;
	}
	p2[0] = 1;
	FOR(i,1,MAXN-1) p2[i]=p2[i-1]*2%mod;
	
	dp[0][0] = 1;
	FOR(i,1,n) {
		dp[i][0] = dp[i-1][0] + dp[i-1][1], dp[i][0] %= mod;
		dp[i][1] = dp[i-1][0];
		// dp[i][2] = dp[i-1][2] * 2 + dp[i-1][1], dp[i][0] %= mod;
	}
	FOR(i,1,n) {
		if(i == 1) {
			ans += (dp[n-1][0] + dp[n-1][1]) % mod * A[i] % mod, ans %= mod;
		} else {
			ans += mult(dp[n-i][0] + dp[n-i][1], dp[i-2][0] + dp[i-2][1]) % mod * A[i] % mod, ans %= mod;
			ans -= mult(dp[n-i][0], dp[i-2][0]) % mod * A[i] % mod, ans += mod, ans %= mod;
		}
	}
	cout<<ans<<'\n';
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef int64_t ll;
const ll maxOne = 1'000'000'007;
ll add(ll a, ll b){
    if(a<0){
        a += maxOne;
    }
    if(b<0){
        b += maxOne;
    }
    return (a+b)%maxOne;
}
ll mul(ll a, ll b){
    if(a<0){
        a += maxOne;
    }
    if(b<0){
        b += maxOne;
    }
    return (a*b)%maxOne;
}
ll sub(ll a, ll b){
    if(a<b){
        a += maxOne;
    }
    return (a-b)%maxOne;
}

int main() {
    ll n;
    cin >> n;
    vector<ll> vals(n);
    for(auto& val:vals){
        cin >> val;
    }
    if(n==1){
        cout << vals[0] << endl;
        return 0;
    }

    ll dpp = vals[0];
    ll dps = 0;
    ll cp = 1;
    ll cs = 0;
    for(ll i=1; i<n; i++){
        ll nextDpp = add(dpp, mul(vals[i], add(cp, cs)));
        nextDpp = add(nextDpp, dps);
        ll nextDps = sub(dpp, mul(vals[i], cp));
        ll nextCp = add(cp, cs);
        ll nextCs = cp;

        dpp = nextDpp;
        dps = nextDps;
        cp = nextCp;
        cs = nextCs;
    }
    cout << add(dpp, dps) << endl;

    return 0;
}
