#include<iostream>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int s[n];
    int ans = -100000000;
    for(int i=0;i<n;i++) cin >> s[i];
    for(int i=0;i<n;i++){
      int a = s[i];
      if(a>ans) ans = a;
      for(int j=i+1;j<n;j++){
	a += s[j];
	if(a>ans) ans = a;
      }
    }
    cout << ans << endl;
  }
  return 0;
}