#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000 + 10;
long long sum[MAXN], pre[MAXN];
int a[MAXN], cnt, N;
long long ans;
long long x[MAXN], y[MAXN], total;
inline long long calc(long long a, long long d, long long b, long long c) {
  return a - b * d + c;
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) scanf("%d", &a[i]);
  ans = 0;
  for (int i = 1; i <= N; ++i) {
    pre[i] = pre[i - 1];
    pre[i] += (long long)i * (long long)a[i];
    sum[i] = sum[i - 1];
    sum[i] += (long long)a[i];
    ans = max(ans, pre[i]);
    {
      ans = max(ans, calc(pre[i], sum[i], x[cnt], y[cnt]));
      int l = 1, r = cnt - 1;
      while (l <= r) {
        int mid = (l + r) / 2;
        ans = max(ans, calc(pre[i], sum[i], x[mid], y[mid]));
        if ((y[mid + 1] - y[mid]) >= sum[i] * (x[mid + 1] - x[mid])) {
          l = mid + 1;
        } else
          r = mid - 1;
      }
    }
    long long delta = sum[i] * (long long)i - pre[i];
    long long k = i;
    long long tx1, tx2, ty1, ty2;
    while (cnt > 1) {
      tx1 = x[cnt] - x[cnt - 1];
      ty1 = y[cnt] - y[cnt - 1];
      tx2 = k - x[cnt - 1];
      ty2 = delta - y[cnt - 1];
      if (tx1 * ty2 - tx2 * ty1 >= 0)
        --cnt;
      else
        break;
    }
    ++cnt;
    x[cnt] = k;
    y[cnt] = delta;
  }
  cout << ans << endl;
  return 0;
}
