#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/segtree>
//using namespace atcoder;

using ll = long long;
using ld = long double;
using pl = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int inf = 1001001001;
const ll mod = 1000000007;
const ll INF = 1ll<<60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

struct UnionFind {
    vector<int> parents;

    UnionFind() {}
    UnionFind(int n) : parents(n, -1) {}

    int leader(int x) {
        if (parents[x] < 0) return x;
        else return parents[x] = leader(parents[x]);
    }
    bool merge(int x, int y) {
        x = leader(x);
        y = leader(y);
        if (x == y) return false;
        if (parents[x] > parents[y]) swap(x, y);
        parents[x] += parents[y];
        parents[y] = x;
        return true;
    }
    bool same(int x, int y) { return leader(x) == leader(y); }
    int size(int x) { return -parents[leader(x)]; }
    void init(int n) { parents.assign(n, -1);}      // reset
};



int main() {
    int n; cin >> n;
    vl a(n); rep(i,n) cin >> a[i];
    vector<pl> aa(n);
    rep(i,n) aa[i].first = a[i], aa[i].second = i;
    sort(all(aa));
    reverse(all(aa));
    UnionFind uf(n);
    ll ans = 0;
    ll m = 1;
    rep(i,n) {
        ll ai = aa[i].first, id = aa[i].second;
        ans = max(ans, m*ai);
        if (id > 0 && a[uf.leader(id)] <= a[uf.leader(id-1)]) {
            chmin(a[uf.leader(id-1)], a[uf.leader(id)]);
            chmin(a[uf.leader(id)], a[uf.leader(id-1)]);
            uf.merge(id, id-1);
            m = max(m, (ll)uf.size(id));
            ans = max(ans, m*ai);
        }
        if (id < n-1 && a[uf.leader(id)] <= a[uf.leader(id+1)]) {
            chmin(a[uf.leader(id+1)], a[uf.leader(id)]);
            chmin(a[uf.leader(id)], a[uf.leader(id+1)]);
            uf.merge(id, id+1);
            m = max(m, (ll)uf.size(id));
            ans = max(ans, m*ai);
        }
    }
    cout << ans << endl;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n; cin>>n;
    vector<int> a(n);
    for(int i= 0; i<n; i++) cin>>a[i];

    int ans = 0;
    for(int i = 0, h; i<n; i++){
        h = a[i];
        for(int j = i; j<n; j++){
            h = min(h, a[j]);
            ans = max(ans, h*(j-i+1));
        }
    }
    cout<<ans<<"\n";
    return 0;
}