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