Go: package main

import "fmt"

func main() {
	var result []int
	for {
		var n, a, maxSum int
		fmt.Scan(&n)

		if n == 0 {
			break
		}

		maxSum = 0
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Scan(&a)
			if i == 0 {
				sum = a
				maxSum = sum
			} else if sum+a < a {
				sum = a
				if maxSum < sum {
					maxSum = sum
				}
			} else {
				sum = sum + a
				if maxSum < sum {
					maxSum = sum
				}
			}
		}

		result = append(result, maxSum)
	}

	for _, v := range result {
		fmt.Println(v)
	}
}

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

C++: #include <iostream>

using namespace std;

int main()
{
    while(1)
    {
        int n;
        cin>>n;if(!n)return 0;
        long long a[5010];
        for(int i=0;i<n;++i){
            cin>>a[i];
        }
        long long ans;
        long long buf;
        for(int i=0;i<n;++i){
            buf=0;
            for(int j=i;j<n;++j){
                buf+=a[j];
                if(buf>ans)ans=buf;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;

int main (void){
  
    int number;
    int max;
    int answer[500] = {0};
    int l = 0;
    while(cin >> number,number)
    {
        int a[5010] = {0};
        vector<int>tempmax(500.500);
        vector<int>tempmax2(1000);
        REP(i,number)
        cin >> a[i];
        for(int i = number;i>=0;i--)
            for(int j = 0; j<i;j++)
            {
                tempmax[i] +=a[j];
            }
        for(int k = 0;k<number;k++)
            for(int m = k;m<number;m++)
            {
                if(k == m)
                    tempmax2[k] = a[k];
                else if(tempmax2[k]+a[m] >= tempmax2[k])
                    tempmax2[k]+= a[m];
                else
                    break;
            }
        sort(tempmax.begin(),tempmax.end(),greater<int>());
        sort(tempmax2.begin(),tempmax2.end(),greater<int>());
        if(tempmax[0]>tempmax2[0])
            answer[l] = tempmax[0];
        else
            answer[l] = tempmax2[0];
        l++;
    }
    REP(i,l)
    cout << answer[i] << endl;
}

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

#include<vector>

#define INF 999999
using namespace std;
int main(){
    int N;
    while(cin>>N,N){
        int num[5500]={0},max=-INF;
        for(int i=0;i<N;i++){
            cin>>num[i];
        }
        for(int i=0;i<N;i++){
            int total=0;
            if(max<num[i])max=num[i];
            total+=num[i];
            for(int j=i+1;j<N;j++){
                total+=num[j];
                if(max<total)max=total;
            }
        }
        cout<<max<<endl;
    }
    return 0;
}