#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const long double eps = 1e-10;
int rd() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * w;
}
struct line {
  long double k, b;
} stk[N], nl;
int n, tp;
long double a[N], ans, sm;
int main() {
  n = rd();
  for (int i = 1; i <= n; ++i) a[i] = rd();
  stk[++tp] = (line){0, 0};
  for (int i = 1; i <= n; ++i) {
    sm += 1ll * a[i] * i;
    a[i] += a[i - 1];
    int l = 1, r = tp - 1;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if ((stk[mid].b - stk[mid + 1].b) / (stk[mid + 1].k - stk[mid].k) >
          a[i] - eps)
        l = mid + 1;
      else
        r = mid - 1;
    }
    ans = max(ans, sm - (stk[l].k * a[i] + stk[l].b));
    nl = (line){(long double)i, sm - a[i] * (long double)i};
    while (tp > 1 &&
           (nl.b - stk[tp].b) / (stk[tp].k - nl.k) >
               (stk[tp].b - stk[tp - 1].b) / (stk[tp - 1].k - stk[tp].k) - eps)
      --tp;
    stk[++tp] = nl;
  }
  printf("%.0Lf\n", ans);
  return 0;
}
