#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i += 1) {
    cin >> a[i];
  }
  int ans1 = 0, ans2 = 0;
  for (int i = 1; i < 31; i += 1) {
    ans2 = 0;
    for (int j = 0; j < n; j += 1) {
      if (a[j] > i) {
        ans2 = 0;
        continue;
      }
      ans2 += a[j];
      if (ans2 < 0) {
        ans2 = 0;
      }
      ans1 = max(ans1, ans2 - i);
    }
  }
  cout << ans1;
}
