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

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

using namespace std;

vector<int> vec;

int main(){
    
	while(true){
		int n,tmp;
		scanf("%d",&n);
		if(n==0)return 0;
		for(int i=0;i<n;i++){
			scanf("%d",&tmp);
			vec.push_back(tmp);
		}
		int sum = 0;
		int maxx = INT_MIN; 
		for(int i=0;i<vec.size();i++){
			sum = max(0,sum+vec[i]);
			maxx = max(maxx,sum);
		}
		printf("%d\n",maxx);
		vec.clear();
	}
}

C++: #include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;



int main()
{
	int n;
	while (cin >> n && n > 0)
	{
		vector<int> a = vector<int>(n);
		for (int i = 0; i < n; i++)
			cin >> a[i];

		vector<int> s = vector<int>(1, 0);
		bool f = true;
		bool plus = false;
		for (int i = 0; i < n; i++)
		{
			if (a[i] >= 0)
			{
				if (!f)
					f = true;
				if (!plus)
					plus = true;
				s[0] += a[i];
			}
			else if(s[0] > abs(a[i]))
			{
				if (f)
				{
					s.push_back(s[0]);
					f = false;
				}
				s[0] += a[i];
			}
			else
			{
				s[0] = 0;
			}

		}
		if (!plus)
		{
			int max = a[0];
			for (int i = 1; i < n; i++)
			{
				if (max < a[i])
					max = a[i];
			}
			cout << max << endl;
			continue;
		}
		for (int i = 1; i < s.size(); i++)
		{
			if (s[i] > s[0])
				s[0] = s[i];
		}
		cout << s[0] << endl;
	}

	return 0;
}

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

using namespace std;

int main(){

  int n;


  while(cin >> n){
    if(n == 0) break;
    vector<int> V;
    int status = 1;
    int in;
    int sum = 0;
    for(int i = 0; i < n; i++){
      cin >> in;
      if(i == 0){
	if(in < 0) status = -1;
	else status = 1;

      } else {	
	if(in < 0 && status == 1){
	  status = -1;
	  V.push_back(sum);
	  sum = 0;
	}else if(in > 0 && status == -1){
	  status = 1;
	  V.push_back(sum);
	  sum = 0;
	}
      }
      sum += in;
    }

    V.push_back(sum);

    int max = -1000000001;
    
    for(int i = 0; i < V.size(); i++){
      sum = 0;
      for(int j = i; j < V.size(); j++){
	sum += V[j];
	if(max < sum) max = sum;
      }
    }
    
    cout << max << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> pint;
#define rep(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

int main(){
	int n;
	int a[5010];
	for(;cin>>n,n;){
		int max=0;
		int m=0;
		for(int i=0;i<n;i++){
			cin>>a[i];
			if(a[i]>0)m+=a[i],max=max<m?m:max;
			else if(a[i]+m>0)m+=a[i];
			else m=0;
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
    int n;
    int i;
    int inp,cur,max;
    while (cin>>n)
    {
        if(n == 0){
            break;
        }
        for(i=0;i<n;i++){
            cin>>inp;
            if(i == 0){
                max = inp;
                if(inp < 0){
                    cur = 0;
                }else{
                    cur = inp;
                }
            }else{
                cur = inp + cur;
                if(cur<0){
                    cur = 0;
                }else{
                    if(cur>max){
                        max = cur;
                    }
                }
            }
        }
        cout<<max<<endl;
    }

    
    return 0;
}

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


int main(){
	int n;
	int ary[5010];
	int sum[5020] = { 0 };

	while (cin >> n, n != 0){
		int max_ = numeric_limits<int>::min();
		for (int i = 0; i < n; i++){
			cin >> ary[i];
		}
		for (int i = 1; i < n+1; i++){
			sum[i] = sum[i - 1] + ary[i-1];
		}
		for (int i = 1; i < n + 1; i++){
			for (int j = i; j < n + 1; j++){
				max_ = max(max_, sum[j] - sum[i - 1]);
			}
		}
		cout << max_ << endl;
	}

	return 0;
}

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

int main(){
  long max;
  char str[10];
  int i, j, k;
  int num, nnum;
  long setdata[2][5001], tmp;
  int focus;

  while(cin>>num){
    if(num==0) break;
    for(i=0; i<num; i++){
      cin>>str;
      setdata[0][i]=(long)atol(str);
    }

    max=100001*(-1);
    for(i=0; i<num; i++){
      if(max<setdata[0][i]) max=setdata[0][i];
    }
    focus=1;
    for(i=num-1; i>=1; i--){
      for(j=0; j<i; j++){
        if(i==num-1){
          setdata[1][j]=setdata[0][j]+setdata[0][j+1];
          if(max<setdata[1][j]) max=setdata[1][j];
        }
        else {
          setdata[focus][j]=setdata[1-focus][j]+setdata[1-focus][j+1]-setdata[focus][j+1];
          if(max<setdata[focus][j]) max=setdata[focus][j];
        }
      }
      focus=1-focus;
    }
    printf("%ld\n", max);
  }

  return 0;
}

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

int main(void) {
    int sum, sum_max;
    int n;
    
    while(cin >> n) {
        if(n == 0) {
            break;
        }
        int array[n] = {};
        for(int i = 0; i < n; ++i) {
            cin >> array[i];
        }
        sum_max = array[0];
        for(int i = 0; i < n; ++i) {
            sum = 0;
            for(int j = i; j < n; ++j) {
                sum += array[j];
                if(sum_max < sum) {
                    sum_max = sum;
                }
            }
        }
        cout << sum_max << endl;
    }
}