#include <bits/stdc++.h>
const long long md = 1e9 + 7;
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, sm = 0, tsm = 0;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int j = 0; j < 31; j++) {
    tsm = 0;
    for (int i = 0; i < n; i++) {
      if (arr[i] > j)
        tsm = 0;
      else {
        tsm += arr[i];
        if (tsm < 0) tsm = 0;
      }
      sm = max(sm, tsm - j);
    }
  }
  cout << sm << "\n";
  return 0;
}
