#include <bits/stdc++.h>
using namespace std;
const long long maxn = 110000;
long long fix[maxn], val[maxn], A[maxn], B[maxn], siz[maxn], ch[maxn][2], n, m,
    tot, root;
inline void pushd(long long x, long long a, long long b) {
  val[x] += a * (siz[ch[x][0]] + 1) + b, A[x] += a, B[x] += b;
}
inline void pushdown(long long x) {
  if (A[x] || B[x]) {
    if (ch[x][0]) pushd(ch[x][0], A[x], B[x]);
    if (ch[x][1]) pushd(ch[x][1], A[x], B[x] + A[x] * (siz[ch[x][0]] + 1));
    A[x] = B[x] = 0;
  }
}
inline void pushup(long long x) { siz[x] = siz[ch[x][0]] + siz[ch[x][1]] + 1; }
inline long long rd(long long x) { return rand() % x + 1; }
inline long long newnode(long long v) {
  val[++tot] = v;
  siz[tot] = 1;
  fix[tot] = rd(n);
  return tot;
}
long long merge(long long x, long long y) {
  if (!x || !y) return x + y;
  pushdown(x);
  pushdown(y);
  if (fix[x] < fix[y]) {
    ch[x][1] = merge(ch[x][1], y);
    pushup(x);
    return x;
  } else {
    ch[y][0] = merge(x, ch[y][0]);
    pushup(y);
    return y;
  }
}
void split(long long rt, long long k, long long &x, long long &y) {
  if (!rt) return x = y = 0, void();
  pushdown(rt);
  if (siz[ch[rt][0]] + 1 <= k) {
    x = rt;
    split(ch[rt][1], k - siz[ch[rt][0]] - 1, ch[x][1], y);
  } else {
    y = rt;
    split(ch[rt][0], k, x, ch[y][0]);
  }
  pushup(rt);
}
long long x, y, z;
long long get(long long rt, long long k) {
  long long x = rt;
  while (1) {
    pushdown(x);
    if (siz[ch[x][0]] + 1 == k) return val[x];
    if (siz[ch[x][0]] >= k)
      x = ch[x][0];
    else
      k -= siz[ch[x][0]] + 1, x = ch[x][1];
  }
}
long long Ans[maxn], top = -1;
void print(long long rt) {
  pushdown(rt);
  if (ch[rt][0]) print(ch[rt][0]);
  Ans[++top] = val[rt];
  if (ch[rt][1]) print(ch[rt][1]);
}
signed main() {
  cin >> n;
  root = newnode(0);
  for (long long i = 1, a; i <= n; ++i) {
    cin >> a;
    long long l = 0, r = i - 2, ans = i - 1;
    while (l <= r) {
      long long mid = l + r >> 1;
      if (get(root, mid + 1) + (mid + 1LL) * a > get(root, mid + 2))
        r = mid - 1, ans = mid;
      else
        l = mid + 1;
    }
    split(root, ans, x, y);
    split(y, 1, y, z);
    long long pos = y;
    x = merge(x, y);
    y = newnode(val[pos]);
    z = merge(y, z);
    pushd(z, a, a * ans);
    root = merge(x, z);
  }
  print(root);
  long long maxx = 0;
  for (long long i = 1; i <= top; ++i) maxx = max(maxx, Ans[i]);
  cout << maxx;
}
