#include <bits/stdc++.h>
using namespace std;
#pragma GCC push_options
#pragma GCC optimize("unroll-loops")
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = 0;
  for (long long i = 30; i >= 1; i--) {
    long long max_sum = 0;
    for (long long j = 0; j < n; j++) {
      if (a[j] > i) {
        max_sum = 0;
        continue;
      }
      max_sum += a[j];
      max_sum = max(max_sum, 0ll);
      ans = max(ans, max_sum - i);
    }
  }
  cout << ans << "\n";
  return 0;
}
