#include <cstdio>
#include <iostream>
#include <stack>
#define ll long long
using namespace std;
int n;
ll ans=0,k=0,x=0;
stack<ll>st;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lld",&x);
while(!st.empty()&&st.top()<x){
k=st.top()*st.size();
ans=max(ans,k);
st.pop();
}
st.push(x);
k=st.top()*st.size();
ans=max(ans,k);
}
printf("%lld",ans);
return 0;
}