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 <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
using namespace std;
int maxsum(int x,vector<int> a){
	
	vector<int> s(x+1,0);
	int max;
	for(int i=1;i<=x;i++){
		if(s[i-1]<0)
			s[i]=a[i];
		else
			s[i]=s[i-1]+a[i];
	}
	for(int i=0;i<=x;i++)
		cout<<s[i]<<" ";
	cout<<endl;
	max = *max_element(s.begin(),s.end());
	return max;
	
}

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

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

int main()
{

	int n, num;
	vector< int > a;

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

		int Max = -100001;

		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] = max( a[i], a[i] + a[i - 1] );
			Max  = max( Max, a[i] );
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}

C++: #include<iostream>

using namespace std;

int main(){
	int n;
	while(cin>>n,n){
		long long int a[n];
		long long int max=-100000;
		int input;
		for(int i=0;i<n;i++){
			a[i]=0;
			cin>>input;
			for(int j=0;j<=i;j++){
				a[j]+=input;
				if(max<a[j])max=a[j];
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(ll i=0;i<n;i++)
using namespace std;
typedef long long ll;

ll sum[100001];
int main() {
	ll n;
	while (scanf("%lld", &n), n) {
		ll cnt = 0;
		rep(i, n) {
			sum[i] = cnt;
			int a; scanf("%d", &a);
			cnt += a;
		}
		sum[n] = cnt;
		ll Max = LLONG_MIN;
		rep(i, n) {
			for (int j = i + 1; j <= n; j++) {
				Max = max(Max, sum[j] - sum[i]);
			}
		}
		cout << Max << endl;
	}
	return 0;
}

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

int main(){
	int n;
	while(cin >> n, n){
		vector<int> vec;
		for(int i = 0; i < n; i++){
			int a;
			cin >> a;
			vec.push_back(a);
		}

		int max = vec[0] + vec[1];
		for(int i = 0; i < vec.size(); i++){
			for(int j = i+1; j < vec.size(); j++){
				int add = 0;
				for(int k = i; k <= j; k++){
					add += vec[k];
				}
				if(max < add) max = add;
			}
		}

		cout << max << endl;
	}
}

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

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

int n;
vector<int> v;
long long s[5000];

int main(){
    while(cin>>n,n){
        v=vector<int>(n);
        REP(i,n)cin>>v[i];
        long long ans=-(1<<30);
        REP(i,n){
            s[i]=v[i];
            ans=max(s[i],ans);
            for(int j=i+1; j<n; j++){
                s[j]=s[j-1]+v[j];
                ans=max(s[j],ans);
            }
        }
        cout<<ans<<endl;
    }
}

C++: #include<stdio.h>

int main(void) 
{
    long int num[5000];
	int cut_i;
	int kousuu;
	long int nyuryoku;
	
	while(1){
		scanf("%d",&kousuu);
		
		if(kousuu == 0){
			break;
		}

		int kou = 0;
		long long int max = -100000;
		for(cut_i=0;cut_i<kousuu;cut_i++){
			num[cut_i]=0;
		}

		for(cut_i=0;cut_i<kousuu;cut_i++){
			scanf("%d",&nyuryoku);

			if(num[kou] * nyuryoku <0){
				kou++;
			}
			num[kou]+=nyuryoku;
			
			if(max<num[kou]){
				max = num[kou];
			}
		}

		kou++;
		cut_i = 0;
		
		for(cut_i=0;cut_i<kou;cut_i++){

			if(max<num[cut_i]){
				max = num[cut_i];
			}
			
			if(num[cut_i]+num[cut_i+1] > 0){
				num[cut_i+1]+=num[cut_i];
			}
		}

		printf("%d\n",max);

	}
    return 0;
}

C++: #include <fstream>
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;

int main() {
  // ifstream cin("../test.txt");
  int n;
  while (true) {
    cin >> n;
    if (!n) break;
    vector<int> a(n);
    vector<int> sub_sum(n); // a[0] + ... + a[i]
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sub_sum[0] = a[0];
    int max_sum = -100000000;
    for (int i = 1; i < n; i++) {
      sub_sum[i] = sub_sum[i-1] + a[i];
      max_sum = max(max_sum, sub_sum[i]);
    }
    for (int i = 1; i < n; i++) {
      for (int j = 0; j < i; j++) {
        max_sum = max(max_sum, sub_sum[i] - sub_sum[j]);
      }
    }
    cout << max_sum << 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
0

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

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<int> maxSum(n);
		int a;
		cin >> a;
		maxSum[0] = a;
		int max = -999999999;
		for(int i = 1; i < n; ++i)
		{
			cin >> a;
			if(maxSum[i - 1] + a < a)
			{
				maxSum[i] = a;
			}
			else
			{
				maxSum[i] = maxSum[i - 1] + a;
			}
			if(max < maxSum[i])
			{
				max = maxSum[i];
			}
		}
		cout << max << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;
int main(void)
{
	int n, a[5001];
	while (1) {
		cin >> n;
		if (n == 0)
			break;
		for (int i = 1; i <= n; i++)
			cin >> a[i];
		int goukei = 0, ryuta = -10000000;
		for (int i = 1; i <= n; i++)
		{
			goukei = 0;
			for (int j = i; j <= n; j++)
			{
				goukei = goukei + a[j];
				ryuta = max(goukei, ryuta);
			}
		}
		cout << ryuta << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio.h>
using namespace std;
int main (){
while (1){
long n,dset[5000],max=-99999,temp=0;
cin>>n;
if (n==0)break;
for (int i=0;i<n;i++){
        cin>>dset[i];
}
for (int i=0;i<n;i++){
        for (int j=i;j<n;j++){
                temp=temp+dset[j];
                if (max<temp){
                        max=temp;
                }
        }
temp=0;
}
printf ("%d\n",max);
}
return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;

#define ITER( c ) __typeof( c ).begin()
#define REP( i, m, n ) for ( int i = m; i < n; i++ )
#define UREP( i, m, n ) for ( unsigned int i = m; i < n; i++ )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) c.begin(), c.end()
#define PB( n ) push_back( n );
#define MP( a, b ) make_pair( a, b )
#define fst first
#define snd second

int main()
{
	while ( true )
	{
		int n;
		cin >> n;

		if ( n == 0 )
		{
			break;
		}

		vector<int> sum;
		sum.PB( 0 );

		REP( i, 0, n )
		{
			int in;
			cin >> in;
			sum.PB( *sum.rbegin() + in );
		}

		int max = INT_MIN;

		REP( i, 0, sum.size() )
		{
			REP( j, i, sum.size() )
			{
				int tmp = sum[j] - sum[i];
				if ( max < tmp )
				{
					max = tmp;
				}
			}
		}

		cout << max << endl;
	}

	return 0;
}

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

int main(){
  int n;
  int a[5000];
  while(cin >> n && n>0){
    for(int i=0;i<n;i++)
      cin >> a[i];
    long long sum=0,tmp=0,ma=-100000;
    int m=-100000;
    bool flg=true;
    for(int i=0;i<n;i++){
      if(flg) m=max(m,a[i]);
      if(a[i]>0){
	flg=false;
	sum+=a[i];
	continue;
      }
      ma=ma>sum?ma:sum;
      for(tmp=sum;i<n && a[i]<=0;i++){
	tmp+=a[i];
      }i--;
      if(tmp>0)
	sum=tmp;
      else
	sum=0;
    }
    ma=ma>sum?ma:sum;

    cout << (flg?m:ma) << endl;
  }
}