#include <bits/stdc++.h>
using namespace std;
int a[200010];
long long sum[200010], p[200010];
int n;
long long dy(int x, int y) { return sum[x] * x - p[x] - sum[y] * y + p[y]; }
int dq[200010], l = 0, r = -1;
long long gao(int i, int j) {
  return p[i] - p[j] - (sum[i] - sum[j]) * (long long)j;
}
bool check(int x, int y, int z) {
  return dy(y, x) * (z - y) <= dy(z, y) * (y - x);
}
long long sol(int i, int l, int r) {
  if (l == r) return gao(i, dq[l]);
  int lo = l, rr = r - 1, ret = lo;
  while (lo <= rr) {
    int m = (lo + rr) >> 1;
    if (dy(dq[m + 1], dq[m]) >= sum[i] * (dq[m + 1] - dq[m]))
      lo = m + 1, ret = m + 1;
    else
      rr = m - 1;
  }
  return gao(i, dq[ret]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum[i] = sum[i - 1] + a[i];
    p[i] = p[i - 1] + 1ll * i * a[i];
  }
  dq[++r] = 0;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, sol(i, l, r));
    while (l < r && check(dq[r - 1], dq[r], i)) r--;
    dq[++r] = i;
  }
  printf("%I64d\n", ans);
  return 0;
}
