## [题目通道](Bear and Bowling - 洛谷)
#include<bits/stdc++.h>
#define int log long
#define fast register int
using namespace std;
const int MAXN=1e5+10;
int n,x,ans=-0x7ffff,dp[MAXN];
signed main(){
cin>>n;
memset(dp,-1e18,sizeof(dp));
for (fast i=1;i<=n;i++){
cin>>x;
for (fast j=i;j>0;j--) {
dp[j]=max(dp[j],dp[j-1]+j*x);
}
}
for (fast i=1;i<=n;i++) {
ans=max(ans,dp[i]);
}
cout<<ans<<endl;
return 0;
}