#include <bits/stdc++.h>
using namespace std;
void test();
int main() {
  int t = 1;
  for (int i = 1; i <= t; i++) {
    test();
    cout << endl;
  }
  return 0;
}
void test() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int ans = 0;
  for (int c = 30; c > 0; c--) {
    int t = 0;
    for (int i = 0; i < n; i++) {
      if (arr[i] > c)
        arr[i] = -10000000;
      else {
        t += arr[i];
        ans = max(ans, t - c);
        if (t < 0) t = 0;
      }
    }
  }
  cout << ans;
}
