#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll a[100005],f[100005][2],g[100005][2],p;
int main(){
	scanf("%d",&n);
	p=1e9+7;
	for (int i=1;i<=n;i++) scanf("%lld",&a[i]);
	g[0][1]=1;
	for (int i=1;i<n;i++){
		g[i][0]=g[i-1][1]%p;
		g[i][1]=(g[i-1][1]+g[i-1][0])%p;
		f[i][0]=(f[i-1][1]+(a[i]*g[i-1][1])%p)%p;
		f[i][1]=(f[i-1][1]+(a[i]*g[i-1][1])%p)%p;
		f[i][1]=(f[i][1]+f[i-1][0]-((a[i]*g[i-1][0])%p)+p)%p;
	}
	printf("%lld",((f[n-1][1]+g[n-1][1]*a[n])%p+(f[n-1][0]-((g[n-1][0]*a[n])%p)+p)%p)%p);
} 
#include <bits/stdc++.h>

#define fi first
#define se second
#define DB double
#define U unsigned
#define P std::pair
#define LL long long
#define LD long double
#define pb emplace_back
#define MP std::make_pair
#define SZ(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 1e5 + 5;
const int ha = 1e9 + 7;
int f[MAXN],n;

inline void add(int &x,int y){
	x += y-ha;x += x>>31&ha;
}

int main(){
	f[0] = 1;f[1] = 2;FOR(i,2,MAXN-1) f[i] = (f[i-1]+f[i-2])%ha;
	int ans = 0;scanf("%d",&n);
	FOR(i,1,n){
		int x;scanf("%d",&x);
		if(i == 1) add(ans,1ll*x*f[n-1]%ha);
		else{
			add(ans,1ll*x*f[i-2]%ha*f[n-i]%ha);
			add(ans,ha-1ll*x*f[std::max(0,i-3)]%ha*f[std::max(0,n-i-1)]%ha);
		}
	}
	printf("%d\n",ans);
	return 0;
}
// f[i] = f[i-1]+f[i-2]
