#include <bits/stdc++.h>
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,popcnt")
using namespace std;
int stk[400010], n, top = 0;
long long a[400010], s[400010], f[400010];
const long long INF = 1LL << 60;
template <class T>
void read(T &x) {
  char ch = x = 0;
  bool fl = false;
  while (!isdigit(ch)) fl |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  x = fl ? -x : x;
}
long long calc(int x, int y) { return f[x] + s[y] - a[y] * x; }
long long crs(int x, int y, int std) {
  return 1LL * (x - std) * (f[y] - f[std]) - 1LL * (f[x] - f[std]) * (y - std);
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++)
    read(a[i]), s[i] = s[i - 1] + a[i] * i, a[i] += a[i - 1];
  for (int i = 1; i <= n; i++) f[i] = a[i] * i - s[i];
  long long ans = 0;
  stk[top = 1] = 0;
  for (int i = 1; i <= n; i++) {
    int l = 1, r = top;
    while (l + 10 < r) {
      int mid1 = (l * 2 + r) / 3, mid2 = (l + r * 2) / 3;
      if (calc(stk[mid1], i) <= calc(stk[mid2], i))
        l = mid1;
      else
        r = mid2;
    }
    for (int j = l; j <= r; j++) ans = max(ans, calc(stk[j], i));
    while (top >= 2 && crs(stk[top], i, stk[top - 1]) >= 0) top--;
    stk[++top] = i;
  }
  printf("%lld\n", ans);
  return 0;
}
