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++: loop do
  n = gets.to_i
  break if n == 0

  max = -1_000_000
  sum = 0
  n.times do
    m = gets.to_i
    sum += m
    max = sum if max < sum
    sum = 0 if sum < 0
  end
  puts max
end

C++: #include <iostream>
#include <string>
#include <stdlib.h>
#include <fstream>

using namespace std;


int sumarray(int *array, int idx1, int idx2);


int main(){
  int n, Max, ibuf;
  int *List;

  //ifstream ifs("input.txt"); // for debug

  while(cin >> n){
    if(n == 0) break; // if n=0, end calc

    List = new int[n];  // allocate List

    for(int i=0; i<n; i++){
      cin >> List[i];
      //cout << List[i] << " "; // for debug
    }

    //cout << endl; // for debug

    Max = 0;
    for(int l=1; l<=n; l++){
      ibuf = sumarray(List, 0, l);
      if(ibuf > Max) Max = ibuf;
      for(int i=0; i<n-l; i++){
	ibuf += List[i+l] - List[i];
	if(ibuf > Max) Max = ibuf;
	//cout << ibuf << endl; // for debug
      }
    }

    cout << Max << endl;

    delete List; // deallocate List
  }

}


int sumarray(int *array, int idx1, int idx2){ // sum array[idx1] ~ array[idx2-1]
  int ret = 0;
  for(int i=idx1; i<idx2; i++){
    ret += array[i];
  }
  return ret;
}

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]);
            printf("%d ",numa[i]);
        }
        printf("\n");
        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);
        for(int i=0;i<suma.size();i++){
            printf("%d ",suma[i]);
        }
        printf("\n");
        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()>=2) 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 <climits>
#include <iostream>

using namespace std;

template <typename Type>
long long Maximum_Sum_Sequence(Type N[], int size)
{
	long long max = LLONG_MIN;

	for (int i = 0; i < size; i++)
	{
		long long sum = 0;

		for (int j = i; j < size; j++)
		{
			sum += N[j];

			if (sum > max) { max = sum; }
		}
	}

	return max;
}

int main()
{
	const int DATASETS = 100;

	int n[DATASETS], a[DATASETS][5000], c = 0;

	while (true)
	{
		cin >> n[c];

		if (n[c] == 0) { break; }

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

		c++;
	}

	for (int i = 0; i < c; i++)
	{
		cout << Maximum_Sum_Sequence(a[i], n[i]) << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include <algorithm>


using namespace std;

int main(){
	int n;
	int max1;
	int maxS;
	int sum=0;
	int sumS=0;
	int  raw[5000];
	int ans;
	while(cin>>n,n!=0){
		sum=0;
		maxS=0;
		sumS=0;
		cin >> raw[0];
		max1=raw[0];
		sum += raw[0];
		if(sum<0)sum=0;
		for(int i=1;i<n;i++){
			cin >> raw[i];
			if(max1<raw[i]) max1 = raw[i];
			if(raw[i]<0){
				if(sumS<sum) sumS=sum;
			}
			sum += raw[i];
			if(sum<0){
				if(maxS<sum)maxS=sum;
				sum=0;
			}
		}
		ans=max(sum,max(sumS,max1),maxS);
		cout<<ans<<endl;
	}
	return 0;
}

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

long long S[5010];

int main(){
	long long a, maximum = -1000000;
	int n;
	S[0] = 0;
	while (cin >> n, n){
		for (int i = 1; i <= n; i++){
			cin >> a;
			S[i] = S[i - 1] + a;
		}

		for (int i = 0; i <= n; i++)
			for (int j = i + 1; j <= n; j++){
				maximum = max(maximum, S[j] - S[i]);
			}
		cout << maximum << endl;
	}
}

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

int main(){
  int n;
  cin >> n;
  while(n!=0){
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a.at(i);

    vector<int> s(n+1);
    s.at(0) = 0;
    for(int i=1;i<n+1;i++) s.at(i) = s.at(i-1)+a.at(i-1);

    int ans=a.at(0);
    for(int i=1;i<n+1;i++){
      for(int j=0;j<i;j++){
        ans = max(s.at(i)-s.at(j),ans);
      }
    }

    cout << ans << endl;

    cin >> n;
  }
}

C++: #include<iostream>
using namespace std;
int main()
{
int n;
while(cin>>n&&n!=0)
{
int a[n];
int A=0;
int R=-100000;
for(int h=0;h<n;h++)
{
	cin>>a[h];
}
for(int i=0;i<n;i++)
{
	for(int j=0;j<n-i;j++)
	{
	//	cout << k << " ";		
		A=A+a[j];
		
	}	
	if(R<A)
	{
		R=A;
	}
//	cout<<endl;
	A=0;
	}
cout<<R<<endl;
}
return 0;
}

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

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

while(1){

cin >> n ;

if(n==0){
break ;
}

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

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

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

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

cout << Ans << endl ;

}

}

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

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