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<stdio.h>

int main(void) 
{
    int num[5000];
	int cut_i,max;
	int kousuu;
	int nyuryoku;

	while(1){
		scanf("%d",&kousuu);
		
		if(kousuu == 0){
			break;
		}

		int kou = 0;
		
		for(cut_i=0;cut_i<kousuu;cut_i++){
			num[cut_i]=0;
		}

		for(cut_i=0;cut_i<kousuu;cut_i++){
			scanf("%d",&nyuryoku);

			if(num[kou] * nyuryoku <0){
				kou++;
			}
			num[kou]+=nyuryoku;

			if(max<num[kou]){
				max = num[kou];
			}
		}

		kou++;
		cut_i = 0;
		
		for(cut_i=0;cut_i<kou;cut_i++){

			if(max<num[cut_i]){
				max = num[cut_i];
			}
			
			if(num[cut_i]+num[cut_i+1] > 0){
				num[cut_i+1]+=num[cut_i];
			}
		}

		printf("%d\n",max);

	}
    return 0;
}

C++: #include <iostream>
#include <vector>

int main() {
	int n;
	std::vector<int> a;
	while(std::cin >> n, n){
		for(;n--;){
			int ai;
			std::cin >> ai;
			a.push_back(ai);
		}
		long long int max_sum = a[0];
		for(int len=1; len<=a.size(); len++){
			for(int begin=0; begin<a.size()-len+1; begin++){
				long long int sum = 0;
				for(int i = begin; i < begin + len; i++){
					sum += a[i];
				}
				if(sum > max_sum){
					/*std::cout << begin << ',' << len << std::endl;*/
					max_sum = sum;
				}
			}
		}
		std::cout << max_sum << std::endl;
		a.clear();
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	while (1){
		int n, a[5001] = { 0 };
		cin >> n;
		if (n == 0)break;
		a[0] = 0;
		int maxv = -100000;
		for (int i = 1; i <= n; i++)
			cin >> a[i];
		for (int i = 1; i <= n; i++){
			a[i] = max(a[i - 1] + a[i], a[i]);
			maxv = max(a[i], maxv);
			if (maxv < a[i])
				maxv = a[i];
		}
		cout << maxv << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n;
	while(cin >> n,n){
		vector<int> data(n);
		rep(i,n)cin >> data[i];
		int ret = 0;
		rep(i,n)ret = min(ret,data[i]);
		rep(i,n){
			int sum = 0;
			for(int j=i;j<n;j++){
				sum += data[j];
				ret = max(sum,ret);
			}
		}
		cout << ret << endl;
	}
}

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

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

		while(1){
			

			cin >> n;

			if( n == 0 ) break;

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

				cin >> A[i];
	
			}

			MAX = -100000;
		
			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 <iostream>

using namespace std;

/** Problem0022 : Maximum Sum Sequence **/

int main()
{
	int n, num[5000]={0}, s;
	int maxNum;
	
	while (1) {
		cin >> n;
		if (n==0) break;
		for (int i=0; i<n; i++) {
			cin >> num[i];
		}
		
		maxNum = 0;
		for (int i=0; i<n; i++) {
			s=0;
			for (int j=i; j<n; j++) {
				s+=num[j];
				if (s>maxNum)
					maxNum=s;
			}
		}
		cout << maxNum << endl;
	}
}

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 = -100001;

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

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

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

	return 0;

}

C++: #include <iostream>
using namespace std;
long long int n,a[5000];
int main(){
	long long int i,j,t,tmp;
	while(cin >> n && n){
		tmp = 0;
		t = -1000000;
		for(i=0;i<n;i++){
			cin >> a[i];
		}
		for(i=0;i<n;i++){
			tmp += a[i];
			if(t < tmp) t = tmp;
				for(j=i+1;j<n;j++){
					tmp += a[j];
					if(t < tmp) t = tmp;
				}
			tmp = 0;
		}
		cout << t << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	while(1){
		int n ; cin >> n ; if(!n) break;
		int* a=new int[n];
		for(int i=0;i<n;i++) cin >> a[i];
		int MAX=a[0];
		for(int i=0;i<n;i++){
			int temp=a[i];
			for(int j=i+1;j<n;j++){
				temp+=a[j];
				if(temp>MAX) MAX=temp;
			};
		};
		cout << MAX << '\n' ;
		delete[] a;
	};
}

C++: // start 20:09
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <sstream>
#include <deque>

#define REP(i, n) for ( int i = 0; i < n; i++ )

using namespace std;

int main() {
    int n;
    vector<int> nums(5001);
    
    while(cin >> n, n) {
        int max_n;

        REP(i, n) cin >> nums[i];

        // cout << nums[0] << " " << nums[1] << " " << nums[2] << endl;        
        max_n = nums[0];

        // cout << "m:" << max_n << endl;

        REP(oft, n) {
            int sum = 0;
            for ( int i = oft; i < n; i++ ) {
                sum += nums[i];
                max_n = max(max_n, sum);
            }
        }
        cout << max_n << endl;
    }

    return 0;
}

C++: // 0022.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define roop(a,t) for(ll a=0;a<t;a++) 
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	while (cin >> n) {
		ll dp[5001]; ll a[5001];
		ll ans = -9000000000;
		roop(i, n) {
			cin >> a[i];
			
			if (i > 0) {
				dp[i] = max(dp[i - 1] + a[i], a[i]);
			}
			else {
				dp[i] = a[i];
			}
		}
		for (int i = 0; i < n; i++) {
			ans = max(dp[i],ans);
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
using ll = long long;
int main(){
    while(1){
        ll n,ans=-10000000000;
        cin >> n;
        if(n==0)    break;
        vector<ll> a(n);
        for(ll i=0;i<n;i++) cin >> a[i];
        for(ll i=0;i<n;i++){
            ll sum=0;
            for(ll j=i;j<n;j++){
                sum+=a[j];
                ans = max(sum,ans);   
            }
        }
        cout << ans << endl;
    }
    return 0;
}