#include <bits/stdc++.h>
int inp() {
  char c = getchar();
  int neg = 1;
  while (c < '0' || c > '9') {
    if (c == '-') neg = -1;
    c = getchar();
  }
  int sum = 0;
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum * neg;
}
long long a[100010];
struct FHQ_Treap {
  struct T {
    int lc;
    int rc;
    long long v;
    long long sum;
    long long lazy;
    int w;
    int size;
  } t[100010];
  int rt, cnt;
  void init() {
    rt = 0;
    cnt = 0;
    t[0].lc = t[0].rc = t[0].sum = t[0].lazy = t[0].size = 0;
  }
  void push_up(int cur) {
    t[cur].size = t[t[cur].lc].size + t[t[cur].rc].size + 1;
    t[cur].sum = t[t[cur].lc].sum + t[t[cur].rc].sum + t[cur].v;
  }
  void push_down(int cur) {
    t[t[cur].lc].lazy += t[cur].lazy;
    t[t[cur].lc].sum += t[cur].lazy * t[t[cur].lc].size;
    t[t[cur].lc].v += t[cur].lazy;
    t[t[cur].rc].lazy += t[cur].lazy;
    t[t[cur].rc].sum += t[cur].lazy * t[t[cur].rc].size;
    t[t[cur].rc].v += t[cur].lazy;
    t[cur].lazy = 0;
  }
  int merge(int a, int b) {
    if (!a || !b) return a + b;
    push_down(a);
    push_down(b);
    if (t[a].w < t[b].w) {
      t[a].rc = merge(t[a].rc, b);
      push_up(a);
      return a;
    } else {
      t[b].lc = merge(a, t[b].lc);
      push_up(b);
      return b;
    }
  }
  void split(int cur, int &a, int &b, int k) {
    if (!cur) {
      a = b = 0;
      return;
    }
    push_down(cur);
    if (t[t[cur].lc].size < k) {
      a = cur;
      split(t[cur].rc, t[a].rc, b, k - t[t[cur].lc].size - 1);
      push_up(a);
    } else {
      b = cur;
      split(t[cur].lc, a, t[b].lc, k);
      push_up(b);
    }
  }
  long long getval(int pos) {
    int a, b;
    split(rt, a, b, pos + 1);
    long long ret = t[a].sum;
    rt = merge(a, b);
    return ret;
  }
  void add(int pos, long long val) {
    int a, b;
    split(rt, a, b, pos);
    t[++cnt] = (T){0, 0, val * pos, val * pos, 0, rand(), 1};
    t[b].lazy += val;
    t[b].v += val;
    t[b].sum += val * t[b].size;
    rt = merge(merge(a, cnt), b);
  }
} t;
int main() {
  t.init();
  int n = inp();
  for (int i = 1; i <= n; i++) a[i] = inp();
  t.add(0, 0);
  for (int i = 1; i <= n; i++) {
    int l = 0;
    int r = i;
    while (l < r) {
      int mid = (l + r) >> 1;
      if (t.getval(mid) <= t.getval(mid - 1) + (a[i] * mid))
        r = mid;
      else
        l = mid + 1;
    }
    t.add(l, a[i]);
  }
  long long ans = -1e18;
  for (int i = 0; i <= n; i++) ans = std::max(ans, t.getval(i));
  printf("%lld\n", ans);
}
