#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
const int N = 1e6 + 10;
const long long mod = 1e9 + 7;
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
long long qpow(long long a, long long b) {
  long long s = 1;
  while (b > 0) {
    if (b & 1) s = s * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return s;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void init() {
  ios::sync_with_stdio(false);
  cin.tie(0);
}
const double PI = 3.1415926535897932;
int a[N];
int main() {
  init();
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  int ans = 0;
  for (int i = 1; i <= 30; ++i) {
    int now = 0;
    for (int j = 1; j <= n; ++j) {
      if (a[j] > i) {
        now = 0;
        continue;
      }
      now = max(0, now + a[j]);
      ans = max(ans, now - i);
    }
  }
  cout << ans;
  return 0;
}
