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 <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 

int main(void){  
  int n;
  while(cin>>n,n){
    int sum = 0, maxs = 0, a;
    REP(i,n){
      cin >> a;
      if(a>=0)
        sum += a;
      else{
        maxs = max(sum, maxs);
        sum = 0;
      }
    }
    cout << maxs << endl;
  }
  return 0;
}

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

int main()
{

	int n, num;
	vector< int > a;

	while( 1 ) {

		int Max = -1000000;

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

		//??????????????????
		a.push_back( 0 );

		for( int i = 0; i < n; i++ ) {
		
			cin >> num;
			a.push_back( num );
			
		}

		for( int i = 1; i < n; i++ ) {
		
			a[i - 1] + a[i] > a[i] ? a[i] = a[i - 1] + a[i] : a[i] = a[i];

			if ( a[i] > Max ) {
				Max = a[i];
			}
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}

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

int main(){
  int n, num, a, maxx;

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

    num = 0;

    for(int i=0;i<n;i++){
      cin >> a;
      num += a;
      if(i == 0) maxx = a;
      maxx = max(maxx,num);
      if(num<0) num = 0;
    }
    cout << maxx << endl;
  }

  return 0;
}

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

C++: #include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
int main() {
  int n, input;
  vector<int> input_v;
  vector<int> part_v;
  int max_num = 0;
  while (cin >> n) {
    if (n == 0) {
      break;
    }
    input_v.clear();
    while(n--) {
      cin >> input;
      input_v.push_back(input);
    }
    max_num = 0;
    for (int i = 0; i < input_v.size(); ++i) {
      for (int len = 3; len <= input_v.size() - i; ++len) {
        part_v.clear();
        for (int m = 0; m < len && i + m < input_v.size(); ++m) {
          part_v.push_back(input_v[i + m]);
        }
        max_num = max(accumulate(part_v.begin(), part_v.end(), 0), max_num);
      }
    }
    cout << max_num << endl;
  }
  return 0;
}

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

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

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

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
1
-1
0

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int n,x[5001],sum=0,maxx=0,c=0;
        cin>>n;
        c=n;
        if(n==0)return 0;
        for(int i=0;i<n;i++){
            cin>>x[i];
        }
        for(int i=0;i<n;i++){
            c--;
            //for(int j=i;j<n;j++){
            //    for(int c=n-1;c>=i;c--){
                    for(int z=i;z<=c;z++){
                        sum+=x[z];
                        maxx=max(maxx,sum);
                    }
                    sum=0;
              //  }
            //}
        }
        cout<<maxx<<endl;
    }
}

C++: #include <iostream>
using namespace std;
int main() {
	int s,h,n,i,a[5000];
	while(true) {
		cin >> n;
		if (n==0) break;
		for (i=0;i<n;i++) cin >> a[i];
		s=0; h=-100000;
		for (i=0;i<n;i++) {
			s=(s+a[i]>=a[i]) ? s+a[i] : a[i];
			h=(s > h)  ? s : h;
		}
        cout << h << endl;
	}
	return 0;
	}

C++: #include<stdio.h>

int main()
{
	int n;
	while(true)
	{
		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]);
			if(a[x]<=10000||a[x]>=-100000)
			{
				x--;
			}
			else
			{
			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>
#include <climits>
using namespace std;
int s[5010];
int main(){
  int n, a;
  while(cin >> n, n){
    int ans = -(INT_MAX-1);
    for(int i = 0 ; i < n ; i++){
      cin >> a;
      if(!i)s[i] = a;
      else{
	s[i] = max(a, a + s[i-1]);
      }
      ans = max(ans, s[i]);
    }
    cout << ans << endl;
  }
  return 0;
}