Go: package main

import "fmt"

func main() {
	var result []int
	for {
		var n, a, maxSum int
		fmt.Scan(&n)

		if n == 0 {
			break
		}

		maxSum = 0
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Scan(&a)
			if i == 0 {
				sum = a
				maxSum = sum
			} else if sum+a < a {
				sum = a
				if maxSum < sum {
					maxSum = sum
				}
			} else {
				sum = sum + a
				if maxSum < sum {
					maxSum = sum
				}
			}
		}

		result = append(result, maxSum)
	}

	for _, v := range result {
		fmt.Println(v)
	}
}

C++: /*??£?¨?*/
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string.h>
#include<string>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
int main()
{
	int max = 0, n, a[5001] = {0},max_=0;
	while (cin >> n, n != 0)
	{
		max_ = 0;
		max = -1000000000;
		rep(i, n)
			cin >> a[i];
		rep(i, n)
		{
			for (int j = i; j < n; j++)
			{
				max_ += a[j];
				if (max < max_)
					max = max_;
			}
			max_ = 0;
		}
		cout << max << endl;
	}
	return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    while (1)
    {
        int n;
        cin >> n;
        if (n == 0)
            break;
        int a[n];
        rep(i, n) cin >> a[i];
        int m = a[0], sum = a[0];
        for (int i = 1; i < n; i++)
        {
            sum = max(sum + a[i], a[i]);
            if (sum > m)
                m = sum;
        }

        OP(m)
    }

    return 0;
}

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

int main(){
    int n;
    while(cin >> n, n){
        vector<int> a(n,0);
        for(int i=0; i<n; ++i){
            cin >> a[i];
        }
        // ????????£?¶??????????????????§??£?¶???????dp??¨?????????
        vector<int> dp(n,0);
        dp[0] = a[0];
        int max = 0;
        for(int i=1; i<n; ++i){
            if(dp[i-1]>0){
                dp[i] = dp[i-1] + a[i];
            } else {
                dp[i] = a[i];
            }
            if(max<dp[i]){
                max = dp[i];
            }
        }
        cout << max << endl;
    }
}

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;
}