#include <bits/stdc++.h>
using namespace std;
struct BLOCK {
  int n;
  long long dt, cnt;
  long long a[318], b[318];
  bool v[318];
  int t[318];
  int c[318], cn;
  double x[318];
  void init() {
    for (int i = 0; i < n; i++) t[i] = i;
  }
  double solvex(int p, int q) { return -(double)(b[p] - b[q]) / (a[p] - a[q]); }
  void release() {
    sort(t, t + n, [&](int p, int q) -> bool {
      if (a[p] != a[q]) return a[p] < a[q];
      return b[p] > b[q];
    });
    cn = 0;
    for (int i = 0; i < n; i++) {
      if (v[t[i]]) continue;
      if (cn - 1 >= 0 && a[c[cn - 1]] == a[t[i]]) continue;
      while (cn >= 2) {
        if (x[cn - 1] < solvex(c[cn - 1], t[i])) break;
        cn--;
      }
      if (cn - 1 >= 0) x[cn] = solvex(c[cn - 1], t[i]);
      c[cn++] = t[i];
    }
  }
  pair<long long, int> get(long long X) {
    int s, e, m;
    for (s = 1, e = cn - 1; s <= e;) {
      m = (s + e) / 2;
      if (x[m] < X)
        s = m + 1;
      else
        e = m - 1;
    }
    return make_pair(a[c[s - 1]] * X + b[c[s - 1]] + dt, c[s - 1]);
  }
} d[318];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &d[i / 318].a[i % 318]);
    d[i / 318].n++;
  }
  int B = (n + 318 - 1) / 318;
  for (int i = 0; i < B; i++) {
    d[i].init();
    d[i].release();
  }
  long long r = 0, rr = 0;
  for (int i = 0; i < n; i++) {
    long long x = 1;
    bool f = true;
    pair<long long, int> M;
    for (int j = 0; j < B; j++) {
      if (d[j].cn) {
        pair<long long, int> re = d[j].get(x);
        re.second += j * 318;
        if (f || M < re) {
          M = re;
          f = false;
        }
      }
      x += d[j].cnt;
    }
    rr += M.first;
    if (r < rr) r = rr;
    int kb = M.second / 318, ki = M.second % 318;
    d[kb].v[ki] = true;
    for (int j = 0; j < ki; j++) d[kb].b[j] += d[kb].a[ki];
    for (int j = ki + 1; j < d[kb].n; j++) d[kb].b[j] += d[kb].a[j];
    d[kb].cnt++;
    d[kb].release();
    for (int j = 0; j < kb; j++) d[j].dt += d[kb].a[ki];
  }
  printf("%I64d", r);
  return 0;
}
