#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <cmath>
#include <iomanip>
#include <iterator>
#include <bitset>
#include <unordered_map>
#include <complex>
#include <unordered_set>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

using namespace std;

clock_t timeStart, timeFinish;

void timeBegin() {
    timeStart = clock();
}

void timeEnd() {
    timeFinish = clock();
}

void timeDuration() {
    timeEnd();
    double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC);
    cout << "Time taken by program is : " << fixed << time_taken << setprecision(5);
    cout << " sec " << endl;
}

class InputReader {
public:
    InputReader() {
        input_file = stdin;
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }

    InputReader(const char *file_name) {
        input_file = fopen(file_name, "r");
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }

    inline InputReader &operator>>(int &n) {
        while ((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
            advance();
        }
        int sign = 1;
        if (buffer[cursor] == '-') {
            sign = -1;
            advance();
        }
        n = 0;
        while ('0' <= buffer[cursor] && buffer[cursor] <= '9') {
            n = n * 10 + buffer[cursor] - '0';
            advance();
        }
        n *= sign;
        return *this;
    }

private:
    FILE *input_file;
    static const int SIZE = 1 << 17;
    int cursor;
    char buffer[SIZE];

    inline void advance() {
        ++cursor;
        if (cursor == SIZE) {
            cursor = 0;
            fread(buffer, SIZE, 1, input_file);
        }
    }
};

const int MOD = 1000000007;
const int MAXN = 100000;

int dp[1 + MAXN][2], sum[1 + MAXN][2], v[1 + MAXN];

int main() {
    timeBegin();
    //ifstream cin("input.in");
    //ofstream cout("output.out");
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    srand(time(0));
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
    }
    dp[1][0] = 1;
    dp[1][1] = 0;
    sum[1][0] = v[1];
    sum[1][1] = 0;
    for (int i = 2; i <= n; i++) {
        dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % MOD;
        dp[i][1] = dp[i - 1][0];
        sum[i][0] = (1LL * v[i] * (dp[i - 1][0] + dp[i - 1][1]) + sum[i - 1][0] + sum[i - 1][1]) % MOD;
        sum[i][1] = (1LL * (MOD - v[i]) * dp[i - 1][0] + sum[i - 1][0]) % MOD;
    }
    cout << (sum[n][0] + sum[n][1]) % MOD << "\n";
    return 0;
}







#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define maxn 100005
using namespace std;

int n,ans,ans1;
int a[maxn],dp[maxn],dp1[maxn],dp2[maxn],dp3[maxn];
//int ni[maxn];

//ni[i]=ni[mod%i]*(mod-mod/i)%mod;

int mi(int a,int t){
	ans1=1;
	while(t){
		if(t%2==1) {ans1*=a;ans1%=mod;}
		a*=a;
		a%=mod;
		t/=2;
	}
	return ans1;
}

signed main()
{
//	freopen("yhc","r",stdin);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	dp[0]=1;
	for(int i=1;i<=n-1;i++) {
		dp1[i]=dp[i-1]%mod;
		dp[i]=(dp1[i-1]%mod+dp[i-1]%mod)%mod;
	}
	dp2[n-1]=dp[n-1];dp3[n-1]=dp1[n-1];
	for(int i=n-2;i>=1;i--) {
		dp2[i]=(dp3[i+1]%mod+dp2[i+1]%mod*mi(dp[i]+dp1[i],mod-2)%mod*dp[i]%mod)%mod;
		dp3[i]=((dp[n-1]-dp2[i])%mod+dp1[n-1]%mod)%mod;
	}
	for(int i=1;i<=n-1;i++) {
		if(dp2[i]<dp3[i]) dp2[i]+=mod;
		ans+=(dp2[i]-dp3[i])%mod*a[i+1];
		ans%=mod;
	}
	ans+=(dp[n-1]%mod+dp1[n-1]%mod)%mod*a[1];
	ans%=mod;
//	for(int i=1;i<=n-1;i++) cout<<dp[i]<<" "<<dp1[i]<<" "<<dp[i]+dp1[i]<<endl;
//	cout<<endl;
//	for(int i=1;i<=n-1;i++) cout<<dp2[i]<<" "<<dp3[i]<<" "<<dp2[i]*1.0/(dp3[i]+dp2[i])<<endl;
	cout<<ans<<endl;
	return 0;
}