#include <bits/stdc++.h>
using namespace std;
long long Pow(long long a, long long b, long long MOD) {
  a %= MOD;
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % MOD;
    b /= 2;
    a = (a * a) % MOD;
  }
  return res;
}
const int maxn = 200000 + 10;
const int MOD = 1e9 + 7;
long long val[maxn];
long long sum[maxn], p[maxn];
int st[maxn], Size;
long long second(int id) { return p[id] - sum[id] * id; }
double G(int x, int y) { return 1.0 * (second(x) - second(y)) / (x - y); }
int solve(long long x) {
  int l = 0, r = Size - 1, res = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (G(st[mid], st[mid - 1]) < -x) {
      res = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return st[res];
}
int main() {
  int i, j, n;
  scanf("%d", &n);
  sum[0] = 0;
  p[0] = 0;
  for (i = 1; i <= n; i++) {
    scanf("%I64d", &val[i]);
    sum[i] = sum[i - 1] + val[i];
    p[i] = p[i - 1] + val[i] * i;
  }
  Size = 0;
  st[Size++] = 0;
  long long res = 0;
  for (i = 1; i <= n; i++) {
    if (i == 1)
      res = max(res, val[i]);
    else {
      int pos = solve(sum[i]);
      res = max(res, p[i] - p[pos] - (sum[i] - sum[pos]) * pos);
    }
    while (Size >= 2 && G(i, st[Size - 1]) < G(st[Size - 1], st[Size - 2]))
      Size--;
    st[Size++] = i;
  }
  printf("%I64d\n", (res));
  return 0;
}
