#include <bits/stdc++.h>
using namespace std;
const long long INF = 1010101010;
long long A[101010];
long long B[101010];
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%lld", &A[i]);
  long long ans = 0;
  for (int i = -30; i <= 30; i++) {
    for (int j = 1; j <= N; j++) {
      if (A[j] > i)
        B[j] = -INF;
      else
        B[j] = A[j];
    }
    long long tmp = -INF;
    long long bef = 0;
    for (int j = 1; j <= N; j++) {
      long long x = max(0LL, bef) + B[j];
      tmp = max(tmp, x);
      bef = x;
    }
    ans = max(ans, tmp - i);
  }
  printf("%lld\n", ans);
  return 0;
}
