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 <iostream>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>

int max(int a,int b){
	if(a>=b)return a;
	else return b;
}

int min(int a,int b){
	if(a>=b)return b;
	else return a;
}

void swap(int *a,int *b){
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

void babbleSort(int *data,int n){
	for(int i=0;i<n;i++){
		for(int j=n-1;j>i;j--){
			if(data[j]>=data[j-1]){
				swap(&data[j],&data[j-1]);
			}
		}
	}
}


using namespace std;

/*
cin.ignore();
	getline(cin,dataStr);
	data = new int[n];
	stringToInteger(&dataStr,data,n);
*/

void stringToInteger(string *str,int *data,int n){
	for(int i=1;i<=n;i++){
		int spaceN = str->find(' ',0);

		data[i] = atoi(str->substr(0,spaceN).c_str());
		str->erase(0,spaceN+1);
	}
}

int main(){

	int n;
	int *a;

	int ans[5001];
	int cnt=0;

	while(1){
	cin>>n;

	if(n==0)break;
	a = new int[n];

	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int max=-10000000;
	int before=0;
	int now=0;

	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			if(j==i){
				before=a[j];
				now=before;
			}
			else{
				now=before+a[j];
			}
			
			if(max<=now){
				max = now;
	
			}
			before=now;
		}
	}
	ans[cnt]=max;
	//cout<<max<<endl;
	cnt++;

	}
	for(int i=0;i<cnt;i++){
		cout<<ans[i]<<endl;
	}


	return 0;
}

C++: #include <iostream>

using namespace std;

inline int max (int a, int b) {
    return a > b ? a : b;
}

int main (void) {
    int n, i, j;
    while (1) {
        cin >> n;
        if (n == 0) break;
        int a[n];
        for (i = 0; i < n; i++) {
            cin >> a[i];
        }
        int sum = 0, s;
        for (i = 0; i < n; i++) {
            s = 0;
            for (j = i; j < n; j++) {
                s += a[j];
                sum = max(sum, s);
            }
        }
        cout << sum << 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];
    int sum=0,tmp=0,max=-100000;
    bool flg=true;
    for(int i=0;i<n;i++){
      if(flg) max=max(max,a[i]);
      if(a[i]>0){
	flg=false;
	sum+=a[i];
	continue;
      }
      for(tmp=sum;a[i]<=0;i++){
	tmp+=a[i];
      }i--;
      if(tmp>0)
	sum=tmp;
      else
	sum=0;
    }

    cout << sum;
  }
}

C++: #include <stdio.h>
#define N 5000

int getsign(int d){
	return d >= 0 ? 1 : -1;
}

int seqsum(int n){
	int a[N];
	int b[N];
	int c = 0;
	int s = 0;

	scanf("%d", a);
	b[0] = a[0];
	s = getsign(a[0]);

	for(int i=1; i<n; ++i){
		scanf("%d", a+i);
		if(s == getsign(a[i])){
			b[c] += a[i];
		}else{
			b[++c] = a[i];
			s = getsign(a[i]);
		}
	}

	int m = a[0] = b[0];
	for(int i=1; i<=c; ++i){
		a[i] = a[i-1] < 0 ? b[i] : a[i-1] + b[i];
		if(m < a[i]){
			m = a[i];
		}
	}

	return m;
}

int main(void){
	int n = 0;
	while(true){
		scanf("%d", &n);
		if(n == 0){ break;}
		printf("%d\n", seqsum(n));
	}
	return 0;
}

C++: #include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define roop(a,t) for(int a=0;a<t;a++) 
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n) {
if(n==0){break;}
        int sum[5001];
        roop(i, n) {
            cin >> sum[i];
            if (i != 0) { sum[i] += sum[i - 1]; }
        }
        int ans = -9000000000;
        for (int i = -1; i < n-1; i++) {
            int sumi = 0;
            if (i != -1)
            {
                sumi = sum[i];
            }
            for (int j = i + 1; j < n; j++) {
 
                int sumj = sum[j];
                ans = max(ans, sumj - sumi);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
	long int n,ans = 0;
	while(cin >> n){
		if(n == 0)break;

		long int a[n];

		for(int i = 0;i < n;i++){
			cin >> a[i];
			ans += a[i];
		}
		cout << ans << endl;
	}
}

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

int main(){
	int n,a[5000],sum=0,out=0;
	while(cin>>n,n){
		sum=0,out=0;
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=0;i<n;i++){
			sum=a[i];
			for(int j=i+1;j<n;j++){
				sum+=a[j];
				out=max(sum,out);
			}
		}
	cout<<out<<endl;
	}
	return 0;
}

C++: #include <stdio.h>
int array[1000];
int n,i,sum=0,k=0;
void tansaku(int a);
int main(void)
{
	while(1)
	{
		sum = 0;
		for(i=0;i<1000;i++)
		{
			array[i] = 0;
		}
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++)
		{
			scanf("%d",&array[i]);
		}
		for(i=0;i<n;i++)
		{
			tansaku(i);
			k = 0;
		}
		printf("%d\n",sum);
	}
	return 0;
}
void tansaku(int a)
{
	if(a>n)return;
	k += array[a];
	if(k > sum)
	{
		sum = k;
	}
	if(a == n)return;
	tansaku(a+1);
}

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

int main()
{
    int n;
    while(cin >> n && n)
    {
        int buf[5001]={};
        int max_sum = INT_MIN;

        /* store input values */
        for(int i=0; i<n; i++)
        {
            cin >> buf[i];
        }
        /* calc maximum sum */
        for(int i=0; i<n; i++)
        {
            int sum = 0;
            for(int j=i; j<n; j++)
            {
                sum += buf[j];
                if(sum > max_sum)
                {
                    max_sum = sum;
                }
            }
            
        }
        cout << max_sum << endl;
    }
    return 0;
}

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

int main(){
  int i,j,n,tmp,ans,a[5000];

  while(scanf("%d",&n) && n){
    for(i=0;i<n;i++)scanf("%d",&a[i]);
    
    ans = a[0];
    for(i=0;i<n;i++){
      for(j=i;j<n;j++){
	if(i==j)tmp = 0;
	tmp += a[j];
	ans = max(tmp,ans);
      }
    }
    printf("%d\n",ans);
  }
}

C++: #include <iostream>
using namespace std;
int main(void){

	int n, max=0;
	int *a;
	int sum;

	do{
		max = 0;
		//cout << endl;
		cin >> n;

		if (n == 0) break;

		a = new int[n];

		sum = 0;

		for (int i = 0; i < n; i++){

			sum = 0;

			cin >> a[i];

			for (int j = i; j >= 0; j--){

				sum += a[j];
				if (max < sum) max = sum;
			}
		}

		cout << max << endl;
	} while (1);
}