#include <bits/stdc++.h>
using namespace std;
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long long MXLL = 4e18;
const int Sz = 1110111;
inline void Read_rap() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
inline void randomizer3000() {
  unsigned int seed;
  asm("rdtsc" : "=A"(seed));
  srand(seed);
}
void files(string problem) {
  if (fopen((problem + ".in").c_str(), "r")) {
    freopen((problem + ".in").c_str(), "r", stdin);
    freopen((problem + ".out").c_str(), "w", stdout);
  }
}
void localInput(string in = "s") {
  if (fopen(in.c_str(), "r"))
    freopen(in.c_str(), "r", stdin);
  else
    cerr << "Input file not found" << endl;
}
struct CHT {
  struct line {
    long long k, b;
    long long calc(long long x) { return k * x + b; }
  };
  vector<line> r;
  double cross(line &a, line &b) {
    return ((double)b.b - a.b) / ((double)a.k - b.k);
  }
  void add_line(line x) {
    while ((int)(r.size()) >= 2 &&
           cross(r[(int)(r.size()) - 2], r[(int)(r.size()) - 1]) >
               cross(r[(int)(r.size()) - 2], x))
      r.pop_back();
    r.push_back(x);
  }
  long long get(long long x) {
    int l = 0, hi = (int)(r.size()) - 2, best = (int)(r.size()) - 1;
    while (l <= hi) {
      int mid = (l + hi) >> 1;
      if (cross(r[mid], r[mid + 1]) >= x) {
        hi = mid - 1;
        best = mid;
      } else {
        l = mid + 1;
      }
    }
    return r[best].calc(x);
  }
};
int n;
int a[Sz];
long long pref[Sz], p[Sz];
int main() {
  localInput();
  Read_rap();
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    pref[i] = pref[i - 1] + a[i];
    p[i] = p[i - 1] + a[i] * 1ll * i;
  }
  long long ans = 0;
  CHT T;
  for (int i = 1; i <= n; i++) {
    int j = i - 1;
    T.add_line({j, j * pref[j] - p[j]});
    long long val = T.get(-pref[i]) + p[i];
    ans = max(ans, val);
  }
  cout << ans;
  return 0;
}
