#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target( \
    "avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const double EPS = 1e-8;
const double Pi = acos(-1);
bool inline equ(double a, double b) { return fabs(a - b) < EPS; }
int _R(int &x) { return scanf("%d", &x); }
int _R(long long &x) { return scanf("%" PRId64, &x); }
int _R(double &x) { return scanf("%lf", &x); }
int _R(char *s) { return scanf("%s", s); }
int _R(char c) { return scanf("%c", &c); }
int R() { return 0; }
template <typename T, typename... U>
int R(T &x, U &...tail) {
  return _R(x) + R(tail...);
}
template <class T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T>
void _W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); _W(*i++))
    if (i != x.cbegin()) putchar(' ');
}
void W() {}
template <class T, class... U>
void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
const int N = 2e5 + 10;
struct Line {
  long long m, b;
  inline long long operator()(long long x) { return m * x + b; }
  inline double operator%(Line r) { return 1. * (r.b - b) / (m - r.m); }
};
int n;
long long a[N], s[N], S[N];
int main() {
  R(n);
  for (int i = (1); i <= (n); i++) {
    R(a[i]);
    s[i] = a[i] + s[i - 1];
    S[i] = i * a[i] + S[i - 1];
  }
  long long ans = 0;
  vector<Line> stk{{0, 0}};
  for (int i = (1); i <= (n); i++) {
    Line ln{-i, -S[i] + i * s[i]};
    while ((int)(stk).size() >= 2 and
           stk[(int)(stk).size() - 2] % stk.back() < stk.back() % ln)
      stk.pop_back();
    stk.push_back(ln);
    int l = 0, r = (int)(stk).size() - 2, prv = (int)(stk).size() - 1;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (stk[mid] % stk[mid + 1] <= s[i]) {
        prv = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    long long tmp = stk[prv](s[i]) + S[i];
    ans = max(ans, tmp);
  }
  W(ans);
}
