#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double epsilon = 1e-7;
inline void fastIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
class point {
 public:
  long double x, y;
  point(long double X = 0, long double Y = 0) { x = X, y = Y; }
  bool operator<(point& that) {
    if (x == that.x) return y < that.y;
    return x < that.x;
  }
};
class line {
 public:
  long double m, c;
  line(long double m, long double c) : m(m), c(c) {}
  long long evaluate(long double x) { return m * x + c; }
};
point intersection(line a, line b) {
  if (a.m == b.m) return point(INT_MAX, INT_MAX);
  point inter;
  inter.x = (long double)(b.c - a.c) / (long double)(a.m - b.m);
  inter.y = a.evaluate(inter.x);
  return inter;
}
class DPConvex {
 public:
  vector<long double> p;
  deque<line> hull;
  void addLine(line a) {
    if (hull.size() == 0) {
      hull.push_back(a);
      return;
    }
    if (hull.size() == 1) {
      point in = intersection(a, hull.back());
      hull.push_back(a);
      p.push_back(in.x);
      return;
    }
    while (p.size()) {
      line r = hull.back();
      hull.pop_back();
      line s = hull.back();
      point in = intersection(a, s);
      if (in.x > p.back()) {
        hull.push_back(r);
        break;
      } else {
        p.pop_back();
      }
    }
    p.push_back(intersection(a, hull.back()).x);
    hull.push_back(a);
  }
  long double findBest(long double x) {
    long long pos = lower_bound(p.begin(), p.end(), x) - p.begin();
    return hull[pos].evaluate(x);
  }
};
signed main(void) {
  fastIO();
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  vector<long long> prefix(n + 1), sum(n + 1);
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + v[i - 1];
    prefix[i] = prefix[i - 1] + i * v[i - 1];
  }
  DPConvex dp;
  line l(0, 0);
  dp.addLine(l);
  long double ans = 0ll;
  for (int i = 1; i <= n; i++) {
    long double val = dp.findBest(-sum[i]) + (long double)prefix[i];
    ans = max(ans, val);
    dp.addLine(line(i, i * sum[i] - prefix[i]));
  }
  cout << (long long)ans << '\n';
  return 0;
}
