#include <bits/stdc++.h>
const int maxn = 2e5 + 10;
int N;
int A[maxn];
long long Q[maxn];
long long sum1[maxn];
long long sum2[maxn];
double X(int i) { return i; }
double Y(int i) { return i * sum1[i] - sum2[i]; };
double slope(int i, int j) { return (Y(i) - Y(j)) / (X(i) - X(j)); }
long long Calc(int i, int j) {
  return sum2[j] - sum2[i] - 1ll * i * (sum1[j] - sum1[i]);
}
int main() {
  scanf("%d", &N);
  for (register int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
    sum1[i] = sum1[i - 1] + A[i];
    sum2[i] = sum2[i - 1] + 1ll * A[i] * i;
  }
  int tail = 0;
  long long Ans = 0;
  for (register int j = 1; j <= N; j++) {
    long long k = sum1[j];
    int l = 0, r = tail;
    while (l < r) {
      int mid = l + r >> 1;
      if (slope(Q[mid], Q[mid + 1]) > k)
        l = mid + 1;
      else
        r = mid;
    }
    int i = Q[r];
    Ans = std::max(Ans, Calc(i, j));
    while (tail >= 1 && slope(Q[tail], Q[tail - 1]) < slope(Q[tail], j)) tail--;
    Q[++tail] = j;
  }
  printf("%I64d\n", Ans);
  return 0;
}
