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

C++: /*
	0022:Maximum Sum Sequence
*/
#include	<iostream>
#include	<algorithm>

using namespace std;

int intervalSum(int cs[], int a, int b);

int main(void) {
	while(1) {
		int n, ans;
		int array[5000], cumsum[5000] = { 0 };
		
		cin >> n;
		if(n == 0) { break; }
		
		for(int i = 0; i < n; i++) {
			cin >> array[i];
			if(i == 0) { cumsum[i] = array[i]; }
			else { cumsum[i] = array[i] + cumsum[i-1]; }
		}
		
		for(int i = 0; i < n; i++) {
			for(int j = i; j < n; j++) {
				int fl;
				if(i == j) {
					fl = array[i];
				} else if(i == 0) {
					fl = cumsum[j];
				} else {
					fl = intervalSum(cumsum, i, j);
				}
				ans = max(ans, fl);
			}
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

int intervalSum(int cs[], int a, int b) {
	return cs[b] - cs[a-1];
}

C++: #include <iostream>
using namespace std;
int main(){
	for (;;){
		int a,goukei=0,max=-999999999,b;
		cin>>a;
		if (a==0)break;
		int data[a+1]={0};
		for (int A=1;A<=a;A++){
			cin>>data[A];
			if (max<data[A])max=data[A];
			goukei+=data[A];
			data[A]=goukei;
			if (max<data[A])max=data[A];
		}
		for (int A=3;A<a;A++){
			b=A-2;
			for (int B=b;B>0;B--){
				goukei=0;
				goukei=data[A]-data[B];
				if (goukei>max) max=goukei;
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;

// ?¨±?????????????????
#define EPS (1e-10)

int main(){
	int n;
	while(cin >> n && n != 0){
        vector<int> a(n);
        REP(i, n) cin >> a[i];
        int ret = 0;
        REP(i, a.size()){
            FOR(j, i, a.size()){
                int sum = 0;
                FOR(k, i, j+1) sum += a[k];
                ret = max(ret, sum);
            }
        }
        cout << ret << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n;

	while( true ) {
		cin >> n;

		if( !n ) {
			break;
		}

		vector< int > num(n);

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

		int ans = num[0];
		int s = 0, sum = 0;

		for(int t = 0; t < n; ) {
			sum += num[t++];
			if(ans < sum) {
				ans = sum;
			} else if(sum - num[s] > ans) {
				sum -= num[s++];
			}
		}

		cout << ans << endl;
	}
}

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

int main() {
    int n;

    while (cin >> n, n) {
        vector<ll> a(n);
        rep(i, n) cin >> a[i];

        ll ans = -1e18, cur = 0;
        rep(i, n) {
            cur = max(cur + a[i], a[i]);
            ans = max(ans, cur);
        }
        cout << ans << endl;
    }

    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
    int n=0,a[5000],saidai=-100000;
    while(cin>>n&&n!=0){
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=0;i<n;i++){
            int kazu=0;
            for(int x=i;x<n;x++){
                kazu=kazu+a[x];
                if(saidai<kazu){
                    saidai=kazu;
                }
            }
        }
        cout<<saidai<<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(max<nyuryoku){
				max = 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;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<int>as(N);
		vector<long long int>sums(N + 1);
		for (int i = 0; i < N; ++i)cin >> as[i];
		for (int i = 0; i < N; ++i) {
			sums[i + 1] = sums[i] + as[i];
		}
		long long int ans = -1e8;
		for (int l = 0; l < N; ++l) {
			for (int r = l + 1; r <= N; ++r) {
				ans = max(ans, sums[r] - sums[l]);
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

C++: #include<iostream>

using namespace std;


int main()
{
	int n,tmp1,tmp0;
	int arr[5001] = {0};
	int sum[5001] = { 0 };
	
	while (1) {
		cin >> n;
		if (n == 0) {
			break;
		}

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

		sum[0] = arr[0];
		int j = 0;
		for (int i = 1; i < n; i++) {
			tmp0 = arr[i - 1];
			tmp1 = arr[i];
			if (tmp1 * tmp0 > 0) {
				if (tmp1 > 0) {
					sum[j] += tmp1;
				}
				else {
					if (sum[j] > 0) {
						sum[j] += tmp1;
					}
					else {
						if (tmp1 > tmp0) {
							sum[j] = tmp1;
						}
					}		
				}	
			}
			else {
				++j;
				if (sum[j-1] > 0) {
					sum[j] = sum[j-1] + tmp1;
				}
				else {
					sum[j] = tmp1;
				}
			}
			//cout << "sum[" << j << "]=" << sum[j] << endl;
		}

		/*for (int i = 0; i <= j; i++) {
			cout << sum[i] << ends;
		}
		cout << endl;*/

		int max = sum[0];
		for (int i = 1; i <= j; i++) {
			if (sum[i] > max) {
				max = sum[i];
			}
		}
		cout << max << endl;
		
	}

	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
int main() {
	long long n, a[5001], rui[5002] = { 0 };
	while (1) {
		cin >> n;
		if (n == 0)break;
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
			rui[i + 1] = rui[i] + a[i];
		}
		int max = -100001;
		for (int i = 0; i <= n; ++i) {
			for (int j = i; j <= n; ++j) {
				if (rui[j] - rui[i] > max) {
					max = rui[j] - rui[i];
				}
			}
		}
		cout << max << endl;
	}
	return 0;
}