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<cstdio>
#include<vector>
#include<deque>
using namespace std;
int main(){
    int n;
    for(;;){
        scanf("%d",&n);
        if(n==0) break;
        vector<int> numa(n);
        deque<int> suma;
        int ans=0;
        for(int i=0;i<n;i++){
            scanf("%d",&numa[i]);
        }
        
        bool isplus=numa[0]>=0;
        int nowsum=numa[0];
        for(int i=1;i<n;i++){
            if((numa[i]>=0) == isplus){
                nowsum+=numa[i];
            }else{
                isplus=numa[i]>=0;
                suma.push_back(nowsum);
                nowsum=numa[i];
            }
        }
        suma.push_back(nowsum);

        if(suma.front()<0){
            if(suma.size()==1){
                int m=0;
                for(int i=0;i<n;i++){
                    if(m==0 || m<numa[i]) m=numa[i];
                }
                ans=m;
            }
            suma.pop_front();
        }else if(suma.size()==1){
            for(int i=0;i<n;i++){
                ans+=numa[i];
            }
        }

        while(!suma.empty()){
            if(suma.size()>=3){
                nowsum=suma.front();
                suma.pop_front();
                while(suma.size()>=2 && suma[0]+suma[1]>0){
                    nowsum+=suma[0]+suma[1];
                    suma.pop_front();
                    suma.pop_front();
                }
                if(suma.size()>0) suma.pop_front();
                if(ans<nowsum) ans=nowsum;
            }else if(suma.size()==2){
                if(ans<suma[0]) ans=suma[0];
                suma.pop_front();
                suma.pop_front();
            }else if(suma.size()==1){
                if(ans<suma[0]) ans=suma[0];
                suma.pop_front();
            }
        }
        printf("%d\n",ans);
    }
}

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

int main(){
	int n;
	int a;
	int result;
	cin >> n;
	while(n){
		for(int i=0;i<n;i++){
			cin >> a;
			if(a > 0){
				result += a;
			}
		}
		cin >> n;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
int main()
{
	while (!std::cin.eof())
	{
		int n;
		std::cin >> n;
		if (n == 0)
		{
			break;
		}
		std::vector<int>a(n);
		for (auto&i : a)
		{
			std::cin >> i;
		}
		int max = -100001;
		for (int i = 0; i < n; i++)
		{
			int max_temp = 0;
			for (int j = 0; j < n - i; j++)
			{
				max_temp += a[i + j];
				if (max < max_temp)
				{
					max = max_temp;
				}
			}
		}
		std::cout << max << std::endl;
	}
	return 0;
}

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


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

    vector<int64_t> a(5010), sum(5010, 0); 
    for(int i=1; i<=n; i++){
      cin >> a[i];
      sum[i] = sum[i-1] + a[i];
    }

    int64_t ans = -99999999;
    for(int i=0; i<=n; i++){
      for(int j=i+1; j<=n; j++){
        ans = max(ans, sum[j]-sum[i]);
      }
    }
    cout << ans << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main()
{
  int n,sum = 0,ans,sumkeep;
  
  while(cin >> n){
    if(n == 0)break;
    
    ans = 0;
    sumkeep = 0;

    int a[n];
    
    for(int i = 0;i < n;i++){
      cin >> a[i];
    }
    
    for(int i = 0;i < n;i++){
      sumkeep = 0;
      for(int j = i;j < n;j++){
	sumkeep += a[j];
	if(i == 0 && j == 0){
	  ans = sumkeep;
	}
	else if(ans < sumkeep){
	  ans = sumkeep;
	}
      }
    }
    cout << ans << endl;
  }
}

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

C++: #include<stdio.h>
#include<iostream>
#include<algorithm>

using namespace std;
int main(void)
{
    int n, a[10000];
    while (1) {
        cin >> n;
        if (n == 0)
            break;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        int goukei = 0, led = -10000000;
        for (int i = 1; i <= n; i++)
        {
            goukei = 0;
            for (int j = i; j <= n; j++)
            {
                goukei = goukei + a[j];
                led = max(goukei, led);
            }
        }
        cout << led << endl;
    }
    return 0;
}

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

	int n, max=0;
	int *a;
	int sum;

	do{
		max = -1000000;
		//cout << endl;
		cin >> n;

		if (n == 0) break;

		a = new long[n + 1];

		sum = 0;

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

			sum = 0;

			cin >> a[i];

			for (int j = i; j >= 0; j--){

				sum += a[j];
				if (max < sum) max = sum;
			}
		}

		cout << max << endl;
	} while (1);
}

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];
        }
        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++: // 2014/08/30 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

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

		int DP[5000];
		DP[0] = a[0];
		int s_max = DP[0];

		for(int i=1; i<n; i++){
			DP[i] = max(DP[i-1]+a[i], a[i]);

			s_max = max(s_max, DP[i]);
		}

		cout << s_max << endl;
	}

	return 0;
}

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

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

typedef long long ll;

int main() {
  
  int N;
  while(cin >> N && N) {
    vector<int> in(N);
    rep(i, N) cin >> in[i];
    vector<int> v(N);
    int mx = -1<<29;
    rep(i, N) {
      if(i-1 >= 0 && v[i-1] >= 0) {
	v[i] = v[i-1] + in[i];
      }
      else {
	v[i] = in[i];
      }
      if(mx < v[i]) { mx = v[i]; }
    }
    cout << mx << endl;
  }
  
  return 0;
}

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

using namespace std;

int calc (vector<int> a, int i, int n) {
    int s = 0, j;
    for (j = 0; j < n; j++) {
        s += a[i + j];
    }
    return s;
}

inline int max (int a, int b) {
    return a > b ? a : b;
}

int main (void) {
    int n, i, j;
    while (1) {
        cin >> n;
        if (n == 0) break;
        vector<int> a(n);
        for (i = 0; i < n; i++) {
            cin >> a[i];
        }
        int sum = 0, s;
        for (i = 1; i <= n; i++) {
            for (j = 0; j + i <= n; j++) {
                s = calc(a, j, i);
                sum = max(sum, s);
            }
        }
        cout << sum << endl;
    }
    return 0;
}