#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int a, b, c, i, j, k, t, n;
  cin >> n;
  int arr[n + 1];
  for (int i = 1; i < n + 1; i++) {
    cin >> arr[i];
  }
  int maxsum = INT_MIN;
  for (int i = 0; i < 31; i++) {
    int tsum = 0;
    for (int j = 1; j < n + 1; j++) {
      if (arr[j] <= i)
        tsum += arr[j];
      else
        tsum = 0;
      tsum = max(0, tsum);
      maxsum = max(maxsum, tsum - i);
    }
  }
  cout << maxsum << endl;
}
