#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > v;
long long a[200001], s[200001], f[200001], ans = 0;
long double inters(long double a, long double b, long double c, long double d) {
  return (d - b) / (a - c);
}
void add(long long k, long long b) {
  if (v.size() <= 1)
    v.push_back({k, b});
  else {
    while (v.size() > 1 &&
           inters(v[v.size() - 2].first, v[v.size() - 2].second, k, b) <
               inters(v[v.size() - 1].first, v[v.size() - 1].second,
                      v[v.size() - 2].first, v[v.size() - 2].second)) {
      v.pop_back();
    }
    v.push_back({k, b});
  }
}
long long get(long long x) {
  int l, r;
  l = 0;
  r = v.size() - 1;
  while (l < r) {
    int m = (l + r) / 2;
    if (inters(v[m].first, v[m].second, v[m + 1].first, v[m + 1].second) >= x)
      r = m;
    else
      l = m + 1;
  }
  return v[l].first * x + v[l].second;
}
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    s[i] = s[i - 1] + a[i] * i;
    f[i] = f[i - 1] + a[i];
  }
  add(0, 0);
  for (long long i = 1; i <= n; i++) {
    ans = max(ans, -get(-f[i]) + s[i]);
    add(-i, -i * f[i] + s[i]);
  }
  cout << ans;
}
