#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int ans = 0;
  for (int i = 1; i <= 30; i++) {
    int sum = 0, maxv = 0;
    for (int j = 0; j < n; j++) {
      sum += a[j];
      maxv = max(maxv, a[j]);
      if (sum < 0 || maxv > i) sum = maxv = 0;
      ans = max(ans, sum - maxv);
    }
  }
  cout << ans << endl;
  return 0;
}
