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++: //0022 Maximum Sum Sequece

//2<=n<=5000ÂÌñ©çA×Ú·éÌaÌÅålð¦æ
//KÉâÁ½ç°i(1¨n-1){i*(n-i)}ñÅ]TÅlÞ©
//Æè ¦¸Ag¤ñÌÉV½ÉÁíÁ½àÌð«µÄAÁ¦éàÌðø­ûjÅ¢¢©


#include<iostream>
#include<algorithm>
#include<numeric>
using namespace std;

int main(void)
{
	const int N = 5000;
	int n;
	int i, j;
	int a[N];
	while(cin >> n, n)
	{
		for(i = 0; i < n; i++)
			cin >> a[i];

		int sum, max_sum = 0;

		//iÂÌðg¤
		for(i = 1; i <= n; i++)
		{
			//Ü¸ÍAÜÆÜÁÄg¤ªÌaðvZµÄ¨­
			sum = accumulate(a, a+i, 0);
			max_sum = max(sum, max_sum);

			for(j = 0; j+i < n; j++)
			{
				//ÌÂðg¢Ü·
				sum -= a[j];
				sum += a[j+i];
				max_sum = max(max_sum, sum);
			}
		}

		cout << max_sum << endl;
	}
	return 0;
}

C++: #include <stdio.h>

#define SGN(X) ((X)>0?1:(X)<0?-1:0)
int compressRead(int a[], int n);

int main(void){
	int n;
	int a[5000];
	int max, cur;
	
	while (scanf("%d", &n), n){
		n = compressRead(a, n);
/*		printf("a[%d]:", n);
		for (int i=0; i<n; i++){
			printf("%d ", a[i]);
		}
		puts(""); */
		max = a[0];
		for (int i=0; i<n; i++){
			cur = 0;
			for (int j=i; j<n; j++){
				cur += a[j];
				if (cur > max) max = cur;
			}
		}
		printf("%d\n", max);
	}
	
	return 0;
}

int compressRead(int a[], int n){
	int sn, idx=0;
	int x;
	
	scanf("%d", &x);
	a[idx]=x;
	for (int i=1; i<n; i++){
		scanf("%d", &x);
		if (x==0) continue;
		if (SGN(a[idx]) != SGN(x)){
			a[++idx] = x;
		}else{
			a[idx]+=x;
		}
	}
	
	return idx+1;
}

C++: #include <iostream>

#define max(X,Y) ((X > Y)?X:Y)

int main(void)
{
	while(true)
	{
		int n;
		int m=0,prev=0;
		std::cin >> n;
		if(!n)
			break;

		prev = -0xFFFF;
		for(int i=0; i<n; i++)
		{
			int a;
			std::cin >> a;
			prev = max( a, prev + a );
			m = max( m, prev );
		}
		std::cout << m << std::endl;
	}
	return 0;
}

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

using namespace std;

typedef long long LINT;

const int MAX_N = 5000;

LINT as[MAX_N+1];

int main ( void )
{
	int n;
	while (cin >> n, n) {
		int p = 0;
		for (int i = 0; i < n; ++i) {
			LINT x;
			cin >> x;

			if (i == 0) { as[0] = x; }
			else {
				if ((LINT)(as[p] * x) < 0LL) {
					as[++p] = x;
				}
				else {
					as[p] += x;
				}
			}
		}

		LINT ans = 0, sum = 0;
		for (int i = 0; i <= p; ++i) {
			sum = max(0LL, sum + as[i]);
			ans = max(ans, max(sum, as[i]));
		}

		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	for (int n; cin >> n&&n;) {
		vector<int> a(n);
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		vector<int> M(n);
		for (int i = 0; i < n; i++) {
			M[i] = a[i];
			int temp = a[i];
			for (int j = i + 1; j < n; j++) {
				temp += a[j];
				M[i] = max(M[i], temp);
			}
		}
		cout << *max_element(ALL(M)) << endl;
	}
	return 0;
}

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


int main(){
  int n;
  int c[12345], b[12345];
  for(;;){
    cin >> n;
    if(n==0) break;
    for(int i=0; i<n; i++){
      cin >> c[i];
    }
    b[0] = 0;
    for(int i=0; i<n; i++){
      b[i+1] = b[i]+c[i];
    }
    
    int mx = 0;
    for(int i=0; i<n+1; i++){
      for(int j=i+1; j<n+1; j++){
        if(mx < b[j]-b[i]){
          mx = b[j]-b[i];
        }
        
      }
    }
    cout << mx << endl;
  }
  return 0;
}

C++: #include <iostream>
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>
#define _USE_MATH_DEFINES
#include<math.h>
#include<iomanip>
#include<string>
#include<algorithm>
using namespace std;

int gcd(long long int m,long long int n){
	while(m!=n){
		if(m>n){m=m-n;
		}
		else n=n-m;
	}
	return m;
}
int lmc(long long int m,long long int n){
return m*n/gcd(m,n);
}

int main(){
int n;
while (cin>>n){
	if (n==0){
		break;
	}
	int a[5000];
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	int temp=-100000;
	for (int i=1;i<=n;i++){
		for (int j=0;j<=n-i;j++){
			int sum=0;
			for (int k=0;k<i;k++){
				sum+=a[j+k];
			}
			if (temp<sum){
				temp=sum;
			}

		}

	}
	cout<<temp<<endl;
}

}

C++: #include <iostream>

using namespace std;

int main() {

	int n;
	int a[5500];

	while(cin >> n) {
		if(n==0)
			break;
		int max=0;
		for(int i=0; i<n; i++) {
			cin >> a[i];
		}
		for(int i=0; i<n; i++) {
			int t=0;
			for(int j=i; j<n; j++) {
				t+=a[j];
				if(t>max)
					max=t;
			}
		}
		cout << max << endl;
	}

	return 0;

}

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

int main()
{
	int n=1, count = 0;
	int a[10000],ans[10000];
	while (n != 0) {
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int sum = 0, max = -10000;
		for (int ai = 0; ai < n - 1; ai++) {
			sum = 0;
			for (int bi = ai; bi < n; bi++) {
				sum = sum + a[bi];
				if (sum > max) {
					max = sum;
				}
				cout << ai << " " << bi << endl;
			}
		}
		ans[count] = max;
		count++;
	}
	for (int ci = 0; ci < count-1; ci++) {
		cout << ans[ci] << endl;
	}
}