#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int a[maxn];
long long s[maxn], ss[maxn];
pair<int, long long> que[maxn];
int tot;
pair<int, long long> operator-(pair<int, long long> b, pair<int, long long> a) {
  pair<int, long long> c;
  c.first = b.first - a.first;
  c.second = b.second - a.second;
  return c;
}
bool operator>(pair<int, long long> b, pair<int, long long> a) {
  double x = 1.0 * a.second / a.first;
  double y = 1.0 * b.second / b.first;
  return x > y;
}
int main() {
  int i, j, n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[n - i + 1]);
  }
  for (i = 1; i <= n; i++) {
    s[i] = s[i - 1] + a[i];
    ss[i] = ss[i - 1] + s[i];
  }
  long long ans = 0;
  for (i = n; i >= 1; i--) {
    ans = max(ans, (long long)a[i]);
    while (tot > 1 && (que[tot - 1] - make_pair(i, ss[i])) >
                          (que[tot - 2] - que[tot - 1])) {
      tot--;
    }
    que[tot++] = make_pair(i, ss[i]);
    if (tot == 1) {
      continue;
    }
    int le = 0, ri = tot - 2;
    int mid;
    while (le <= ri) {
      mid = (le + ri) / 2;
      double x = (que[mid].second - que[mid + 1].second) * 1.0 /
                 (que[mid].first - que[mid + 1].first);
      if (x >= s[i - 1]) {
        ri = mid - 1;
      } else
        le = mid + 1;
    }
    ans = max(ans,
              que[le].second - ss[i - 1] - (que[le].first - i + 1) * s[i - 1]);
  }
  cout << ans << endl;
}
