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++: #define REP(i,n) for (int i=0;i<(n);i++)
#include <iostream>
using namespace std;

int main(){
        int N;
        while(cin >> N && N > 0){
                int a[N];
                REP(i,N){
                        cin >> a[i];
                }

                int maximum = 0;
                REP(i,N){
                        int maximum_i = 0;
                        REP(j,N-i){
                                int sum = 0;
                                REP(k,i+1){
                                        sum += a[j+k];
                                }
                        maximum_i = max(sum,maximum_i);
                        }
                maximum = max(maximum_i,maximum);
                }
                cout << maximum << endl;

        }
}

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

int main(){
	const int nmax = 5001;
	int n;
	int nums[nmax];
	while(cin >> n){
		if(n == 0) break;
		int a;
		for(int i = 1;i <= n; i++){
			cin >> a;
			nums[i] = a;
		}
		int total_max = -INT_MAX;
		for(int i = 1; i <= n; i++){
			int total = 0;
			for(int j = i; j <= n; j++){
				total += nums[j];
				total_max = max(total_max, total);
			}
		}
		cout << total_max << endl;
	}
	return 0;
}

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

int main(void)
{
    int n;
    int num[5001];
    int sum;
    int max;
    
    while (scanf("%d", &n)){
        if (n == 0) break;
        memset(num, 0, 5001);
        max = 0;
        sum = 0;
        for (int i = 0; i < n; i++){
            scanf("%d", &num[i]);
        }
        
        for (int i = 0; i < n; i++){
            sum = 0;
            for (int j = i; j < n; j++){
                sum += num[j];
                if (max < sum) max = sum;
            }
        }
        
        printf("%d\n", max);
    }
}

C++: #include<iostream>
using namespace std;
int main()
{
int n;
while(cin>>n&&n!=0)
{
int a[n];
int A=0;
int R=-100000;
for(int h=0;h<n;h++)
{
	cin>>a[h];
}
for(int i=0;i<n;i++)
{
	for(int j=i;j<n;j++)
	{		
		A=A+a[j];
		
	}	
	if(R<A)
	{
		R=A;
	}
	A=0;
	}
cout<<R<<endl;
}
return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
int n;
int b;
int c;
int d;
int e;
while(cin >>n){
if(n!=0){break;}
int a[n];
b=0;
while(b<n){
cin >>a[b];
b=b+1;}
d=a[0];
b=0;
while(b<n){
e=0;
c=b;
while(c<n){
e=e+a[c];
if(e>d){d=e;}
c=c+1;}
b=b+1;}
cout <<d<<endl;}}

C++: #include <iostream>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000001
#define IN_MAX -223372036854775808

using namespace std;
#define ll long long
#define dbg if(0)



int main(){
    while(true){
        int n;
        ll ans= IN_MAX;
        cin>>n;
        if (n==0)break;

        ll rui[n+1];
        rui[0]=0;
        for(int i=1;i<=n;i++){
            cin >>rui[i];
            rui[i]+=rui[i-1];
            dbg cout <<rui[i]<<" ";
        }
        dbg cout <<endl;
        //次を見る
        //今までの最小値を更新したか？
        //したなら暫定解を確定しansと比較。最大値=最小値=発見した最小値にする
        //してなければ最大値の更新をする
        //見る場所が一番後ろまで行ったら終了。
        ll nmin=rui[1],nmax=rui[1];
        for(int i=0;i<=n;i++){
            if (rui[i]<nmin){
                ans=max(nmax-nmin,ans);
                nmax=rui[i];
                nmin=rui[i];
            }else{
                if(rui[i]>nmax){
                    nmax=rui[i];
                }
            }
            dbg cout <<nmax<<" "<<nmin<<endl;
        }
        ans=max(nmax-nmin,ans);
        dbg cout << endl;
        cout<<ans<<endl;
    }

    return 0;
}

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

int n, a[5001], sum[5001];

// a[i] + a[i+1] + ... + a[j] テ」ツつ津ィツソツ氾」ツ?? (テァツエツッテァツゥツ催・ツ陳?
int f(int i, int j){
	return sum[i] - sum[j+1];
}

int main(){
	while( cin >> n, n ){
		for(int i = 0; i < n; i++) cin >> a[i];
		
		sum[0] = 0;
		for(int i = 0; i < n; i++) sum[0] += a[i];
		for(int i = 0; i < n; i++) sum[i+1] = sum[i] - a[i];
		
		int ans = a[0];
		for(int i = 0; i < n; i++){
			for(int j = i; j < n; j++){
				ans = max(ans, f(i, j));
			}
		}
		cout << ans << endl;
	}
}

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

int main(){
    int n;
    while(cin >> n && n){
        vector<int> a(n,0);
        for(int i=0; i<n; ++i){
            cin >> a[i];
        }
        // ????????£?¶??????????????????§??£?¶???????dp??¨?????????
        vector<int> dp(n,0);
        dp[0] = a[0];
        int max = 0;
        for(int i=1; i<n; ++i){
            if(dp[i-1]>0){
                dp[i] = dp[i-1] + a[i];
            } else {
                dp[i] = a[i];
            }
            if(max<dp[i]){
                max = dp[i];
            }
        }
        cout << max << endl;
    }
}

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

int main(){
    long long int n, ans, sum;
    long long int a[5001];
    
    while(cin >> n){
        if(n == 0){
            break;
        }
        
        memset(a, 0, sizeof(a));
        ans = 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];
                ans = max(sum, ans);
            }
        }
        
        cout << ans << endl;
    }

    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000
using namespace std;
int main() {
	int n;
	while (cin >> n,n) {
		int ans = -INF, cnt = 0;
		rep(i, n) {
			int a;
			cin >> a;
			if (cnt < 0) cnt = a;
			else cnt += a;
			ans = max(Max, cnt);
		}
		cout << ans << endl;
	}
	return 0;
}

C++: 3
1000
-200
201

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

int n,s[5000+10];

int bigger(int n){
    int M=-100000;
    for(int p=1;p<n;p++){
        if(s[p]>M) M=s[p];
        for(int q=0;q<p-1;q++){
            if(s[p]-s[q]>M) M=s[p]-s[q];
        }
    }
    return M;
}

int main(){
    int n;
    while(cin){
        cin >> n;
        if(n==0) break;
        int a[5000+10];
        for(int i=0;i<n;i++){
            cin >> a[i];
            if(i==0) s[i]=a[i];
            else s[i]=s[i-1]+a[i];
        }
        cout << bigger(n) << endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    for(;;){
        long long int n,a[5001]={},ma=0,sum=0;
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        ma=-1e9;
        for(int i=0;i<n;i++){
            sum=0;
            for(int j=i;j<n;j++){
                sum+=a[j];
                ma=max(ma,sum);
            }
        }
        cout<<ma<<endl;
    }
return 0;
}

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

using namespace std;

int main() {
  int N;
  while (cin >> N) {
    if (N == 0) break;
    int num[5000];
    for (int i = 0; i < N; i++) {
      cin >> num[i];
    }
    int m = num[0];
    for (int i = 0; i < N; i++) {
      int sum = 0;
      for (int j = i; j < N; j++) {
        sum += num[j];
        m = max(m, sum);
      }
    }
    cout << m << endl;
  }

  return 0;
}