#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stack>
using namespace std;
struct node
{
long long x;
int id;
};
int main()
{ long long a[100005];
int r[100005],l[100005];
int i,j,k,m,n;
while(~scanf("%d",&n) && n)
{ long long ans=-1;
for(int i=1;i<=n;i++)scanf("%I64d",&a[i]);
stack<node>s;
while(!s.empty())s.pop();
node temp;
temp.id=1;
temp.x=a[1];
s.push(temp);
for(int i=2;i<=n;i++)
{ node temp;
if(!s.empty())temp=s.top();
if(a[i]>=temp.x || s.empty())
{
node tempp;
tempp.id=i;
tempp.x=a[i];
s.push(tempp);
}
else
if(a[i]<temp.x)
{
while(a[i]<temp.x && !s.empty())
{
r[temp.id]=i-1;
s.pop();
if(!s.empty())temp=s.top();
}
node tempp;
tempp.id=i;
tempp.x=a[i];
s.push(tempp);
}
}
while(!s.empty())
{
node temp=s.top();
r[temp.id]=n;
s.pop();
}
while(!s.empty())s.pop();
temp.id=n;
temp.x=a[n];
s.push(temp);
for(int i=n-1;i>=1;i--)
{
node temp;
if(!s.empty())temp=s.top();
if(a[i]>=temp.x || s.empty())
{
node tempp;
tempp.id=i;
tempp.x=a[i];
s.push(tempp);
}
else
if(a[i]<temp.x)
{
while(a[i]<temp.x && !s.empty())
{
l[temp.id]=i+1;
s.pop();
if(!s.empty())temp=s.top();
}
node tempp;
tempp.id=i;
tempp.x=a[i];
s.push(tempp);
}
}
while(!s.empty())
{
node temp=s.top();
l[temp.id]=1;
s.pop();
}
for(int i=1;i<=n;i++)
{
long long tt=(long long)a[i]*(r[i]-l[i]+1);
if(tt>ans)ans=tt;
}
printf("%I64d\n",ans);
}
return 0;
}