#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
const long double eps = 1e-8;
const long double INF = 1e30;
long long s[maxn], sum[maxn], f[maxn];
long long a[maxn];
int n;
struct node {
  int id;
  long double k;
  node(int _id = 0, long double _k = 0) {
    id = _id;
    k = _k;
  }
  bool operator<(const node b) const { return k > b.k; }
};
node st[maxn];
int stn;
void solve() {
  sum[0] = 0;
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + a[i];
  }
  s[0] = 0;
  for (int i = 1; i <= n; i++) {
    s[i] = s[i - 1] + (long long)i * a[i];
  }
  long long ans = 0;
  stn = 1;
  st[0] = node(0, INF);
  for (int i = 1; i <= n; i++) {
    int pos =
        upper_bound(st, st + stn, node(0, (long double)sum[i] - eps)) - st;
    pos--;
    int key = st[pos].id;
    f[i] = s[i] - s[key] - key * sum[i] + key * sum[key];
    ans = max(ans, f[i]);
    while (stn > 1) {
      long long xc = i, yc = i * sum[i] - s[i];
      int tmp = st[stn - 1].id;
      long long xb = tmp, yb = tmp * sum[tmp] - s[tmp];
      tmp = st[stn - 2].id;
      long long xa = tmp, ya = tmp * sum[tmp] - s[tmp];
      if (((long double)yc - (long double)yb) /
              ((long double)xc - (long double)xb) >=
          ((long double)yb - (long double)ya) /
              ((long double)xb - (long double)xa)) {
        stn--;
      } else {
        break;
      }
    }
    long long xc = i, yc = i * sum[i] - s[i];
    int tmp = st[stn - 1].id;
    long long xb = tmp, yb = tmp * sum[tmp] - s[tmp];
    st[stn] = node(i, ((long double)yc - (long double)yb) /
                          ((long double)xc - (long double)xb));
    stn++;
  }
  printf("%I64d\n", ans);
}
int main() {
  while (scanf("%d", &n) != EOF) {
    for (int i = 1; i <= n; i++) {
      scanf("%I64d\n", &a[i]);
    }
    solve();
  }
  return 0;
}
