#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n;
    while(scanf("%d",&n),n){
        int stage[100000] = {0};
        for(int i = 1;i <= n; i++){
            scanf("%d",&stage[i]);
        }
        int dp[100000]={0};
        dp[1] = stage[1];
        dp[2] = max(stage[2],dp[1]+stage[2]);
        int x = 0;
        int ans=dp[2];
        for(int i = 2;i <= n; i++){
            x = max(stage[i+1],stage[i+1]+dp[i]);
            if(x > ans)ans = x;
            dp[i+1] = x;
        }
        printf("%d\n",ans);
    }
    return 0;
}