#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1.0);
const int N = 200020;
int n;
long long sum[N], mul[N];
int q[N], t;
inline long long Y(int j, int k) {
  return j * sum[j] - mul[j] - k * sum[k] + mul[k];
}
inline long long X(int j, int k) { return j - k; }
long long work() {
  long long ans = -1e18;
  t = 1, q[t - 1] = 0;
  for (int i = 1; i <= n; i++) {
    while (t > 1 && Y(i, q[t - 1]) * X(q[t - 1], q[t - 2]) >=
                        Y(q[t - 1], q[t - 2]) * X(i, q[t - 1]))
      t--;
    q[t++] = i;
    int l = 0, r = t - 1;
    while (l < r) {
      int mid = (l + r) >> 1;
      if (Y(q[mid + 1], q[mid]) <= X(q[mid + 1], q[mid]) * sum[i])
        r = mid;
      else
        l = mid + 1;
    }
    ans = max(ans, mul[i] + q[r] * sum[q[r]] - mul[q[r]] - sum[i] * q[r]);
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int u;
    scanf("%d", &u);
    sum[i] = sum[i - 1] + u;
    mul[i] = mul[i - 1] + (long long)u * i;
  }
  printf("%lld\n", work());
  return 0;
}
