#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& pr) {
  os << pr.first << " " << pr.second;
  return os;
}
template <class T1>
ostream& operator<<(ostream& os, const vector<T1>& v) {
  for (auto it = v.begin(); it != v.end(); it++) os << (*it) << " ";
  return os;
}
template <class T1>
ostream& operator<<(ostream& os, const set<T1>& s) {
  for (auto it = s.begin(); it != s.end(); it++) os << (*it) << " ";
  return os;
}
template <class T1>
ostream& operator<<(ostream& os, const vector<vector<T1>>& v) {
  for (vector<T1> u : v) {
    for (T1 i : u) cout << i << " ";
    cout << endl;
  }
  return os;
}
template <class T1, class T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
  is >> p.first >> p.second;
  return is;
}
template <class T1>
istream& operator>>(istream& is, vector<T1>& v) {
  for (auto& x : v) is >> x;
  return is;
}
istream& operator>>(istream& is, string& s) {
  getline(is, s);
  return is;
}
template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
unsigned int nextPowerOf2(unsigned int n) {
  n--;
  n |= n >> 1;
  n |= n >> 2;
  n |= n >> 4;
  n |= n >> 8;
  n |= n >> 16;
  n++;
  return n;
}
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  int bstans = INT_MIN;
  for (int cmx = -30; cmx <= 30; cmx++) {
    int prev = 0, cur_sum = INT_MIN, bst = INT_MIN;
    bool fnd = false;
    for (int i = 0; i < n; i++) {
      if (a[i] > cmx) {
        cur_sum = 0;
        prev = 0;
        continue;
      } else if (a[i] == cmx)
        fnd = true;
      cur_sum = max(prev + a[i], a[i]);
      bst = max(bst, cur_sum);
      prev = cur_sum;
    }
    if (fnd) bstans = max(bstans, bst - cmx);
  }
  cout << bstans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
