#include <bits/stdc++.h>
using namespace std;
int n;
long long dp[100005], ans;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  memset(dp, -6, sizeof(dp));
  dp[0] = 0;
  for (int i = 1, u; i <= n; i++) {
    cin >> u;
    for (int j = i; j >= 1; j--) dp[j] = max(dp[j], dp[j - 1] + 1ll * j * u);
  }
  for (int i = 1; i <= n; i++) ans = max(ans, dp[i]);
  cout << ans;
}
