#include<bits/stdc++.h>
#define int long long
using namespace std;
int const MOD=1000000007ll;
int n,a[233333],fp,fs,gp,gs;
signed main(){
	ios::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	fs=a[1];gs=1;
	for(int i=2;i<=n;i++){
		int pgs=gs,pgp=gp,pfp=fp,pfs=fs;
		gs=(pgs+pgp)%MOD;
		gp=pgs;
		fs=(pfs+pfp+gs*a[i]%MOD)%MOD;
		fp=(pfs-gp*a[i]%MOD+MOD)%MOD; 
	}
	cout<<(fp+fs)%MOD<<endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,x,n) for(int i = x;i <= n;++i)
#define forr(i,x,n) for(int i = n;i >= x;--i)
#define Angel_Dust ios::sync_with_stdio(0);cin.tie(0)

const int N = 1e5+7,MOD = 1e9+7;
int a[N],f[N][2],c[N][2];

int main()
{
    int n;scanf("%d",&n);
    forn(i,1,n) scanf("%d",&a[i]);
    f[1][0] = a[1];
    c[2][0] = 1;c[2][1] = 1;
    forn(i,3,n) c[i][0] = (c[i - 1][0] + c[i - 1][1]) % MOD,c[i][1] = c[i - 1][0];
    forn(i,2,n)
    {
        f[i][0] = (1ll * f[i - 1][0] + f[i - 1][1] + 1ll * c[i][0] * a[i] % MOD) % MOD;
        f[i][1] = ((f[i - 1][0] - 1ll * c[i][1] * a[i] % MOD) % MOD + MOD) % MOD;
    }
    printf("%d\n",((f[n][0] + f[n][1]) % MOD + MOD) % MOD);
    return 0;
}   
