#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = INT_MIN;
  for (int mx = 0; mx <= 30; mx++) {
    int curr = 0;
    int val = INT_MIN;
    for (int i = 0; i < n; i++) {
      if (a[i] <= mx) {
        curr = curr + a[i];
      } else {
        curr = 0;
      }
      if (curr < 0) {
        curr = 0;
      }
      val = max(val, curr);
    }
    ans = max(ans, val - mx);
  }
  cout << ans << endl;
  return 0;
}
