#include <bits/stdc++.h>
using namespace std;
int n;
long long a[200015], b[200015], c[200015];
vector<pair<long long, long long> > ev;
bool chkbad(int l1, int l2, int l3) {
  return (ev[l3].second - ev[l1].second) * (ev[l1].first - ev[l2].first) >
         (ev[l2].second - ev[l1].second) * (ev[l1].first - ev[l3].first);
}
void addline(long long slope, long long yb) {
  ev.push_back(make_pair(slope, yb));
  while ((int)ev.size() >= 3 &&
         chkbad((int)ev.size() - 3, (int)ev.size() - 2, (int)ev.size() - 1))
    ev.erase(ev.end() - 2);
}
long long bns(long long x) {
  int l = 0, r = (int)ev.size() - 1;
  while (l <= r) {
    int m = (l + r) >> 1;
    if (m + 1 < (int)ev.size() && (ev[m + 1].first * x + ev[m + 1].second >
                                   ev[m].first * x + ev[m].second))
      l = m + 1;
    else
      r = m - 1;
  }
  return ev[l].first * x + ev[l].second;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = b[i - 1] + a[i];
    c[i] = c[i - 1] + i * a[i];
  }
  long long res = 0ll;
  for (int i = 1; i <= n; i++) {
    addline(1ll - i, (i - 1ll) * b[i - 1] - c[i - 1]);
    res = max(res, c[i] + bns(b[i]));
  }
  cout << res;
  return 0;
}
