#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long ret = 0, t = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') t = -1, c = getchar();
  while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
  return ret * t;
}
const long long MAXN = 100100;
struct tree {
  long long ls, rs, val, sum, rnd, siz, tag;
} t[MAXN];
long long top, root;
long long newnode(long long x) {
  ++top;
  t[top].val = x, t[top].rnd = rand(), t[top].siz = 1;
  return top;
}
void pushup(long long x) {
  t[x].siz = t[(t[x].ls)].siz + t[(t[x].rs)].siz + 1,
  t[x].sum = t[(t[x].ls)].sum + t[(t[x].rs)].sum + t[x].val;
}
void cover(long long x, long long k) {
  t[x].val += k, t[x].tag += k, t[x].sum += k * t[x].siz;
}
void pushdown(long long x) {
  if (t[x].tag) {
    cover((t[x].ls), t[x].tag);
    cover((t[x].rs), t[x].tag);
    t[x].tag = 0;
  }
}
void split(long long x, long long k, long long &a, long long &b) {
  if (!x) {
    a = b = 0;
    return;
  }
  pushdown(x);
  if (t[(t[x].ls)].siz + 1 <= k)
    a = x, split((t[x].rs), k - t[(t[x].ls)].siz - 1, (t[x].rs), b);
  else
    b = x, split((t[x].ls), k, a, (t[x].ls));
  pushup(x);
}
long long merge(long long x, long long y) {
  if (!x || !y) return x + y;
  if (t[x].rnd < t[y].rnd) {
    pushdown(x), t[x].rs = merge((t[x].rs), y), pushup(x);
    return x;
  } else {
    pushdown(y), t[y].ls = merge(x, t[y].ls);
    pushup(y);
    return y;
  }
}
void insert(long long pos) {
  long long r1, r2;
  split(root, pos, r1, r2);
  root = merge(merge(r1, newnode(0)), r2);
}
void modify(long long l, long long r, long long k, long long L, long long R,
            long long x) {
  if (R < l) return;
  if (l <= L && R <= r) {
    cover(x, k);
    return;
  }
  long long mid = L + t[(t[x].ls)].siz;
  pushdown(x);
  if (l <= mid && mid <= r) t[x].val += k;
  if (l < mid) modify(l, r, k, L, mid - 1, (t[x].ls));
  if (mid < r) modify(l, r, k, mid + 1, R, (t[x].rs));
  pushup(x);
}
long long query(long long l, long long r, long long L, long long R,
                long long x) {
  if (l <= L && R <= r) return t[x].sum;
  long long mid = L + t[(t[x].ls)].siz, ret = 0;
  pushdown(x);
  if (l <= mid && mid <= r) ret += t[x].val;
  if (l < mid) ret += query(l, r, L, mid - 1, (t[x].ls));
  if (mid < r) ret += query(l, r, mid + 1, R, (t[x].rs));
  pushup(x);
  return ret;
}
long long n, a[MAXN];
signed main() {
  srand(time(NULL));
  n = read();
  long long i, j;
  for (i = 1; i <= n; i++) a[i] = read();
  insert(1);
  for (i = 1; i <= n; i++) {
    long long l = 1, r = i, div = i;
    while (l <= r) {
      long long mid = (l + r) >> 1;
      if (query(1, mid + 1, 1, t[root].siz, root) <
          query(1, mid, 1, t[root].siz, root) + (mid)*a[i])
        r = mid - 1, div = mid;
      else
        l = mid + 1;
    }
    insert(div);
    modify(div + 1, div + 1, (div - 1) * a[i], 1, t[root].siz, root);
    modify(div + 1, t[root].siz, a[i], 1, t[root].siz, root);
  }
  long long ans = 0, s = 0;
  for (i = 1; i <= n + 1; i++)
    s += query(i, i, 1, t[root].siz, root), ans = max(ans, s);
  printf("%lld\n", ans);
  return 0;
}
