#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void zz() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
const long long mx = 1e5 + 5;
long long n;
vector<long long> v(mx);
long long f(long long x) {
  long long ms = -inf;
  for (long long i = 0; i < n; i++) {
    long long j = i;
    if (v[i] > x) continue;
    long long cnt = 0;
    while (j < n) {
      if (v[j] <= x) {
        cnt += v[j];
      } else
        break;
      ms = max(ms, cnt);
      if (cnt < 0) cnt = 0;
      j += 1;
    }
    i = j;
  }
  ms -= x;
  return ms;
}
int32_t main() {
  zz();
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> v[i];
  long long ans = 0;
  long long ms = 0;
  for (long long i = -30; i <= 30; i++) {
    long long ans = f(i);
    ms = max(ms, ans);
  }
  cout << ms << endl;
}
