#include <bits/stdc++.h>
using namespace std;
const int INF = 10000;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, i, num, m = -INF, ms, s;
  cin >> n;
  vector<int> em(n);
  set<int> ns;
  for (i = 0; i < n; i++) {
    cin >> em[i];
    ns.insert(em[i]);
  }
  for (auto it = ns.rbegin(); it != ns.rend(); it++) {
    s = 0;
    ms = -INF;
    for (i = 0; i < n; i++) {
      num = (em[i] > (*it) ? -INF : em[i]);
      if (s + num > num)
        s += num;
      else
        s = num;
      ms = max(ms, s);
    }
    m = max(m, ms - (*it));
  }
  cout << m << "\n";
  return 0;
}
