#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
using ll = long long;
using vi = vector<int>;
vector<ll> m, b;
bool bad(int t1, int t2, int t3) {
  return 1.0 * (b[t3] - b[t1]) * (m[t1] - m[t2]) >
         1.0 * (b[t2] - b[t1]) * (m[t1] - m[t3]);
}
void add(ll _m, ll _b) {
  m.push_back(_m);
  b.push_back(_b);
  int i = (int)(m).size();
  while (i >= 3 && bad(i - 3, i - 2, i - 1)) {
    i--;
    m.erase(m.end() - 2);
    b.erase(b.end() - 2);
  }
}
ll f(int i, ll x) { return m[i] * x + b[i]; }
ll query(ll x) {
  if ((int)(m).size() == 0) return 0;
  int lo = 0, hi = (int)(m).size() - 1, best = 0;
  while (lo <= hi) {
    int del = (hi - lo) / 3;
    int mid1 = lo + del;
    int mid2 = hi - del;
    if (f(mid1, x) > f(mid2, x)) {
      hi = mid2 - 1, best = mid1;
    } else {
      lo = mid1 + 1, best = mid2;
    }
  }
  return f(best, x);
}
const int N = 2e5 + 10;
ll s[N], p[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    ll x;
    cin >> x;
    s[i] = s[i - 1] + i * x;
    p[i] = p[i - 1] + x;
  }
  add(0, 0);
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, query(p[i]) + s[i]);
    add(-i, i * p[i] - s[i]);
  }
  printf("%lld\n", ans);
}
