#include <vector>
#include <functional>

using namespace std;

template<typename T>
class SegmentTree
{
    int n;
    function<T(T,T)> op;
    vector<T> V;

    T q(int l, int r)
    {
        if (l >= r)
            return V[0];
        T a = q((l+1)/2, r/2);
        if (l%2 != 0)
            a = op(a, V[l]);
        if (r%2 != 0)
            a = op(a, V[r-1]);
        return a;
    }

public:
    SegmentTree(int n_, function<T(T,T)> op, T init):
        op(op)
    {
        n = 1;
        while (n < n_)
            n *= 2;
        V = vector<T>(2*n, init);
        for (int i=n-1; i>0; i--)
            V[i] = op(V[i*2], V[i*2+1]);
    }

    T get(int p) const
    {
        return V[p+n];
    }

    void set(int p, T v)
    {
        p += n;
        V[p] = v;
        for (p/=2; p>0; p/=2)
            V[p] = op(V[p*2], V[p*2+1]);
    }

    //  init OP v[l] OP v[l+1] OP ... OP v[r-1]
    T query(int l, int r)
    {
        return q(l+n, r+n);
    }
};

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<int> A(N);
    for (int &a: A)
        cin>>a;

    int MA = 0;
    for (int a: A)
        MA = max(MA, a+1);

    vector<int> L(N);
    SegmentTree<int> STL(MA, [&](int x, int y){return max(x, y);}, -1);
    for (int i=0; i<N; i++)
    {
        L[i] = STL.query(0, A[i]);
        STL.set(A[i], i);
    }
    vector<int> R(N);
    SegmentTree<int> STR(MA, [&](int x, int y){return min(x, y);}, N);
    for (int i=N-1; i>=0; i--)
    {
        R[i] = STR.query(0, A[i]);
        STR.set(A[i], i);
    }
    int ans = 0;
    for (int i=0; i<N; i++)
        ans = max(ans, A[i]*(R[i]-L[i]-1));
    cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+105;
const ll mod=1e9+7;
int a[maxn];
int main(){
	
     int n,ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++){
		int tp=a[i];
		for(int j=i+1;j<=n;j++) {
			if(a[j]<a[i]){
				break;
			}
			tp=tp+a[i];
		}
		for(int j=i-1;j>=1;j--){
			if(a[j]<a[i]){
				break;
			}
			tp=tp+a[i];
		}
		ans=max(ans,tp); 
		     
	}
	
	printf("%d\n",ans);
	
	return 0;
} 