#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
struct Line {
  long long a, b;
  Line() {}
  Line(long long a, long long b) : a(a), b(b) {}
};
deque<Line> dq;
bool Bad(Line d1, Line d2, Line d3) {
  return (d3.b - d1.b) * (d1.a - d2.a) < (d2.b - d1.b) * (d1.a - d3.a);
}
void Add(Line d) {
  while (dq.size() >= 2 && Bad(d, dq[0], dq[1])) dq.pop_front();
  dq.push_front(d);
}
long long f(Line d, long long x) { return d.a * x + d.b; }
long long Query(long long x) {
  int l = 0, r = (int)dq.size() - 1;
  while (l < r) {
    int m = (l + r) >> 1;
    if (f(dq[m], x) >= f(dq[m + 1], x)) {
      r = m;
    } else
      l = m + 1;
  }
  if (r > 0 && f(dq[r - 1], x) > f(dq[r], x)) --r;
  if (r < (int)dq.size() - 1 && f(dq[r + 1], x) > f(dq[r], x)) ++r;
  return f(dq[r], x);
}
int n;
int a[N];
long long P[N], S[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i) {
    S[i] = S[i - 1] + a[i];
    P[i] = P[i - 1] + (long long)i * a[i];
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    long long a = -(i - 1), b = (long long)(i - 1) * S[i - 1] - P[i - 1];
    Add(Line(a, b));
    ans = max(ans, P[i] + Query(S[i]));
  }
  printf("%I64d", ans);
  return 0;
}
