#include <bits/stdc++.h>

using namespace std;
#define fast	ios::sync_with_stdio(0);cin.tie(0);
#define ll	long long int
#define INFL    1e18L
#define INF     2e9
#define nl     	'\n'
#define ld long double
#define precision(x)	fixed << setprecision(x)
const ll mod = 998244353;

ll gcd(ll a, ll b) {
	if (b == 0)  return a;
	return gcd(b , a % b);
}


ll powm(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)
			res = (res * 1LL * a) % mod;
		b >>= 1LL;
		a = (a * 1LL * a) % mod;
	}
	return res;
}
const int N = 2e5 + 5;
const int M = 10;


//--------------------------------------------------------------------------------------------------------------------------//


void solve() {
	int n;
	cin >> n;
	ll mn[n][n];
	ll a[n];

	for (int i = 0; i < n; i++) cin >> a[i];
	ll ans = 0;
	for (int len = 1; len <= n; len++) {
		for (int i = 0; i <= n - len; i++) {
			int j = i + len - 1;
			if (i == j) {
				mn[i][j] = a[i];
				ans = max(ans, mn[i][j]);
			} else {
				mn[i][j] = min(a[j], mn[i][j - 1]);
				ans = max(ans, mn[i][j] * len);
			}
		}
	}
	cout << ans << nl;
}
int main() {
	fast
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int tc = 1;
	// cin >> tc;
	int _ = 0;
	while (_++ < tc) {
		solve();
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define endl "\n" 
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     ll tt,n;
//     cin >> tt;
//    while(tt--){
    cin>>n;
    int a[n+1];
    rep(i,n)
        cin>>a[i];
    stack<pair<int,int> >s;
    vector<int>v1,v2;
    for(int i=0;i<n;i++)    //smallest nearest to left
    {
        if(s.empty())
            v1.pb(0);
        else if(a[i]>s.top().second)
            v1.pb(s.top().first);
        else
        {
            while(s.size()>0&&s.top().second>=a[i])
                s.pop();
            if(s.empty())
                v1.pb(0);
            else
                v1.pb(s.top().first);
        }
        s.push(mp(i+1,a[i]));
    }
    while(!s.empty())
        s.pop();

    for(int i=n-1;i>=0;i--)    //smallest nearest to right
    {
        if(s.empty())
            v2.pb(n+1);
        else if(a[i]>s.top().second)
            v2.pb(s.top().first);
        else
        {
            while(s.size()>0&&s.top().second>=a[i])
                s.pop();
            if(s.empty())
                v2.pb(n+1);
            else
                v2.pb(s.top().first);
        }
        s.push(mp(i+1,a[i]));
    }
    reverse(v2.begin(),v2.end());
    
    ll ans=0,area=0;
    for(int i=0;i<n;i++)
    {
        area=a[i]*(v2[i]-v1[i]-1);
        ans=max(ans,area);
    }
    cout<<ans<<endl;
     
//    }
	return 0;
}