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++: 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;
}

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;