#include<iostream>
#include<limits>
using namespace std;

int main()
{
    while(1){
        int n;
        cin >> n;
        if( !n ) break;
        
        int a;
        int sum=0, max=0;
        for(int i=0; i<n; i++){
            cin >> a;
            
            if( a<=0 && sum<=0) continue;
            else sum += a;
            
            if( sum <= 0 ) {sum = 0; continue;}

            if( sum > max ) max = sum;
        }
        cout << max << endl;
    }
    return 0;
}