#include<stdio.h>
#include<iostream>
#include<stack>
typedef long long ll;
using namespace std;
ll arr(ll *ar,ll n)
{
stack<ll> s;
ll maxi=0;
ll tp;
ll parr;
ll i=0;
while(i<n)
{
if(s.empty() || ar[s.top()]<=ar[i])
s.push(i++);
else
{
tp=s.top();
s.pop();
parr=ar[tp]*(s.empty() ? i : i - s.top() - 1);
if(parr>maxi)
maxi=parr;
}
}
if(s.empty()==false)
{
tp=s.top();
s.pop();
parr=ar[tp]*(s.empty() ? i : i - s.top() - 1);
if(parr>maxi)
maxi=parr;
}
return maxi;
}
int main()
{
ll n,i,ans;
ll ar[100005];
scanf("%lld",&n);
for(i=0;i<n;i++)
scanf("%lld",&ar[i]);
ans=arr(ar,n);
printf("%lld\n",ans);
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPHN0YWNrPgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKbGwgYXJyKGxsICphcixsbCBuKQp7CiAgICBzdGFjazxsbD4gczsKCWxsIG1heGk9MDsKCWxsIHRwOwoJbGwgcGFycjsKCWxsIGk9MDsKCXdoaWxlKGk8bikKCXsKCQlpZihzLmVtcHR5KCkgfHwgYXJbcy50b3AoKV08PWFyW2ldKQoJCXMucHVzaChpKyspOwoJCWVsc2UKCQl7CgkJCXRwPXMudG9wKCk7CgkJCXMucG9wKCk7CgkJCXBhcnI9YXJbdHBdKihzLmVtcHR5KCkgPyBpIDogaSAtIHMudG9wKCkgLSAxKTsKCQkJCgkJCWlmKHBhcnI+bWF4aSkKCQkJbWF4aT1wYXJyOwoJCX0KCX0KCWlmKHMuZW1wdHkoKT09ZmFsc2UpCgl7CgkJdHA9cy50b3AoKTsKCQlzLnBvcCgpOwoJICAgIHBhcnI9YXJbdHBdKihzLmVtcHR5KCkgPyBpIDogaSAtIHMudG9wKCkgLSAxKTsKCQlpZihwYXJyPm1heGkpCgkJbWF4aT1wYXJyOwoJfQoJcmV0dXJuIG1heGk7Cn0KaW50IG1haW4oKQp7CglsbCBuLGksYW5zOwoJbGwgYXJbMTAwMDA1XTsKCXNjYW5mKCIlbGxkIiwmbik7Cglmb3IoaT0wO2k8bjtpKyspCglzY2FuZigiJWxsZCIsJmFyW2ldKTsKCWFucz1hcnIoYXIsbik7CglwcmludGYoIiVsbGRcbiIsYW5zKTsKCXJldHVybiAwOwp9