/*-------------必要なときに使うもの------------------*/
//#define _GLIBCXX_DEBUG
/*#include<atcoder/modint>
#include<atcoder/math>
using namespace atcoder;
using mint=modint1000000007;
using MINT=modint998244353;*/
/*#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")*/
/*-------------------end-----------------------------*/
#include<bits/stdc++.h>
using namespace std;
/*---------------------マクロ-------------------------*/
#define int long long
#define rep(i, n) for (int i = 0; i < (long long)(n); i++)
#define stoi stoll
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define debug(x) cout<<#x<<" : "<<x<<endl
#define endl '\n'
/*------------------------end---------------------------*/
/*-----------------------型エイリアス--------------------*/
using ll = long long;
using lint=long long;
using P=pair<long long,long long>;
using vi=vector<long long>;
using vvi=vector<vi>;
using vb=vector<bool>;
using vc=vector<char>;
using vvc=vector<vc>;
using vs=vector<string>;
using vd=vector<double>;
/*------------------------end---------------------------*/
/* ----------------よく使う数字や配列-------------------- */
constexpr long long INF = LLONG_MAX/3;
constexpr long long dx[]={1,0,-1,0},dy[]={0,1,0,-1};
constexpr long long mod = 1e9 + 7;
constexpr long long MOD=998244353;
constexpr long double pi = 3.141592653589793238462643383279;
constexpr double EPS=1e-14;
/* ----------------------end-----------------------------*/
/*---------------------template------------------------*/
template<class T>inline bool chmin(T& a,T b){
  if(a>b){a=b;return true;}
  return false;
}
template<class T>inline bool chmax(T& a,T b){
  if(a<b){a=b;return true;}
  return false;
}
template<class T>inline void mainend(T x){cout<<x<<endl;exit(0);}
/*----------------------end-------------------------*/
void Main(){
  int N;cin>>N;
  vector<int>A(N);rep(i,N)cin>>A[i];
  vector<vector<int>>ruiseki_min(N,vector<int>(N,INF));
  int MAX=-INF;
  rep(i,N){
    ruiseki_min[i][i]=A[i];
    chmax(MAX,A[i]);
    for(int j=i+1;j<N;j++){
      ruiseki_min[i][j]=min(ruiseki_min[i][j-1],A[j]);
      chmax(MAX,ruiseki_min[i][j]*(j-i+1));
    }
  }
  cout<<MAX<<'\n';
}
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(16);
  Main();
  return 0;
}
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD_1000000007 = 1000000007LL;
const ll MOD_998244353 = 998244353LL;

// ModInt begin

using ll = long long;
template<ll mod>
struct ModInt {
    ll v;
    ll mod_pow(ll x, ll n) const {
        return (!n) ? 1 : (mod_pow((x*x)%mod,n/2) * ((n&1)?x:1)) % mod;
    }
    ModInt(ll a = 0) : v((a %= mod) < 0 ? a + mod : a) {}
    ModInt operator+ ( const ModInt& b ) const {
        return (v + b.v >= mod ? ModInt(v + b.v - mod) : ModInt(v + b.v));
    }
    ModInt operator- () const {
        return ModInt(-v);
    }
    ModInt operator- ( const ModInt& b ) const {
        return (v - b.v < 0 ? ModInt(v - b.v + mod) : ModInt(v - b.v));
    }
    ModInt operator* ( const ModInt& b ) const {return (v * b.v) % mod;}
    ModInt operator/ ( const ModInt& b ) const {return (v * mod_pow(b.v, mod-2)) % mod;}
    
    bool operator== ( const ModInt &b ) const {return v == b.v;}
    bool operator!= ( const ModInt &b ) const {return !(*this == b); }
    ModInt& operator+= ( const ModInt &b ) {
        v += b.v;
        if(v >= mod) v -= mod;
        return *this;
    }
    ModInt& operator-= ( const ModInt &b ) {
        v -= b.v;
        if(v < 0) v += mod;
        return *this;
    }
    ModInt& operator*= ( const ModInt &b ) {
        (v *= b.v) %= mod;
        return *this;
    }
    ModInt& operator/= ( const ModInt &b ) {
        (v *= mod_pow(b.v, mod-2)) %= mod;
        return *this;
    }
    ModInt pow(ll x) { return ModInt(mod_pow(v, x)); }
    // operator int() const { return int(v); }
    // operator long long int() const { return v; }
};

template<ll mod>
ModInt<mod> pow(ModInt<mod> n, ll k) {
    return ModInt<mod>(n.mod_pow(n.v, k));
}

template<ll mod>
ostream& operator<< (ostream& out, ModInt<mod> a) {return out << a.v;}
template<ll mod>
istream& operator>> (istream& in, ModInt<mod>& a) {
    in >> a.v;
    return in;
}

// ModInt end

using mint = ModInt<MOD_1000000007>;
mint dp[100010][2], sum[100010][2];

int main() {
    int N; scanf("%d", &N);

    dp[0][1] = mint(1);
    for(int i=0; i<N; i++) {
        int A; scanf("%d", &A);
        // 場合の数
        dp[i+1][0] += dp[i][0] + dp[i][1];
        dp[i+1][1] += dp[i][0];
        // 和
        sum[i+1][0] += sum[i][0] + sum[i][1] + dp[i+1][0] * mint(A);
        sum[i+1][1] += sum[i][0] - dp[i+1][1] * mint(A);
        // fprintf(stderr, "dp = %lld, %lld, sum = %lld, %lld\n", dp[i+1][0].v, dp[i+1][1].v, sum[i+1][0].v, sum[i+1][1].v);
    }
    mint ans = sum[N][0] + sum[N][1];
    cout << ans << endl;
    return 0;
}
