Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var infty = 100000 * 2
var scanner = bufio.NewScanner(os.Stdin)

func nextInt() (int, error) {
	scanner.Scan()
	return strconv.Atoi(scanner.Text())
}

func findMaximumSubarray(arr []int) int {
	currentMaxSum, maxSumContainsTail := -infty, -infty

	for j := range arr {
		if arr[j] > maxSumContainsTail+arr[j] {
			maxSumContainsTail = arr[j]
		} else {
			maxSumContainsTail += arr[j]
		}
		if currentMaxSum < maxSumContainsTail {
			currentMaxSum = maxSumContainsTail
		}

		// fmt.Println(arr[j], currentMaxSum, maxSumContainsTail)
	}
	return currentMaxSum
}

func main() {
	scanner.Split(bufio.ScanWords)
	for {
		size, _ := nextInt()
		if size == 0 {
			break
		}

		arr := make([]int, size)
		for i := range arr {
			n, _ := nextInt()
			arr[i] = n
		}

		maximumSum := findMaximumSubarray(arr)
		fmt.Println(maximumSum)
	}
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

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

int main()
{
	for(int n;cin>>n,n;){
		vi a(n);
		rep(i,n)
			cin>>a[i];
		
		vi sum(1);
		rep(i,n)
			sum.push_back(sum.back()+a[i]);
		int res=0;
		rep(i,n)
			repi(j,i+1,n+1)
				res=max(res,sum[j]-sum[i]);
		cout<<res<<endl;
	}
	
	return 0;
}

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

int main(){
	int n, k = 0;
	int a[100][5000];
	int b[100] = {0}, c[100] = {0};
	while(cin >> n){
		if(n == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin >> a[k][i];
			b[k] = b[k]+a[k][i];
			if(b[k] < 0){
				b[k] = 0;
			}
			if(b[k] > c[k]){
				c[k] = b[k];
			}
		}
		k++;
	}
	for(int i = 0; i < k; i++){
		cout << c[i] << endl;
	}
}

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