#include <bits/stdc++.h>
#pragma optimize("O3")
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;
const int base = 2e5 + 1;
const int MAX = 1e5 + 2;
const double EPS = 1e-9;
const double PI = acos(-1.);
const int MAXN = 2 * 1e5 + 47;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (long long i = (0); i < (n); ++i) cin >> a[i];
  long long res = 0;
  for (long long mx = (0); mx < (31); ++mx) {
    long long pref = 0;
    long long best = 0;
    for (long long i = (0); i < (n); ++i) {
      pref += (a[i] > mx ? -INF : a[i]);
      best = min(best, pref);
      res = max(res, (pref - best) - mx);
    }
  }
  cout << res;
  return 0;
}
