#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int64_t INF = INT64_MAX;
const long long MAXN = 2e5 + 7;
long long n;
long long ara[MAXN], pre[MAXN], sum[MAXN];
vector<long long> M, C;
bool bad(long long f1, long long f2, long long f3) {
  return __int128(C[f3] - C[f1]) * (M[f1] - M[f2]) <
         __int128(C[f2] - C[f1]) * (M[f1] - M[f3]);
}
long long f(long long x, long long i) { return M[i] * x + C[i]; }
void insert(long long m, long long c) {
  M.push_back(m), C.push_back(c);
  long long sz = M.size();
  while (sz >= 3 && bad(sz - 1, sz - 2, sz - 3)) {
    M.erase(M.end() - 2);
    C.erase(C.end() - 2);
    sz--;
  }
}
long long query(long long x) {
  long long L = 0, R = M.size() - 1;
  long long ans = -INF;
  while (L <= R) {
    long long mid1 = (L + L + R) / 3;
    long long mid2 = (L + R + R) / 3;
    long long y1 = f(x, mid1), y2 = f(x, mid2);
    if (y1 > y2)
      ans = max(ans, y1), R = mid2 - 1;
    else
      ans = max(ans, y2), L = mid1 + 1;
  }
  return ans;
}
int32_t main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> ara[i];
    pre[i] = pre[i - 1] + ara[i];
    sum[i] = sum[i - 1] + i * ara[i];
  }
  long long ans = 0;
  insert(0, 0);
  for (long long r = 1; r <= n; r++) {
    ans = max(ans, query(pre[r]) + sum[r]);
    insert(-r, r * pre[r] - sum[r]);
  }
  cout << ans;
  return 0;
}
