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 <climits>
using namespace std;

long long  n, a[5010], memo[5010];
const long long INF = -(INT_MAX)-1;
void solve(){
  memo[0] = a[0];
  long long ans = INF;
  for(int i = 1 ; i < n ; i++){
    memo[i] = max(a[i], a[i] + memo[i-1]);
    ans = max(memo[i], ans);
  }
  cout << ans << endl;
}
int main(){

  while(cin >> n, n){
    for(int i = 0 ; i < n ; i++){
      cin >> a[i];
    }
    solve();
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int a[5000];
int main(){
int n;
while(true){
cin>>n;
if(n==0)
break;
int best=0;
for(int i=0;i<n;i++)
 cin>>a[i];
 
for(int start=0;start<n;start++){
 int count=0;
 for(int len=start;len<n;len++){
  count+=a[len];
  best=max(best,count);
 }
}

cout<<best<<endl;
}
return 0;   
}

C++: #include <iostream>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000001

using namespace std;
#define ll long long
#define dbg if(0)



int main(){
    while(true){
        int n,t;
        ll ans= - INT_MAX;
        cin>>n;
        if (n==0)break;

        ll rui[n+1];
        rui[0]=0;
        for(int i=1;i<=n;i++){
            cin >>rui[i];
            rui[i]+=rui[i-1];
            dbg cout <<rui[i]<<" ";
        }
        //次を見る
        //今までの最小値を更新したか？
        //したなら暫定解を確定しansと比較。最大値=最小値=発見した最小値にする
        //してなければ最大値の更新をする
        //見る場所が一番後ろまで行ったら終了。
        ll nmin=MAX,nmax=0;
        for(int i=0;i<=n;i++){
            if (rui[i]<nmin){
                ans=max(nmax-nmin,ans);
                nmax=rui[i];
                nmin=rui[i];
            }else{
                if(rui[i]>nmax){
                    nmax=rui[i];
                }
            }
            dbg cout <<nmax<<" "<<nmin<<endl;
        }
        ans=max(nmax-nmin,ans);
        dbg cout << endl;
        cout<<ans<<endl;
    }

    return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int n;
	int a[10000];

	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}

		for (int i = 0; i < n; i++){
			scanf("%d", a + i);
		}

		int ans = -100000;
		for (int i = 0; i < n; i++){
			int sum = 0;
			for (int j = i; j < n; j++){
				sum += a[j];
				if (ans < sum){
					ans = sum;
				}
			}
		}

		printf("%d\n", ans);
	}
	return (0);
}

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

using namespace std;

int main(){
  int n,x[5000];
  while(1){

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

  for(int i=0; i < n;i++)cin >> x[i];

  int now=0;
  int Max=-100001,tmp;
  for(int i = 0;i < n; i++){
    now+=x[i];
    tmp=now;

    for(int j=0;j < i;j++){
      Max=max(Max,now);
      now-=x[j];
      }

    now=tmp;
    }
  cout << Max << endl;
} 

  return 0;
}

C++: #include <iostream>
main(){for(int n,i,m,a[5000];std::cin>>n,n;std::cout<<m<<"\n"){for(i=0;i<n;i++)std::cin>>a[i];for(i=0,m=-1e9;i<n;i++)for(int j=i,s=0;j<n;m=s>m?s:m,j++)s+=a[j];}}

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

int main()
{
	int n;
	while(cin>>n){
		if(n==0) break;
		int a[n], S[n], sum=0;
		for(int i=0;i<n;++i){
			cin>>a[i];
			sum+=a[i];
			S[i]=sum;
		}

		long max=S[0];
		for(int i=0;i<n;++i){
			if(S[i]>max) max=S[i];
			for(int j=0;j<n;++j){
				if(S[i]-S[j]>max) max=S[i]-S[j];
			}
		}

		cout<<max<<endl;
	}

	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<algorithm>

using namespace std;
int main(void)
{
	int n, a[5001];
	cin >> n;
	if (n == 0)
		return 0;
	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>
using namespace std;

int main(){
int n;
int a[5001];
int sum;
int big=0;
while(cin>>n){
for(int i=0;i<n;i++){
cin>>a[n];}
for(int i=1;i<n+1;i++){
for(int j=0;j<n-i;j++){
sum=0;
for(int k=0;k<i;k++){
sum+=a[j+k];}
if(sum>big){big=sum;}}}
cout<<big<<endl;}}

C++: #include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <stack>
#include <cstring>

using namespace std;

int main(){
	int n;
	int max,tmpmax1,tmpmax2;
	while(cin >> n && n != 0){
		max = -100001;
		int *factor = new int[n];
		
		for(int i = 0; i < n; i++){
			cin >> factor[i];
		}

		for(int i = 0; i < n - 1; i++){
			tmpmax1 = 0;
			tmpmax2 = -100001;
			for(int j = i; j < n; j++){
				tmpmax1 += factor[j];
				if(tmpmax2 < tmpmax1){
					tmpmax2 = tmpmax1;
					if(tmpmax2 < 0){
						if(j != n -1 && factor[j + 1] < 0){
							tmpmax2 += factor[j + 1];
							break;

						}
					}
				}
			}
			if(max < tmpmax2){
				max = tmpmax2;
			}
		}
		delete [] factor;
		cout << max << endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <ctype.h>

using namespace std;

int main() {
    int n;
    while((cin>>n)){
        if(n==0){
            break;
        }
        int a[n];
        for(int i=0; i<n; i++){
            cin >> a[i];
        }
        
        int max = -99999999;
        for(int i=0; i<n; i++){
            int sum=0;
            for(int j=i; j<n; j++){
                sum += a[j];
                if(max<sum){
                    max=sum;
                }
            }

        }
        cout<<max<<endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,a,saidai=-100000;
	while(cin>>n&&n!=0){
		int a[n];
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=0;n>i;i++){
			for(int x=n;x>=i;x--){
				int kazu=0;
				for(int y=x;y>=i;y--){
					kazu=kazu+a[y];
				}
				if(kazu>saidai){
					saidai=kazu;
				}
			}
		}
		cout<<saidai<<endl;
	}
}

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

#define MAX 5000

using namespace std;

int main(void){

	int n,a[5000];
	int wa,max;

	while(1){
		cin>>n;
		if(n==0) break;
		wa=0;
		cin>>a[0];
		max=a[0];
		for(int i=1;i<n;i++){
			cin>>a[i];
			if(max<a[i]) max=a[i];
		}
		
		for(int i=n-1;i>=0;i--){
			wa+=a[i];
			if(wa<max) wa=0;
			if(wa>max&&wa!=0) max=wa;
		}
		cout<<max<<endl;
	}
	return 0;
}