#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int main(){

    int n, k;
    int d[5555];
    while(cin >> n){
      
      memset(d, 0, sizeof(d));
      for(int i=1;i<=n;i++){
	cin >> k;
	d[i] = d[i-1]+k;
      }
      
      int ans = 0;  
      for(int i=0;i<=n;i++){
	for(int j=i;j<=n;j++){
	  ans = max(ans, d[j]-d[i]);
	}
      }
      
    cout << ans << endl;
    }
}