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>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;

int main (void){
  
    int number;
    int max;
    int l = 0;
    while(cin >> number,number)
    {
        int a[5010] = {0};
        vector<int>tempmax2(5010,0);
        int temp = 0;
        REP(i,number)
        cin >> a[i];
        for(int j = 0; j<number;j++)
            for(int k = j;k<number;k++)
            {
                for(int l = k;l<number;l++)
                {
                    if(k == l)
                        tempmax2[k] = a[k];
                    else{
                        
                        tempmax2[k] += a[l];
                    }
                    if(temp <= tempmax2[k])
                        temp = tempmax2[k];
                }
            
            }
        //sort(tempmax.begin(),tempmax.end(),greater<int>());
        //sort(tempmax2.begin(),tempmax2.end(),greater<int>());
        //if(tempmax[0]>temp)
            //answer[l] = tempmax[0];
        //else
        // answer[l] = temp;
        printf("%d\n",temp);
        temp = 0;
    }
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	while(n != 0){
		int sum[n][n];
		for (int i = 0; i < n; ++i){
			for (int j = 0; j < n; ++j){
				sum[i][j] = 0;
			}
		}

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

		int maximum = 0;
		for(int i = 0; i < n - 1; i++){
			for(int j = 1; j < n - i; j++){
				sum[i][j] = sum[i][j-1] + sum[i+j][0];
				maximum = max(maximum, sum[i][j]);
			}
		}

		cout << maximum << endl;
		cin >> n;
	}
	return 0;
}

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

int main() {
int n,b;
int a[5001];
while(1){
	cin>>n;
	if(n==0){
		break;
	}
	for (int kkk=1;kkk<=n;kkk++){
		a[kkk]=0;
	}
	for (int kk=1;kk<=n;kk++){
		cin>>b;
		a[kk]=b;
	}
	int high=a[1];
	for (int k=1;k<=n;k++){
		for(int l=k;l<=n;l++){
			int sum=0;
			for(int m=k;m<=l;m++){
				sum=sum+a[m];
				if(sum>=high){
		high=sum;
			}
		}
	}
	
	}
cout<<high<<endl;
}
	return 0;
}

C++: 
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>
#include <climits>

using namespace std;

double sq(double x){return x*x;}

int a[5001];

int main(){
	int n;
	while(cin>>n,n){
		for (int i = 0; i < n; i++){
			cin>>a[i+1];
			a[i+1] += a[i];
		}
		int ans = INT_MIN;
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < i; j++)
			{
				ans = max(ans,a[i+1] - a[j]);
			}
		}
		cout << ans << endl;
	}

	return 0;
}

C++: //Maximum Sum Sequence
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
  int n;
  while(true){
    ll max=0, tmp=0, d;
    cin>>n;
    if(n==0)break;
    for(int i=0; i<n; i++){
      cin>>d;
      tmp=(tmp>0 ? tmp+d : d);
      if(max<tmp)max=tmp;
    }
    cout<<max<<endl;
  }
  return 0;
}

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

int main()
{
	int N;
	while(cin>>N && N){
	
		vector<int> n(N), dp(N);
		for(int i=0;i<N;i++){
			cin>>n[i];
		}
		int ans = -1<<29;
		int dp[5000];
		for(int i=0;i<a;i++){
			if(i-1 >= 0 && dp[i-1]>0){
				dp[i] += dp[i-1] + n[i];
			}else{
				dp[i] = n[i];
			}
			ans = max(ans, dp[i]);
		}
		
		cout<<max_ret<<endl;
	}
	
	
	return 0;
}

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

int main() {
	int i, j, n, a, max_so_far, max_ending_here;
	
	while (1) {
		cin >> n;
		if (n == 0)break;
		max_so_far = 0;
		max_ending_here = 0;
		for (i = 0; i < n; i++) {
			cin >> a;
			max_ending_here = max_ending_here + a;
			if (max_ending_here < 0)max_ending_here = 0;
			if (max_so_far < max_ending_here)max_so_far = max_ending_here;
		}
		cout << max_so_far << endl;

	}

	return 0;
}

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

using namespace std;

int main(){
	while(true) {
		long long int n, tmp;
		cin >> n;
		if (n<=0) {
			//cout << 0 << endl;
			return 0;
		}
		vector<long long int> intervalos;
		intervalos.reserve(n);
		cin >> tmp;
		bool esNegativo = tmp < 0;
		intervalos.push_back(tmp);
		for (int i = 1; i < n; ++i){
			cin >> tmp;
			if (esNegativo == tmp < 0){
				intervalos.back() += tmp;
			} else {
				intervalos.push_back(tmp);
				esNegativo ^= true;
			}
		}
		long long int best = 0;
		long long int current = 0;
		for (int i = 0; i < intervalos.size(); ++i){
			if (intervalos[i]+current <= 0) {
				current = 0;
			} else {
				current+=intervalos[i];
				if (current > best) {
					best=current;
				}
			}
		}
		intervalos.clear();
		cout << best << endl;
		}
	
}

C++: #include<stdio.h>

int main()
{
	int n;
	while(scanf("%d",&n))
	{
		if(n==0){return 0;}
		
		if( n >= 1 && n <= 5000){
		int a[5000]={0},max=0;
		for(int x=0;x<n;x++)
		{
			scanf("%d",&a[x]);

			for(int y=0;y<=x;y++)
			{
				if(y!=x)
				{
					a[y]+=a[x];
				}
				if(max<a[y])
				{
					max=a[y];
				}
			}
		}
		printf("%d\n",max);
		}
	}
}

C++: #include <iostream>

using namespace std;

int main()
{
	int num;

	while( cin >> num ) {
		if (num == 0 )
			break;

		long int tmpnum = 0;
		long int currnum;
		long int maxnum = 0;
		for( int i = 0; i < num; i++ ) {
			cin >> currnum;

			if( currnum + tmpnum > maxnum ) {
				maxnum = currnum + tmpnum;
			}
			
			if( currnum + tmpnum > 0 )
				tmpnum += currnum;
			else
				tmpnum = 0;
		}
		cout << maxnum << endl;
	}
	return 0;
}

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

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