#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
int dx[] = {0, 0, +1, -1, +1, +1, -1, -1};
int dy[] = {+1, -1, 0, 0, +1, -1, +1, -1};
const int mx = 2e5 + 123;
long long s[mx], p[mx], a[mx];
vector<pair<long long, long long> > line;
bool bad(int f1, int f2, int f3) {
  return (double)((double)(line[f3].second - line[f1].second) *
                  (double)(line[f1].first - line[f2].first)) >=
         (double)((double)(line[f2].second - line[f1].second) *
                  (double)(line[f1].first - line[f3].first));
}
void add(long long m, long long c) {
  line.push_back({m, c});
  int l = (int)line.size();
  while (l >= 3 && bad(l - 3, l - 2, l - 1)) {
    line.erase(line.end() - 2);
    l--;
  }
}
long long func(int i, long long x) {
  return (line[i].first * x) + line[i].second;
}
long long query(long long x) {
  int l = 0, r = (int)line.size() - 1;
  long long ans = -1e18;
  while (r - l >= 3) {
    int mid1 = (l + l + r) / 3;
    int mid2 = (l + r + r) / 3;
    long long y1 = func(mid1, x);
    long long y2 = func(mid2, x);
    if (y1 <= y2) {
      l = mid1 + 1;
    } else {
      r = mid2 - 1;
    }
  }
  for (int i = l; i <= r; i++) ans = max(ans, func(i, x));
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    s[i] = s[i - 1] + (i * a[i]);
    p[i] = p[i - 1] + a[i];
  }
  add(0, 0);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, query(p[i]) + s[i]);
    add(-i, (i * p[i]) - s[i]);
  }
  cout << ans;
  return 0;
}
