#include<bits/stdc++.h>
using namespace std;
int main() {
  long n,ans,k;
  cin>>n;
  ans=0;
  vector<long> vec(n);
  vector<long> fibo(n+2);
  for(long i=0; i<n; i++){
    cin>>vec.at(i);
    vec.at(i)=vec.at(i)%1000000007;
  }
  fibo.at(0)=0;
  fibo.at(1)=1;
  for(long i=2; i<n+2; i++){
    fibo.at(i)=fibo.at(i-1)+fibo.at(i-2);
    fibo.at(i)=fibo.at(i)%1000000007;
  }
  ans=fibo.at(n+1)*vec.at(0);
  for(int i=1; i<n; i++){
    k=(fibo.at(i-1)*fibo.at(n-i+1)+fibo.at(i)*fibo.at(n-i-1))%1000000007;
    ans=ans+vec.at(i)*k;
    ans=ans%1000000007;
  }
  cout<<ans;
}
#include <cstdio>

typedef long long LL;
const int Mod = 1000000007;
int N;

int main() {
	int A = 0, B = 0, C = 0, D = 0;
	scanf("%d%d", &N, &A);
	C = 1;
	for (int i = 2; i <= N; ++i) {
		int x;
		scanf("%d", &x);
		int nA = (int)(((LL)(C + D) * x + A + B) % Mod);
		int nB = (int)(((LL)(Mod - C) * x + A) % Mod);
		int nC = (C + D) % Mod;
		int nD = C;
		A = nA, B = nB, C = nC, D = nD;
	}
	printf("%d\n", (A + B) % Mod);
	return 0;
}