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 <iostream>
using namespace std;

int main() {
	int n;
	int max;
	while(1) {
		cin >> n;
		if(n == 0) break;
		int a[5010];
		for(int i = 0; i < n; i++) {
			cin >> a[i];
		}
		max = a[0];
		for(int i = 0; i < n; i++) {
			int temp = 0;
			for(int j = i; j < n; j++) {
				temp += a[j];
				if(temp > max) max = temp;
			}
		}
		cout << max << endl;
	}
	return 0;
}

C++: /* AOJ 0022 Maximum Sum Sequence */

#include <iostream>
#include <climits>

using namespace std;

void update(int i, int x);
void init();

const int MAX_N = 5000;
const int MIN_A = -100000;

int max_sum[MAX_N + 1];

int
main()
{
    for (;;) {
        int n, i;

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

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

            cin >> a;
            update(i, a);
            cout << max_sum[i] << " ";
        }
        cout << endl;

        cout << *max_element(max_sum + 1, max_sum + n + 1) << endl;
    }

    return 0;
}

void
update(int i, int a)
{
    max_sum[i] = max(max_sum[i - 1] + a, a);
}

void
init()
{
    max_sum[0] = INT_MIN - MIN_A + 1;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,i,j;
  cin >> n;
  while(n!=0) {
    long long sum[5001]={};
    int b;
    vector <long long> v;
    cin >> sum[1];
    for(i=2;i<=n;i++){
      cin >> b;
      sum[i]=sum[i-1]+b;
      //cout << sum[i] << endl;
    }
    
    for(i=0;i<=n;i++){
      for(j=i+1;j<=n;j++){
	v.push_back(sum[j]-sum[i]);
      }
    }
    sort(v.begin(),v.end());
    cout << v[v.size()-1] << endl;
    cin >> n;
  }
  return 0;
  
}

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

int a[5001]={0};

int main(){
    int n;
    while(cin >> n, n != 0){
        for(int i=0;i<n;++i)cin >> a[i];
        int maxi = INT_MIN;
        for(int i=0;i<n;++i){
            int sum = a[i];
            if(sum > maxi)maxi = sum;
            for(int j=1;i+j<n;++j){
                sum += a[i+j];
                if(sum > maxi)maxi = sum;
            }
        }
        cout << maxi << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

int main(void){
	const int INF=-100001;
	int n;
	int a,b;
	int num[5001];
	int ans=INF,ans2=0;
	while(1){
		ans=INF,ans2=0;
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++)cin >>num[a];
		for(b=0;b<n;b++){
			ans2=0;
			for(a=b;a<n;a++){
				ans2+=num[a];
				ans=max(ans,ans2);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <stack>
#include <cstring>

using namespace std;

int main(){
	int n;
	int max,tmpmax1,tmpmax2;
	while(cin >> n && n != 0){
		max = -100001;
		int *factor = new int[n];
		
		for(int i = 0; i < n; i++){
			cin >> factor[i];
		}

		for(int i = 0; i < n - 1; i++){
			tmpmax1 = 0;
			tmpmax2 = -100001;
			for(int j = i; j < n; j++){
				tmpmax1 += factor[j];
				if(tmpmax2 < tmpmax1){
					tmpmax2 = tmpmax1;
				}
			}
			if(tmpmax2 < 0){
				for(int i = 0; i < n; i++){
					if(tmpmax2 == factor[i]){
						if(i != n - 1 && factor[i + 1] <= 0){
							tmpmax2 += factor[i + 1];
							break;
						}
					}
				}
			}
			if(max < tmpmax2){
				max = tmpmax2;
			}
		}
		delete [] factor;
		cout << max << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include <algorithm>


using namespace std;

int main(){
	int n;
	int max1;
	int maxS;
	int sum=0;
	int sumS=0;
	int  raw[5000];
	int ans;
	while(cin>>n,n!=0){
		sum=0;
		maxS=0;
		sumS=0;
		cin >> raw[0];
		max1=raw[0];
		sum += raw[0];
		if(sum<0)sum=0;
		for(int i=1;i<n;i++){
			cin >> raw[i];
			if(max1<raw[i]) max1 = raw[i];
			if(raw[i]<0){
				if(sumS<sum) sumS=sum;
			}
			sum += raw[i];
			if(sum<0){
				if(maxS<sum)maxS=sum;
				sum=0;
			}
		}
		ans=max(sum,max(max(sumS,max1),maxS));
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include<iostream>

int n;
int a[1000];

void add( int i, int x )
{	
	while( i <= n ){
		a[i] += x;
		i += i & (-i);
	}
	
	return;
}

int sum( int i )
{
	if( i == 0 ) return 0;

	int s = 0;
	while( i > 0 ){
		s += a[i];
		i -= i & (-i);
	}
	
	return s;
}

int main()
{
	while( 1 ){
		memset( a, 0, sizeof( a ) );
	
		std::cin >> n;
		if( !n ) break;
		
		for( int i = 1; i <= n; i++ ){
		 	int x;
			std::cin >> x;
			add( i, x );
		}
		
		int ans = 0;
		
		for( int i = 0; i < n; i++ ){
		 	for( int j = i + 1; j <= n; j++ ){
				ans = std::max( ans, sum( j ) - sum( i - 1 ) );
			}
		}
		
		std::cout << ans << std::endl;
	}
	
 	return 0;
}

C++: #include <iostream>
#include <limits.h>
using namespace std;

int main() {
  int n;
  int a[5000];
  int sum[5001];
  int tmp;
  int max;
  while (cin >> n, n) {
    for (int i=0; i<n; i++) {
      cin >> a[i];
    }
    sum[0] = 0;
    for (int i=0; i<n; i++) {
      sum[i+1] = sum[i] + a[i];
    }

    max = -INT_MAX;
    for (int i=0; i<n; i++) {
      for (int j=i+1; j<=n; j++) {
        tmp = sum[j] - sum[i];
        if (tmp > max) max = tmp;
      }
    }
    cout << max << endl;
  }

  return 0;
}

C++: #include <stdio.h>

#define SGN(X) ((X)>0?1:(X)<0?-1:0)
int compressRead(int a[], int n);

int main(void){
	int n;
	int a[5000];
	int max, cur;
	
	while (scanf("%d", &n), n){
		n = compressRead(a, n);
/*		printf("a[%d]:", n);
		for (int i=0; i<n; i++){
			printf("%d ", a[i]);
		}
		puts(""); */
		max = a[0];
		for (int i=0; i<n; i++){
			cur = 0;
			for (int j=i; j<n; j++){
				cur += a[j];
				if (cur > max) max = cur;
			}
		}
		printf("%d\n", max);
	}
	
	return 0;
}

int compressRead(int a[], int n){
	int idx=0;
	int x,last;
	
	scanf("%d", &x);
	last=a[idx]=x;
	for (int i=1; i<n; i++){
		scanf("%d", &x);
		if (x==0) continue;
		if (x<0){
			a[++idx] = x;
//			printf("a[%d] = \%d\n",idx,x);
		}else{
			if (last<0) a[++idx]=0;
			a[idx]+=x;
//			printf("a[%d] += %d (=%d)\n", idx, x, a[idx]);
		}
		last = x;
	}
	
	return idx+1;
}

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

	int n, max=0;
	int *a;
	int sum;

	do{
		max = 0;
		//cout << endl;
		cin >> n;

		if (n == 0) break;

		a = new int[n];

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

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

			sum = 0;

			cin >> a[i];

			for (int j = i; j >= 0; j--){

				sum += a[j];
				if (max < sum) max = sum;
			}
		}

		cout << max << endl;
	} while (1);
}

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