#include <bits/stdc++.h>
using namespace std;
struct S {
  int a, b;
  S() {}
  S(int _a, int _b) {
    a = _a;
    b = _b;
  }
  const bool operator<(const S &o) const { return a < o.a; }
};
string exm;
inline void exf(void) {
  cout << exm << "\n";
  exit(0);
}
template <typename T>
inline void showAll(vector<T> &v, string sep = "") {
  for (T &here : v) cout << here << sep;
}
template <typename T>
inline void showAll(T a[], int st, int end, string sep = "") {
  for (int i = st; i <= end; i++) cout << a[i] << sep;
}
template <typename T>
inline void showAll(T a[], int x, int y, int z, int w, string p, string q) {
  for (int i = x; i <= y; i++) {
    for (int j = z; j <= w; j++) {
      cout << a[i][j] << p;
    }
    cout << q;
  }
}
template <typename T>
inline vector<int> int_seperation(T N, int d = 10) {
  vector<int> v;
  while (N) {
    v.push_back(N % d);
    N /= d;
  }
  reverse(v.begin(), v.end());
  return v;
}
const int SIZE = 100009;
int psum[SIZE], arr[SIZE];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
    psum[i] = psum[i - 1] + arr[i];
  }
  int ans = 0;
  for (int i = 30; i >= -30; i--) {
    int mn = 0;
    for (int j = 1; j <= n; j++) {
      if (arr[j] > i)
        mn = psum[j];
      else {
        ans = max(ans, psum[j] - mn - i);
        mn = min(mn, psum[j]);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
