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>
int main(){
	int n, v[5000], m;
	while(std::cin >> n, n){
		for(int i=0;i<n;i++)std::cin >> v[i];

		m = v[0];
		for(int i=0;i<n;i++)
			for(int j=i,k=v[i];j<n;j++,k+=v[j])
				if(k>m)m=k;

		std::cout << m << '\n';
	}	
}

C++: #include <bits/stdc++.h>

using namespace std;

int main() {

    int n;

    while(cin >> n, n) {

        int num[n];
        int dp[n + 1][n + 1];

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

        memset(dp, 0, sizeof(dp));

        for(int i = 1; i <= n; ++i) {
            for(int j = i; j <= n; ++j) {
                dp[i][j] = dp[i][j - 1] + num[j - 1];
                if(dp[i][0] < dp[i][j]) {
                    dp[i][0] = dp[i][j];
                }
            }
            if(dp[i][0] < dp[i - 1][0]) {
                dp[i][0] = dp[i - 1][0];
            }
        }

        cout << dp[n][0] << endl;

    }

}

C++: #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <fstream>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int> > vpii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;
int sum[3000];
int main(){
	int N;
	int ans = 0;
	while(cin>>N&&N){
		int index=0;
		ans = INT_MIN;
		FOR(i,1,N+1){
			cin>>sum[i];
			sum[i] += sum[i-1];
		}
		FOR(i,1,N+1){
			FOR(j,i,N+1){
				ans = max(ans,sum[j]-sum[i-2]);
			}
		}
		cout<< ans <<endl;
	}
}

C++: #include "bits/stdc++.h"

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[1000];
        
        rep(i,n) cin>>data[i];
        
        ll maxi=-999999999999;
        
        for(int i=0;i<n;i++){
            ll sum[1000]={};
            sum[i]=data[i];
            maxi=max(maxi,sum[i]);
            
            for(int j=i+1;j<n;j++){
                sum[j]=sum[j-1]+data[j];
                maxi=max(maxi,sum[j]);
            }

        }
        
        
        cout<<maxi<<endl;
    }
}

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

int main(){
	int n;
	int a;
	int sum;
	int sum2;
	int sum3;
	long int max;
	cin >> n;
	while(n){
		cin >> sum;
		cin >> sum2;
		sum += sum2;
		max = sum;
		for(int i=0;i<n-2;i++){
			cin >> sum3;
			sum += sum3;
			sum2 += sum3;
			if(sum < sum2){
				sum = sum2;
			}
			if(sum > max){
				max = sum;
			}
			sum2 = sum3;
		}
		cout << max << endl;
		cin >> n;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
using namespace std;
int maxsum(int x,vector<int> a){
	
	vector<int> s(x+1,0);
	int max;
	for(int i=1;i<=x;i++){
		if(s[i-1]<0)
			s[i]=a[i];
		else
			s[i]=s[i-1]+a[i];
	}
	for(int i=0;i<=x;i++)
		cout<<s[i]<<" ";
	cout<<endl;
	max = *max_element(s.begin(),s.end());
	return max;
	
}

int main(){
	
	int n;
	while(cin>>n,n!=0){
		
		vector<int> a(n+1,0);
		
		for(int i=1;i<=n;i++)
			cin>>a[i];
		
		cout<<maxsum(n,a)<<endl;
	}
	
 	
}

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

int main()
{

	int n, num;
	vector< int > a;

	while( 1 ) {
	
		cin >> n;
		if( n == 0 ) break;

		int Max = -100001;

		a.push_back( 0 );

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

			cin >> num;
			a.push_back( num );

		}

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

			a[i] = max( a[i], a[i] + a[i - 1] );
			Max  = max( Max, a[i] );
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}

C++: #include<iostream>

using namespace std;

int main(){
	int n;
	while(cin>>n,n){
		long long int a[n];
		long long int max=-100000;
		int input;
		for(int i=0;i<n;i++){
			a[i]=0;
			cin>>input;
			for(int j=0;j<=i;j++){
				a[j]+=input;
				if(max<a[j])max=a[j];
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(ll i=0;i<n;i++)
using namespace std;
typedef long long ll;

ll sum[100001];
int main() {
	ll n;
	while (scanf("%lld", &n), n) {
		ll cnt = 0;
		rep(i, n) {
			sum[i] = cnt;
			int a; scanf("%d", &a);
			cnt += a;
		}
		sum[n] = cnt;
		ll Max = LLONG_MIN;
		rep(i, n) {
			for (int j = i + 1; j <= n; j++) {
				Max = max(Max, sum[j] - sum[i]);
			}
		}
		cout << Max << endl;
	}
	return 0;
}

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

int main(){
	int n;
	while(cin >> n, n){
		vector<int> vec;
		for(int i = 0; i < n; i++){
			int a;
			cin >> a;
			vec.push_back(a);
		}

		int max = vec[0] + vec[1];
		for(int i = 0; i < vec.size(); i++){
			for(int j = i+1; j < vec.size(); j++){
				int add = 0;
				for(int k = i; k <= j; k++){
					add += vec[k];
				}
				if(max < add) max = add;
			}
		}

		cout << max << endl;
	}
}

C++: #include <iostream>
#include <map>
#include <cmath>
#include <cstring>
#include <vector>
using namespace std;

#define REP(i,n) for(int i=0; i<n; i++)

int n;
vector<int> v;
long long s[5000];

int main(){
    while(cin>>n,n){
        v=vector<int>(n);
        REP(i,n)cin>>v[i];
        long long ans=-(1<<30);
        REP(i,n){
            s[i]=v[i];
            ans=max(s[i],ans);
            for(int j=i+1; j<n; j++){
                s[j]=s[j-1]+v[j];
                ans=max(s[j],ans);
            }
        }
        cout<<ans<<endl;
    }
}

C++: #include<stdio.h>

int main(void) 
{
    long int num[5000];
	int cut_i;
	int kousuu;
	long int nyuryoku;
	
	while(1){
		scanf("%d",&kousuu);
		
		if(kousuu == 0){
			break;
		}

		int kou = 0;
		long long int max = -100000;
		for(cut_i=0;cut_i<kousuu;cut_i++){
			num[cut_i]=0;
		}

		for(cut_i=0;cut_i<kousuu;cut_i++){
			scanf("%d",&nyuryoku);

			if(num[kou] * nyuryoku <0){
				kou++;
			}
			num[kou]+=nyuryoku;
			
			if(max<num[kou]){
				max = num[kou];
			}
		}

		kou++;
		cut_i = 0;
		
		for(cut_i=0;cut_i<kou;cut_i++){

			if(max<num[cut_i]){
				max = num[cut_i];
			}
			
			if(num[cut_i]+num[cut_i+1] > 0){
				num[cut_i+1]+=num[cut_i];
			}
		}

		printf("%d\n",max);

	}
    return 0;
}