#include "bits/stdc++.h"

#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define ordered_set tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
using namespace __gnu_pbds;
#define int long long int
using namespace std;
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
//#define mp make_pair
#define ll long long
#define mod 1000000007
//#define mod 998244353
#define so(v) sort(v.begin(), v.end())
#define fi first
#define se second

void __print(long x)
{
    cerr << x;
}
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x)
        cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v))
        cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif
//__builtin_popcount
//vector<vector<int>>
//     dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
#define mp make_pair
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int mI(int a, int m)
{
    return power(a, m - 2, m);
}

#define double long double
int n;
vec v;
int mul(int i,int j){
    return (i * j) % mod;
}
int add(int i,int j){
    return (i + j) % mod;
}
int sub(int i,int j){
    int ans =(i - j) % mod;
    if(ans<0)
        ans += mod;
    return ans;
}

vector<vector<pair<int, int>>> dp(100005);
pair<int,int> fun(int i,int j){

    // debug(i, j);
    if(i==n-1)
        return mp(0,1);
    if(dp[i][j].se!=-1)
        return dp[i][j];
    pair<int,int> ans;
    pair<int, int> x, y;
    y = mp(0, 0);
    x = fun(i + 1, 1);
    if(j==1){
        y = fun(i + 1, 0);
    }
    ans.fi = add(add(x.fi , y.fi) , mul(sub(x.se , y.se) , v[i + 1]));
    ans.se = add(x.se , y.se);

    return dp[i][j]=ans;
}
void solve()
{
    fo(i,100005){
        dp[i].resize(2, {-1, -1});
    }
   
    cin >> n;
    v.resize(n);
    fo(i, n) cin >> v[i];
    pair<int,int> ans = fun(0, 1);
    int ans1 = add(mul(ans.se, v[0]), ans.fi);
    cout << ans1;
}

int32_t main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    srand(time(0));
    //initfact();
    int t = 1;
    //cin >> t;

    while (t--)
    {
        solve();
    }
}
#include<bits/stdc++.h>
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define task "nondec"
#define pii pair<pll, ll>
using namespace std;
using ll = long long;
const int  N = 1e5+5;
const ll mod = 1e9 + 7;
const ll base = 350;
const ll cs = 331;
ll m, n, t, k, tong, ans, a[N], b[N], fe[N], c[N], d[N];
vector<ll> adj[N];
vector<ll> kq;
ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}
void add(ll& x, ll y)
{
    x += y;
    if(x >= mod)x -= mod;
}

void sol()
{
    cin >> n;
    b[1] = 1;
    c[1] = 1;
    d[1] = 2;
    c[0] = 1;
    d[0] = 1;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        if(i > 1)
        {
            b[i] = d[i-2];
            c[i] = b[i-1] + c[i-1];
            if(b[i] >= mod)b[i] -= mod;
            if(c[i] >= mod)c[i] -= mod;
            d[i] = b[i] + c[i];
            if(d[i] >= mod)d[i] -= mod;
            //cout << b[i] <<" "<<c[i] << '\n';
        }
    }
    ans = a[1] * d[n-1] % mod;
    for(int i = 2; i <= n; i ++)
    {
        ans = (ans + a[i] * d[i-2] % mod * d[n-i] % mod) % mod;
        ans = (ans - a[i] * c[i-2] % mod * c[n-i] % mod + mod) % mod;
        //cout << d[i-2] * d[n-i] % mod <<" "<<c[n-i] * c[i-2] % mod << '\n';
    }
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(fopen(task".in", "r"))
    {
        freopen(task".in", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}
/*
4 3
3 2 1 1
2
1 2
3 4
*/
