#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int a[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int ans = 0;
  for (int maxx = 30; maxx >= -30; maxx--) {
    int sum = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] <= maxx) {
        sum = max(sum, 0) + a[i];
        ans = max(ans, sum - maxx);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
