#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long B = 1e18;
long long arr[200009], cof[200009], par[200009];
struct CHT {
  vector<long long> m, b;
  CHT() {
    m.clear();
    b.clear();
  }
  long long intersection(long long l1, long long l2) {
    return (b[l2] - b[l1]) / (m[l1] - m[l2]);
  }
  void upd(long long x, long long y) {
    m.push_back(x);
    b.push_back(y);
    while (m.size() >= 3 and intersection(m.size() - 2, m.size() - 3) >=
                                 intersection(m.size() - 3, m.size() - 1)) {
      m.erase(m.end() - 2);
      b.erase(b.end() - 2);
    }
  }
  long long tap(long long x) {
    long long st = 0, en = m.size() - 1;
    while (st < en) {
      long long mid = (st + en) >> 1;
      if (intersection(mid, mid + 1) <= x)
        st = mid + 1;
      else
        en = mid;
    }
    return m[st] * x + b[st];
  }
} S;
int main() {
  long long a;
  scanf("%lld", &a);
  for (long long i = 1; i <= a; i++) {
    scanf("%lld", arr + i);
    par[i] = par[i - 1] + arr[i];
    cof[i] = cof[i - 1] + arr[i] * i;
  }
  long long ans = 0;
  for (long long i = 1; i <= a; i++) {
    S.upd(i - 1, -(cof[i - 1] - (i - 1) * par[i - 1]));
    umax(ans, cof[i] + S.tap(-par[i]));
  }
  printf("%lld\n", ans);
  return 0;
}
