#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
  int i,j,n,tmp,ans,a[5000];

  while(scanf("%d",&n) && n){
    for(i=0;i<n;i++)scanf("%d",&a[i]);
    
    ans = a[0];
    for(i=0;i<n;i++){
      for(j=i;j<n;j++){
	if(i==j)tmp = 0;
	tmp += a[j];
	ans = max(tmp,ans);
      }
    }
    printf("%d\n",ans);
  }
}