#include <bits/stdc++.h>
using namespace std;
vector<long long> m, b;
bool bad(long long f1, long long f2, long long f3) {
  return (b[f3] - b[f1]) * (m[f1] - m[f2]) >= (b[f2] - b[f1]) * (m[f1] - m[f3]);
}
void add(long long m_, long long b_) {
  m.push_back(m_);
  b.push_back(b_);
  long long sz = m.size();
  while (sz >= 3 && bad(sz - 3, sz - 2, sz - 1)) {
    m.erase(m.end() - 2);
    b.erase(b.end() - 2);
    sz--;
  }
}
long long f(long long i, long long x) { return m[i] * x + b[i]; }
long long query(long long x) {
  long long ans = 0;
  int lo = 0, hi = m.size() - 1;
  while (lo <= hi) {
    long long mid1 = (lo + lo + hi) / 3;
    long long mid2 = (lo + hi + hi) / 3;
    long long y1 = f(mid1, x), y2 = f(mid2, x);
    if (y1 <= y2)
      ans = max(ans, y2), lo = mid1 + 1;
    else
      ans = max(ans, y1), hi = mid2 - 1;
  }
  return ans;
}
long long p[200005], s[200005];
long long n;
void solve() {
  long long Max = max(0LL, p[1]);
  for (int i = 1; i <= n; i++) {
    add(-i, i * p[i] - s[i]);
    Max = max(Max, query(p[i]) + s[i]);
  }
  cout << Max;
}
int main() {
  cin >> n;
  long long a[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    p[i] = p[i - 1] + a[i];
    s[i] = s[i - 1] + i * a[i];
  }
  solve();
}
