Go: package main

import (
        "fmt"
)

func main() {
        for {
                var n int
                _, err := fmt.Scanf("%d", &n)
                if err != nil || n == 0 {
                        break
                }

                var sum [5001]int

                for i := 1; i <= n; i++ {
                        fmt.Scanf("%d", &(sum[i]))
                        if i > 1 {
                                sum[i] += sum[i-1]
                        }
                }

                max_sum := sum[1]
                for i := 1; i <= n; i++ {
                        for j := 0; j < i; j++ {
                                if max_sum < sum[i] - sum[j] {
                                        max_sum = sum[i] - sum[j]
                                }
                        }
                }
                fmt.Printf("%d\n", max_sum)
        }
}

C++: #include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int main()
{
	int n, k, p, m;
	bool isPlus = true;
	while (cin >> n){
		if (0 == n) break;
		vector<int> A(n, 0);
		m = INT_MIN;
		p = 0;
		for (int i = 0; i < n; ++i){
			cin >> k;
			if (m < k) m = k;
			if (0 == i){
				A[p] = k;
				isPlus = (k > 0);
			}
			else {
				if (isPlus == (k > 0)){
					A[p] += k;
				}else{
					++p;
					A[p] = k;
					isPlus = !isPlus;
				}
			}
		}
		vector<int> B(p + 1, 0);
		vector<int> C(p + 1, 0);
		for (int i = 0; i <= p; ++i){
			if (0 == i)
				C[0] = B[0] = A[0];
			else{
				int s = B[i - 1];
				for (int j = 0; j <= i; ++j){
					C[j] += A[i];
					if (s < C[j]) s = C[j];
				}
				B[i] = s;
			}
		}
		if (m < B[p]) m = B[p];
		cout << m << "\n";
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (!n) return 0;
    int s, m = 0, r;
    cin >> r;
    s = r;
    for (int i = 1; i < n; i++) {
      int x;
      cin >> x;
      s += x;
      if (s < m)
        m = s;
      else
        r = max(r, s-m);
    }
    cout << r << endl;
  }
}

C++: #include <cstdio>
int main(){int n,i,j,s,m,a[5000];while(scanf("%d", &n)&&n){for(i=0;i<n;i++)scanf("%d",&a[i]);m=-2147483647;for(i=0;i<n;i++,s=0)for(j=i;j<n;j++)if((s+=a[j])>m)m=s;printf("%d\n",m);}}

C++: #include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<long long int> hyou(n+1, 0);
		long long int a;
		long long int MAX = 0;
		int maxn = 0;
		for (int i = 0; i < n; i++) {
			cin >> a;
			hyou[i+1] = hyou[i] + a;
			if (i == 0) {
				MAX = hyou[1];
			}
		}
		for (int i = 2; i <= n; i++) {
			MAX = max(MAX, hyou[i]);
			for (int j = 1; j < i; j++) {
				if (hyou[j] < 0) {
					MAX = max(MAX, hyou[i]-hyou[j]);
				}
			}
		}
		cout << MAX << endl;
	}
	return 0;
}

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

 int main()
 {
     while(1){
         int n;
         cin >> n;
         if( !n ) break;

         int a;
         int max = numeric_limits<int>::min();
         int sum = numeric_limits<int>::min();
         for(int i=0; i<n; i++){
             cin >> a;

             if( max<0 && a<0 && max<a ) { max = a; continue; }
             else if( max<0 && a<0 && max>a){ continue; }

             if( a>0 ){
                 if( sum<0 ) sum = a;
                 else sum += a;
             }else{
                 if( sum+a>0 ) sum += a;
                 else sum = a;
             }
             if( sum > max ) max = sum;
         }
         cout << max << endl;
    }

    return 0;
}

C++: #include <iostream>
using namespace std;
int main (){
while (1){
long n,dset[5000],temp=0,max;
cin>>n;
if (n==0)break;
for (int i=0;i<n;i++){
        cin>>dset[i];
}
max=-99999;
for (int i=0;i<n;i++){
        for (int j=i;j<n;j++){
                temp=temp+dset[j];
                if (max<temp){
                        max=temp;
                }
        }
temp=0;
}
cout<<max<<endl;
}
return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>

typedef long long ll;
using namespace std;

int main()
{
	int T;
	int maxS=numeric_limits<int>::min();
	while(~scanf("%d",&T)){
		int* dp = new int[T+1]();
		if(T==0) break;
		for(int t=0;t<T;t++){
			int tmp;
			scanf("%d",&tmp);
			dp[t+1] = max(dp[t] + tmp,tmp);
			//printf("dp[%d+1] = %d,dp[%d] = %d\n",t,dp[t+1],t,dp[t]);
		}

		sort(dp,dp+T+1,greater<int>());
		cout << dp[0] << endl;

		delete[] dp;
	}
}

C++: #include <stdio.h>

int main(void)
{
	int i;
	int max;
	int total;
	int a[5010];
	int n;
	
	while (scanf("%d", &n), n != 0){
		max = 0;
		total = 0;
		for (i = 0; i < n; i++){
			scanf("%d", &a[i]);
			total += a[i];
			if (max < total){
				max = total;
			}
			if (total < 0){
				total = 0;
			}
		}
		printf("%d\n", max);
	}
	return (0);
}

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

using namespace std;

int main()
{
    int n;

    while (scanf("%d", &n), n) {
        int s[5001] = {};

        for (int i = 1; i <= n; ++i) {
            int a; scanf("%d", &a);
            s[i] = a + s[i - 1];
        }

        int ma = INT_MIN;

        for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j) {
            ma = max(ma, s[i] - s[j - 1]);
        }

        printf("%d\n", ma);
    }
}

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

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

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

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

int main(){
	int n;
	while(cin >> n){
if(!n)break;
		n++;
		vector<int> t(n), v(n);
		t[0] = 0;
		for(int i = 1;i < n;i++){
			cin >> v[i];
			t[i] = max(t[i-1]+v[i], v[i]);
		}
		cout << *max_element(t.begin(), t.end()) << endl;
	}
	return 0; 
}

/*
7
-5
-1
6
4
9
-6
-7
*/

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main (){
while (1){
long n,dset[5000],max=-99999,temp=0;
cin>>n;
if (n==0)break;
for (int i=0;i<n;i++){
        cin>>dset[i];
}
for (int i=0;i<n;i++){
        for (int j=i;j<n;j++){
                temp=temp+dset[j];
                if (max<temp){
                        max=temp;
                }
        }
temp=0;
}
printf ("%ld\n",max);
}
return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n;
	while(cin >> n,n){
		vector<int> data(n);
		rep(i,n)cin >> data[i];
		int ret = 0;
		rep(i,n){
			int sum = 0;
			for(int j=i;j<n;j++){
				sum += data[j];
				ret = max(sum,ret);
			}
		}
		cout << ret << endl;
	}
}