#include <bits/stdc++.h>

#define foreach(i,v) for(auto&& i: v)
#define all(x) (x).begin(), (x).end()

typedef std::vector< std::string > VS;
typedef std::vector<int> VI;
typedef long long ll;
typedef std::pair<int, int> ii;

template <class C> C& mini(C& a, C b) { if (b < a) a = b; return a; }
template <class C> C& maxi(C& a, C b) { if (a < b) a = b; return a; }

template <typename T> void read(std::vector<T>& A) { for (T& x: A) std::cin >> x; }
template <typename T> void readv(std::vector<T>& A) { int N; std::cin >> N; A.resize(N); read(A); }

using namespace std;

#define MOD 1000000007

template <typename T>
void imfix(T& r) {
    if (r >= MOD)
        r -= MOD;
}

template <typename T>
T mfix(T r) {
    return r >= MOD ? r - MOD : r;
}

int main(int argc, const char* argv[]) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.precision(20); cout.setf(ios::fixed);
    VI A;
    readv(A);
    int N = A.size();
    vector<ll> B(N+1), C(N+1);
    B[N] = 0;
    B[N-1] = A.back();
    C[N] = 1;
    C[N-1] = 1;
    for (int i = N-2; i >= 0; i--) {
        B[i] = (A[i] * C[i+1] + B[i+1]) % MOD + ((MOD + A[i] - A[i+1]) * C[i+2] + B[i+2]) % MOD;
        imfix(B[i]);
        imfix(C[i] = C[i+1] + C[i+2]);
    }
    cout << B[0] << endl;
    return 0;
}

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <string> vs;
typedef vector <vector <int>> vvi;
typedef vector <vll> vvll;
typedef map<int, int> mi;
typedef map<string, int> ms;
typedef map<char, int> mc;
typedef map <int, bool> mb;
typedef map<ll, ll> mll;
typedef unordered_map<int, int> umi;
typedef unordered_map<string, int> ums;
typedef unordered_map<char, int> umc;
typedef unordered_map <int, bool> umb;
typedef unordered_map<ll, ll> umll;
typedef vector <ld> vld;
typedef vector <bool> vb;
typedef pair <int, int> pii;
typedef pair<ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
#define FOR(i,N) for(ll i = 0 ; i < N;i++)
#define eFOR(i,a,b) for(ll i = a; i <=b;i++)
#define dFOR(i,N) for(ll i = N - 1; i>=0;i--)
#define edFOR(i,b,a) for(ll i = b ; i >=a;i--)
#define all(x) x.begin(),x.end()
#define SORT(x) sort(all(x))
#define RSORT(x) sort(x.rbegin(),x.rend())
#define UNQ(x)  unique(all(x))
#define mine(x) min_element(all(x))
#define maxe(x) max_element(all(x))
#define lb(v, x) lower_bound(all(v) , x)
#define ub(v , x) upper_bound(all(v) , x)
#define pb push_back
#define PI 3.141592653589793
#define FIX cout << fixed << setprecision(15)
#define g(i , a) get<i>(a)
const ll mod = 1e9 + 7;
int CASE = 1;
const int mxn = 1e5 + 1;
const ll INF = 1e18;
bool prime(int n)
{
	if (n <= 1)
		return false;
	if (n == 2 or n == 3)
		return true;
	if (n % 2 == 0 or n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6)
		if (n % i == 0 || n % (i + 2) == 0)
			return false;
	return true;
}
ll __gcd(ll a, ll b)
{
	return !b ? a : __gcd(b, a % b);
}
ll a[mxn], dp[mxn][2], way[mxn][2];
void solve()
{
	int n;
	cin >> n;
	eFOR(i, 1, n)
		cin >> a[i];
	dp[1][0] = a[1];
	way[1][0] = 1;
	eFOR(i, 2, n)
	{
		dp[i][0] = (dp[i - 1][0] + dp[i - 1][1] + a[i] * (way[i - 1][0] + way[i - 1][1])) % mod;
		dp[i][1] = (dp[i - 1][0] + mod - a[i] * way[i - 1][0] % mod) % mod;
		way[i][0] = (way[i - 1][0] + way[i - 1][1]) % mod;
		way[i][1] = way[i - 1][0];
	}
	cout << (dp[n][0] + dp[n][1] + mod) % mod;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
	while (T--)
	{
		solve();
	}
	return 0;
}
