#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 9;
long long m[N], c[N], sz = 0;
bool remo() {
  if (sz < 3) return false;
  return 1.0 * (c[sz - 2] - c[sz]) * (m[sz] - m[sz - 1]) <=
         1.0 * (c[sz - 1] - c[sz]) * (m[sz] - m[sz - 2]);
}
void add(long long sl, long long yc) {
  sz++;
  m[sz] = sl;
  c[sz] = yc;
  while (remo()) {
    m[sz - 1] = sl;
    c[sz - 1] = yc;
    sz--;
  }
}
long long query(long long x) {
  long long l = 1, r = sz;
  while (r - l >= 2) {
    long long md = (l + r) / 2;
    long long y1 = m[md] * x + c[md];
    long long y2 = m[md + 1] * x + c[md + 1];
    if (y1 >= y2)
      r = md;
    else
      l = md + 1;
  }
  long long mx = LLONG_MIN;
  while (l <= r) {
    mx = max(mx, m[l] * x + c[l]);
    l++;
  }
  return mx;
}
int main() {
  long long n;
  cin >> n;
  long long ar[n + 5], sum[n + 5];
  sum[0] = 0;
  ar[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
    sum[i] = ar[i] + sum[i - 1];
  }
  long long mx = 0;
  add(0, 0);
  long long pr = 0;
  for (int i = 1; i <= n; i++) {
    pr += i * ar[i];
    mx = max(mx, query(sum[i]) + pr);
    add(-i, i * sum[i] - pr);
  }
  cout << mx << "\n";
}
