#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 9;
long long n, a[MAX], l, r, mid1, mid2, s[MAX], p[MAX], ans;
long long cal(long long l, long long r) {
  return (s[r] - s[l - 1]) - (l - 1) * (p[r] - p[l - 1]);
}
long long f(long long len) {
  long long ret = 0;
  for (int i = 1; i <= n - len; i++) ret = max(ret, cal(i, i + len));
  return ret;
}
int main() {
  cin >> n, r = n + 1;
  for (long long i = 1; i <= n; i++)
    cin >> a[i], p[i] = p[i - 1] + a[i], s[i] = s[i - 1] + i * a[i];
  while (l < r - 2) {
    mid1 = (l * 2 + r) / 3, mid2 = (l + r * 2) / 3;
    if (f(mid1) < f(mid2))
      l = mid1;
    else
      r = mid2;
  }
  for (long long i = max(0LL, l - 500); i < min(r + 500, n + 1); i++)
    ans = max(ans, f(i));
  cout << ans;
}
