#include <bits/stdc++.h>
template <class T>
inline void chkmax(T &x, const T &y) {
  if (x < y) x = y;
}
template <class T>
inline void chkmin(T &x, const T &y) {
  if (x > y) x = y;
}
const int N = 2e5;
const long long INF = 1ll << 60;
const long double eps = 1e-9;
int n;
int val[N + 9];
long long suf1[N + 9], suf2[N + 9];
long long u[N + 9], v[N + 9];
struct pot {
  long double x, y;
  pot() { x = y = 0; }
  pot(long double _x, long double _y) : x(_x), y(_y) {}
  inline friend pot operator+(const pot &p, const pot &q) {
    return pot(p.x + q.x, p.y + q.y);
  }
  inline friend pot operator-(const pot &p, const pot &q) {
    return pot(p.x - q.x, p.y - q.y);
  }
  inline friend long double operator*(const pot &p, const pot &q) {
    return p.x * q.x + p.y * q.y;
  }
  inline friend long double operator^(const pot &p, const pot &q) {
    return p.x * q.y - p.y * q.x;
  }
  inline friend pot operator*(const pot &p, const long double &k) {
    return pot(p.x * k, p.y * k);
  }
};
inline int get(const pot &x) {
  if (x.x < 0 && x.y <= 0)
    return 0;
  else if (x.x >= 0 && x.y < 0)
    return 1;
  else if (x.x > 0 && x.y >= 0)
    return 2;
  else
    return 3;
}
struct line {
  pot p, v;
  int id;
  line() {}
  line(pot _p, pot _v, int _id) : p(_p), v(_v), id(_id) {}
  inline friend bool operator<(const line &p, const line &q) {
    int a = get(p.v), b = get(q.v);
    if (a != b)
      return a < b;
    else
      return (p.v ^ q.v) > 0;
  }
} g[N + 9], a[N + 9], b[N + 9], c[N + 9];
long long ans[N + 9];
line q[N + 9];
pot p[N + 9];
inline pot get(const line &p, const line &q) {
  pot w = q.p - p.p;
  long double k = (w ^ p.v) / (p.v ^ q.v);
  return q.p + q.v * k;
}
inline long long get(int d, int x) { return u[d] * x + v[d]; }
inline bool onright(const pot &p, const line &l) {
  return ((p - l.p) ^ l.v) > 0;
}
void dac(int l, int r) {
  if (l == r) return;
  int mid = (l + r) >> 1;
  dac(l, mid), dac(mid + 1, r);
  int an = mid - l + 1, bn = r - mid, cn = 0;
  std::copy(g + l + 1, g + mid + 2, a + 1);
  std::copy(g + mid + 2, g + r + 2, b + 1);
  for (int i = 1, j = 1; i <= an || j <= bn;)
    if (i <= an && (j > bn || a[i] < b[j]))
      c[++cn] = a[i++];
    else
      c[++cn] = b[j++];
  int h = 0, t = 0;
  q[h = t = 1] = b[1];
  for (int i = 2; i <= bn; ++i) {
    while (h < t && onright(p[t - 1], b[i])) --t;
    while (h < t && onright(p[h], b[i])) ++h;
    if (fabs(b[i].v.x - q[t].v.x) <= eps && fabs(b[i].v.y - q[t].v.y) <= eps) {
      if (onright(q[t].p, b[i])) q[t] = b[i];
    } else
      q[++t] = b[i];
    if (h < t) p[t - 1] = get(q[t], q[t - 1]);
  }
  for (int i = l, j = h; i <= mid; ++i) {
    while (j < t && p[j].x < i) ++j;
    chkmax(ans[i], get(q[j].id, i));
  }
  std::copy(c + 1, c + cn + 1, g + l + 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", val + i);
  for (int i = n; i >= 1; --i) {
    suf1[i] = suf1[i + 1] + 1ll * i * val[i];
    suf2[i] = suf2[i + 1] + val[i];
  }
  for (int i = 1; i <= n; ++i) {
    u[i] = suf2[i], v[i] = -suf1[i];
    pot x = pot(0, v[i]), y = pot(1, u[i] + v[i]);
    g[i] = line(x, y - x, i);
  }
  dac(0, n - 1);
  long long owaski = 0, sum = suf1[1];
  for (int i = 0; i < n; ++i) {
    chkmax(owaski, ans[i] + sum);
    sum -= suf2[i + 1];
  }
  std::cout << owaski << std::endl;
  return 0;
}
