#include <bits/stdc++.h>
using namespace std;
using ll = long long;

vector<int> a(10010);

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a.at(i);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int x = a[i];
		for (int j = i; j < n; j++) {
			x = min(x, a[j]);
			ans = max(ans, x * (j - i + 1));
		}
	}
	cout << ans << endl;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll h[100005],s[5000005],w[5000005];
int n,p;
int main()
{
    while (scanf ("%d",&n)!=EOF)
    {
        if (n==0) return 0;
        memset(h,0,sizeof(h));
        memset(s,0,sizeof(h));
        for (int i=1;i<=n;i++)
          scanf ("%d",&h[i]);
        h[n+1]=p=0;//增加一个高度为0的矩形，避免扫描栈结束后有剩余矩形 
        ll ans=0;
        for (int i=1;i<=n+1;i++)
        {
            if (h[i]>s[p])
            {
                s[++p]=h[i];
                w[p]=1;
            }
            else //如果当前矩形比之前矩形低，那就出栈栈中矩形，直到有矩形比它低 
            {//用一个  宽度为出栈矩形总宽 高度为当前矩形  的新矩形代替之前矩形 
                ll wid=0;
                while (s[p]>h[i])
                {
                    wid+=w[p];//统计宽度 
                    ans=max(ans,1LL*(wid*s[p]));//计算出栈的矩形面积，更新答案 
                    p--;//出栈 
                }
                w[++p]=wid+1;//将新矩形入栈 
                s[p]=h[i];
            }
        }
        while (p!=0)//将所有矩形出栈，按照上面的方法计算面积，更新答案 
        {
            ans=max(ans,1LL*(s[p]*w[p]));
            p--;
        }
        printf("%lld\n",ans);
    }
}