#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
const long long INF = 1e15;
struct State {
  long long id, suf, suf2;
  double x, y, k;
  void in(double dx, double dy) {
    x = dx;
    y = dy;
  }
  bool operator<(const State& rhs) const { return k > rhs.k; }
};
State Q[maxn], tmp[maxn];
bool cmp(const State& A, const State& B) {
  return A.x == B.x ? A.y < B.y : A.x < B.x;
}
int n, Stack[maxn];
long long v[maxn], ans[maxn];
void solve(int L, int R) {
  if (L == R) {
    Q[L].in(1.0 * Q[L].suf, 1.0 * (-Q[L].suf2 - (Q[L].suf * Q[L].id)));
    return;
  }
  int M = L + R >> 1, k1 = L, k2 = M + 1;
  for (int i = L; i <= R; i++) {
    if (Q[i].id <= M)
      tmp[k1++] = Q[i];
    else
      tmp[k2++] = Q[i];
  }
  for (int i = L; i <= R; i++) Q[i] = tmp[i];
  solve(M + 1, R);
  int k = 0, c = 1;
  for (int i = M + 1; i <= R; i++) {
    while (k >= 2 && (Q[i].y - Q[Stack[k]].y) / (Q[i].x - Q[Stack[k]].x) >=
                         (Q[Stack[k]].y - Q[Stack[k - 1]].y) /
                             (Q[Stack[k]].x - Q[Stack[k - 1]].x))
      k--;
    Stack[++k] = i;
  }
  for (int i = L; i <= M; i++) {
    while (c < k && (Q[Stack[c + 1]].y - Q[Stack[c]].y) /
                            (Q[Stack[c + 1]].x - Q[Stack[c]].x) >=
                        Q[i].k)
      c++;
    ans[Q[i].id] = max(ans[Q[i].id], Q[i].suf2 - Q[Stack[c]].suf2 -
                                         Q[Stack[c]].id * Q[Stack[c]].suf +
                                         Q[i].id * Q[Stack[c]].suf);
  }
  solve(L, M);
  sort(Q + L, Q + R + 1, cmp);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &v[i]);
  for (int i = n; i; i--) Q[i].suf = Q[i + 1].suf + v[i];
  for (int i = n; i; i--) Q[i].suf2 = Q[i + 1].suf2 + Q[i].suf;
  for (int i = 1; i <= n + 1; i++) {
    Q[i].id = i;
    Q[i].k = -1.0 * i;
  }
  sort(Q + 1, Q + 2 + n);
  solve(1, n + 1);
  long long res = -INF;
  for (int i = 1; i <= n; i++) res = max(res, ans[i]);
  printf("%lld\n", res);
  return 0;
}
