#include <bits/stdc++.h>
std::mt19937 rd(time(0));
const int N = 1e5 + 5;
int n;
struct FHQ {
  int tot = 1, rt = 1, sz[N] = {0, 1}, ls[N], rs[N], fix[N];
  long long val[N], a[N], b[N];
  inline int Newd(long long v) {
    int p = ++tot;
    return val[p] = v, fix[p] = rd(), p;
  }
  inline void Up(int p) { sz[p] = sz[ls[p]] + sz[rs[p]] + 1; }
  inline void Tg(int p, long long A, long long B) {
    if (p) val[p] += A * (sz[ls[p]] + 1) + B, a[p] += A, b[p] += B;
  }
  inline void Down(int p) {
    if (a[p] || b[p])
      Tg(ls[p], a[p], b[p]), Tg(rs[p], a[p], b[p] + a[p] * (sz[ls[p]] + 1)),
          a[p] = b[p] = 0;
  }
  inline int Merge(int x, int y) {
    if (!x || !y) return x | y;
    Down(x), Down(y);
    if (fix[x] < fix[y]) return rs[x] = Merge(rs[x], y), Up(x), x;
    return ls[y] = Merge(x, ls[y]), Up(y), y;
  }
  inline void Split(int p, int &x, int &y, int v) {
    if (!p) {
      x = y = 0;
      return;
    }
    Down(p);
    if (sz[ls[p]] < v)
      x = p, Split(rs[p], rs[x], y, v - sz[ls[p]] - 1);
    else
      y = p, Split(ls[p], x, ls[y], v);
    Up(p);
  }
  inline void Ins(int p, long long v) {
    int x, y;
    Split(rt, x, y, p), rt = Merge(Merge(x, Newd(v)), y);
  }
  inline long long Kth(int k) {
    int p = rt;
    while (1)
      if (Down(p), k == sz[ls[p]] + 1)
        return val[p];
      else if (k <= sz[ls[p]])
        p = ls[p];
      else
        k -= sz[ls[p]] + 1, p = rs[p];
    return -1e18;
  }
  inline void Add(int p, long long A, long long B) {
    int x, y;
    Split(rt, x, y, p), Tg(y, A, B), rt = Merge(x, y);
  }
  inline long long Query(int p) {
    if (!p) return -1e18;
    Down(p);
    return std::max(val[p], std::max(Query(ls[p]), Query(rs[p])));
  }
} f;
int main() {
  scanf("%d", &n);
  int i, l, r, I, E;
  long long x;
  for (i = 1; i <= n; i++) {
    scanf("%lld", &x);
    for (l = 0, r = i - 2, E = i - 1; l <= r;)
      if (I = l + r >> 1, f.Kth(I + 1) + (long long)(I + 1) * x > f.Kth(I + 2))
        E = I, r = I - 1;
      else
        l = I + 1;
    f.Ins(E + 1, f.Kth(E + 1)), f.Add(E + 1, x, (long long)x * E);
  }
  printf("%lld\n", f.Query(f.rt));
  return 0;
}
