#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
#include <cassert>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using namespace std;
//#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); }
void Yes() { cout << "Yes" << endl; exit(0); }
void No() { cout << "No" << endl; exit(0); }


//---------- 1000000007 ----------
const int MOD = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% MOD + MOD) % MOD) {}
	mint operator-() const { return mint(-x); }
	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 *= a.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 pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(MOD - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

mint m_comb(mint n, mint r)
{
	int i;
	mint p = 1;
	for (i = 1; i <= r.x; i++)
	{
		p *= n - i + 1;
		p /= i;
	}
	return p;
}
mint m_comb_with_rep(mint n, mint r)
{
	return m_comb(n + r - 1, r);
}
mint m_perm(mint n, mint r)
{
	mint a = 1;
	for (int i = n.x; i > n.x - r.x; i--)
	{
		a *= i;
	}
	return a;
}

struct St
{
	mint sum;
	mint cnt;
	St() {}
	St(mint sum, mint cnt) : sum(sum), cnt(cnt) {}
};

int N;
mint A[100010];

bool _flg[100010];
St _memo[100010];
mint _p[100010];

St func(int n)
{
	if (_flg[n])
	{
		return _memo[n];
	}

	if (n == 2)
	{
		return St(-A[N - 1] - A[N - 2], 1);
	}
	else if (n == 1)
	{
		return St(0, 0);
	}

	mint sum = 0;
	mint cnt = 0;

	//mint p = ((mint)2).pow(n - 2);
	cnt += _p[n - 2];
	sum -= (A[N - n] + A[N - n + 1]) * _p[n - 2];

	St st;
	st = func(n - 1);
	cnt += st.cnt;
	sum += st.sum + st.cnt * A[N - n];

	st = func(n - 2);
	cnt += st.cnt;
	sum += st.sum + st.cnt * (-A[N - n] + A[N - n + 1]);

	_flg[n] = true;
	_memo[n] = St(sum, cnt);
	return _memo[n];
}


signed main()
{
	cin >> N;
	REP(i, N) cin >> A[i];

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

	REP(i, 100001)
	{
		_p[i] = ((mint)2).pow(i);
	}

	mint ans = 0;
	ans = ((mint)2).pow(N - 1) * A[0];
	St f = func(N - 1);
	ans -= f.sum;
	ans -= f.cnt * A[0];
	cout << ans << endl;
}




#include <bits/stdc++.h>
#define pb(x) push_back(x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F(w,x,y) for(ll w=x; w<y; w++)
#define endl "\n"
#define mod 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

void play()
{
    ll n;
    cin>>n;
    vector <ll> v(n);
    F(i,0,n)
    cin>>v[i];
    ll dp[n][2]; // number of ways to arrange + and - so that the last operation is - (0) or + (1)

    dp[0][1]=1;
    dp[0][0]=0;

    F(i,1,n)
    {
        dp[i][0]=(dp[i-1][1])%mod;
        dp[i][1]=(dp[i-1][0]%mod+dp[i-1][1]%mod)%mod;
    }

    ll ans[n][2];

    ans[0][1]=v[0];
    ans[0][0]=0;

    F(i,1,n)
    {
        ans[i][0]=(ans[i-1][1]%mod-(dp[i][0]%mod*v[i]%mod)%mod+mod)%mod;
        ans[i][1]=((ans[i-1][1]%mod+ans[i-1][0]%mod)%mod+(dp[i][1]%mod*v[i]%mod)%mod)%mod;
    }

    cout<<(ans[n-1][0]%mod+ans[n-1][1]%mod)%mod<<endl;
}

int main()
{
    //freopen("milkvisits.in","r",stdin);
    //freopen("milkvisits.out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //pre();
    ll t;
    t=1;
    //cin>>t;
    F(i,1,t+1)
    {
        //cout<<"Case #"<<i<<": ";
        play();
    }
    return 0;
}
