#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
  int n;
  cin >> n;
  int arr[n + 1];
  for (int i = 1; i <= n; i++) cin >> arr[i];
  int long long ans = 0;
  for (int mx = 0; mx < 31; mx++) {
    int long long cur = 0;
    int long long best = 0;
    for (int i = 1; i < n + 1; i++) {
      int val = (arr[i] > mx ? -INF : arr[i]);
      cur += val;
      best = min(best, cur);
      ans = max(ans, (cur - best) - mx);
    }
  }
  cout << ans << '\n';
  return 0;
}
