#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int best = 0;
  for (int m = 31; m >= -31; --m) {
    int sum_lo = 0;
    int sum = 0;
    int max_a = -31;
    for (int i = 0; i < n; ++i) {
      if (a[i] >= m) {
        sum = 0;
        sum_lo = 0;
        max_a = -31;
      } else {
        sum += a[i];
        max_a = max(max_a, a[i]);
        best = max(best, sum - sum_lo - max_a);
        sum_lo = min(sum, sum_lo);
      }
    }
  }
  cout << best << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return (0);
}
