#include <bits/stdc++.h>
using namespace std;
const int Maxn = 2e5 + 5;
const long long Maxk = 2e12 + 5;
const long long INF = 2e18;
class line {
 public:
  long long k, b;
  bool operator<(const line &o) const {
    return k < o.k || (k == o.k && b < o.b);
  }
  bool operator==(const line &o) const { return k == o.k && b == o.b; }
};
set<line> ss;
int n;
int a[Maxn];
long long s1[Maxn], s2[Maxn];
long long ans = 0, temp;
bool check(line l1, line l2, line l3) {
  double d =
      1.0 * (l3.k - l1.k) * (l2.b - l1.b) - 1.0 * (l2.k - l1.k) * (l3.b - l1.b);
  if (d <= 0) return true;
  return false;
}
void insert(line o) {
  if (ss.size() < 2) {
    ss.insert(o);
    return;
  }
  set<line>::iterator r = ss.lower_bound(o), l = r, t;
  if (l == ss.begin() || r == ss.end()) {
    ss.insert(o);
    if (l != ss.begin()) l--;
  } else {
    l--;
    if (check(*l, o, *r)) return;
    ss.insert(o);
  }
  if (l != ss.begin()) {
    t = l--;
    while (l != ss.begin()) {
      if (check(*l, *t, o))
        ss.erase(t);
      else
        break;
      t = l--;
    }
  }
  if (r != ss.end()) {
    t = r++;
    while (r != ss.end()) {
      if (check(o, *t, *r))
        ss.erase(t);
      else
        break;
      t = r++;
    }
  }
}
long long gety(line o, int x) { return o.k * x + o.b; }
long long calc(int x) {
  set<line>::iterator it;
  long long lb = -Maxk, ub = Maxk, mi;
  while (ub - lb > 1) {
    mi = (ub + lb) >> 1;
    it = ss.lower_bound(line{mi, INF});
    if (it == ss.end())
      ub = mi;
    else if (it == ss.begin())
      lb = mi;
    else if (gety(*prev(it), x) > gety(*it, x))
      ub = mi;
    else
      lb = mi;
  }
  it = ss.lower_bound(line{lb, INF});
  return gety(*it, x);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    s1[i] = s1[i - 1] + a[i];
    s2[i] = s2[i - 1] + (long long)i * a[i];
  }
  ss.insert(line{-Maxk, -INF});
  ss.insert(line{Maxk, -INF});
  for (int i = n - 1; i >= 0; i--) {
    temp = (long long)i * s1[i] - s2[i];
    insert(line{-s1[i + 1], s2[i + 1]});
    ans = max(ans, temp + calc(i));
  }
  printf("%I64d\n", ans);
  return 0;
}
