#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 10;
int a[M];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  int maxn = 0;
  for (int c = 1; c <= 30; c++) {
    int ans = 0, temp = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] > c)
        ans = 0;
      else {
        ans = max(a[i], ans + a[i]);
        temp = max(temp, ans);
      }
    }
    maxn = max(maxn, temp - c);
  }
  printf("%d\n", maxn);
  return 0;
}
