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 <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=-100000000;
		rep(i,n) a[i]=0;
		cin>>a[0];
		/*
		rep(i,n-1) cin>>a[i+1];
		c=n-1;
		*/
		
		rep(i,n-1){
			int t;
			cin>>t;
			if(a[c]*t<0){
				a[++c]=t;
			}
			else a[c]+=t;
		}
		
		for(int i=1;i<=c+1;i++){
			rep(j,c+2-i){
				MAX=max(MAX,sum(j,i));
			}
		}
		cout<<MAX<<endl;
	}
	return 0;
}

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

int main(){
  int n;
  int a[5000];
  while(cin >> n && n>0){
    for(int i=0;i>n;i++)
      cin >> a[i];
    int sum=0,tmp=0,max=-100000;
    bool flg=true;
    for(int i=0;i<n;i++){
      if(flg) max=max(max,a[i]);
      if(a[i]>0){
	flg=false;
	sum+=a[i];
	continue;
      }
      for(tmp=sum;a[i]<=0;i++){
	tmp+=a[i];
      }i--;
      if(tmp>0)
	sum=tmp;
      else
	sum=0;
    }

    cout << sum;
  }
}

C++: #include<iostream>
using namespace std;
int main()
{
for(;;){
int n,a[5000],r[5000],x=0,ans=-200000;
cin >> n;
if(n==0)return 0;
for(int i=0;i<n;i++)cin >> a[i];
for(int i=0;i<n;i++){
x+=a[i];
r[i]=x;
}
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
ans=max(ans,r[j]-r[i]);
}
}
cout << ans << "\n";
}
return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int a[5000],i,j,sum=0,max[5000]={-999999},c=0,n;
	
	while(1){
		scanf("%d",&n);
		if( n == 0)
			break;
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);

		for(i=0;i<n;i++){
			for(j=i;j<n;j++){
				sum = sum + a[j];
				if(max[c] < sum)
					max[c] = sum;
			}
			sum = 0;
		}
		c++;
	}
	for(i=0;i<c;i++){
		printf("%d\n",max[i]);
	}
	return 0;
}

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

using namespace std;

int main() {
  int n;
  vector<int> datas;
  vector<int> sums;

  while (cin >> n, n != 0) {
    int input;
    for (int n_i = 0; n_i < n; n_i++) {
      cin >> input;
      datas.push_back(input);
    }
    for (int data_i = 0; data_i < n-1; data_i++) {
      sums.push_back(datas[data_i]+datas[data_i+1]);
    }

    int max = *sums.begin();
    for (vector<int>::iterator sum_i = sums.begin(); sum_i != sums.end(); sum_i++)
      if (max < *sum_i)
        max = *sum_i;
    cout << max << endl;
  }

  return 0;
}

C++: #include <iostream>

using namespace std;

int S[5000];

int main(){
	int n;
	while(cin >> n,n){
		S[0] = 0;
		int tmp,sum = 0;
		for(int i = 1; i < n; i++){
			cin >> tmp;
			sum += tmp;
			S[i] = sum;
		}
		tmp = S[1] - S[0];
		for(int i = 0; i < n; i++){
			for(int j = i + 1; i < n; j++){
				if(tmp < S[j] - S[i]) tmp = S[j] - S[i];
			}
		}
		cout << tmp << endl;
	}
	return 0;
}

C++:  
 #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 
 using namespace std;
 
 int arr[5000+5];
 int result[5000+5];
  
 int main()
 {
   int n;
   int count=0;
   while(cin>>n&&(n!=0))
   {
     int sum=0;
     int max=0;
     for(int i=0;i<n;i++)
     {
       cin>>arr[i];
       if(i==0) 
       {
         sum=arr[i];
         max=arr[i];
         continue;         
       }
       if((sum+arr[i])>0)
       { 
         sum=sum+arr[i];
         if(sum>max) max=sum;
         continue;
       }        
       if(arr[i]>max)
       {
         max=arr[i];
         sum=arr[i];
       }
     }       
     result[count++]=max;              
   }
   for(int i=0;i<count;i++) cout<<result[i]<<endl;
   //while(1);      
   return 0;    
 }

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

int main() {
	int n;
	long sum, max;

	while (true) {
		sum = max = 0;
		cin >> n;
		if (n == 0) break;

		int a[n];

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

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

		cout << max << endl;
	}
	return 0;
}

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

int main(){
	long long int n;
	long long int i;
	long long int max;
	long long int sum[1000000];
	long long int t;
	while(cin>>n,n){
		max=0;
		for(i=0;i<n;i++)cin>>sum[i];
		for(i=t=0;i<n;i++){
			if(t<0)t=sum[i];else t+=sum[i];
			if(max<t)max=t;
		}
		cout<<max<<endl;
	}
}

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

int main()
{
    int n;
    while(1){
        vector<int>vec;
        int ans=-100000;
        cin>>n;
        vector<int>dp(n);
        if(n==0)break;
        for(int i=0;i<n;i++){
            int a;cin>>a;
            vec.push_back(a);
        }
        dp[0]=vec[0];
        for(int i=1;i<n;i++){
            dp[i]=max(dp[i-1]+vec[i],vec[i]);
        }
        for(int i=0;i<n;i++){
            ans=max(ans,dp[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <climits>
#include <numeric>
int main()
{
  while (1) {
    int n;
    std::cin >> n;
    if (n == 0) break;
    int max = -INT_MAX;
    int a[n];
    for (int i = 0;i < n; i++) {
      std::cin >> a[i];
    }
    for (int i  = 0; i < n; i++) {
      for (int j = i + 1; j <= n; j++) {
        int temp = std::accumulate(a + i, a + j, 0);
        if (temp > max) max = temp;
      }
    }
    std::cout << max << std::endl;
  }
}

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

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;

const int INF = 1000000000;
const int MOD = 1000000007;
const double EPS = 1e-8;

int main() {
	int n;
	while (cin >> n, n) {
		int a[n], ans = -10000000;
		rep (i, n) cin >> a[i];
		int dp[n];
		dp[0] = a[0];
		REP (i, 1, n) {
			dp[i] = max(dp[i - 1] + a[i], a[i]);
		}
		rep(i, n) {
			cout << dp[i] << " ";
			ans = max(ans, dp[i]);
		}
		cout << endl;
		cout << ans << endl;
	}
}

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

int main() {
	int n;
	while (true) {
		cin >> n;
		if (n == 0)break;
		int* nums = new int[n];
		for (int i = 0; i < n; i++) {
			cin >> nums[i];
		}
		long int max = -100001; 
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n - i; j++) {
				long int tmp = 0;
				for (int k = i; k <= j; k++) {
					tmp += nums[k];
				}
				if (max < tmp)max = tmp;
			}
		}
		cout << max << endl;
	}
}

C++: #include <algorithm>
#include <iostream>
using namespace std;
int a[5010];
int main(){
	int i,n,max_so_far,max_ending_here;//maximum subarray problem
	cin>>n;
	while(n!=0){

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

		max_ending_here=-100000;
		max_so_far=-100000;

		for(i=0;i<n;i++){
			max_ending_here = max(0,max_ending_here + a[i]);
			max_so_far = max(max_so_far,max_ending_here);
		}
	cout << max_so_far << endl;
	cin>>n;//kousinn
	}
}