#include <bits/stdc++.h>
using namespace std;
bool solve(int);
int main() {
  int test = 0;
  while (solve(test++))
    ;
  return 0;
}
const int N = 100 * 1000 + 5;
const int S = 350;
int n, a[N];
int x[N], pos[N];
long long dts[N], dt[N];
vector<int> sq[N], o[N];
bool cmp(const int i, const int j) {
  if (a[i] != a[j]) return a[i] < a[j];
  if (dt[i] != dt[j]) return dt[i] > dt[j];
  return i < j;
}
long long div_down(long long a, long long b);
long long div_up(long long a, long long b) {
  if (b < 0) return div_down(-a, -b);
  if (a < 0) return -div_down(-a, b);
  return (a + b - 1) / b;
}
long long div_down(long long a, long long b) {
  if (b < 0) return div_up(-a, -b);
  if (a < 0) return -div_up(-a, b);
  return a / b;
}
long long cross(long long a1, long long b1, long long a2, long long b2) {
  assert(a1 != a2);
  return div_up(b2 - b1, a1 - a2);
}
long long val(int i, long long x) { return a[i] * x + dt[i] + dts[i / S]; }
long long move(int id) {
  if (int(sq[id].size()) == 0) return -1;
  while (pos[id] + 1 < int(sq[id].size()) &&
         make_pair(val(sq[id][pos[id]], x[id]), -sq[id][pos[id]]) <
             make_pair(val(sq[id][pos[id] + 1], x[id]), -sq[id][pos[id] + 1]))
    ++pos[id];
  return val(sq[id][pos[id]], x[id]);
}
bool used[N];
void build(int id) {
  int l = id * S, r = min(n, (id + 1) * S) - 1;
  if (int(o[id].size()) == 0) {
    for (int i = l; i <= r; ++i) o[id].push_back(i);
  }
  assert(dts[id] == 0);
  assert(int(o[id].size()) > 0);
  sort(o[id].begin(), o[id].end(), cmp);
  stack<int> st;
  for (int i = 0; i < int(int(o[id].size())); ++i) {
    int t = o[id][i];
    if (used[t]) continue;
    while (int(st.size()) >= 2) {
      int s = st.top();
      st.pop();
      int r = st.top();
      if (a[s] == a[t]) {
        if (make_pair(dt[t], -t) > make_pair(dt[s], -s)) continue;
        st.push(s);
        break;
      }
      long long rs = cross(a[r], dt[r], a[s], dt[s]);
      long long rt = cross(a[r], dt[r], a[t], dt[t]);
      if (rt >= rs) {
        st.push(s);
        break;
      }
    }
    if (st.empty() || a[st.top()] != a[t]) st.push(t);
  }
  sq[id] = vector<int>();
  while (!st.empty()) sq[id].push_back(st.top()), st.pop();
  reverse(sq[id].begin(), sq[id].end());
  pos[id] = 0;
  move(id);
}
bool solve(int) {
  if (scanf("%d", &n) != 1) return false;
  for (int i = 0; i < int(n); ++i) scanf("%d", &a[i]);
  int bc = (n + S - 1) / S;
  for (int i = 0; i < int(bc); ++i) {
    x[i] = 1;
    build(i);
  }
  long long res = 0, cur = 0;
  for (int _ = 0; _ < int(n); ++_) {
    long long v = -1e18;
    int w = -1;
    for (int i = 0; i < int(bc); ++i) {
      if (int(sq[i].size()) && move(i) > v) {
        v = move(i);
        w = sq[i][pos[i]];
      }
    }
    assert(w != -1);
    cur += v;
    res = max(res, cur);
    assert(!used[w]);
    used[w] = true;
    int wb = w / S;
    for (int i = 0; i < int(wb); ++i) dts[i] += a[w];
    for (int i = wb + 1; i < bc; ++i) {
      x[i]++;
      move(i);
    }
    int l = wb * S;
    int r = min(n, l + S) - 1;
    for (int i = l; i <= r; ++i) dt[i] += dts[wb];
    dts[wb] = 0;
    for (int i = l; i < w; ++i) dt[i] += a[w];
    for (int i = w + 1; i <= r; ++i) dt[i] += a[i];
    build(wb);
  }
  cout << res << endl;
  return true;
}
