#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::istream;
using std::ostream;
using std::vector;
using ll = long long;
using ull = unsigned long long;

// Mod int
const int mod = 1000000007;
struct mint {
  uint x;
  mint(): x(0) {}
  mint(ll x):x((x%mod+mod)%mod) {}
  mint operator-() const { return mint(0) - *this;}
  mint operator~() const { return mint(1) / *this;}
  mint& operator+=(const mint& a) { if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a) { if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a) { x=(ull)x*a.x%mod; return *this;}
  mint& operator/=(const mint& a) { x=(ull)x*a.pow(mod-2).x%mod; return *this;}
  mint operator+(const mint& a) const { return mint(*this) += a;}
  mint operator-(const mint& a) const { return mint(*this) -= a;}
  mint operator*(const mint& a) const { return mint(*this) *= a;}
  mint operator/(const mint& a) const { return mint(*this) /= a;}
  mint pow(ll t) const {
    if(!t) return 1;
    mint res = pow(t/2);
    res *= res;
    return (t&1)?res*x:res;
  }
  bool operator<(const mint& a) const { return x < a.x;}
  bool operator==(const mint& a) const { return x == a.x;}
  bool operator!=(const mint& a) const { return x != a.x;}
};
mint ex(mint x, ll t) { return x.pow(t);}
istream& operator>>(istream&i,mint&a) {i>>a.x;return i;}
//*
ostream& operator<<(ostream&o,const mint&a) {o<<a.x;return o;}

int main() {
	int n;
	cin >> n;
	
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	
	vector<mint> fib(n + 2);
	fib[0] = fib[1] = 1;
	for (int i = 2; i <= n + 1; ++i) 
	    fib[i] = fib[i - 1] + fib[i - 2];
	
	mint ans = fib[n] * a[0];
	for (int i = 1; i < n; ++i) {
		mint coeff = fib[i] * fib[n - i] - fib[i - 1] * fib[n - i - 1];
		ans += coeff * a[i];
	}
	
	cout << ans << '\n';
	
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define sfd(x) scanf("%d",&x)
#define sfd2(x,y) scanf("%d%d",&x,&y)
#define sfd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define sfs(x) scanf("%s",x)
#define sfll(x) scanf("%lld",&x)
#define sfll2(x,y) scanf("%lld%lld",&x,&y)
#define pfd(x) printf("%d",x)
#define pfs(x) printf("%s",x)
#define pfll(x) printf("%lld",x)
#define nl printf("\n")
#define sp printf(" ")
#define pfyes printf("YES")
#define pfno printf("NO")
#define pf0 printf("0")
#define FOR(i,a,b,in) for(int i=a;i<=b;i+=in)
#define RFOR(i,a,b,de) for(int i=a;i>=b;i-=de)
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define mkp make_pair
#define mod 1000000007
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
// ------------------------//
int main()
{
	int n;
	sfd(n);
	ll a[n];
	rep(i,n)
	sfll(a[i]);
	if(n==1)
	{
		pfll(a[0]);
		return 0;
	}
	ll dp[n][2];
	rep(i,n)
	{
		rep(j,2)
		dp[i][j]=0;
	}
	dp[1][0]=(a[0]+a[1])%mod;
	dp[1][1]=(a[0]-a[1])%mod;
	if(dp[1][1]<0)
	dp[1][1]+=mod;
	ll cp[n];
	ll cn[n];
	rep(i,n)
    {
      cp[i]=0;
      cn[i]=0;
    }
	cp[1]=1;
	cn[1]=1;
	for(int i=2;i<n;i++)
	{
		dp[i][0]=(dp[i-1][0]+dp[i-1][1]+(((a[i]*((cp[i-1]+cn[i-1])%mod))%mod)))%mod;
		dp[i][1]=(dp[i-1][0]-((a[i]*(cp[i-1])%mod)))%mod;
    	cp[i]=(cp[i-1]+cn[i-1])%mod;
    	cn[i]=cp[i-1];
		if(dp[i][0]<0)
		dp[i][0]+=mod;
		if(dp[i][1]<0)
		dp[i][1]+=mod;
	}
	pfll((dp[n-1][0]+dp[n-1][1])%mod);
	return 0;
}