#include <bits/stdc++.h>
using namespace std;
long long int n;
long long int arr[100001] = {0};
long long int ans = 0;
void solve() {
  ans = 0;
  for (long long int i = 0; i <= 30; i++) {
    long long int sum = 0;
    long long int flag = 0;
    for (long long int j = 1; j <= n; j++) {
      sum += arr[j];
      if (arr[j] == i) {
        flag = 1;
      }
      if (arr[j] > i || sum < 0) {
        sum = 0;
        flag = false;
      }
      if (flag) {
        ans = max(ans, sum - i);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  solve();
  cout << ans << endl;
  return 0;
}
