Go: package main

import (
        "fmt"
)

func main() {
        for {
                var n int
                _, err := fmt.Scanf("%d", &n)
                if err != nil || n == 0 {
                        break
                }

                var sum [5001]int

                for i := 1; i <= n; i++ {
                        fmt.Scanf("%d", &(sum[i]))
                        if i > 1 {
                                sum[i] += sum[i-1]
                        }
                }

                max_sum := sum[1]
                for i := 1; i <= n; i++ {
                        for j := 0; j < i; j++ {
                                if max_sum < sum[i] - sum[j] {
                                        max_sum = sum[i] - sum[j]
                                }
                        }
                }
                fmt.Printf("%d\n", max_sum)
        }
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){

	int A[100000]={};
	int n,MAX = -100000;

		while(1){
			MAX = -100000;

			cin >> n;

			if( n == 0 ) break;

			for(int i = 0; i < n; i++){

				cin >> A[i];
	
			}

			for(int i = 1; i < n; i++){

				A[i] = max(A[i],A[i] + A[i-1]);
				MAX = max(A[i], MAX);

			}
	
			cout  << MAX << endl;

		}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

main(){
	while(true){
		int n;
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		int a[n];
		for(int i=0; i<n; ++i){
			cin >> a[i];
		}
		
		long long maxv = a[0];
		for(int l=0; l<n; ++l){
			long long sumv = 0;
			for(int r=l; r<n; ++r){
				sumv += a[r];
				if(sumv >= maxv){
					maxv = sumv;
				}
			}
		}
		
		cout << maxv << endl;
	}
}

C++: #include <iostream>

using namespace std;

int main(){
    seq();
    return 0;
}

int seq(){
    int a;
    while(cin >> a,a){
        int b[a];
        for(int i = 0; i < a; i++){
            cin >> b[i];
        }
        cout << max() << endl;
    }
}

int max(){
    int max = -10000000;
    int sum = 0;
    for(int len = 1; len <= a ; len++){
        for(int i = 0; i < a-len; i++){
            for(int j = 0, sum = 0; j < len; j++){
                sum += b[i+j];
            }
            if (sum > max) max = sum;
        }
    }
    return max
}

C++: #include <iostream>
#include <vector>
using namespace std;

int main()
{

	int n, num;
	vector< long int > a;
	vector< long int > res;

	while( 1 ) {

		int Max = -1000001;

		cin >> n;
		if( n == 0 ) break;

		a.push_back( 0 );

		for( int i = 0; i < n; i++ ) {
		
			cin >> num;
			a.push_back( num );
			
		}

		//?????§???
		for( int i = 1; i < n; i++ ) {
		
			a[i - 1] + a[i] > a[i] ? a[i] = a[i - 1] + a[i] : a[i] = a[i];

			if ( a[i] > Max ) {
				Max = a[i];
			}
		
		}

		res.push_back( Max );
		a.clear();
	
	}

	if( n != 0 ) {
		for( vector< long int > :: iterator mIt = res.begin(); mIt != res.end(); ++mIt ) {
			cout << *mIt << endl;
		}
	}

	return 0;

}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
void maxSum(int a[],int n);
int main(){
	int n;
	while(cin>>n,n){
		int sum=0,a[5001],ans=-999999999;
		for(int i=0;i<n;i++)
            cin>>a[i];
        for(int i=0;i<n;i++){
            sum=0;
            for(int j=i;j<n;j++){
                sum+=a[j];
                ans=max(sum,ans);
            }
        }
    cout << ans << endl;
	}
	return 0;
}

void maxSum(int a[],int n){
    int sum = 0;
    int ans = -1;
    for(int i=0;i<n;i++){
        sum=0;
        for(int j=i;j<n;j++){
            sum+=a[j];
            ans=max(sum,ans);
        }
    }
    cout << ans << endl;
}

C++: #include <iostream>
int main(){
	int x;
	while(std::cin >> x){
		std::cerr << x << '\n';
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n,b;
	vector<int>a;
	while (1){
		int max_v = 0;
		a.clear();
		cin >> n;
		if (n == 0)break;
		a.push_back(0);
		for (int i = 0; i < n; i++){
			cin >> b;
			a.push_back(b);
		}
		for (int i = 1; i <= n; i++){
			a[i] = max(a[i - 1] + a[i], a[i]);
			if (a[i]>max_v){
				max_v = a[i];
			}
		}
		cout << max_v << endl;
	}
}

C++: #include <iostream>
#include <vector>
using namespace std;

int main()
{

	int n, num;
	vector< int > a;

	while( 1 ) {

		int Max = -100000;

		cin >> n;
		if( n == 0 ) break;

		a.push_back( 0 );

		for( int i = 0; i < n; i++ ) {
		
			cin >> num;
			a.push_back( num );
			
		}

		for( int i = 1; i < n - 1; i++ ) {
		
			a.at( i - 1 ) + a.at( i ) > a.at( i ) ? a.at( i ) = a.at( i - 1 ) + a.at( i ) : a.at( i ) = a.at( i );

			if ( a.at( i ) > Max ) {
				Max = a.at( i );
			}
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}

C++: #include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

int main(void){
	ll ans[10000];
	ll N=0;
	while(true){
		int n;
		cin>>n;
		if(n==0)break;
		ll a[5000];
		// ll b[5000];
		// int N=0;
		// bool plus=true;
		// rep(i,n){//????????£?¶???????????¬?????????¨???????????¨??????
		// 	cin>>a[i];
		// 	if(i==0){
		// 		if(a[0]<0)plus=false;
		// 	}
		// 	if((plus && a[i]<0)||(!plus && a[i]>=0)){//?¬????????????????
		// 		N+=1;
		// 	}
		// 	b[N]+=a[i];
		// }

		rep(i,n){//????????£?¶???????????¬?????????¨???????????¨??????
			cin>>a[i];
		}
		ll max=0;
		ll current;
		rep(i,n){
			current=0;
			reg(j,i,n-1){
				current+=a[j];
				if(current>max)max=current;
			}
		}
		ans[N]=max;
		N++;
	}
	rep(i,N)cout<<ans[i]<<endl;
	return 0;
}

C++: /*
#include <iostream>
#include <vector>
using namespace std;

int main()
{

	int n, num;
	vector< long int > a;

	while( 1 ) {

		int Max = -1000001;

		cin >> n;
		if( n == 0 ) break;

		for( int i = 0; i < n; i++ ) {
		
			cin >> num;
			a.push_back( num );
			
		}

		//?????§???
		for( int i = 1; i < n; i++ ) {
		
			a[i - 1] + a[i] > a[i] ? a[i] = a[i - 1] + a[i] : a[i] = a[i];

			if ( a[i] > Max ) {
				Max = a[i];
			}
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}
*/

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{

	int n, num;
	vector< int > a;

	while( 1 ) {
	
		cin >> n;
		if( n == 0 ) break;

		int Max = -100001;

		for( int i = 0; i < n; i++ ) {

			cin >> num;
			a.push_back( num );

		}

		for( int i = 1; i < n; i++ ) {

			a[i] = max( a[i], a[i] + a[i - 1] );
			Max  = max( Max, a[i] );
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}

C++: #include <stdio.h>

int main() {
        int n, a;

        while (true) {
                scanf("%d", &n);
                if (!n) {
                        break;
                }

                int sum = 0, max = 0;
                for (int i = 0; i < n; i++) {
                        scanf("%d", &a);
                        sum += a;
                        if (sum < 0) {
                                sum = 0;
                                continue;
                        }
                        if (sum > max) {
                                max = sum;
                        }
                }
                printf("%d\n", max);
        }

        return 0;
}