#include<bits/stdc++.h>
#define int long long
#define ld long double
#define all(x) x.begin(),x.end()
#define fr(i,n) for(int i=0;i<(int)n;i++)
#define ff first
#define ss second
#define tc int t;cin>>t;while(t--)
#define FILE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define pb push_back
#define all(x) x.begin(),x.end()
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ps(x,y) fixed<<setprecision(y)<<x
const int mod = 1000000007;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;

const int INF = 0x3f3f3f3f3f3f3f3f;

const int N=1e5+5;
#define out(x) cout<<x<<"\n"
#define deb(x) cout<<#x<<": "<<x<<"\n"
#define mod2 998244353

// template<typename T>
// using min_pq=priority_queue<T, std::vector<T>, greater<T>>;
#define pii pair<int,int>

int add(int x,int y,int m=mod){
  return (x%m + y%m)%m;
}
int sub(int x,int y,int m=mod){
  return (x%m - y%m +m)%m;
}
int mul(int x,int y,int m=mod){
  return ((x%m)*(y%m))%m;
}

int n;
int a[N];
int dp[N][2];
int dp1[N][2];

int power(int a, int b, int m = mod)
{
  long long ans = 1;
  while (b > 0)
  {
    if (b & 1LL)
    {
      ans = (ans * a) % m;
    }
    a = (a * a) % m;
    b = (b >> 1LL);
  }
  return ans;
}

int f2(int i,int last){
  if(i==n-1)
    return dp1[i][last]=dp1[i][last^1]=1;
  int &ans=dp1[i][last];
  if(ans!=-1)
    return ans;
  ans=0;
  if(last==0){
    ans=f2(i+1,1)%mod;
  }else{
    ans=add(f2(i+1,0),f2(i+1,1));
  }
  return ans;
}

int f(int i,int last){
  //f(i) gives the required sum from i...n
  if(i==n){
    return 0;
  }

  if(dp[i][last]!=-1)
    return dp[i][last];

  //two options
  int ans=0;
  int num=dp1[i][last];
  // num=power(2,num);
  if(last==0){
    //negative
    ans=sub(f(i+1,1),mul(num,a[i]));

  }else{

    ans=add(f(i+1,0),f(i+1,1));
    ans=add(ans,mul(num,a[i]));
  }
  // deb(num);
  // deb(ans);
  return dp[i][last]=ans;

}


inline void solve(){
  // int n;
  cin>>n;
  fr(i,n){
    cin>>a[i];
  }
  memset(dp,-1,sizeof(dp));
  memset(dp1,-1,sizeof(dp1));
  f2(0,1); 
  int ans=0;
  ans=f(0,1);
  // deb(dp[2][0]);
  out(ans);
}


inline void solve2(){
  int n;
  cin>>n;
  out(n);
}



int32_t main() {
  fio;

  int t=1;
  // cin>>t;
  
  fr(j,t){
    // cout<<"Case #"<<j+1<<": ";
    solve();
  }
  printclock;
  return 0;
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define ud unsigned int
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x3f
#define MAX_INF_VAL 0x3f3f3f3f
#define MAX_INF_VAL_LL 0x3f3f3f3f3f3f3f3f
//#define pi 3.141592653589
#define eps 1e-9
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
//#define p 2173412051LL
//#define sz 2

using namespace std;

template< typename T > void read( T &x ) {
	x = 0;
	char ch = getchar();
	ll f = 1;
	while( !isdigit( ch ) ) {
		if( ch == '-' )
		f *= -1;
		ch = getchar();
	}
	while( isdigit( ch ) ) {
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	x *= f;
}

struct custom_hash {
    static uint64_t splitmix64( uint64_t x ) {
        x += 0x9e3779b97f4a7c15;
        x = ( x ^ ( x >> 30 ) ) * 0xbf58476d1ce4e5b9;
        x = ( x ^ ( x >> 27 ) ) * 0x94d049bb133111eb;
        return x ^ ( x >> 31 );
    }

    size_t operator() ( uint64_t x ) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64( x + FIXED_RANDOM );
    }
};

const ll p = 1e9 + 7;

ll a[ 100010 ];
ll f[ 100010 ][ 2 ];
ll g[ 100010 ][ 2 ];

int main() {
	ios::sync_with_stdio( false );
	cin.tie( 0 ), cout.tie( 0 );
	int n;
	cin >> n;
	for( int i = 1; i <= n; ++i )
		cin >> a[ i ];
	f[ 1 ][ 0 ] = a[ 1 ];
	g[ 1 ][ 0 ] = 1;
	for( int i = 1; i < n; ++i ) {
		if( f[ i ][ 0 ] != MAX_INF_VAL_LL ) {
			if( f[ i + 1 ][ 0 ] == MAX_INF_VAL_LL )
				f[ i + 1 ][ 0 ] = f[ i ][ 0 ] + g[ i ][ 0 ] * a[ i + 1 ] % p;
			else
				f[ i + 1 ][ 0 ] += f[ i ][ 0 ] + g[ i ][ 0 ] * a[ i + 1 ] % p;
			g[ i + 1 ][ 0 ] = ( g[ i + 1 ][ 0 ] + g[ i ][ 0 ] ) % p;
			if( f[ i + 1 ][ 1 ] == MAX_INF_VAL_LL )
				f[ i + 1 ][ 1 ] = f[ i ][ 0 ] - g[ i ][ 0 ] * a[ i + 1 ] % p;
			else
				f[ i + 1 ][ 1 ] += f[ i ][ 0 ] - g[ i ][ 0 ] * a[ i + 1 ] % p;
			g[ i + 1 ][ 1 ] = ( g[ i + 1 ][ 1 ] + g[ i ][ 0 ] ) % p;
		}
		if( f[ i ][ 1 ] != MAX_INF_VAL_LL ) {
			if( f[ i + 1 ][ 0 ] == MAX_INF_VAL_LL )
				f[ i + 1 ][ 0 ] = f[ i ][ 1 ] + g[ i ][ 1 ] * a[ i + 1 ] % p;
			else
				f[ i + 1 ][ 0 ] += f[ i ][ 1 ] + g[ i ][ 1 ] * a[ i + 1 ] % p;
			g[ i + 1 ][ 0 ] = ( g[ i + 1 ][ 0 ] + g[ i ][ 1 ] ) % p;
		}
		if( f[ i + 1 ][ 0 ] != MAX_INF_VAL_LL )
			f[ i + 1 ][ 0 ] = ( f[ i + 1 ][ 0 ] % p + p ) % p;
		if( f[ i + 1 ][ 1 ] != MAX_INF_VAL_LL )
			f[ i + 1 ][ 1 ] = ( f[ i + 1 ][ 1 ] % p + p ) % p;
	}
	cout << ( f[ n ][ 0 ] + f[ n ][ 1 ] ) % p;
	return 0;
}