Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func main() {
	sum := make([]int, 5001)
	for {
		n := nextInt()
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			a := nextInt()
			sum[i+1] = sum[i]+a
		}
		ret := sum[1]
		for i := 0; i <= n; i++ {
			for j := i + 1; j <= n; j++ {
				ret = max(ret, sum[j]-sum[i])
			}
		}
		fmt.Println(ret)
	}
}

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

C++: #include<cstdio>
int main(){int n,i,j,s,m,a[5000];while(scanf("%d",&n)&&n){for(i=0;i<n;i++)scanf("%d",&a[i]);m=-2147483647;for(i=0;i<n;i++,s=0)for(j=i;j<n;)if((s+=a[j++])>m)m=s;printf("%d\n",m);}}

C++: #include<cstdio>

int main(){
	int n,max,sum,t;
	scanf("%d", &n);
	while(n){
		scanf("%d", &t);
		max = sum = t;
		for(int i = 1; i < n; i++){
			if(sum < 0){
				sum = 0;
			}
			scanf("%d", &t);
			sum += t;
			if(sum > max){
				max = sum;
			}
		}
		printf("%d\n", max);
		scanf("%d", &n);
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main(){
  for(;;){
    int n;scanf("%d",&n);
    if(!n){break;}
    int min=0, max=0x80000000, sum=0;
    REP(i,n){
      int a;scanf("%d",&a);
      min=std::min(min,sum);
      max=std::max(std::max(max,sum+a-min),a);
      sum+=a;
    }
    printf("%d\n",max);
  }
}

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

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		int num[5001];
		for(int i = 0; i < n; i++){
			cin>>num[i];
		}
		
		int dp[5001];
		dp[0]=num[0];
		int maxNum=max(0,dp[0]);
		for(int i = 1; i < n; i++){
			dp[i]=max(num[i],dp[i-1]+num[i]);
			maxNum=max(maxNum,dp[i]);
		}
		cout<<maxNum<<endl;
		
	}

	return 0;
}

C++: 
#include<stdio.h>
#include <iostream>
#include<bits/stdc++.h> 

using namespace std;
int length=0;
int* sums;

int main(){
  string str="";
  while(1){
  cin>>length;
  if(length==0)break;
  sums=new int[length+1];
  sums[0]=0;
  int s=0;
  for(int i=0;i<length;i++){
    int v=0;
    cin>>v;
    s+=v;
    sums[i+1]=s;
  }
  int max=INT_MIN;
  for(int i=0;i<length+1;i++){
    for(int j=i;j<length+1;j++){
      int diff=sums[j]-sums[i];
      if(diff>max){
        max=diff;
      }
    }
  }
  cout<<max;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef complex<double> P;

int main(){
	int n;
	while(cin >> n && n){
		int ans = 0;
		int tot = 0;
		for(int i = 0 ; i < n ; i++){
			if( tot < 0 ) tot = 0;
			int x;
			cin >> x;
			tot += x;
			ans = max(ans,tot);
		}
		cout << ans << endl;
	}
}

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

using namespace std;
int main(void)
{
	int n,sum,log;
	while(scanf("%d",&n))
	{
		if(n == 0) break;
		int a[5001] = {0};
		for(int i = 0;i < n;i++)
		{
			scanf("%d",&a[i]);
		}
		sum = 0;
		for(int i = 0;i < n;i++)
		{
			log = 0;
			for(int j = i;j < n;j++)
			{
				log += a[j];
				if(sum < log)
				{
					sum = log;
				}
				else
				{
				}
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,a[5000],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];
				cout<<kazu<<endl;
				if(kazu>saidai){
					saidai=kazu;
				}
			}
		}
		cout<<saidai<<endl;
	}
}

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]);

			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);
		}
	}
}