#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  int f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
  return x * f;
}
void print(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int N = 210000;
int n;
long long a[N], sum[N], sum2[N], ans;
int q[N], tail;
long long Y(int j) { return sum[j] * j - sum2[j]; }
long long X(int j) { return j; }
double slope(int i, int j) { return (double)(Y(i) - Y(j)) / (X(i) - X(j)); }
long long calc(int i, int j) {
  return sum2[i] - sum2[j] - (sum[i] - sum[j]) * j;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + (a[i] = read());
  for (int i = 1; i <= n; i++) sum2[i] = sum2[i - 1] + a[i] * i;
  for (int i = 1; i <= n; i++) {
    int l = 0, r = tail, res = tail;
    while (l <= r) {
      int mid = l + r >> 1;
      if (calc(i, q[mid]) >= calc(i, q[mid - 1]))
        res = mid, l = mid + 1;
      else
        r = mid - 1;
    }
    int j = q[res];
    ans = max(ans, calc(i, j));
    while (tail && slope(q[tail], q[tail - 1]) < slope(q[tail], i)) tail--;
    q[++tail] = i;
  }
  print(ans), putchar('\n');
}
