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

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)  return 0;
        int result = INT_MIN/2;
        int tmp = INT_MIN/2;
        for(int i=0; i<n; ++i){
            int a;
            cin >> a;
            tmp = max(tmp + a, a);
            result = max(result, tmp);
        }
        cout << result << endl;
    }
}