#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, j, i, sum = 0, ans = 0, a[100010];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (j = 1; j <= 30; j++) {
    sum = 0;
    for (i = 0; i < n; i++) {
      if (a[i] > j) {
        sum = 0;
      } else {
        sum = max((long)0, sum + a[i]);
      }
      ans = max(ans, sum - j);
    }
  }
  cout << ans;
}
