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<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int a[5001];
int sum[5001];
main(){
  while(1){
    int res=0;
    scanf("%d",&n);
    if(n==0) break;
    int sm=0;
    sum[-1]=0;
    memset(sum,0,sizeof(sum));
    for(int i=0;i<n;i++){
      scanf("%d",&a[i]);
      sm+=a[i];
      sum[i]=sm;
    }
    for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++)
	res=max(res,sum[j]-sum[i-1]);
    printf("%d\n",res);
  }
}

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 <climits>
#include <vector>
using namespace std;
typedef vector <int> vi;

int maxv(vi &x){
	int tmp=x[0];
	for (int i=1; i<x.size(); i++)
		if (x[i]>tmp) tmp=x[i];
	return tmp;
}


int main(void){
	int n;
	vi x;
	while (cin>>n){
		int s=INT_MIN;
		if (n==0) break;
		for (int i=0; i<n; i++){
			int n2;
			cin>>n2;
			for (int j=0; j<x.size(); j++){
				x[j] += n2;
			}
			x.push_back(n2);
			if (i==0 || n2>0) s=max(s, maxv(x));
		}
		cout<<s<<endl;
		x.clear();
	}

	return 0;
}

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

int main (int argc, char const* argv[]){
  int n, max1, a[5001];
  
  while(cin >> n && n!=0){
    for(int i=0;i<n;i++) cin >> a[i];
    
    max1 = a[0];
    for (int i = 0; i < n; i += 1){
      int sum = 0;
      for(int j=i;j<n;j++){
        sum += a[j];
        max1 = max(max1,sum);
      }
    }
    cout << max1 << endl;
    
  }
  
  return 0;
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;


int n;
ll a[5000];

ll sum(int i,int j){
	ll s=0;
	rep(k,j){
		s+=a[i+k];
	}
	return s;
}

int main(){
	while(cin>>n,n!=0){
		int c=0;
		ll MAX=-1000000000000000000;
		rep(i,n) a[i]=0;
		int cou=0;
		rep(i,n){
			cou++;
			cin>>a[0];
			//cout<<"a[0]= "<<a[0]<<endl;
			if(a[0]!=0){
				break;
			}
			
		}
		//cout<<"cou= "<<cou<<endl;
		n-=cou;
			
		/*
		rep(i,n-1) cin>>a[i+1];
		c=n-1;
		*/
		rep(i,n){
			int t;
			cin>>t;
			if(a[c]*t<0){
				a[++c]=t;
			}
			else a[c]+=t;
		}
		c++;
		for(int i=1;i<=c;i++){
			rep(j,c+1-i){
				MAX=max(MAX,sum(j,i));
			}
		}
		cout<<MAX<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,a[5000],saidai=-100000;
	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+1;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>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int v[5001];
int main(){
	int n;
	while(cin >> n,n){
		rep(i,n) cin >> v[i];
		int sum = 0 , mx = *max_element(v,v+n);
		for(int i = 0 ; i < n ; i++){
			if(sum+v[i]<0){
				sum = 0;
			}else{
				sum += v[i];
				mx = max(sum,mx);
			}
		}
		cout << mx << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main() {
	int n;
	while (cin >> n, n) {
		int a[5001], ans = -114514;
		for (int i = 0; i < n; i++)cin >> a[i];
		for (int i = 0; i < n; i++) {
			int cnt = 0;
			for (int j = i; j < n; j++) {
				cnt += a[j];
				if (ans < cnt)ans = cnt;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){

	long long int A[5001]={0};
	long long int n,MAX = -100000;

		while(1){

			cin >> n;

			if( n == 0 ) break;

			for(int i = 1; i <= n; i++){

				cin >> A[i];
	
			}

			MAX = -100000;
		
			for(int i = 1; i <= n; i++){

				A[i] = max(A[i], A[i] + A[i-1]);
				MAX = max(A[i], MAX);

			}
	
			cout  << MAX << endl;

		}
	return 0;
}

C++: #include <iostream>
int main(){
	int n, v[5000], m;
	while(std::cin >> n, m=n){
		for(;m--;)std::cin >> v[m];

		m = *v;
		for(int i=0;i<n;i++)
			for(int j=i,k=v[i];j<n;j++,k+=v[j])
				m=k>m?k:m;

		std::cout << m << '\n';
	}	
}

C++: #include <stdio.h>

int main()
{
	int n, x, p, i, j, k;
	
	while(scanf("%d", &n) != 0){
		if (n == 0) break;

		int a[n];

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

		x = a[0];

		for(i = 1; i <= n; i++){
			for(j = 0; j < n-i+1; j++){
				p = 0;

				for(k = 0; k < i; k++){
					p += a[j+k];
				}

				if(x < p) x = p;
			}
		}

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

	return 0;
}

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

int main()
{
	int a,max_ret=0;
	while(1){
		cin>>a;
		if(a==0){
			return 0;
		}
		int n[5000];
		for(int i=0;i<a;i++){
			cin>>n[i];
		}
		int dp[5000];
		dp[0] = n[0];
		int Max=0;
		for(int i=1;i<a;i++){
			if(dp[i-1]>0){
				dp[i] = dp[i-1] + n[i];
			}else{
				dp[i] = n[i];
			}
			max_ret = max( dp[i], Max);
		}
		
		cout<<max_ret<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    while(cin >> n, n){
        vector<int> a(n, 0), sum(n + 1, 0);
        rep(i, 0, n){
            cin >> a[i];
        }
        rep(i, 1, n + 1){
            sum[i] += sum[i - 1] + a[i - 1];
        }
        int MAX = -1e10;
        rep(i, 0, n + 1){
            rep(j, i + 1, n + 1){
                MAX = max(MAX, sum[j] - sum[i]);
            }
        }
        cout << MAX << endl;
    }
}

C++: #include<iostream>

using namespace std;

int main(){
	int n;	
	while (true) {
		cin >> n;
		if (n != 0) {
			int *num = new int[n];
			for (int i = 0; i < n; i++) {
				cin >> num[i];
			}
			/*最大を更新していきたい*/
			int max_v = -999999999;
			for (int i = 0; i < n; i++) {
				int j = i, tmp_total = 0;
				for (j; j < n; j++) {
					tmp_total += num[j];
					if (tmp_total > max_v) {
						max_v = tmp_total;
					}

				}
			}
			cout << max_v << endl;

		}
		else if(n==0){
			break;
		}

	}
	return 0;
}