#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int dp[100005];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long ans = 0;
  for (int i = 30; i >= 1; i--) {
    long long sum = 0;
    for (int j = 1; j <= n; j++) {
      if (a[j] <= i) {
        sum += a[j];
        ans = max(ans, sum - i);
        if (sum < 0) sum = 0;
      } else
        sum = 0;
    }
  }
  cout << ans;
}
