#include <bits/stdc++.h>
using namespace std;
struct CHT {
  int ptr, sz;
  vector<long long int> M, C;
  CHT() {
    ptr = sz = 0;
    M.clear();
    C.clear();
  }
  bool bad(long long int m, long long int c) {
    return (long double)(c - C[sz - 2]) / (1.0 * M[sz - 2] - m) <
           (long double)(C[sz - 1] - C[sz - 2]) / (1.0 * M[sz - 2] - M[sz - 1]);
  }
  void addLine(long long int m, long long int c) {
    while (sz >= 2 && bad(m, c)) {
      M.pop_back();
      C.pop_back();
      sz--;
    }
    M.push_back(m);
    C.push_back(c);
    sz++;
  }
  void printHull() {
    cout << "HULL" << endl;
    for (int i = 0; i < sz; i++)
      cout << i << " : " << M[i] << ' ' << C[i] << endl;
  }
  long long int getY(int pos, long long int x) { return M[pos] * x + C[pos]; }
  long long int sortedQuery(long long int x) {
    if (ptr >= sz) ptr = sz - 1;
    while (ptr < sz - 1 && getY(ptr + 1, x) >= getY(ptr, x)) ptr++;
    return M[ptr] * x + C[ptr];
  }
  double intersection(int a, int b) {
    return -1.0 * (C[a] - C[b]) / (M[a] - M[b]);
  }
  long long int BSQuery(long long int x) {
    int lo = 0, hi = sz - 2, md;
    if (sz == 1) return M[sz - 1] * x + C[sz - 1];
    if (intersection(hi, hi + 1) <= x) return M[sz - 1] * x + C[sz - 1];
    while (lo < hi) {
      md = (lo + hi) / 2;
      if (intersection(md, md + 1) >= x)
        hi = md;
      else
        lo = md + 1;
    }
    return M[hi] * x + C[hi];
  }
};
long long int n, a[200005], S[200005], M[200005];
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = 1; i <= n; i++) S[i] = S[i - 1] + a[i];
  for (int i = 1; i <= n; i++) M[i] = M[i - 1] + i * a[i];
  CHT cht = CHT();
  long long int dp = 0;
  long long int ans = 0;
  cht.addLine(0, 0);
  for (int i = 1; i <= n; i++) {
    dp = max(dp, M[i] + cht.BSQuery(-S[i]));
    cht.addLine(i, -M[i] + i * S[i]);
  }
  printf("%lld\n", dp);
}
