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 <vector>
#include <algorithm>
using namespace std;

int main(){
    int n;


    while(cin >> n, n != 0){
        vector<int> a(n);
        for(int i=0; i<n; i++){
            cin >> a[i];
        }

        int minimum = 0;
        int x = 0;
        int maximum = -9999999;
        for(int i=0; i<a.size(); i++){
            x += a[i];
            maximum = max(maximum, x-minimum);
            minimum = min(minimum, x);
        }

        cout << maximum << endl;

    }

    return 0;
}

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

int main(){
	bool flag[5000] = {false};
	int n, in[5000];
	long long ans, tmp = 0ll;
	
	while(true){
		cin >> n;
		if(n == 0)
			break;

		for(int i = 0; i < n; ++i){
			cin >> in[i];
			if(in[i] > 0)
				flag[i] = true;
		}//input

		for(int i = 0; i < n; ++i){
			for(int j = i; j < n; ++j){
				if(flag[i] && flag[j]){
					for(int k = i; k <= j; ++k)
						tmp += in[k];
					if(tmp > ans){
						ans = tmp; 
						tmp = 0ll;
					}	
					else
						tmp = 0;
				}
			}
		}
		
		cout << ans << endl;//output
		
		ans = 0;
		for(int i = 0; i < n; ++i)
			flag[i] = false;//intialize
	
	}
	return 0;
}

C++: #include<stdio.h>

int N[5001]={};
int main(){

int n,x;

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


for(int i=0;i<n;i++)
scanf("%d",&N[i]);
int t=N[0],s=0;
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
{
s+=N[j];if(t<s)t=s;
}
s=0;
}
printf("%d\n",t);
}
return 0;
}

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

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

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

int main(){
	int n;
	cin >> n;
	while(n != 0){	

		int a[n];
		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 >> a[i];
		}
		int maximum = 0;
		

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

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

	return 0;
}

C++: 
#include<iostream>
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 Max = a[0];
        
        for(int i=0; i<n; i++){
            int sum=0;
            for(int j=i; j<n; j++){
                sum+=a[j];
                if(Max < sum) Max = sum;
            }
        }
        cout << Max << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
//	cut here before submit 
//	freopen ("testcase.MSS", "r", stdin );
	int n;
	while (scanf ("%d", &n ), n ){
		vector<int> a (n+1, 0 );
		vector<int> sum (n+1, 0 );
		for (int i = 1; i <= n; i++ ){
			scanf ("%d", &a[i] );
		} // end rep
		for (int i = 1; i <= n; i++ ){
			sum[i] = sum[i-1] + a[i];
		} // end for
		int res = 0;
		for (int i = 1; i <= n; i++ ){
			int curr = 0;
			for (int j = i+1; j <= n; j++ ){
				curr = sum[j] - sum[i-1];
				res = max (res, curr );
			} // end for
		} // end for
		printf ("%d\n", res );
	} // end loop
	
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>

using namespace std;
int main(){
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		long long int a, sum = 0, hold = 0;
		
		bool start = false;
		for(int i = 0;i < n;i++){
			cin >> a;
			if(a > 0) start = true;
			if(start){
				sum += a;
				if(hold < sum){
					hold = sum;
				}
			}
		}
		cout << hold << endl;
	}
	
	return 0;
}

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

int a[5000];

int main()
{
	int n, i, j, s, max;

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

		for (i = 0; i < n; i++)
			cin >> a[i];

		max = -2147483647;
		for (i = 0; i < n; i++)
		{
			s = 0;
			for (j = i; j < n; j++)
			{
				s += a[j];
				if (s > max)
					max = s;
			}
		}
		cout << max << endl;
	}
	return 0;
}

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

using namespace std;

int ret = 0, a[5000], n;

int main()
{
    while( scanf( "%d", &n ) != EOF )
    {
        if( n == 0 ) break;
        for( int i = 0; i < n; i++ )
        {
            scanf( "%d", &a[i] );
        }

        int l = 0;
        while( l < n )
        {
            int r = l , sum = 0;
            while( r < n )
            {
                sum += a[r];
                ret = max( ret, sum );
                r++;
            }
            l++;
        }
        printf( "%d\n", ret );
    }

    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int nn[5001] = { 0 }, temp, n, max = -110000;
	while (cin >> n && (n != 0)){
		for (int i = 0; i < n; i++){
			cin >> nn[i];
		}
		temp = nn[0];
		for (int i = 1; i < n; i++){
			temp += nn[i];
			if (temp < nn[i]) temp = nn[i];
			if (max < temp) max = temp;
		}if (max < nn[0]) cout << nn[0] << endl;
		else cout << max << endl;
		max = -110000;
	}
	return 0;

C++: #include <iostream>

using namespace std;

int main()
{
    while(1)
    {
        int n;
        cin>>n;if(!n)return 0;
        long long a[5010];
        for(int i=0;i<n;++i){
            cin>>a[i];
        }
        long long ans=-20000000000;
        long long buf;
        for(int i=0;i<n;++i){
            buf=0;
            for(int j=i;j<n;++j){
                buf+=a[j];
                if(buf>ans)ans=buf;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}