#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<map>
#include<vector>
#include<list>
#include<set>
#include<stack>
using namespace std;
#define IOS ios::sync_with_stdio(0)
#define ci cin>>
#define ct cout<<
#define ce endl
#define st(x,y) sort(x+1,x+y+1)
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)
#define un(x,y) unique(x+1,x+y+1)
#define IT iterator
#define lb(x,y,z) lower_bound(x+1,x+y+1,z)-x;
#define ub(x,y,z) upper_bound(x+1,x+y+1,z)-x;
#define x first
#define y second
typedef long long ll;
typedef stack<int> STI;
typedef vector<int> VI;
typedef map<int,int> MII;
typedef pair<int,int> PII;
typedef string S;
typedef list<int> LI;
typedef set<int> SI;
const int N=1e3+5;
const int INF=0x3f3f3f3f;
const int FNI=-0x3f3f3f3f;
const int eps=1e-6;
int n;
int a[N];
STI stl,str;
int sum[N],l[N],r[N];
int ans;
inline void solve(){
ci n;
rep(i,1,n)
{
ci a[i];
sum[i]=sum[i-1]+a[i];
}
rep(i,1,n)
{
while(!stl.empty()&&a[stl.top()]>a[i])
{
stl.pop();
}
if(!stl.empty())
{
l[i]=stl.top();
}
else
{
l[i]=i;
}
stl.push(i);
}
per(i,n,1)
{
while(!str.empty()&&a[str.top()]>a[i])
{
str.pop();
}
if(!str.empty())
{
r[i]=str.top()-1;
}
else
{
r[i]=i;
}
str.push(i);
}
rep(i,1,n)
{
ans=max(ans,(sum[r[i]]-sum[l[i]])*a[i]);
}
ct ans;
}
main(){
IOS;
int T = 1;
rep(opopop,1,T){
solve();
}
}