#include <bits/stdc++.h>
using namespace std;
template <class T>
using vec = vector<T>;
template <typename Iter>
ostream &_IterOutput_(ostream &o, Iter b, Iter e, const string ss = "",
                      const string se = "") {
  o << ss;
  for (auto it = b; it != e; it++) o << (it == b ? "" : ", ") << *it;
  return o << se;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &o, pair<T1, T2> &pair) {
  return o << "(" << pair.first << ", " << pair.second << ")";
}
template <typename T>
ostream &operator<<(ostream &o, const vector<T> &vec) {
  return _IterOutput_(o, begin(vec), end(vec), "[", "]");
}
template <typename T>
ostream &operator<<(ostream &o, const set<T> &st) {
  return _IterOutput_(o, begin(st), end(st), "{", "}");
}
template <typename T, size_t N>
ostream &operator<<(ostream &o, const array<T, N> &arr) {
  return _IterOutput_(o, begin(arr), end(arr), "|", "|");
}
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const map<T1, T2> &mp) {
  o << "{";
  for (auto it = mp.begin(); it != mp.end(); it++) {
    o << (it == mp.begin() ? "" : ", ") << it->first << ":" << it->second;
  }
  o << "}";
  return o;
}
const long long MX = 212345;
struct Deque {
  long long v[MX * 4];
  long long hd, tl;
  void clear() { hd = tl = 0; }
  void push_back(long long a) { v[tl++] = a; }
  void pop_back() { tl--; }
  void pop_front() { hd++; }
  long long size() { return tl - hd; }
  long long &operator[](long long a) {
    if (a < 0) return v[tl + a];
    return v[hd + a];
  }
  friend ostream &operator<<(ostream &o, Deque &dq) {
    cout << "[";
    for (long long i = dq.hd; i < dq.tl; i++)
      o << dq.v[i] << ",]"[i == dq.tl - 1];
    return o;
  }
} dq;
long long ip[MX];
long long sm[MX], ism[MX];
long long A[MX], B[MX];
using pii = pair<long long, long long>;
long long over(long long i, long long j, long long x) {
  assert(i > j);
  return (A[j] - A[i]) * x <= (B[i] - B[j]);
}
double pt(long long i, long long j) {
  return 1.0 * (B[j] - B[i]) / (A[i] - A[j]);
}
bool better(long long o, long long i, long long j) {
  bool res = (A[o] - A[i]) * (B[j] - B[o]) <= (A[o] - A[j]) * (B[i] - B[o]);
  return res;
}
long long getp(long long i) {
  long long sz = ((long long)(dq).size());
  long long tar = sm[i];
  long long l = 0, r = sz - 1;
  while (l < r) {
    long long md = (l + r) / 2;
    bool res;
    if (md == sz - 1) {
      res = true;
    } else {
      long long mx = dq[md], my = dq[md + 1];
      res = over(my, mx, tar);
    }
    if (!res) {
      r = md;
    } else
      l = md + 1;
  }
  return dq[l];
}
long long dp[MX];
long long cost(long long x, long long i) {
  return ism[i] - ism[x] - (x)*sm[i] + (x)*sm[x];
}
int32_t main() {
  do {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  } while (0);
  long long N;
  cin >> N;
  for (long long i = 1; i <= N; i++) cin >> ip[i];
  for (long long i = 1; i <= N; i++) {
    sm[i] = sm[i - 1] + ip[i];
    ism[i] = ism[i - 1] + i * ip[i];
  }
  for (long long i = 0; i <= N; i++) {
    A[i] = -(i);
    B[i] = -ism[i] + (i)*sm[i];
  }
  dq.push_back(0);
  long long ans = 0;
  for (long long i = 1; i <= N; i++) {
    long long x = getp(i);
    dp[i] = ism[i] - ism[x] - (x)*sm[i] + (x)*sm[x];
    ans = max(ans, dp[i]);
    while (((long long)(dq).size()) >= 2) {
      if (better(dq[-2], i, dq[-1]))
        dq.pop_back();
      else
        break;
    }
    dq.push_back(i);
  }
  cout << ans << endl;
  return 0;
}
