#include<bits/stdc++.h>
using namespace std;
int a[100010],st[100010],stw[100010];
int main(){
int n,top;
while(cin>>n){
long long ans=0;
memset(st,0,sizeof(st));
memset(stw,0,sizeof(stw));
if(n==0){
break;
}
top=0,st[n+1]=0;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n+1;i++){
if(a[i]>st[top]){
st[++top]=a[i];
stw[top]=1;
}
else{
int w=0;
while(st[top]>a[i]){
w+=stw[top];
ans=max(ans,(long long)(w*st[top]));
top--;
}
st[++top]=a[i];
stw[top]=w+1;
}
}
cout<<ans<<endl;
}
return 0;
}
样例能过,提交WA