include[HTML_REMOVED]
using namespace std;
long long q[100005],w[100005];
int n,h,top=0;
long long num=0;
int main(){
while(cin>>n){
if(n==0)return 0;
num=0;
top=0;
q[top]=-1;
w[top]=0;
for(int i=1;i<=n+1;i){
if(i<=n)
cin>>h;
else h=0;
if(h>q[top]){
w[top]=1;
q[top]=h;
}else{
int ant=0;
while(q[top]>=h){
ant+=w[top];
num=max(num,ant*q[top]);
top–;
}
w[++top]=ant+1;
q[top]=h;
}
}
cout<<num<<endl;
}
}