#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 200000;
int n;
int x[MAXN];
long long sum[MAXN + 1];
long long psum[MAXN + 1];
int m;
int a[MAXN];
long long b[MAXN];
long long cmp(long long a, long long b, long long c, long long d) {
  if (a < 0 && c < 0) return cmp(-c, d, -a, b);
  if (a < 0) return -1;
  if (c < 0) return +1;
  while (true) {
    long long diff = a / b - c / d;
    if (diff != 0) return diff;
    a %= b;
    c %= d;
    if (a == 0 || c == 0) return a - c;
    swap(a, d);
    swap(b, c);
  }
}
void add(int aa, long long bb) {
  while (m >= 2 && cmp(bb - b[m - 1], a[m - 1] - aa, b[m - 1] - b[m - 2],
                       a[m - 2] - a[m - 1]) >= 0)
    --m;
  a[m] = aa, b[m] = bb, ++m;
}
long long solve(long long x) {
  int l = -1, h = m - 1;
  while (l + 1 < h) {
    int mid = l + (h - l) / 2;
    if (cmp(x, 1, b[mid + 1] - b[mid], a[mid] - a[mid + 1]) >= 0)
      h = mid;
    else
      l = mid;
  }
  long long ret = a[h] * x + b[h];
  return ret;
}
void run() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) scanf("%d", &x[i]);
  sum[0] = 0;
  for (int i = (0); i < (n); ++i) sum[i + 1] = sum[i] + x[i];
  psum[0] = 0;
  for (int i = (0); i < (n); ++i)
    psum[i + 1] = psum[i] + (long long)(i + 1) * x[i];
  long long ret = 0;
  m = 0;
  for (int i = (0); i < (n); ++i) {
    add(-i, i * sum[i] - psum[i]);
    long long cur = psum[i + 1] + solve(sum[i + 1]);
    if (cur > ret) ret = cur;
  }
  printf("%I64d\n", ret);
}
int main() {
  run();
  return 0;
}
