#include <bits/stdc++.h>
using namespace std;
const double PI = acos(0) * 2;
const double EPS = 1e-8;
const long long MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcounll(s);
}
struct Convexhull {
  struct Line {
    long long a, b;
    Line(long long a = 0, long long b = 0) : a(a), b(b) {}
    bool operator<(const Line& oth) const {
      return make_pair(-a, b) < make_pair(-oth.a, oth.b);
    }
    bool operator==(const Line& oth) const {
      return make_pair(a, b) == make_pair(oth.a, oth.b);
    }
    bool operator!=(const Line& oth) const {
      return make_pair(a, b) != make_pair(oth.a, oth.b);
    }
  };
  long double intersect(Line ln1, Line ln2) {
    return (double)(ln2.b - ln1.b) / (ln1.a - ln2.a);
  }
  int bad(Line ln1, Line ln2, Line ln3) {
    return (double)(ln1.a - ln2.a) * (ln2.b - ln3.b) >=
           (double)(ln2.a - ln3.a) * (ln1.b - ln2.b);
  }
  set<Line> hull;
  set<pair<double, Line> > pos;
  void clear() {
    hull.clear();
    pos.clear();
  }
  void add(long long a, long long b) {
    Line ln(a, b);
    if (hull.find(ln) != hull.end()) return;
    hull.insert(ln);
    set<Line>::iterator it = hull.find(ln);
    if (it == hull.begin()) {
      pos.insert(make_pair(-oo, ln));
      if (++it != hull.end()) pos.erase(make_pair(-oo, *it));
      it--;
    } else {
      Line prv = *(--it);
      it++;
      if (prv.a == ln.a) {
        hull.erase(ln);
        return;
      }
      if (*it != *hull.rbegin()) {
        Line nxt = *(++it);
        it--;
        if (bad(prv, ln, nxt)) {
          hull.erase(ln);
          return;
        }
        pos.erase(make_pair(intersect(prv, nxt), nxt));
      }
    }
    Line u, v;
    if (it != hull.begin()) {
      v = *(--it);
      while (it != hull.begin()) {
        u = *(--it);
        if (bad(u, v, ln)) {
          pos.erase(make_pair(intersect(u, v), v));
          hull.erase(v);
          it = hull.find(v = u);
        } else {
          it++;
          break;
        }
      }
      pos.insert(make_pair(intersect(v, ln), ln));
      it++;
    }
    if (*it != *hull.rbegin()) {
      u = *(++it);
      while (*it != *hull.rbegin()) {
        v = *(++it);
        if (ln.a == u.a || bad(ln, u, v)) {
          pos.erase(make_pair(intersect(u, v), v));
          hull.erase(u);
          it = hull.find(u = v);
        } else {
          it--;
          break;
        }
      }
      pos.insert(make_pair(intersect(ln, u), u));
      it--;
    }
  }
  long long query(long long x) {
    if (!pos.size()) return oo;
    set<pair<double, Line> >::iterator it =
        pos.upper_bound(make_pair(x, Line(-oo, -oo)));
    it--;
    return it->second.a * x + it->second.b;
  }
} cvh;
int n;
long long s[200100], S[200100], ans, a[200100];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    S[i] = S[i - 1] + a[i] * i;
    s[i] = s[i - 1] + a[i];
  }
  ans = S[n];
  cvh.add(0, 0);
  for (int i = 1; i <= n; i++) {
    cvh.add(i, S[i] - (long long)(i)*s[i]);
    ans = max(ans, S[i] - cvh.query(s[i]));
  }
  cout << ans;
}
