#include<iostream>
using namespace std;
long long h[100010],w[100010];
int main(){
cin.tie(0);
ios::sync_with_stdio(false); int n;
while(cin>>n){
if(n==0){
break;
}
long long ans=0;
int tot=0;
for(int i=1;i<=n;i++){
int tmp;
cin>>tmp;
int tw=1;
while(tmp<=h[tot]&&tot){
long long wi=w[tot];
w[tot-1]+=wi;
tw+=wi;
ans=max(ans,wi*h[tot]);
tot--;
}
tot++;
h[tot]=tmp;
w[tot]=tw;
}
while(tot){
long long wi=w[tot];
w[tot-1]+=wi;
ans=max(ans,wi*h[tot]);
tot--;
}
cout<<ans<<"\n";
}
cout<<flush;
return 0;
}