#include <bits/stdc++.h>
using namespace std;
void solve(int* arr, int n) {
  int max_sum = 0;
  int answer = 0;
  for (int i = 1; i <= 30; i++) {
    int current = 0;
    max_sum = 0;
    for (int j = 0; j < n; j++) {
      if (arr[j] > i) {
        current = 0;
        continue;
      }
      current = current + arr[j];
      if (current < 0) {
        current = 0;
      }
      max_sum = max(current, max_sum);
    }
    answer = max(answer, max_sum - i);
  }
  cout << answer << endl;
}
int main() {
  int n;
  cin >> n;
  int arr[200005];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  solve(arr, n);
}
