#include <bits/stdc++.h>
using namespace std;
const long long int is_query = LLONG_MIN;
struct Line {
  long long int m, b;
  mutable function<const Line*()> succ;
  bool operator<(const Line& rhs) const {
    if (rhs.b != is_query) return m < rhs.m;
    const Line* s = succ();
    if (!s) return 0;
    long long int x = rhs.m;
    return b - s->b < (s->m - m) * x;
  }
};
struct HullDynamic : public multiset<Line> {
  bool bad(iterator y) {
    auto z = next(y);
    if (y == begin()) {
      if (z == end()) return 0;
      return y->m == z->m && y->b <= z->b;
    }
    auto x = prev(y);
    if (z == end()) return y->m == x->m && y->b <= x->b;
    return (x->b - y->b) * (z->m - y->m) >= (y->b - z->b) * (y->m - x->m);
  }
  void Add(long long int m, long long int b) {
    auto y = insert({m, b});
    y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };
    if (bad(y)) {
      erase(y);
      return;
    }
    while (next(y) != end() && bad(next(y))) erase(next(y));
    while (y != begin() && bad(prev(y))) erase(prev(y));
  }
  long long int Query(long long int x) {
    auto l = *lower_bound((Line){x, is_query});
    return l.m * x + l.b;
  }
};
long long int m[200005];
long long int cIA[200005];
long long int cA[200005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &m[i]);
  for (int i = 1; i <= n; i++) cA[i] = cA[i - 1] + m[i];
  for (int i = 1; i <= n; i++) cIA[i] = cIA[i - 1] + i * m[i];
  long long int Max = 0;
  HullDynamic ch;
  ch.Add(0, 0);
  for (int i = 1; i <= n; i++) {
    Max = max(Max, ch.Query(cA[i]) + cIA[i]);
    ch.Add(-i, -cIA[i] + i * cA[i]);
  }
  cout << Max << endl;
}
