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++: #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(1){

    // input part //////////////////////////////////////////
    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];


    // solve part //////////////////////////////////////////
    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 << 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<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n,b;
	vector<int>a;
	while (1){
		int max_v = -1000000;
		a.clear();
		cin >> n;
		if (n == 0)break;
		a.push_back(0);
		for (int i = 0; i < n; i++){
			cin >> b;
			a.push_back(b);
		}
		for (int i = 1; i <= n; i++){
			a[i] = max(a[i - 1] + a[i], a[i]);
			if (a[i]>max_v){
				max_v = a[i];
			}
		}
		cout << max_v << endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>

//#define PI 3.141592653589

using namespace std;


int main()
{
	int n;
	int seisuu[5000];
	int wa = 0;
	int wa_max = -100001;
	
	while (1)
	{
		wa_max = -100001;
		
		cin >> n;
		if (n == 0) break;
		
		for (int i=0; i<n; i++)
		{
			cin >> seisuu[i];
		}
		
		for (int i=0; i<n; i++)
		{
			for (int j=i; j<n; j++)
			{
				wa += seisuu[j];
				wa_max = max(wa_max, wa);
			}
			wa = 0;
		}
		cout << wa_max << endl;
		
		/*
		for (int i=0; i<n; i++)
		{
			cout << seisuu[i] << " ";
		}
		*/
	}
	
	return 0;
}

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

int main(){
  int n;
  int list[5000];

  while((cin>>n)!=0){
    int temp=0;
    int max=0;
    for(int i=0; i<n; i++){
      cin >> list[i];
    }
    for(int i=0; i<n; i++){
      temp += list[i];
      if( temp<=0 ){
        temp=0;
      }
      if(max<temp){
        max=temp;
      }
    }

    cout << "output: " << max << endl;
  }

  return 0;
}

C++: #include <stdio.h>

int main(void) {

  int n;

  int a[6000];

  while(1) {

    int max_a=-100000;
    int sum;

    int i,j;

    scanf("%d",&n);
    getchar();

    if(n==0) break;

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

    //for(i=0;i<n;i++) printf("%d ",a[i]);

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

      sum=0;

      for(j=i;j<n;j++) {

	sum+=a[j];

	if(max_a<sum) max_a=sum;
	//printf("%d ",max_a);
      }

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

  }

  return 0;

}

C++: /*
 * AOJ-Volume0-0022
 */
#include <iostream>
#include <limits.h>
#include <vector>
#include <cstdio>

using namespace std;

typedef long long ll;

/*
 * Find maximum sum.
 *   array: number list
 */
ll findMaximumSum(vector<int> &array){
  ll sumValue = array[0];
  ll maxValue = INT_MIN;
  int length = array.size();

  for(int i = 1; i < length; i++){
    ll value = array[i];

    if(sumValue < 0){
      sumValue = value;
    }else{
      sumValue += value;
    }

    if(maxValue < sumValue){
      maxValue = sumValue;
    }
  }

  return maxValue;
}

void solve(int n){
  vector<int> a(n);

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

  printf("%d\n", findMaximumSum(a));
}

int main(){
  int n;

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

    solve(n);
  }

  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

#define ARRAY_MAX 5005

int main(){


    ll n;
    while(cin >> n,n){
        vector<ll> arr(ARRAY_MAX,0);
        REP(i,n){
            cin >> arr[i+1];
        }
        REP(i,n){
            arr[i+1] += arr[i];
        }

        ll maxi = -INF;
        for(int i = n;i >= 0;i--){
            for(int j = 0;j < i-1;j++){
                maxi = max(maxi,arr[i]-arr[j]);
            }
        }
        cout << maxi << endl;
    }

    return 0;
}

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

int main(){
	long long a, maximum;
	int n;
	S[0] = 0;
	while (cin >> n, n){
		maximum=-1000000
		long long S[5010] = {};
		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 <iostream>
#include <algorithm>
using namespace std;

int main() {
  int n;
  while(cin >> n, n) {
    int x[n];
    for (int i=0; i<n; i++)
      cin >> x[i];

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

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


int main() {
    int n;
    std::cin >> n;
    while (n != 0) {
        std::vector vec(n+1, 0);
        int x;
        for (int i = 1; i <= n; ++i) {
            std::cin >> x;
            vec[i] = x;
        }
        std::vector<int> sum;
        sum.assign(n+1, 0);
        sum[1] = vec[1];
        for (int i = 1; i < n; i++) {
            sum[i+1] = sum[i] + vec[i+1];
        }
        int ans = -1000000000;
        for (int l = 1; l <= n; ++l) {
            for (int r = l; r <= n; ++r) {
                ans = std::max(ans, sum[r] - sum[l-1]);
            }
        }
        std::cout << ans << std::endl;
        std::cin >> n;
    }
}

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