#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1000000000;
const ll LINF = 1001002003004005006ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
struct IOSetup {
  IOSetup() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(12);
  }
} iosetup;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++)
    os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
  return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &x : v) is >> x;
  return is;
}
template <typename T>
struct LiChaoTree {
  struct Line {
    T a, b;
    Line(T a, T b) : a(a), b(b) {}
    T get(T x) const { return a * x + b; }
    bool over(const Line &b, const T &x) { return get(x) < b.get(x); }
  };
  vector<T> xs;
  vector<Line> seg;
  int sz;
  LiChaoTree(const vector<T> &x, T INF) : xs(x) {
    sz = 1;
    while (sz < (int)xs.size()) sz <<= 1;
    while ((int)xs.size() < sz) xs.push_back(xs.back() + 1);
    seg.assign(2 * sz, Line(0, INF));
  }
  void update(Line &x, int k, int l, int r) {
    int m = (l + r) / 2;
    bool lc = x.over(seg[k], xs[l]), mc = x.over(seg[k], xs[m]);
    if (mc) swap(seg[k], x);
    if (l + 1 >= r)
      return;
    else if (lc != mc)
      update(x, 2 * k, l, m);
    else
      update(x, 2 * k + 1, m, r);
  }
  void update(T a, T b) {
    Line l(a, b);
    update(l, 1, 0, sz);
  }
  T query(int k) {
    T x = xs[k];
    k += sz;
    T ret = seg[k].get(x);
    while (k > 1) {
      k >>= 1;
      chmin(ret, seg[k].get(x));
    }
    return ret;
  }
};
signed main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  cin >> a;
  vector<ll> A(n + 1), S(n + 1);
  A[0] = S[0] = 0;
  for (int i = 0; i < (n); i++) {
    A[i + 1] = A[i] + a[i] * (i + 1);
    S[i + 1] = S[i] + a[i];
  }
  if (false) {
    int l, r;
    cin >> l >> r;
    cout << A[r] - A[l] - (S[r] - S[l]) * l << endl;
  }
  map<ll, int> id;
  auto v = S;
  sort(begin(v), end(v));
  for (int i = 0; i < (n + 1); i++) id[v[i]] = i;
  LiChaoTree<ll> seg(v, LINF);
  ll res = -LINF;
  for (int i = 0; i < (n + 1); i++) {
    seg.update(i, A[i] - S[i] * i);
    chmax(res, A[i] - seg.query(id[S[i]]));
  }
  cout << res << endl;
  return 0;
}
