import std.stdio;
import std.conv;
import std.string;
import std.cstream;

void main(string args[]){
char[] inN;

while(true){

inN = din.readLine();
inN = chomp(inN);
int n = to!(int)(inN);

if(n == 0)break;

int val[5555];

for(int i;i<n;i++){
  inN = readln().dup;
  inN = chomp(inN);
  val[i] = to!(int)(inN);
}

auto sum=val[0];
int ans = 0;

for(int i;i<n;i++){
  sum = 0;
  for(int j=i;j<n;j++){
    sum+=val[j];
    if(ans<=sum){
      ans=sum;
    }

  }
}

writeln(ans);

}

}