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++: /*Filename: aoj0022.cpp
 *Author: Mushiyo
 */

#include <iostream>
#include <cmath>
#include <climits>

using namespace std;

int main(){
	int n = 0;

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

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

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

        int maxSum = INT_MIN;
        int minSum = 0;
        for(int i = 0; i < n; ++i){
        	maxSum = max(maxSum, sum[i] - minSum);
        	minSum = min(minSum, sum[i]);
        }
        
        cout << maxSum << endl;
    }

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
	
	for(int n;cin>>n,n;){
		int ans,tmp,k;
		cin>>ans;
		tmp=ans;
		for(n--;n--;){
			cin>>k;
			if(tmp<=0){
				ans=max(ans,k);
				tmp=k;
			}
			else{
				ans=max(ans,tmp+k);
				tmp+=k;
			}
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

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

C++: #include<stdio.h>
#define INF 1000000000
int ar[5000];
int d[5001];

int max(int a,int b){
	if(a>=b)return a;
	else return b;
}

int main(){
	int n,i,j;
	while(1){
		scanf("%d",&n);
		if(n==0)return 0;
		for(i=0;i<n;i++){
			scanf("%d",&ar[i]);
		}
		d[0]=0;
		int ans=INF;
		for(i=1;i<n+1;i++)d[i]=d[i-1]+ar[i-1];
		for(i=0;i<n;i++)for(j=i+1;j<n+1;j++){
			ans=max(ans,d[j]-d[i]);
		}
		printf("%d\n",ans);
	}
}

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

C++: //まともに使い方を理解していないくせにincludeしまくる人間のクズ
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <iostream>


//using namespace stdしないと表記がめんどくさいからね、仕方ないね
using namespace std;

//可読性を上げるためのdefineが仇となる典型的パターン
#define rep(i,n) for(int i = 0; i < x; i++)

//ローカル変数とグローバル変数は使い分けよう！
stack<short> x, y;
long long int h, m, s, ans, n, array[5000];

//関数って楽しいよね！（魔王スマイル）

void solve(long long int sum, short i){
    if(ans < sum) ans = sum;
    if(i = n) return;
    solve(sum + array[i], i + 1);
    solve(0, i + 1);
}

int main(){
    while(true){
        scanf("%lld", &n);
        if(n == 0) return 0;
        ans = 0;
        rep(i,n) scanf("%lld", &array[i]);
        solve(0, 0);
        printf("%lld\n", ans);
    }
}

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

int main() 
{
    int n;
    while (scanf("%d", &n)&&n!=0) {
        long long int a[n];
        for (int i=0; i<n; i++) scanf("%lld", &a[i]);
        long long int dp[n];
        dp[0] = a[0];
        long long int res = dp[0];
        for (int i=1; i<n; i++) {
            dp[i] = max(a[i], dp[i-1]+a[i]);
            res = max(res, dp[i]);
        }
        printf("%lld\n", res);
    }
}

C++: //include----------------------------------------------------------------------------------------------------------------------
#include <bits/stdc++.h>
//using namespace--------------------------------------------------------------------------------------------------------------
using namespace std;

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
//const------------------------------------------------------------------------------------------------------------------------
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 25;

//global-----------------------------------------------------------------------------------------------------------------------
LL a, b, n, ans = 0;
vector<LL> ar;
vector<LL> sum_ar;
//#define DEBUG
//function--------------------------------------------------------------------------------------------------------------------

int main() {
	while ( scanf( "%lld", &n ) && n ) {
		sum_ar.PB( 0 );
		ans = 0;
		rep( i, n ) {
			scanf( "%lld", &a );
			ar.PB( a );
			sum_ar.PB( sum_ar[ i ] + a );
		}
		rep( i, n ) {
			FOR( j, i, n ) {
#ifdef DEBUG
				debug(i)
				debug(j)
#endif
				ans = max( ans, sum_ar[ j ] - sum_ar[ i ] );
			}
		}
		printf( "%lld\n", ans );
		sum_ar = vector<LL>();
	}
	return 0;
}

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

int main()
{
	int n=1, count = 0;
	int a[10000],ans[10000];
	while (n != 0) {
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int sum = 0, max = -10000,sin=1;
		for (int ai = 0; ai < n - 1; ai++) {
			if (a[ai] > 0 || sin == 0) {
				sin = 0;
				for (int bi = n - 1; bi > ai; bi--) {
					sum = 0;
					for (int k = ai; k < bi; k++) {
						sum = sum + a[k];
					}
					if (sum > max) {
						max = sum;
					}
					//cout << ai << " " << bi << endl;
				}
			}
		}
		ans[count] = max;
		count++;
	}
	for (int ci = 0; ci < count-1; ci++) {
		cout << ans[ci] << endl;
	}
}