#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, sgn = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') sgn = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
  return x * sgn;
}
const int N = 1e5 + 10;
const long long inf = 0x3f3f3f3f3f3f3f3f;
int rt, ch[N][2], sz[N], n, nodenum, stk[N], top, fa[N];
long long A[N], B[N], v[N];
void pushup(int u) { sz[u] = sz[ch[u][0]] + sz[ch[u][1]] + 1; }
void add(int u, long long a, long long b) {
  A[u] += a;
  B[u] += b;
  v[u] += (sz[ch[u][0]] + 1) * a + b;
}
void pushdown(int x) {
  if (A[x] || B[x]) {
    if (ch[x][0]) add(ch[x][0], A[x], B[x]);
    if (ch[x][1]) add(ch[x][1], A[x], B[x] + (sz[ch[x][0]] + 1) * A[x]);
    A[x] = B[x] = 0;
  }
}
void Rotate(int x) {
  int y = fa[x], z = fa[y], k = ch[y][1] == x;
  fa[x] = z;
  if (z) ch[z][ch[z][1] == y] = x;
  ch[y][k] = ch[x][k ^ 1];
  fa[ch[x][k ^ 1]] = y;
  ch[x][k ^ 1] = y;
  fa[y] = x;
  pushup(y);
  pushup(x);
}
void Splay(int x) {
  stk[top = 1] = x;
  for (int i = x; fa[i]; i = fa[i]) stk[++top] = fa[i];
  while (top) pushdown(stk[top--]);
  while (fa[x]) {
    int y = fa[x], z = fa[y];
    if (z) (ch[z][0] == y) ^ (ch[y][0] == x) ? Rotate(x) : Rotate(y);
    Rotate(x);
  }
  rt = x;
}
long long getval(int x) {
  int u = rt;
  while (1) {
    if (sz[ch[u][0]] + 1 == x) {
      Splay(u);
      return v[u];
    } else if (sz[ch[u][0]] >= x)
      u = ch[u][0];
    else
      x -= sz[ch[u][0]] + 1, u = ch[u][1];
  }
}
long long getmax(int x) {
  if (!x) return -inf;
  pushdown(x);
  return max(getmax(ch[x][0]), max(getmax(ch[x][1]), v[x]));
}
int main() {
  n = read();
  rt = nodenum = sz[1] = 1;
  for (int i = 1; i <= n; i++) {
    long long x = read();
    int l = 0, r = i - 2, ps = i - 1;
    while (l <= r) {
      int mid = l + r >> 1;
      if (getval(mid + 1) + (mid + 1) * x > getval(mid + 2))
        r = mid - 1, ps = mid;
      else
        l = mid + 1;
    }
    getval(ps + 1);
    ++nodenum;
    fa[nodenum] = rt;
    v[nodenum] = v[rt];
    ch[nodenum][1] = ch[rt][1];
    fa[ch[rt][1]] = nodenum;
    ch[rt][1] = nodenum;
    add(nodenum, x, x * ps);
    Splay(nodenum);
  }
  printf("%lld\n", getmax(rt));
  return 0;
}
