#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long int a[n];
  long long int maxi = INT_MIN;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > maxi) maxi = a[i];
  }
  if (maxi <= 0) {
    cout << 0 << endl;
    return 0;
  }
  long long int sum = 0;
  long long int ans = 0;
  for (int x = 1; x <= maxi; x++) {
    long long int best = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] > x) {
        sum = 0;
        continue;
      }
      sum = max(sum + a[i], a[i]);
      best = max(sum, best);
    }
    ans = max(ans, best - x);
    sum = 0;
  }
  cout << ans << endl;
}
