#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long n;
  cin >> n;
  long long a[n], b[n], ans = 0, min1 = LLONG_MAX, max1 = -LLONG_MAX;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    min1 = min(min1, a[i]);
    max1 = max(max1, a[i]);
  }
  for (int num = min1; num <= max1; ++num) {
    for (int i = 0; i < n; ++i) {
      b[i] = a[i];
      if (b[i] > num) b[i] = -LLONG_MAX;
    }
    long long temp = 0, sum = -LLONG_MAX;
    for (int i = 0; i < n; ++i) {
      temp += b[i];
      sum = max(sum, temp);
      if (temp < 0) temp = 0;
    }
    ans = max(ans, sum - num);
  }
  cout << ans << "\n";
  return 0;
}
