#include <bits/stdc++.h>
using namespace std;
int q[200005];
int l, r, n;
long long s[200005], ps[200005], ps2[200005], res;
long double slope(int j, int k) {
  long double dy = (j * ps[j] - ps2[j]) - (k * ps[k] - ps2[k]);
  long double dx = (j - k);
  return dy / dx;
}
int search(long long v) {
  int L = l, R = r;
  while (R - L > 1) {
    int md = (L + R) >> 1;
    long double kk = slope(q[md], q[md - 1]);
    if (slope(q[md], q[md - 1]) > v)
      L = md;
    else
      R = md;
  }
  return q[L];
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); i++) {
    scanf("%lld", &s[i]);
    ps[i] = ps[i - 1] + s[i];
    ps2[i] = ps2[i - 1] + i * s[i];
  }
  q[r++] = 0;
  for (int i = (1); i <= (n); i++) {
    int opt = search(ps[i]);
    long long cb = ps2[i] - ps2[opt] - opt * (ps[i] - ps[opt]);
    res = max(res, cb);
    while (l + 1 < r && slope(q[r - 1], q[r - 2]) < slope(i, q[r - 1])) r--;
    q[r++] = i;
  }
  printf("%lld\n", res);
  return 0;
}
