#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 50;
int a[MAXN], N;
bool flag[MAXN];
long long s[MAXN], res;
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &a[i]);
    flag[i] = 1;
    res += (long long)a[i] * i;
    s[i] = s[i - 1] + a[i];
  }
  for (int i = 0; i < 20; ++i) {
    int k(1);
    long long now(0);
    for (int j = 1; j <= N; ++j) {
      if (flag[j] && (long long)a[j] * k + s[N] - s[j] < 0)
        flag[j] = 0;
      else if (!flag[j] && (long long)a[j] * k + s[N] - s[j] >= 0)
        flag[j] = 1;
      if (flag[j]) {
        s[j] = s[j - 1] + a[j];
        now += (long long)a[j] * k;
        ++k;
      } else
        s[j] = s[j - 1];
    }
    res = max(res, now);
  }
  cout << res << endl;
}
