#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using vtll = vector<tll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); }
void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); }
template<typename T,typename U>
ostream& operator<<(ostream& os, const pair<T,U>& p) { 
    cerr << ' ' <<  p.x << ',' << p.y; return os; }
template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) { 
    for(auto x: v) os << ' ' <<  x; return os; }
template <typename T> 
ostream& operator<<(ostream& os, const set<T>& v) { 
    for(auto x: v) os << ' ' <<  x; return os; }
template<typename T,typename U>
ostream& operator<<(ostream& os, const map<T,U>& v) { 
    for(auto x: v) os << ' ' <<  x; return os; }
struct d_ {
    template<typename T> d_& operator,(const T& x) {
        cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define deb(X ...) dbg(#X, "=", X);
#define EPS (1e-10)
#define INF (1LL<<61)
#define YES(x) cout << (x ? "YES" : "NO") << endl;
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

const ll MOD = 1e9+7;
ll mod(ll a, ll b=MOD) {
  return ((a%b)+b)%b;
}
ll extended_euclid(ll a,ll b,ll &x,ll &y) {
    if (a == 0) { x = 0; y = 1; return b;}
    ll x1, y1; ll d = extended_euclid(b%a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
ll mod_inverse(ll a, ll n=MOD) {
  ll x, y;
  ll d = extended_euclid(a, n, x, y);
  if (d > 1) return -1;
  return mod(x,n);
}
struct Mt {
    ll x = 0;
    Mt(){}
    Mt(ll y):x(mod(y)){}
    bool operator==(Mt &y){return x==y.x;}
    Mt operator+(Mt y){return mod(x+y.x);}
    Mt operator-(){return mod(-x);}
    Mt operator-(Mt y){return mod(x-y.x);}
    Mt operator*(Mt y){return mod(x*y.x);}
    Mt operator/(Mt y){return mod(x*mod_inverse(y.x));}
    Mt operator+=(Mt y){return x=(*this+y).x;}
    Mt operator-=(Mt y){return x=(*this-y).x;}
    Mt operator*=(Mt y){return x=(*this*y).x;}
    Mt operator/=(Mt y){return x=(*this/y).x;}
};
ostream& operator<<(ostream& os, const Mt&m){
    os << m.x; return os;
}

const ll N = 1e5+7;
ll a[N];
ll n;
ll CNT[N][2];
Mt cnt(ll x, bool lm) {
    ll &ret = CNT[x][lm];
    if(~ret) return ret;
    if(x==n) return 1;
    Mt r = cnt(x+1,0);
    if(x && !lm) r += cnt(x+1, 1);
    return ret=r.x;
}

ll DP[N][2];
Mt dp(ll x, bool lm) {
    ll &ret = DP[x][lm];
    if(~ret) return ret;
    if(x==n) return 0;
    Mt r = Mt(a[x])*cnt(x+1,0) + dp(x+1, 0);
    if(x && !lm) r += Mt(-a[x])*cnt(x+1,1) + dp(x+1, 1);
    return ret=r.x;
}

int main(void) {
    ios_base::sync_with_stdio(false);
    CL(DP,-1); CL(CNT,-1);
    cin >> n;
    F(n) cin >> a[i];
    cout << dp(0,0) << endl;
    return 0;
}

#include <bits/stdc++.h>
#define clog(x) std::clog << (#x) << " is " << (x) << '\n';
using LL = long long;

template<int N>
class MInt {
	static inline constexpr int M = N;
	int n;
	static int inv(int x) {
		// assert(std::gcd(x, M) == 1);
		return x == 1 ? x : 1LL * (M - M / x) * inv(M % x) % M;
	}
public:
	static void setMod(int m) {
		M = m;
	}
	static constexpr int mod() {
		return M;
	}
	// 请自行确保 0 <= x < M
	static MInt raw(int x) {
		MInt A;
		A.n = x;
		return A;
	}
	MInt(int x = 0) : n(x % M) {
		if (n < 0) n += M;
	}
	MInt(LL x) : n(x % M) {
		if (n < 0) n += M;
	}
	operator int() const {
		return n;
	}
	MInt operator-() const {
		return n == 0 ? *this : raw(M - n);
	}
	MInt& operator++() {
		if (++n == M) n = 0;
		return *this;
	}
	MInt& operator--() {
		if (--n == -1) n += M;
		return *this;
	}
	MInt& operator+=(const MInt &A) {
		n += A.n;
		if (n >= M) n -= M;
		return (*this);
	}
	MInt& operator-=(const MInt &A) {
		n -= A.n;
		if (n < 0) n += M;
		return (*this);
	}
	MInt& operator*=(const MInt &A) {
		n = 1LL * n * A.n % M;
		return (*this);
	}
	MInt& operator/=(const MInt &A) {
		return (*this) *= A.inv();
	}
	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 operator<<(int x) const {
		LL r = n;
		r <<= x;
		return MInt(r);
	}
	MInt& operator<<=(int x) {
		return (*this) = (*this) << x;
	}
	MInt& operator>>=(int x) {
		n >>= x;
		return (*this);
	}
	MInt operator>>(int x) const {
		return MInt(*this) >> x;
	}
	MInt operator&(int x) const {
		return MInt(*this) & x;
	}
	MInt& operator&=(int x) {
		n &= x;
		return (*this);
	}
	bool operator==(const MInt &A) const {
		return n == A.n;
	}
	MInt inv() const {
		return inv(n);
	}
	friend MInt pow(MInt A, int n) {
		MInt R(1);
		while (n) {
			if (n& 1) R *= A;
			n >>= 1;  A *= A;
		}
		return R;
	}
	friend std::istream &operator>>(std::istream &in, MInt &A) {
		LL x;
		in >> x;
		A = MInt(x);
		return in;
	}
	friend std::ostream &operator<<(std::ostream &out, const MInt &A) {
		out << A.n;
		return out;
	}
};

using mod = MInt<int(1e9 + 7)>;
// 根据情况换成 bool
void solve() {
	int n;
	std::cin >> n;
	std::vector<mod> a(n);
	for (auto &x : a) std::cin >> x;
	mod ans[2]{0, a[0]};
	mod cnt[2]{0, 1};
	for (int i = 1; i < n; ++i) {
		mod t = ans[1] - cnt[1] * a[i];
		ans[1] += ans[0] + (cnt[0] + cnt[1]) * a[i];
		ans[0] = t;
		cnt[0] += cnt[1];
		std::swap(cnt[0], cnt[1]);
	}
	std::cout << ans[0] + ans[1] << '\n';
}

int main() {
	//freopen("in", "r", stdin);
	std::cin.tie(nullptr)->sync_with_stdio(false);
	int cas = 1;
	// std::cin >> cas; // 根据情况注释掉
	while (cas--) {
		solve();
	}
	return 0;
}