#include <bits/stdc++.h>
using namespace std;
struct eq {
  long long m, c, l, r;
  eq(long long _m, long long _c) {
    m = _m;
    c = _c;
    l = r = -1;
  }
  eq() {
    m = 0;
    c = 0;
    l = r = -1;
  }
  long long f(long long x) { return 1LL * m * x + c; }
};
vector<eq> v;
long long get_new() {
  v.emplace_back();
  return v.size() - 1;
}
void update(long long &n, long long l, long long r, eq cur) {
  if (n == -1) {
    n = get_new();
    v[n] = cur;
    return;
  }
  long long mid = (l + r) / 2;
  bool x = cur.f(l) > v[n].f(l);
  bool y = cur.f(mid) > v[n].f(mid);
  if (y) {
    swap(cur, v[n]);
    swap(cur.l, v[n].l);
    swap(cur.r, v[n].r);
  }
  if (l == r) {
    return;
  }
  if (x == y) {
    long long R = v[n].r;
    update(R, mid + 1, r, cur);
    v[n].r = R;
  } else {
    long long L = v[n].l;
    update(L, l, mid, cur);
    v[n].l = L;
  }
}
long long query(long long n, long long l, long long r, long long x) {
  if (n == -1) return -10000000000000000LL;
  long long mid = (l + r) / 2;
  if (l == r) return v[n].f(x);
  if (x <= mid)
    return max(v[n].f(x), query(v[n].l, l, mid, x));
  else
    return max(v[n].f(x), query(v[n].r, mid + 1, r, x));
}
long long arr[200005], cum[200005], sum[200005];
void solve() {
  long long n;
  cin >> n;
  long long root = -1;
  for (long long i = 1; i <= n; i++) {
    cin >> arr[i];
    cum[i] = cum[i - 1] + arr[i] * i;
    sum[i] = sum[i - 1] + arr[i];
  }
  update(root, -2000000000000LL, 2000000000000LL, eq(0, 0));
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    ans = max(ans,
              query(root, -2000000000000LL, 2000000000000LL, sum[i]) + cum[i]);
    long long x = -i;
    long long y = i * sum[i] - cum[i];
    update(root, -2000000000000LL, 2000000000000LL, eq(x, y));
  }
  cout << ans << endl;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
