#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+10;
int h[N];
int s[N];
ll w[N];
int p;
int main(){
int n;
while(cin>>n&&n){
p=0;
for(int i=1;i<=n;i++) scanf("%d",&h[i]);
h[n+1]=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(h[i]<=s[p]&&p){
wid+=w[p];
ans=max(ans,wid*s[p]);
p--;
}
s[++p]=h[i],w[p]=wid+1;
}
}
printf("%lld\n",ans);
}
return 0;
}