#include <iostream>
#include <string>
#include <stdlib.h>
#include <fstream>

using namespace std;


int sumarray(int *array, int idx1, int idx2);


int main(){
  int n, Max, ibuf;
  int *List;

  //ifstream ifs("input.txt"); // for debug

  while(cin >> n){
    if(n == 0) break; // if n=0, end calc

    List = new int[n];  // allocate List

    for(int i=0; i<n; i++){
      cin >> List[i];
      //cout << List[i] << " "; // for debug
    }

    //cout << endl; // for debug

    Max = 0;
    for(int l=1; l<=n; l++){
      for(int i=0; i<=n-l; i++){
	ibuf = sumarray(List, i, i+l);
	if(ibuf > Max) Max = ibuf;
	//cout << ibuf << endl; // for debug
      }
    }

    cout << Max << endl;

    delete List; // deallocate List
  }

}


int sumarray(int *array, int idx1, int idx2){ // sum array[idx1] ~ array[idx2-1]
  int ret = 0;
  for(int i=idx1; i<idx2; i++){
    ret += array[i];
  }
  return ret;
}