#include <bits/stdc++.h>
using namespace std;
bool check(long long n, long long pos) { return n & (1LL << pos); }
long long Set(long long n, long long pos) { return n = n | (1LL << pos); }
struct line {
  long long m, c;
  line(long long x, long long y) {
    m = x;
    c = y;
  }
};
struct CHT {
  vector<line> vec;
  long long t;
  void init(long long x) {
    t = x;
    vec.clear();
  }
  long long func(long long idx, long long x) {
    long long ret = vec[idx].m * x + vec[idx].c;
    return ret;
  }
  bool bad(line f1, line f2, line f3) {
    __int128 a = (f3.c - f1.c);
    a = a * (f1.m - f2.m);
    __int128 b = (f2.c - f1.c);
    b = b * (f1.m - f3.m);
    if (t == 1) return a <= b;
    if (t == 2) return a >= b;
    if (t == 3) return a >= b;
    if (t == 4) return a <= b;
    assert(0);
  }
  void add(line x) {
    long long sz = vec.size();
    while (sz >= 2 && bad(vec[sz - 2], vec[sz - 1], x)) {
      vec.pop_back();
      sz--;
    }
    vec.push_back(x);
  }
  long long ask(long long x) {
    if (vec.empty()) {
      add(line(0, 0));
    }
    long long lo = 0;
    long long hi = vec.size() - 1;
    long long ret = (t & 1) ? LLONG_MAX : -LLONG_MAX;
    while (lo <= hi) {
      long long mid1 = (lo + (hi - lo) / 3);
      long long mid2 = (hi - (hi - lo) / 3);
      long long ans1 = func(mid1, x);
      long long ans2 = func(mid2, x);
      if (ans1 > ans2) {
        if (t & 1) {
          ret = min(ret, ans2);
          lo = mid1 + 1;
        } else {
          ret = max(ret, ans1);
          hi = mid2 - 1;
        }
      } else {
        if (t & 1) {
          ret = min(ret, ans1);
          hi = mid2 - 1;
        } else {
          ret = max(ret, ans2);
          lo = mid1 + 1;
        }
      }
    }
    return ret;
  }
};
long long arr[200005];
long long xx[200005];
long long yy[200005];
int main() {
  long long i, j, k, l, m, n, o, r, q;
  long long testcase;
  long long input, flag, tag, ans;
  while (cin >> n) {
    for (long long i = 1; i <= n; i++) scanf("%lld", &arr[i]);
    for (long long i = 1; i <= n; i++) {
      xx[i] = arr[i] + xx[i - 1];
      yy[i] = (i * arr[i]) + yy[i - 1];
    }
    CHT cht;
    cht.init(2);
    ans = 0;
    for (long long i = 1; i <= n; i++) {
      ans = max(ans, cht.ask(xx[i]) + yy[i]);
      cht.add(line(-i, i * xx[i] - yy[i]));
    }
    printf("%lld\n", ans);
  }
}
