#include <bits/stdc++.h>
using namespace std;

int main() {
	ios_base::sync_with_stdio( false );

	int n;
	while( (cin >> n) && n != 0 ) {
		vector<int> a( n );
		for( auto& v: a ) { cin >> v; }

		int result = INT_MIN;
		for( int i = 0; i < n; ++i ) {
			int x = 0;

			for( int j = i; j < n; ++j ) {
				x += a[j];

				if( x > result ) {
					result = x;
				}
			}
		}

		cout << result << '\n';
	}
}

