#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int a[10010];

int solve() {
    int res = 0;
    for (int i = 0; i < n; i++) {
        int k = 1;
        for (int j = i-1; j >= 0; j--) {
            if (a[i] <= a[j]) {
                k++;
            } else {
                break;
            }
        }
        for (int j = i+1; j < n; j++) {
            if (a[i] <= a[j]) {
                k++;
            } else {
                break;
            }
        }
        res = max(res, a[i] * k);
    }
    return res;
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (ll i = 0; i < N; i++)

int main()
{
int m=1000000007;
ll n; cin >> n;
vector<ll> a(n);
rep(i,n) cin >>  a[i];
vector<vector<ll>> f(n+2,vector<ll>(2));
f[0][0]=0; f[0][1]=1;
rep(i,n){
    f[i+1][0]=f[i][1]%m;
    f[i+1][1]=(f[i][0]+f[i][1])%m;
}
ll ans=0;
rep(i,n){
    ans=(ans%m)+(a[i]%m)*(((f[i][1]*f[n-i][1])%m)-((f[i][0]*f[n-i][0])%m))%m;
}
ans%=m;
if (ans < 0) ans += m;
cout << ans << endl;
}



