#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double

int main() {
    ll mod = 1e9+7;
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    vector<vector<ll>> sum(N, vector<ll>(2, 0)), cnt(N, vector<ll>(2, 0));
    sum[0][0] = A[0];
    cnt[0][0] = 1;
    for (int i = 1; i < N; i++) {
        sum[i][0] = (sum[i-1][0]+sum[i-1][1]+A[i]*(cnt[i-1][0]+cnt[i-1][1]))%mod;
        sum[i][1] = (sum[i-1][0]+(mod-A[i])*cnt[i-1][0])%mod;
        cnt[i][0] = (cnt[i-1][0]+cnt[i-1][1])%mod;
        cnt[i][1] = cnt[i-1][0];
    }
    cout << (sum[N-1][0]+sum[N-1][1])%mod << endl;
    return 0;
}

#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <deque>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define PB push_back
#define MP make_pair
#define PF first
#define PS second
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
#define OUT(x) cout << x << endl;
#define OUTD(x) cout << fixed << x << endl;
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 1000000007;
const ll INF = 1e9;
const ld PI = 3.14159265369;
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};

unsigned GetDigit(unsigned num){
    return std::to_string(num).length();
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  IN(ll,n);
  AIN(ll,a,n);
  vvll dp(2,vector<ll>(n,0));
  dp[0][0]=1,dp[1][0]=0;
  REP(i,n-1){
    dp[0][i+1]=(dp[0][i]+dp[1][i])%MOD;
    dp[1][i+1]=dp[0][i];
  }
  ll ans = 0;
  REP(i,n){
    ans+=a[i]*(dp[0][i]*(dp[0][n-i-1]+dp[1][n-i-1])%MOD-dp[1][i]*dp[0][n-i-1]%MOD)%MOD;
    ans%=MOD;
  }
  OUT((ans+MOD)%MOD);
}