#include <bits/stdc++.h>
const long long way[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
using namespace std;
const long long inf = 0x7fffffff;
const double PI = acos(-1.0);
const double eps = 1e-6;
const long long mod = 1e9 + 7;
const long long N = 2e5 + 5;
long long n, ans, sum;
long long a[N];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long maxx = 1; maxx <= 30; maxx++) {
    sum = 0;
    for (long long i = 0; i < n; i++) {
      if (a[i] > maxx) {
        sum = 0;
        continue;
      }
      sum += a[i];
      if (sum < 0) sum = 0;
      ans = max(ans, sum - maxx);
    }
  }
  cout << ans << '\n';
  return 0;
}
