#include <bits/stdc++.h>
using namespace std;
long long int abss(long long int a) {
  if (a < 0) return -a;
  return a;
}
long long int fast_pow(long long int b, long long int e,
                       long long int width = 1000000007) {
  if (e == 0) {
    return 1;
  } else if (e == 1) {
    return b % width;
  }
  b = b % width;
  long long int ans = 1;
  while (e > 0) {
    if ((e & 1) == 1) {
      ans = (ans * b) % width;
    }
    e >>= 1;
    b = (b * b) % width;
  }
  return ans;
}
long long int mod_inv(long long int a, long long int width = 1000000007) {
  return fast_pow(a, width - 2, width);
}
template <typename Number, Number width>
class ModularArithmetic {
 private:
  Number n;

 public:
  friend ostream &operator<<(ostream &os, ModularArithmetic const &num) {
    return os << num.n;
  }
  friend istream &operator>>(istream &is, ModularArithmetic &num) {
    is >> num.n;
    return is;
  }
  ModularArithmetic() : n(0) {}
  ModularArithmetic(Number n) : n(n % width) {
    if (this->n < 0) this->n += width;
  }
  Number get() const { return n; }
  ModularArithmetic operator+(const ModularArithmetic &b) {
    Number t = (n + b.get()) % width;
    if (t < 0) return ModularArithmetic(width + t);
    return ModularArithmetic(t);
  }
  ModularArithmetic operator-(const ModularArithmetic &b) {
    Number t = (n - b.get()) % width;
    if (t < 0) return ModularArithmetic(width + t);
    return ModularArithmetic(t);
  }
  ModularArithmetic operator*(const ModularArithmetic &b) {
    Number t = (n * b.get()) % width;
    if (t < 0) return ModularArithmetic(width + t);
    return ModularArithmetic(t);
  }
  ModularArithmetic operator/(const ModularArithmetic &b) {
    assert(b.get() != 0);
    Number ans = n * mod_inv(b.get(), width);
    if ((ans) < 0) return ModularArithmetic(width + (ans) % width);
    return ModularArithmetic(ans % width);
  }
  ModularArithmetic &operator+=(const ModularArithmetic &b) {
    n = (n + b.get()) % width;
    if (n < 0) n = n + width;
    return *this;
  }
  ModularArithmetic &operator-=(const ModularArithmetic &b) {
    n = (n - b.get()) % width;
    if (n < 0) n = n + width;
    return *this;
  }
  ModularArithmetic &operator*=(const ModularArithmetic &b) {
    n = (n * b.get()) % width;
    if (n < 0) n = n + width;
    return *this;
  }
  ModularArithmetic &operator/=(const ModularArithmetic &b) {
    assert(b.get() != 0);
    n = (n * mod_inv(b.get(), width)) % width;
    if (n < 0) n = n + width;
    return *this;
  }
};
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
  return os << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &p) {
  os << "[";
  for (auto &it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &p) {
  os << "[";
  for (auto &it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream &operator<<(ostream &os, const multiset<T> &p) {
  os << "[";
  for (auto &it : p) os << it << " ";
  return os << "]";
}
template <class S, class T>
ostream &operator<<(ostream &os, const map<S, T> &p) {
  os << "[";
  for (auto &it : p) os << it << " ";
  return os << "]";
}
template <class S, class T>
istream &operator>>(istream &is, const pair<S, T> &p) {
  return is >> p.first >> p.second;
}
template <class T>
istream &operator>>(istream &is, vector<T> &p) {
  for (auto &itr : p) is >> itr;
  return is;
}
template <class T>
void dbs(string str, T t) {
  cerr << str << ":" << t << "\n";
}
template <class T, class... S>
void dbs(string str, T t, S... second) {
  long long int idx = str.find(',');
  cerr << str.substr(0, idx) << ":" << t << ",";
  dbs(str.substr(idx + 1), second...);
}
long long int n;
vector<long long int> arr;
vector<long long int> dp;
long long int kadane(vector<long long int> &A) {
  long long int N = A.size();
  vector<long long int> dp(N, 0);
  dp[0] = A[0];
  for (long long int i = 1; i < N; ++i) {
    dp[i] = max(A[i], A[i] + dp[i - 1]);
  }
  long long int mx = dp[0];
  for (long long int i = 0; i < N; ++i)
    if (dp[i] > mx) mx = dp[i];
  return mx;
}
void solve() {
  cin >> n;
  vector<long long int>(n).swap(arr);
  for (long long int i = 0; i < n; ++i) cin >> arr[i];
  long long int ans;
  for (long long int val = -30; val < 31; ++val) {
    vector<long long int> temp = arr;
    for (long long int i = 0; i < n; ++i)
      if (temp[i] > val) temp[i] = -10000000;
    if (val == -30) {
      ans = kadane(temp) - val;
    } else {
      long long int tt = kadane(temp) - val;
      if (tt > ans) {
        ans = tt;
      }
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
