#include <bits/stdc++.h>
using namespace std;
const int N = 400400;
int n, i;
long long tmp, ans;
long long f[N], g[N];
int a[N];
struct Line {
  long long k, b;
  Line() {}
  Line(long long k1, long long k2) : k(k1), b(k2) {}
};
inline long long eval(Line a, long long q) { return a.k * q + a.b; }
vector<Line> ch;
inline bool bad(Line a, Line b, Line c) {
  return (a.k - c.k) * (a.b - b.b) <= (a.b - c.b) * (a.k - b.k);
}
inline void add_line(Line a) {
  ch.push_back(a);
  while ((int)ch.size() > 2 &&
         bad(ch[(int)ch.size() - 2], ch[(int)ch.size() - 3], ch.back())) {
    Line J = ch.back();
    ch.pop_back();
    ch.pop_back();
    ch.push_back(J);
  }
}
inline long long find_best(long long e) {
  assert(!ch.empty());
  long long ret = -(long long)9e18;
  int l = 0, r = (int)ch.size() - 1;
  for (int iter = 0; iter < 100; iter++) {
    int m0 = (l + r) / 2;
    long long f0 = eval(ch[m0], e);
    ret = max(ret, f0);
    if (m0 + 1 < (int)ch.size()) {
      long long f1 = eval(ch[m0 + 1], e);
      ret = max(ret, f1);
      if (f1 >= f0) {
        l = m0 + 1;
      } else {
        r = m0;
      }
    }
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    f[i] = f[i - 1] + a[i];
    g[i] = g[i - 1] + 1ll * i * a[i];
  }
  for (int i = 1; i <= n; i++) {
    add_line(Line(1 - i, 1ll * (i - 1) * f[i - 1] - g[i - 1]));
    tmp = g[i] + find_best(f[i]);
    ans = max(ans, tmp);
  }
  cout << ans;
  return 0;
}
