#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 7;
const double INF = 99999999999999999, eps = 1e-10;
int n, op;
long long sum[N], g[N], ans, f;
int S[N];
int dcmp(double x) {
  if (fabs(x) < eps) return 0;
  return x < 0 ? -1 : 1;
}
double X(int a) { return 1.0 * a; }
double Y(int a) { return -1.0 * g[a] + 1.0 * a * sum[a]; }
double Slope(int a, int b) {
  double x = X(b) - X(a), y = Y(b) - Y(a);
  if (dcmp(x) == 0) return y > 0 ? INF : -INF;
  return y / x;
}
int query(long long k) {
  int l = 0, r = op;
  if (r <= 0) return 0;
  while (r - l >= 5) {
    int len = (r - l) / 3, d1 = l + len, d2 = l + len * 2;
    if (-g[S[d1]] - 1ll * S[d1] * (k - sum[S[d1]]) <
        -g[S[d2]] - 1ll * S[d2] * (k - sum[S[d2]]))
      l = d1;
    else
      r = d2;
  }
  int sel = 0;
  long long maxn = -999999999999999999;
  for (; l <= r; l++)
    if (-g[S[l]] - 1ll * S[l] * (k - sum[S[l]]) > maxn) {
      maxn = -g[S[l]] - 1ll * S[l] * (k - sum[S[l]]);
      sel = l;
    }
  return S[sel];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &sum[i]);
    g[i] = 1ll * i * sum[i];
    g[i] += g[i - 1];
    sum[i] += sum[i - 1];
  }
  for (int i = 1; i <= n; i++) {
    int x = query(sum[i]);
    f = (g[i] - g[x]) - 1ll * x * (sum[i] - sum[x]);
    ans = max(ans, f);
    while (op > 1 && Slope(S[op], i) > Slope(S[op - 1], S[op])) op--;
    S[++op] = i;
  }
  printf("%lld\n", ans);
  return 0;
}
