while True: n=int(input()) if n==0:break nums=list(map(int,input().split(' '))) now_sum=ans=0 for num in nums: now_sum+=num if now_sum<=0:now_sum=0 ans=max(ans,now_sum) print(ans)