#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &it : a) cin >> it;
  int maximum = *max_element(a.begin(), a.end());
  int minimum = *min_element(a.begin(), a.end());
  int best = -INF;
  for (int mx = minimum; mx <= maximum; mx++) {
    int most = -INF, sum = 0;
    for (int i = 0; i < n; i++) {
      sum = max(sum, 0);
      sum += (a[i] <= mx ? a[i] : -INF);
      most = max(most, sum);
    }
    best = max(best, most - mx);
  }
  cout << best << "\n";
}
