#include <bits/stdc++.h>
using namespace std;
char buf[1 << 21], *p1 = buf, *p2 = buf;
inline long long read() {
  long long w = 0, f = 1;
  char c = ' ';
  while (c < '0' || c > '9')
    c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++),
    f = c == '-' ? -1 : f;
  while (c >= '0' && c <= '9')
    w = w * 10 + c - 48,
    c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++);
  return w * f;
}
long long n, a[100005], ans, sum, minn;
const long long inf = 1e9;
signed main() {
  n = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  for (long long i = 1; i <= 30; i++) {
    sum = minn = 0;
    for (long long j = 1; j <= n; j++)
      sum += (a[j] > i ? -inf : a[j]), minn = minn > sum ? sum : minn,
                                       ans = max(ans, sum - minn - i);
  }
  printf("%lld", ans);
  return 0;
}
