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 <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
//	cut here before submit 
//	freopen ("testcase.MSS", "r", stdin );
	int n;
	while (scanf ("%d", &n ), n ){
		vector<int> a (n+1, 0 );
		vector<int> sum (n+1, 0 );
		for (int i = 1; i <= n; i++ ){
			scanf ("%d", &a[i] );
		} // end rep
		for (int i = 1; i <= n; i++ ){
			sum[i] = sum[i-1] + a[i];
		} // end for
		int res = INT_MIN;
		for (int i = 1; i <= n; i++ ){
			int curr = 0;
			for (int j = i; j <= n; j++ ){
				curr = sum[j] - sum[i-1];
				res = max (res, curr );
			} // end for
		} // end for
		printf ("%d\n", res );
	} // end loop
	
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <cstdio>
#include <cmath>
#include <time.h>
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) ((c).rbegin(),(c).rend())
//#define sort(v,n) sort(v,v+n)
#define ll long long
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;

int main() {
	while (cin >> n, n) {
		int a[5001];
		ll s[5001];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			if (i == 0) {
				s[0] = a[0];
			}
			else {
				s[i] = s[i - 1] + a[i];
			}
		}

		ll ans=-500000000;
		for (int i = 0; i < n; i++) {
			ans = max(ans, s[i]);
			for (int j = 0; j < i; j++) {
				if (s[i] - s[j] > s[i]) {
					ans = max(ans, s[i] - s[j]);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
#define NMAX 5100

//int dp[NMAX][NMAX];
int a[NMAX];

int main()
{
    int n;
    while(cin>>n)
    {
        if(n==0)break;
        memset(a,0,sizeof(int)*NMAX);

        for(int i =1;i<=n;++i)
        {
            cin >> a[i];
        }
        int sum = 0,ans = a[1];
        for(int first = 1;first<=n; ++first)
        {
            sum = a[first];
            if(ans<sum) ans = sum;
            for(int last = first+1;last<=n;++last)
            {
                sum += a[last];
                if(ans<sum) ans = sum;
            }
            sum = 0;
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main(void){
	int n;
	int i;
	int temp;
	int sum[5000];
	int num = 0;
	
	while(1){
		for(i=0; i<5000; i++){
			sum[i] = 0;
		}
	
		scanf("%d", &n);
		if(n == 0) break;
		
		for(i=0; i<n; i++){
			scanf("%d", &temp);
			if(temp > 0 && sum[num] < 0){
				num++;
				sum[num] = temp;
			}else if(temp >= 0){
				sum[num] += temp;
			}else{
				num++;
				sum[num] = sum[num-1] + temp;
			}	
		}
		
		sort(sum, sum + 5000, greater<int>());
		
		printf("%d\n", sum[0]);
		
	}
	
	return 0;
}

C++: #include <iostream>
int main(){
int a,b,c=1,d=0;
while(c=1){
    std::cin>>a;
     
    int z=-100000;
 
    if(a==0){
        return 0;
    }
    int aa[a];
    for(int t=1;t<=a;t++){
        std::cin>>b;
     
        aa[t]=b;
    }
     
    for(int s=1;s<=a;s++){
         
            for(int l=s;l<=a;l++){
                d=d+aa[l];
                if(z<d){
                    z=d;
                }
            }d=0;
         
         
    }
    std::cout<<z<<std::endl;
     
}
}

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

int main(){
	int n;
	cin >> n;
	while(n != 0){
		int a[n];
		

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

		int maximum = 0;
		for(int i = 0; i < n; i++){
			int sum = 0;
			for(int j = i; j < n; j++){
				sum += a[j];
				maximum = max(maximum, sum);
			}
		}

		cout << maximum << endl;
		cin >> n;
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int a[5001];
int sum[5001];
main(){
  while(1){
    int res=0;
    scanf("%d",&n);
    if(n==0) break;
    int sm=0;
    for(int i=0;i<n;i++){
      scanf("%d",&a[i]);
      sm+=a[i];
      sum[i]=sm;
    }
    for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++)
	res=max(res,sum[j]-sum[i-1]);
    printf("%d\n",res);
  }
}

C++: #include <stdio.h>

int main()
{
	int n, x, p, i, j, k;
	
	while(scanf("%d", &n) != 0){
		if (n == 0) break;

		int a[n];

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

		x = a[0];

		for(i = 1; i <= n; i++){
			for(j = 0; j < n-i+1; j++){
				if(j == 0 || a[j+i-1] > a[j-1]){
					p = 0;

					for(k = 0; k < i; k++){
						p += a[j+k];
					}

					if(x < p) x = p;
				}
			}
		}

		printf("%d\n", x);
	}

	return 0;
}

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