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>
#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,n!=0){
	int a[5000];
	long int sum[5000]={0};
	long int prev=-10000;
	int num;
	for (int i=0;i<n;i++){
		cin>>a[i];
		if(i==0){
			sum[i]=a[i];
		}
		else
		{sum[i]=sum[i-1]+a[i];}
		if(sum[i]>prev){
			prev=sum[i];
			num=i;
		}
	}
	int ans[5000]={0};
	for (int i=0;i<5000;i++){
		ans[i]=-100001;
	}

	ans[0]=prev;
	for (int i=0;i<num;i++){
		ans[i+1]=prev-sum[i];
	}
	sort(ans,ans+5000);
	cout<<ans[4999]<<endl;
}

}

C++: 
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>
#include <climits>

using namespace std;

double sq(double x){return x*x;}

int a[5001];

int main(){
	int n;
	while(cin>>n,n){
		for (int i = 0; i < n; i++){
			cin>>a[i+1];
			a[i+1] += a[i];
		}
		int ans = INT_MIN;
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j <= i; j++)
			{
				ans = max(ans,a[i+1] - a[j]);
			}
		}
		cout << ans << endl;
	}

	return 0;
}

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

int main(){
    int n;
    while(cin>>n && n!=0){
       int* A=new int[n];
       int* S=new int[n+1];
       S[0]=0;
       for(int i=0;i<n;++i){
           cin>>A[i];
           if(i==0){
               S[i+1]=A[i];
           }
           else{
               S[i+1]=S[i]+A[i];
           }
       }

       int maxsum=0;
       for(int i=0;i<n+1;++i){
           for(int j=i;j<n+1;++j){
               maxsum=(S[j]-S[i]>maxsum?S[j]-S[i]:maxsum);
           }
       }

       cout<<maxsum<<"\n";
       delete[] A;
       delete[] S;
    }
}

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

int main(){
	
	int n;
	int in[6000],ans;
	
	while(cin>>n,n){
		for(int i=0;i<n;i++){
			cin>>in[i];
		}
		ans=in[0];
		for(int i=0;i<n;i++){
			int sum=0;
			for(int j=i;j<n;j++){
				sum=sum+in[j];
				ans=max(sum,ans);
			}
		}
		
		cout<<ans<<endl;
	}
	return 0;
}

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

int main(){
	int n, a;
	while(cin >> n, n){
		n++;
		vector<int> t(n);
		t[0] = 0;
		for(int i = 1;i < n;i++){
			cin >> a;
			t[i] = max(t[i-1]+a, a);
		}
		cout << *max_element(t.begin()+1, t.end()) << endl;
	}
	return 0; 
}

C++: #include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    int n;
    
    while(cin>>n){
        
        if(n==0)break;
        int data[10000]={};
        rep(i,n) cin>>data[i];
        
        
        int maxi=-999999999;
        rep(i,n){
            int dp[5001]={};
            for(int j=i;j<n+1;j++){
                if(j-1>=0){
                    dp[j]=dp[j-1]+data[j-1];
                    maxi=max(maxi,dp[j]);
                }
            }
        }
        cout<<maxi<<endl;
    }
    return 0;
}

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

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(void){
        int n; int num[5000]; int max1=-100000;
        while(cin >> n ,n){
                for(int i=0; i<n; i++)
                        cin >> num[i];
		max1=num[0];
                for(int i=0; i<n; i++){
                        int sum=0;
                        for(int j=i;j<n;j++){
                                sum+=num[j];
                                max1=max(max1,sum);
                        }
                }
                cout << max1 << endl;
        }
 
 
}

C++: #include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <cmath>
#include <sstream>
#define F first
#define S second
#define FOR(i,n) for(int i=0;i<(int)n;i++)
#define FORI(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
int main() {
	int n;
	while (cin >> n && n) {
		vector<long long> a;
		a.push_back(0);
		for(int i=0;i<n;i++)
		{
			long long x;
			cin>>x;
			a.push_back(x);
		}
		for(int i=1;i<a.size();i++)
		{
			a[i]+=a[i-1];
		}
		long long ans=0;
		for(int r=0;r<a.size();r++)
		{
			for(int l=r+1;l<a.size();l++)
			{
				ans=max(ans,a[l]-a[r]);
			}
		}
		cout<<ans<<endl;
	}




	return 0;
}