Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var infty = 100000 * 2
var scanner = bufio.NewScanner(os.Stdin)

func nextInt() (int, error) {
	scanner.Scan()
	return strconv.Atoi(scanner.Text())
}

func findMaximumSubarray(arr []int) int {
	currentMaxSum, maxSumContainsTail := -infty, -infty

	for j := range arr {
		if arr[j] > maxSumContainsTail+arr[j] {
			maxSumContainsTail = arr[j]
		} else {
			maxSumContainsTail += arr[j]
		}
		if currentMaxSum < maxSumContainsTail {
			currentMaxSum = maxSumContainsTail
		}

		// fmt.Println(arr[j], currentMaxSum, maxSumContainsTail)
	}
	return currentMaxSum
}

func main() {
	scanner.Split(bufio.ScanWords)
	for {
		size, _ := nextInt()
		if size == 0 {
			break
		}

		arr := make([]int, size)
		for i := range arr {
			n, _ := nextInt()
			arr[i] = n
		}

		maximumSum := findMaximumSubarray(arr)
		fmt.Println(maximumSum)
	}
}

C++: /*Filename: aoj0022.cpp
 *Author: Mushiyo
 */

#include <iostream>
#include <cmath>
#include <climits>

using namespace std;

int main(){
	int n = 0;

    while(cin >> n){
    	if(n == 0){
    		break;
    	}

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

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

        int maxSum = INT_MIN;
        int minSum = 100000 * 5000 + 1;
        for(int i = 0; i < n; ++i){
        	maxSum = max(maxSum, sum[i] - minSum);
        	minSum = min(minSum, sum[i]);
        }
        
        cout << maxSum << endl;
    }

	return 0;
}

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

int main(){
int n,Sum,Ans ;

while(1){

Ans=0 ;

cin >> n ;

if(n==0){
break ;
}

vector<int> vec(n+1,0) ;

for(int i=1;i<n+1;i++){
cin >> vec.at(i) ;
}

for(int j=0;j<n;j++){
vec.at(j+1)=vec.at(j)+vec.at(j+1) ;
}

for(int k=0;k<n+1;k++){
    for(int l=k;l<n+1;l++){
    Sum=vec.at(l)-vec.at(k);
    Ans=max(Sum,Ans) ;
    }
}
cout << Ans << endl ;

}
}

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

int main(){
	int n, max1, max2, a[5001];

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

		for(int i=0 ; i<n ; i++){
			int sum = 0;
			for(int j=i ; j<n ; j++){
				sum += a[j];
				max1 = max( max1 , sum );
			}
		}
		cout << max1 << endl;
	}

C++: #include<iostream>
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<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);
}