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 <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

int main() {
	int n;
	while (cin >> n, n){
		vector<int> vi;
		REP(i, n){
			int j;
			cin >> j;
			vi.push_back(j);
		}
		vector<int> vi2;
		vi2.push_back(0);
		REP(i, n){
			if (i > 0)vi2.push_back(vi2[i] + vi[i]);
			else vi2.push_back(vi[0]);
		}
		int max=-100000;
		FOR(i,0 ,n){
			FOR(j,i+1, n+1){
				int plus = vi2[j] - vi2[i];
				if (max < plus)max = plus;
			}
		}
		cout << max << endl;
	}
}

C++: #include<stdio.h>

int main(){
	int n,a[5000],b[5000],i,j,max;
	
	while(0<=scanf("%d",&n)){
		if(n==0)break;
		max=0;
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		b[0]=a[0];
		for(i=1;i<n;i++){
			b[i]=b[i-1]+a[i];
			if(b[i]>max)max=b[i];
		}
		
		for(i=1;i<n;i++){
			for(j=i;j<n;j++){
				if(max<b[j]-b[i-1])max=b[j]-b[i-1];
			}
		}
		
		printf("%d\n",max);
	}
	return 0;
}

C++: /* AOJ 0022*/

#include<iostream>
using namespace std;

int m;
int n;

void calc(int *data,int num,int sum){
	if(sum>=m){
		m=sum;
	}
	if(num==n){
		return;
	}
	else{
		calc(data,num+1,sum+data[num]);
	}
}

int main(){

	while(cin>>n){
		if(n==0){
			break;
		}
		int *data = new int[n];
		m=0;
		for(int i=0;i<n;i++){
			cin>>data[i];
		}

		for(int i=0;i<n;i++){
			calc(data,i,0);
		}
		cout<<m<<endl;
	}

	return 0;
}

C++: //O(n^2)
#include<stdio.h>
#include<math.h>

long long n,rui[10000];

long long max( long long x,long long y ){
	if( x > y )
		return x;
	return y;
}

int main()
{
	long long i,j;
	long long ans;
	while( scanf("%lld",&n) != EOF )
	{
		if( n == 0 )break;
		ans = -10000000000;
		for( i = 0;i < n;i++ ){
			scanf("%lld",rui+i );
			if( i )rui[i] += rui[i-1];
		}
		
		for( i = 0;i < n;i++ ){
			for( j = i;j < n;j++ ){
				if( i )
					ans = max( ans, rui[j]-rui[i-1] );
				else
					ans = max( ans,rui[j] );
			}
		}
		
		printf("%lld\n",ans);
	}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<(int)n;i++)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
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)
	            REP(j,i+1,n+1)
	                res=max(res,sum[j]-sum[i]);
	        cout<<res<<endl;
	    }
	return 0;
}

C++: #include<stdio.h>

int main()
{
	int n;
	while(scanf("%d",&n))
	{
		if(n==0){return 0;}
		
		int a[5000]={0},max=0;
		for(int x=0;x<n;x++)
		{
			scanf("%d",&a[x]);

			for(int y=0;y<=x;y++)
			{
				if(y!=x)
				{
					a[y]+=a[x];
				}
				if(max<a[y])
				{
					max=a[y];
				}
			}
		}
		printf("%d\n",max);
	}
}

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

int main(){
        int n,a[5010];
        while(cin>>n && n){
                for(int i=0; i<n; i++) cin >> a[i];
                long max = 0;
                for(int k = 2; k<=n; k++){
                        long sum = 0;
                        for(int i=0; i<k; i++){
                                sum += a[i];
                        }
                        cout << sum << "_";
                        max = (max>sum)? max:sum;
                        for(int i=0; i<n-k; i++){
                                sum += (a[k+i] - a[i]);
                                cout << sum << "_";
                                max = (max>sum)? max:sum;
                        }
                        cout << endl;
                }
                cout << max << endl;
        }
        return 0;
}

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

using namespace std;

int main()
{
	int n;

	while (scanf("%d", &n), n) {
		int s[5001];

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

		int ma = -100000;

		for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j) {
			ma = max(ma, s[i] - s[j - 1]);
		}

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

C++: #include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
	long long int n,ans = 0;
	while(1){
		cin >> n;
		if(n == 0)break;

		long int a[n];

		ans = 0;

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