#include<iostream>
#include<fstream>
using namespace std;
int n;
long long h[100003];
int lef[100003];
int rig[100003];
void read(){
// ifstream cin("in.txt");
int i,j,k;
while(scanf("%d",&n))
{
if(n==0) return;
for(i=1;i<=n;i++)
scanf("%lld",&h[i]);
h[0]=h[n+1]=-1;
for(i=1;i<=n;i++)
lef[i]=i;
for(i=1;i<=n;i++)
while(h[i]<=h[lef[i]-1])
lef[i]=lef[lef[i]-1];
for(i=1;i<=n;i++)
rig[i]=i;
for(i=n;i>=1;i--)
while(h[i]<=h[rig[i]+1])
rig[i]=rig[rig[i]+1];
long long ans=0;
for(i=1;i<=n;i++)
if(ans<(rig[i]-lef[i]+1)*h[i])
ans=(rig[i]-lef[i]+1)*h[i];
cout<<ans<<endl;
}
}
int main(){
read();
return 0;
}