#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll N = 1e5 + 10;
ll n, a[N], ans, cnt, t, pl[N], pr[N], b[N];
stack<ll> st1, st2;
int main(){
cin >> n;
for(ll i = 1; i <= n; i++){
cin >> a[i];
b[i] = b[i - 1] + a[i];
}
for(ll i = 1; i <= n; i++){
while(!st1.empty() && a[st1.top()] > a[i]){
pr[st1.top()] = i - 1;
st1.pop();
}
st1.push(i);
}
while(!st1.empty()){
pr[st1.top()] = n + 1;
st1.pop();
}
for(ll i = n; i >= 1; i--){
while(!st2.empty() && a[st2.top()] > a[i]){
pl[st2.top()] = i + 1;
st2.pop();
}
st2.push(i);
}
while(!st2.empty()){
pl[st2.top()] = 0;
st2.pop();
}
for(ll i = 1; i <= n; i++){
ans = max(ans, (b[pr[i]] - b[pl[i] - 1]) * a[i]);
}
cout << ans;
return 0;
}