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() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int* a = new int[n];
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        long long max = a[0];
        for (int i = 0; i < n; i++) {
            long long sum = 0;
            for (int j = i; j < n; j++) {
                sum += a[j];
                if (max < sum) {
                    max = sum;
                }
            }
        }
        cout << max << endl;
        delete[] a;
    }
}

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

bool state = false ;

int main()
{
	int n ;
	while(1)
	{
		cin >> n ;
		if( ! n ) return 0 ;
		
		int * p = new int [n] ;
		
		for(int i = 0 ; i < n ; i ++)
		{
			cin >> p[i] ;
		}
		
		int max , pos_b , pos_e , contain ;
		max = pos_b = pos_e = contain = 0 ;
		
		for(int i = 0 ; i < n ; i ++)
		{
			if(contain < 0) contain = 0 ;
			else 
			{
				contain += p[i] ;
			}
			
			if(contain > max) max = contain ;
		}
		
		if(state) cout << endl ;
		state = true ;
		cout << max ;
	} 
	return 0 ;
 }

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

int main()
{
    while (true) {
        int n;
        std::cin >> n;
        if (n == 0) break;

        int a[5000];
        for (int i = 0; i < n; ++i) std::cin >> a[i];

        int max = std::numeric_limits<int>::min();
        for (int i = 0; i < n; ++i) {
            int sum = a[i];
            if (max < a[i]) max = a[i];
            for (int j = i + 1; j < n; ++j) {
                sum += a[j];
                if (max < sum) max = sum;
            }
        }
        std::cout << max << std::endl;
    }
}

C++: #include<stdio.h>
int main(){
	int a;
	while(1){
		scanf("%d",&a);
		if(a==0)return 0;
		long long int n[10000];
		for(int i=0;i<a;i++)scanf("%lld",n+i);
		long long int dp[10000];
		dp[0]=n[0];
		long long int max=0;
		for(int i=1;i<a;i++){
			if(dp[i-1]>0)dp[i]=dp[i-1]+n[i];
			else dp[i]=n[i];
			if(max<dp[i])max=dp[i];
		}
		printf("%lld\n",max);
	}
}

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

#define MAX 5000

using namespace std;

int main(void){

	int n,a[5000];
	int wa,max;

	while(1){
		cin>>n;
		wa=0;
		for(int i=0;i<n;i++) cin>>a[i];
		max=a[0];
		for(int i=n-1;i>=0;i--){
			wa+=a[i];
			if(wa<0) wa=0;
			if(wa>max) max=wa;
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

int arr[5000];

int p14(int size) {
	int i=0;
	int j=0;
	int sum = arr[0];
	int smax = arr[0];
	
	int s = 0;
	
	for (int t=1; t<size; t++) {
		sum+=arr[t];
		
		if ( sum > smax ) {
			i = s;
			j = t;
			smax = sum;
		}
		
		if (sum < 0 ) {
			for(; s<=t; s++) {
				sum -= arr[s];
				if ( sum > smax ) {
					i = s;
					j = t;
					smax = sum;
				}
			}
		}
	}
	
	return smax;
}

int main(void) {
	while(true) {
		int n;
		scanf("%d", &n);
		if ( n==0 ) { return 0; }
		
		for(int i=0; i<n; i++) {
			scanf("%d", &arr[i]);
		}
		
		printf("%d\n", p14(n));
	}
}

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 sum(vector<int> &nums, int oft, int len) {
    int ret = 0;
    for ( int i = 0; i < len; i++ ) {
        ret += nums[oft+i];
    }
    return ret;
}

int main() {
    int n;
    
    while(cin >> n, n) {
        int max_n;
        vector<int> nums(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) for( int len = 1; len <= n-oft; len++ ) {
            // cout << oft << " " << len << endl;
            max_n = max(max_n, sum(nums, oft, len));
            cout << max_n << " " << oft << " " << len << endl;
        }
        cout << max_n << endl;
    }

    return 0;
}

C++: #include<stdio.h>
int ar[5000];
int d[5000];

int max(int a,int b){
	if(a>=b)return a;
	else return b;
}

int main(){
	int n,i,j;
	while(1){
		scanf("%d",&n);
		if(n==0)return 0;
		for(i=0;i<n;i++){
			scanf("%d",&ar[i]);
		}
		d[0]=0;
		int ans=0;
		for(i=1;i<n+1;i++)d[i]=d[i-1]+ar[i-1];
		for(i=0;i<n;i++)for(j=i+1;j<n+1;j++){
			ans=max(ans,d[j]-d[i]);
		}
		printf("%d\n",ans);
	}
}