#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ll long long
#define ld long double
#define ALL(a) (a).begin(), (a).end()
#define Mod 1000000007

int main() {
  int n;
  cin >> n;
  
  ll ans;
  cin >> ans;
  vector<vector<ll>> a(2, vector<ll>(n));
  a[0][0] = ans;
  
  ll x=1, y=0, z;
  for(int i=1; i < n; i++){
    ll b;
    cin >> b;
    b %= Mod;
    a[0][i] += a[0][i-1] % Mod + (x*b) % Mod + a[1][i-1] % Mod + (y*b) % Mod;
    a[1][i] += a[0][i-1] % Mod - (x*b) % Mod;
    z = (x+y) % Mod;
    y = x % Mod;
    x = z;
  }
  
  ans = (a[0][n-1] + a[1][n-1]) % Mod;
  cout << ans << endl;
  
  return 0;
}
#include <bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long
#define pb push_back

long long dp[100010], a[100010];
ll mod = 1e9+7;

int main()
{
    int n, prvi;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    dp[0]=1;
    dp[1]=2;
    for(int i=2;i<=n-1;i++) dp[i] = (dp[i-1]+dp[i-2])%mod;

    if(n==2){
        cout<<2*a[1]<<endl;
        return 0;
    }

    long long res = (a[1]*dp[n-1])%mod;
    for(int i=2;i<=n;i++){
        long long pos = (dp[ i-2 ]*dp[n-i])%mod, neg;
        if(i==2){
            neg = dp[n-3];
        }
        else if(i==n){
            neg = dp[n-3];
        }
        else{
            neg = (dp[i-3]*dp[n-i-1])%mod;
        }
        res+=(a[i]*(pos-neg+mod)%mod)%mod;
        res%=mod;
    }

    cout<<res<<endl;

    return 0;
}









