#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793238;
int arr[200005], N;
int get_sol() {
  int ans = 0;
  for (int i = 1; i <= 30; i++) {
    int sum = 0;
    int mx_sum = 0;
    for (int j = 0; j < N; j++) {
      sum += arr[j];
      if (arr[j] > i || sum < 0) {
        sum = 0;
      }
      mx_sum = max(mx_sum, sum - i);
    }
    ans = max(ans, mx_sum);
  }
  return ans;
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &arr[i]);
  }
  printf("%d\n", get_sol());
  return 0;
}
