#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
typedef vector<int> vec;
#define INF (1<<20)

int main(){
	int n;
	while( cin >> n, n ){
		vec data(n);
		for( int i = 0; i < n; i++ ){
			cin >> data[i];
		}
		int ans = -INF;
		vector<vec> dp(n, vec(n));
		for( int i = 0; i < n; i++ ){
			for( int j = i; j < n; j++ ){
				if( i == 0 ){
					if( j == 0 ) dp[0][0] = data[0];
					else dp[0][j] = dp[0][j-1] + data[j];
					ans = max(ans, dp[i][j]);
				}else{
					//if( i <= j ){
						dp[i][j] = dp[i-1][j] - data[i-1];
						ans = max(ans, dp[i][j]);
					//}
				}
			}
		}
		/*for( int i = 0; i < n; i++ ){
			for( int j = 0; j < n; j++ ){
				printf("%4d", dp[i][j]);
			}
			cout << endl;
		}
		*/
		cout << ans << endl;
	}
}