#include<iostream>
using namespace std;
int main(){
    int n;
    int i;
    int inp,cur,max;
    while (cin>>n)
    {
        if(n == 0){
            break;
        }
        for(i=0;i<n;i++){
            cin>>inp;
            if(i == 0){
                max = inp;
                if(inp < 0){
                    cur = 0;
                }else{
                    cur = inp;
                }
            }else{
                cur = inp + cur;
                if(cur<0){
                    cur = 0;
                }else{
                    if(cur>max){
                        max = cur;
                    }
                }
            }
        }
        cout<<max<<endl;
    }

    
    return 0;
}
