#include "bits/stdc++.h"
using namespace std;

#define ll long long int 
#define pb(a) push_back(a)
#define vll vector<ll>
#define loop(i, n) for(ll i=1;i<=n;i++)
#define loop0(i, n) for(ll i=0;i<n;i++)
#define in(i) scanf("%lld", &i);
#define out(i) printf("%lld", i)
#define pll pair<ll, ll>
#define vpll vector<pair<ll, ll>>
#define mp(i, j) make_pair(i, j)
#define google cout<<"Case #"<<tc-t<<": ";
const ll mod = 1000000007;
const ll big = 2999999999999999999;
const ll small = -2999999999999999999;
void in2(ll& a, ll& b) { in(a); in(b); }
void in3(ll& a, ll& b, ll& c) { in(a); in(b); in(c); }
void swap(ll& a, ll& b) { a = a+b; b = a-b; a = a-b; }
void arrayIn(vll& a, ll& n) { loop0(i, n) in(a[i]); }

ll n;
vll a;
vector<vpll> dp;

pll solve(ll i, bool pm)
{
  if(i == n)
    return {0, 1};
  if(dp[i][pm].second != -1)
    return dp[i][pm];
  if(pm)
  {
    pll b = solve(i+1, false);
    return dp[i][pm] = {(b.first + (b.second*a[i])%mod)%mod, b.second};
  }
  else
  {
    pll b = solve(i+1, false);
    pll c = solve(i+1, true);
    return dp[i][pm] = {((b.first+c.first)%mod+(((b.second-c.second+mod)%mod)*(a[i]%mod))%mod)%mod, (b.second+c.second)%mod};
  }
}

void solve()
{
  in(n);
  a.resize(n);
  dp.resize(n+1, vpll(2, {-1, -1}));
  loop0(i, n)
    in(a[i]);
  cout<<solve(0, true).first;
}

int main()
{
  solve();
}

#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;
}
