#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll MOD = 1000000007;
//cout << std::fixed << std::setprecision(15) << res << endl;
//int di[] = {-1,0,1,0};
//int dj[] = {0,-1,0,1};
//printf("%.10f %.10f\n), ans.real(), ans.imag());

int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<ll> A(N);
  rep (i, N) cin >> A[i];


  if (N == 1) {
    cout << A[0] << endl;
    return 0;
  } else if (N == 2) {
    cout << 2 * A[0] % MOD << endl;
    return 0;
  }


  vector<ll> X(N+1);
  X[0] = 1;
  X[1] = 1;
  ll psum = 0;
  vector<ll> pow2(N,0);
  pow2[0] = 1;
  for (ll k = 1; k < N; k++) {
    pow2[k] = (2 * pow2[k-1]) % MOD;
    if (k - 2 >= 0) {
      psum *= 2;
      psum %= MOD;
      psum += X[k-2];
      psum %= MOD;
    }
    X[k+1] = pow2[k] - psum;
    if (X[k+1] < 0 ) X[k+1] += MOD;
  }

  ll res = 0;
  res += (A[0] * X[N]);
  res %= MOD;
  
  res += A[1] * ((X[N] - X[N-2]) - X[N-2]);
  //if (res < 0) res += MOD;
  res %= MOD;

  for (ll k = 2; k < N - 1; k++) {
    ll tmp = (X[N-k-1] * X[k-1]) % MOD;
    res += A[k] * (X[N] - tmp - tmp);
    //if (res < 0) res += MOD;
    res %= MOD;
  }

  res += A[N-1] * ((X[N] - X[N-2]) - X[N-2]);
  res %= MOD;
  if (res < 0) res += MOD;

  
  cout << res << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007

const ll mod = 1e9 + 7;

ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	vl v(n);
	for (auto &i : v)
		cin >> i;
	vector <vl> dp(n, vl (2, 0));
	dp[0][0] = 1;
	dp[0][1] = 1;
	for (ll i = 1; i < n; i++) {
		dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % mod;
		dp[i][1] = dp[i - 1][0];
	}
	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		ll l, r;
		l = i;
		r = n - i - 1;
		if (l == 0)
			l = 1;
		else if (l == 1)
			l = 1;
		else
			l = (dp[l - 2][0] + dp[l - 2][1]) % mod;
		if (r == 0)
			r = 1;
		else
			r = (dp[r - 1][0] + dp[r - 1][1]) % mod;
		ans = (ans + ((l * r) % mod * v[i]) % mod) % mod;
		if (i == 0)
			continue;
		l = i;
		r = n - i - 1;
		if (l == 1)
			l = 1;
		else
			l = (dp[l - 2][0]) % mod;
		if (r == 0)
			r = 1;
		else
			r = (dp[r - 1][0]) % mod;
		ans = (ans - ((l * r) % mod * v[i]) % mod + mod) % mod;
		//cout << ans << "\n";
	}
	cout << ans;
}
