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++: // 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
#ifdef DAIJOBU
#include "/home/v-o_o-v/deb.h"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif 
#include <climits>
using namespace std;
long double eps = 1e-9;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n;
	while(cin >> n){
		if(n == 0)break;
		int a[n];
		int sum = 0, ans = INT_MIN;
		for(int i = 0; i < n; i++){
			cin >> a[i];
			sum += a[i];
			ans = max(ans, sum);
			if(sum < 0)sum = 0;
		}
		cout << ans << '\n';
	}
	return 0;
}
// Write Here

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<<"\n";
  cout<<max;
  cout<<" ";
  }
  return 0;
}

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

int main()
{
	int n;
	while (cin >> n)
	{
		int num[5001] = {};
		int maxim = -100001;
		if (n == 0) break;
		for (int i = 0; i < n; i++) cin >> num[i];
		for (int i = 0; i < n ; i++)
		{
			int sum = 0;
			for (int j = i; j < n; j++)
			{
				sum += num[j];
				maxim = (maxim >= sum) ? maxim : sum;
			}
		}
		cout << maxim << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
int main() {
	long long n, a[5001], rui[5002] = { 0 },ans[5002],cnt=0;
	while (1) {
		cnt++;
		cin >> n;
		if (n == 0)break;
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
			rui[i + 1] = rui[i] + a[i];
		}
		int max = -100001;
		for (int i = 0; i <= n; ++i) {
			for (int j = i; j <= n; ++j) {
				if (rui[j] - rui[i] > max) {
					max = rui[j] - rui[i];
				}
			}
		}
		ans[cnt] = max;
	}
	for (int i = 1; i < cnt; ++i) {
		cout << ans[i] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <stack>
#include <stdio.h>
#include <cmath>
#include <utility>
using namespace std;
int main()
{
    int n;
	while(cin>>n&&n){
		int a[5000]={},sum[5000]={},m=-1000000;
		for(int i=0;i<n;i++){
			cin>>a[i];
			sum[i+1]=sum[i]+a[i];
		}
		for(int i=0;i<n;i++){//start
			for(int j=i;j<n;j++){//end
				int tmp=sum[j+1]-sum[i];
				//if(tmp<=0){i=j;break;}
				//printf("%d-%d:%d\n",i,j,tmp);
				m=max(m,tmp);
			}
		}
		cout<<m<<endl;
	}
    return 0;
}

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

int main() {
	int n;
	while (cin >> n, n) {
		int k[5003];
		for (int i = 0;i < n;i++)cin >> k[i];

		int dp[5002];
		dp[0] = 0;
		for (int i = 1;i <= n;i++) {
			dp[i] = max(dp[i - 1] + k[i - 1], k[i - 1]);
		}

		int ans = 1e-8;
		for (int i = 1;i <= n;i++)ans = max(ans, dp[i]);
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>

int calcMaxSum(int amount_set);

int main()
{
    while (true) {
        int amount_set;
        std::cin >> amount_set;
        if(amount_set == 0) {
            break;
        }
        std::cout << calcMaxSum(amount_set) << std::endl;
    }

    return 0;
}

int calcMaxSum(int amount_set)
{
    const int MAXNUMBER = 100000;//??\????????????????????§??????

    int *data;
    data = new int[amount_set + 1];
    int *sum = new int[amount_set + 1];

    sum[0] = 0;//???????????????????????????????????´??????sum[0]??§??????

    std::cin >> data[1];//?????????????????±???
    sum[1] = data[1];//?????????????????????

    for (int number = 2; number <= amount_set; number++) {
        std::cin >> data[number];//????????????????????????
        sum[number] = sum[number - 1] + data[number];// ????????´??°
    }

    int max = -MAXNUMBER;//????????????????????¨??¨-MAXNUMBER???????????????????????§???????????????????????????????°????

    for (int number_big = 1; number_big < amount_set; number_big++) {
        for (int number_small = 0; number_small < number_big; number_small++)
            if (sum[number_big] - sum[number_small] > max) {
                max = sum[number_big] - sum[number_small];
            }
    }
    delete [] data;
    delete [] sum;

    return max;

}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define EPS 1e-8

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

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n, a[5000];
	for(;;){
		cin >> n;
		if(n == 0) break;
		for(int i = 0; i < n; i++) cin >> a[i];
		for(int i = 1; i < n; i++) a[i] += a[i - 1];
		int min_sum = 0, ans = a[0];
		for(int i = 1; i < n; i++){
			min_sum = min(min_sum, a[i - 1]);
			ans = max(ans, a[i] - min_sum);
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
  int n, x, max_;
  int dp[5000];
  while(1){
    cin >> n;
    if(!n) break;
    cin >> x;
    max_=x; dp[0]=x;
    for(int i=1; i<n; ++i){
      cin >> x;
      dp[i] = max(x, dp[i-1]+x);
      max_ = max(max_, dp[i]);
    }
    cout << max_ << endl;
  }
  return 0;
}

C++: /*
	0022:Maximum Sum Sequence
*/
#include	<iostream>
#include	<algorithm>

using namespace std;

int main(void) {
	while(1) {
		int n, ans = -10000;
		int array[5000];
		
		cin >> n;
		if(n == 0) { break; }
		
		for(int i = 0; i < n; i++) {
			cin >> array[i];
		}
		
		/*長さmlxの範囲を変えていく*/
		for(int mxl = 0; mxl < n; mxl++) {
			/*mlxの範囲内の最初の項（左端）をさす*/
			for(int i = 0; i < n - mxl; i++) {
				/*mlxの範囲の和を求める*/
				int sSum = 0;
				for(int j = 0; j <= mxl; j++) {
					sSum += array[i+j];
				}
				ans = max(ans, sSum);
			}
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

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

int main()
{

	int n, num;
	vector< long int > a;
	vector< long int > res;

	while( 1 ) {

		int Max = INT_MAX * -1;

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

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

		res.push_back( Max );
		a.clear();
	
	}

	for( vector< long int > :: iterator mIt = res.begin(); mIt != res.end(); ++mIt ) {
		cout << *mIt << endl;
	}

	return 0;

}