#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline long long isqrt(long long k) {
  long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline int sign(long double x, long double y) { return sign(x - y); }
const long long oo = (long long)1e18;
struct DynamicLineHull {
  struct Line {
    long long a, b;
    Line(long long a = 0, long long b = 0) : a(a), b(b) {}
    int operator<(const Line& rhs) const {
      return make_pair(-a, b) < make_pair(-rhs.a, rhs.b);
    }
    int operator==(const Line& rhs) const {
      return make_pair(a, b) == make_pair(rhs.a, rhs.b);
    }
    int operator!=(const Line& rhs) const {
      return make_pair(a, b) != make_pair(rhs.a, rhs.b);
    }
    long long query(long long x) { return a * x + b; }
  };
  long double intersect(Line ln1, Line ln2) {
    return (long double)(ln2.b - ln1.b) / (ln1.a - ln2.a);
  }
  int bad(Line ln1, Line ln2, Line ln3) {
    return (long double)(ln1.a - ln2.a) * (ln2.b - ln3.b) >=
           (long double)(ln2.a - ln3.a) * (ln1.b - ln2.b);
  }
  set<Line> hull;
  set<pair<long double, Line> > pos;
  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<long double, Line> >::iterator it =
        pos.upper_bound(make_pair(x, Line(-oo, -oo)));
    it--;
    return it->second.a * x + it->second.b;
  }
} dlh;
const long long maxn = 2e5 + 5;
long long a[maxn];
long long cum[maxn];
long long cumm[maxn];
void output() {
  long long n;
  cin >> n;
  a[0] = 0;
  for (int i = (1); i < (n + 1); i++) {
    cin >> a[i];
  }
  cum[0] = 0;
  cumm[0] = 0;
  for (int i = (1); i < (n + 1); i++) {
    cum[i] = cum[i - 1] + a[i];
    cumm[i] = cumm[i - 1] + i * a[i];
  }
  DynamicLineHull dlh;
  dlh.add(0, 0);
  long long ans = 0;
  for (int i = (1); i < (n + 1); i++) {
    ans = min(ans, dlh.query(cum[i]) - cumm[i]);
    dlh.add(i, -cum[i] * i + cumm[i]);
  }
  cout << -ans << endl;
}
int main() {
  long long t = 1;
  for (int i = (0); i < (t); i++) {
    output();
  }
  return 0;
}
