#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long INF = 1e18 + 7;
long long A[N];
long long S[N], P[N];
long long M[N], C[N];
double pp[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    S[i] = A[i] + S[i - 1];
    P[i] = i * A[i] + P[i - 1];
  }
  long long ans = 0;
  int k = 0;
  M[++k] = 0;
  C[k] = -P[0];
  pp[k] = -INF;
  for (int i = 1; i <= n; i++) {
    int p = lower_bound(pp + 1, pp + k + 1, -S[i]) - pp - 1;
    ans = max(ans, -M[p] * S[i] + C[p] + P[i]);
    M[++k] = i;
    C[k] = i * S[i] - P[i];
    pp[k] = (double)(C[k] - C[k - 1]) / (M[k - 1] - M[k]);
    while (k >= 3 &&
           (double)(C[k] - C[k - 2]) / (M[k - 2] - M[k]) <=
               (double)(C[k - 1] - C[k - 2]) / (M[k - 2] - M[k - 1])) {
      M[k - 1] = M[k];
      C[k - 1] = C[k];
      k--;
      pp[k] = (double)(C[k] - C[k - 1]) / (M[k - 1] - M[k]);
    }
  }
  cout << ans << "\n";
  return 0;
}
