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 <sstream>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;

#define ITER( c ) __typeof( c ).begin()
#define REP( i, m, n ) for ( int i = m; i < n; i++ )
#define UREP( i, m, n ) for ( unsigned int i = m; i < n; i++ )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) c.begin(), c.end()
#define PB( n ) push_back( n );
#define MP( a, b ) make_pair( a, b )
#define fst first
#define snd second

int main()
{
	while ( true )
	{
		int n;
		cin >> n;

		if ( n == 0 )
		{
			break;
		}

		vector<ll> sum;
		sum.PB( 0 );

		REP( i, 0, n )
		{
			int in;
			cin >> in;
			sum.PB( *sum.rbegin() + in );
		}

		ll max = LLONG_MIN;

		REP( i, 0, sum.size() )
		{
			REP( j, i, sum.size() )
			{
				ll tmp = sum[j] - sum[i];
				if ( max < tmp )
				{
					max = tmp;
				}
			}
		}

		cout << max << endl;
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
#define N 5000

int main(void)
{
	while(1) {
		int n;
		long an[N] = {0};
		long long sum = 0, max = 0;
		cin >> n;

		if(n == 0)	break;

		for(int i = 0; i < n; i++) {
			cin >> an[i];
		}

		for(int i = 0; i < n; i++) {
			sum = 0;
			for(int j = i; j < n; j++) {
				sum += an[j];
				if(sum > max) {
					max = sum;
				}
			}
		}

		cout << max << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
	long long int n,ans = 0;
	while(cin >> n){
		if(n == 0)break;

		long int a[n];

		for(int i = 0;i < n;i++){
			cin >> a[i];
			ans += a[i];
		}
		cout << ans << endl;
	}
}

C++: #include<stdio.h>
int main(void)
{
	int a[5000],i,j,sum=0,max[5000]={-10001},c=0,n;
	
	while(1){
		scanf("%d",&n);
		if( n == 0)
			break;
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		for(i=0;i<n;i++){
			for(j=i;j<n;j++){
				sum = sum + a[j];
				if(max[c] < sum)
					max[c] = sum;
			}
			sum = 0;
		}
		c++;
	}
	for(i=0;i<c;i++){
		printf("%d\n",max[i]);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,a[5000],saidai=0;
	while(cin>>n&&n!=0){
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=0;n<i;i++){
			for(int x=n;x>=i;x--){
				int kazu=0;
				for(int y=x;y>=i;y--){
					kazu=kazu+a[y];
				}
				if(kazu>saidai){
					saidai=kazu;
				}
			}
		}
	}
	cout<<saidai<<endl;
}

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

int main(){
	int n;
	while(cin>>n, n){
		int mat[n];
		int maxi = 0;
		for(int x=0;x<n;++x){
			int j;cin>>j;
			mat[x] = j;
			maxi = max(maxi,j);
		}
		for(int j=2;j<=n;++j){
			for(int i=0;i<n;++i){
				int tmp = 0;
				for(int x=i;i+j<=n && x<i+j;++x){
					tmp += mat[x];
				}
				maxi = max(maxi,tmp);
			}
		}
		cout<<maxi<<endl;
	}
	return 0;
}

C++: #include <iostream>

int calcMaxSum(int amount_set);

int main()
{
    while (true) {
        int amount_set;
        std::cin >> amount_set;
        if(amount_set == 0) {
            break;
        }
        std::cout << calcMaxSum(amount_set) << std::endl;
    }

    return 0;
}

int calcMaxSum(int amount_set)
{
    const int MAXNUMBER = 100000;//??\????????????????????§??????

    int *data;
    data = new int[amount_set + 1];
    int *sum = new int[amount_set + 1];

    sum[0] = 0;//???????????????????????????????????´??????sum[0]??§??????

    std::cin >> data[1];//?????????????????±???
    sum[1] = data[1];//?????????????????????

    for (int number = 2; number <= amount_set; number++) {
        std::cin >> data[number];//????????????????????????
        sum[number] = sum[number - 1] + data[number];// ????????´??°
    }

    int max = -MAXNUMBER;//????????????????????¨??¨-MAXNUMBER???????????????????????§???????????????????????????????°????

    for (int number_big = 1; number_big < amount_set; number_big++) {
        for (int number_small = 0; number_small < number_big; number_small++) {
            if (sum[number_big] - sum[number_small] > max) {
                max = sum[number_big] - sum[number_small];
            }
        }
    }
    delete [] data;
    delete [] sum;

    return max;

}

C++: #include <stdio.h>
#define mx(a,b) (a<b?b:a)
int main() {int i,j,k,n;while (scanf("%d",&n)!=EOF && n) {j=i=0;while (n--) {scanf("%d",&k);j+=k;i=mx(i,j);j=mx(j,0);} printf("%d\n",i);} return 0;}

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

int main() {
	int n,a[5000],i,j,max,sum;
	
	while(cin>>n,n){
		
		for(i=0;i<n;++i)cin>>a[i];
		
		max=-10000;
		
		for(i=0;i<n;++i){
			sum=0;
			for(j=i;j<n;++j){
				sum+=a[j];
				if(sum>max)max=sum;
			}
		}
		
		cout << max << endl;
	}
}

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

int main(){
        int n,a[5010];
        while(cin>>n && n){
                for(int i=0; i<n; i++) cin >> a[i];
                long max = 0;
                for(int k = 0; k < n; k++){
                        long sum = 0;
                        for(int i=0; i<n-k; i++){
                                sum += a[i];
                        }
                        max = (max>sum)? max:sum;
                        for(int i=0; i<=k; i++){
                                sum += (a[n-k+i]-a[i]);
                                max = (max>sum)? max:sum;
                        }
                }
                cout << max << endl;
        }

}

C++: #include <iostream>
using namespace std;
int main(){
	for (;;){
		int a,goukei=0,max=-999999999,b;
		cin>>a;
		if (a==0)break;
		int data[a+1]={0};
		for (int A=1;A<=a;A++){
			cin>>data[A];
			if (max<data[A])max=data[A];
			goukei+=data[A];
			data[A]=goukei;
			if (max<data[A])max=data[A];
		}max=-999999999;
		for (int A=1;A<=a;A++){
			b=A-2;
			for (int B=A-1;B>=0;B--){
				goukei=0;
				goukei=data[A]-data[B];
				if (goukei>max) max=goukei;
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: 7
-5
-1
6
4
9
-6
-7
13
1
2
3
2
-2
-1
1
2
3
2
1
-2
1
3
1000
-200
201
0

C++: #include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;

int main(){
	int n;
	int A[5000];
	int sum=0,max=0;
	scanf("%d",&n);
	while(n != 0){
			memset(A,0,sizeof(A));
			for(int i=0;i<n;i++)cin >> A[i];

			for(int i=0;i<n;i++){
				int next = i + 1;
				sum = A[i];
				if(sum > max)max = sum;
				while(next < n){
					sum += A[next];
					if(sum > max)max = sum;

					next++;
				}
			}

			cout << max << endl;
			max = 0;
			scanf("%d",&n);	
	}


}

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

int main(void)
{
  int n, max1, a[5001];
  
  while(cin >> n, n) {
    for(int i = 0 ; i < n ; i++) {
      cin >> a[i];
    }
    max1 = a[0];
    
    /* ツ全ツ探ツ催オ */
    for(int i = 0 ; i < n ; i++) {
      int sum = 0;

      for(int j = i ; j < n ; j++) {
	sum += a[j];
	max1 = max( max1, sum);
      }
    }
    cout << max1 << endl;
  }
  return 0;
}