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 <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<n;i++)
#define rep(i,n) for(int i=0;i<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()
{
	int n;
	while(cin >> n,n){
		vector<int>dp;
		dp.pb(0);
		rep(i,n){
			int t;
			cin >> t;
			dp.pb(dp[i]+t);
		}
		int mx=0;
		rp(i,dp){
			REP(j,1,dp.size()){
				mx=max(mx,dp[j]-dp[i]);
			}
		}
		cout << mx << endl;
	}
	return 0;
}

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

int main(){
    int n;
    while(scanf("%d",&n) && n != 0){
        int arr[n];
        for(int i = 0; i < n; i++){
            scanf("%d",&arr[i]);
        }
        int max_e = arr[0], max_s = arr[0];
        for(int cur = 1; cur < n; cur++){
            max_e = max(arr[cur], max_e + arr[cur]);
            max_s = max(max_s, max_e);
        }
        printf("%d\n",max_s);
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    int n;
    while(cin>>n,n){
        ll a[5010];
        ll dp[5010];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        ll ans=-LINF;
        for(int j=0;j<n;j++){
            if(dp[j]<0){
                dp[j+1]=a[j];
            }else{
                dp[j+1]=dp[j]+a[j];
            }
            ans=max(dp[j+1],ans);
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

using namespace std;

inline int max (int a, int b) {
    return a > b ? a : b;
}

int main (void) {
    int n, i, j;
    while (1) {
        cin >> n;
        if (n == 0) break;
        int a[n];
        for (i = 0; i < n; i++) {
            cin >> a[i];
        }
        int sum = INT_MIN, s;
        for (i = 0; i < n; i++) {
            s = 0;
            for (j = i; j < n; j++) {
                s += a[j];
                sum = max(sum, s);
            }
        }
        cout << sum << endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int num;

	while( cin >> num ) {
		if (num == 0 )
			break;

		long int tmpnum = 0;
		long int currnum;
		long int maxnum = 0;
		for( int i = 0; i < num; i++ ) {
			cin >> currnum;
			if( currnum + tmpnum > maxnum ) {
				maxnum = currnum + tmpnum;
			}
			
			if( currnum + tmpnum > currnum )
				tmpnum += currnum;
			else
				tmpnum = currnum;
		}
		cout << maxnum << endl;
	}
	return 0;
}

C++: #include <stdio.h>

int arr[5000];

int p14(int size) {
	int i=0;
	int j=0;
	int sum = 0;
	int smax = -10000000;
	
	int s = 0;
	
	for (int t=0; t<size; t++) {
		sum+=arr[t];
		
		if ( sum > smax ) {
			i = s;
			j = t;
			smax = sum;
		}
		
		if (sum < 0 ) {
			for(; s<t; s++) {
				sum -= arr[s];
				if ( sum > smax ) {
					i = s;
					j = t;
					smax = sum;
				}
			}
		}
	}
	
	printf("%d-%d  sum: %d\n", i, j, smax);
	return smax;
}

int main(void) {
	while(true) {
		int n;
		scanf("%d", &n);
		if ( n==0 ) { return 0; }
		
		for(int i=0; i<n; i++) {
			scanf("%d", &arr[i]);
		}
		
		printf("%d\n", p14(n));
	}
}

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

int main(){
	int n, max, sum, a[5001];

	while( cin >> n ){
		if(n==0) break;
		max = 0;
		for(int i=0 ; i<n ; i++){
			cin >> a[i] ;
		}
		
		for(int i=0 ; i<n ; i++){
			sum = 0;
			for(int j=i ; j<n ; j++){
				sum += a[j];
				max = (sum>max)? sum : max;
			}
		}
		cout << max << endl;
	}
}

C++: #include <iostream>
using namespace std;
int main(void){

	int n, max=0;
	int *a;
	int *sum;

	do{
		max = 0;
		//cout << endl;
		cin >> n;

		if (n == 0) break;

		a = new int[n];
		sum = new int [n];

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

		for (int i = 0; i < n; i++){

			cin >> a[i];

			for (int j = i; j >= 0; j--){

				sum[i] += a[j];
				if (max < sum[i]) max = sum[i];
			}
		}

		cout << max << endl;
	} while (1);
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    int n;
    while(cin>>n,n){
        vi v(n+1,0);
        rep(i,n)cin>>v[i];
        ll ans=v[0], temp;
        for(int i=0;i<n;i++){
            temp=v[i];
            for(int j=i+1;j<n;j++){
                temp+=v[j];
                ans=max(ans,temp);
            }
        }
        cout<<ans<<endl;
    }
}

C++: #include <stdio.h>

int gets(int d){
	return d >= 0 ? 1 : -1;
}

int seqsum(int n){
	int a = 0;
	int b[5000];
	int c = 0;
	int s = 0;
	int f = 0;

	scanf("%d", &a);
	b[0] = a;
	f = a;
	s = gets(a);

	for(int i=1; i<n; ++i){
		scanf("%d", &a);
		if(s == gets(a)){
			b[c] += a;
		}else{
			b[++c] = a;
			s = gets(a);
		}
	}

	int m = b[0];
	int sum = m;
	for(int i=1; i<=c; ++i){
		if(sum < 0 && m < b[i]){
			sum = m = b[i];
		}else{
			sum += b[i];
			if(m < sum){
				m = sum;
			}
		}
	}
	return m > f ? m : f;
}

int main(void){
	int n = 0;
	while(true){
		scanf("%d", &n);
		if(n == 0){ break;}
		printf("%d\n", seqsum(n));
	}
	return 0;
}