#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int arr[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  int ans = 0;
  for (int val = 1; val <= 30; val++) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if (arr[i] > val) {
        sum = 0;
      } else {
        sum += arr[i];
        ans = max(ans, sum - val);
        if (sum < 0) {
          sum = 0;
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
