#include <iostream>
#include <vector>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;

// ?¨±?????????????????
#define EPS (1e-10)

int main(){
	int n;
	while(cin >> n && n != 0){
        vector<int> a(n);
        REP(i, n) cin >> a[i];
        int ret = 0;
        REP(i, a.size()){
            FOR(j, i, a.size()){
                int sum = 0;
                FOR(k, i, j+1) sum += a[k];
                ret = max(ret, sum);
            }
        }
        cout << ret << endl;
    }
    return 0;
}