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>
using namespace std;

int main(){
        int n, a[5010],b[5010];
        while(cin >> n && n){
                for(int i=0; i<n; i++) cin >> a[i];
                b[0] = 0;
                for(int i=1; i<n+1; i++){
                        b[i] = b[i-1] + a[i-1];
                } 
                int max=0;
                for(int r=1; r<n+1; r++){
                        for(int i=0; i<n-r+1; i++){
                                int x = b[r+i] - b[i];
                                max = (max > x)? max : x;
                        }
                }
                cout << max << endl;
        }
}

C++: 7
-5
-1
6
4
9
-6
-7
13
1
2
3
2
-2
-1
1
2
3
2
1
-2
1
3
1000
-200
201
1
-1
0

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int n,x[5001],sum=0,maxx=0,c=0;
        cin>>n;
        c=n;
        if(n==0)return 0;
        for(int i=0;i<n;i++){
            cin>>x[i];
        }
        for(int i=0;i<n;i++){
            c--;
            //for(int j=i;j<n;j++){
            //    for(int c=n-1;c>=i;c--){
                    for(int z=i;z<=c;z++){
                        sum+=x[z];
                        maxx=max(maxx,sum);
                    }
                    sum=0;
              //  }
            //}
        }
        cout<<maxx<<endl;
    }
}

C++: #include <iostream>
using namespace std;
int main() {
	int s,h,n,i,a[5000];
	while(true) {
		cin >> n;
		if (n==0) break;
		for (i=0;i<n;i++) cin >> a[i];
		s=0; h=-100000;
		for (i=0;i<n;i++) {
			s=(s+a[i]>=a[i]) ? s+a[i] : a[i];
			h=(s > h)  ? s : h;
		}
        cout << h << endl;
	}
	return 0;
	}

C++: #include<stdio.h>

int main()
{
	int n;
	while(true)
	{
		scanf("%d",&n);
		if(n==0){return 0;}
		
		if( n >= 1 && n <= 5000){
		int a[5000]={0},max=0;
		for(int x=0;x<n;x++)
		{
			scanf("%d",&a[x]);
			if(a[x]<=10000||a[x]>=-100000)
			{
				x--;
			}
			else
			{
			for(int y=0;y<=x;y++)
			{
				if(y!=x)
				{
					a[y]+=a[x];
				}
				if(max<a[y])
				{
					max=a[y];
				}
			}
			}
		}
		printf("%d\n",max);
		}
	}
}

C++: #include <iostream>
#include <climits>
using namespace std;
int s[5010];
int main(){
  int n, a;
  while(cin >> n, n){
    int ans = -(INT_MAX-1);
    for(int i = 0 ; i < n ; i++){
      cin >> a;
      if(!i)s[i] = a;
      else{
	s[i] = max(a, a + s[i-1]);
      }
      ans = max(ans, s[i]);
    }
    cout << ans << endl;
  }
  return 0;
}

C++: 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#endif

#define ITER(c)         __typeof__((c).begin())
#define FOREACH(it, c)  for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)        __typeof__((c).rbegin())
#define RFOREACH(it, c) for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)       REPEAT(i, 0, n)
#define REPEAT(i, k, n) for (int i = (k); i < (n); ++i)
#define REVREP(i, n)    for (int i = ((n)-1); i >= 0; --i)
#define FIND(c, n)      std::find((c).begin(), (c).end(), (n));
#define BSEARCH(c, n)   std::binary_search((c).begin(), (c).end(), (n))
#define LLPOW(p1,p2)    ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)      (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)      (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)      (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC     do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)       fgets((p), sizeof(p), stdin)
#define CHOMP(p)        do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n') *_q = 0; } while(0)

int main(){
    int n;
    while(cin >> n, n){
        list<int> v;
        int p = 0;
        REP(i, n){
            int in;
            cin >> in;
            if((p <= 0 && in < 0) || p >= 0 && in > 0 || in == 0){
                p += in;
            } else {
                v.push_back(p);
                p = in;
            }
        }
        v.push_back(p);

        while(v.size() >= 3){
            bool f = false;
            FOREACH(it, v){
                int p1 = *it;
                if(p1 < 0) continue;
                ITER(v) it2 = it; it2++;
                if(it2 == v.end()) break;
                int p2 = *it2;
                ITER(v) it3 = it2; it3++;
                if(it3 == v.end()) break;
                int p3 = *it3;

                if(p2+p3 >= 0){
                    v.erase(it2);
                    v.erase(it3);
                    *it += (p2+p3);
                    f = true;
                    break;
                }
            }
            if(!f) break;
        }

        int max = -1e9;
        FOREACH(it, v){
            if(max < *it) max = *it;
        }
        cout << max << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,a[5000],saidai=-100000;
	while(cin>>n&&n!=0){
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=0;n>i;i++){
			int kazu=0;
			for(int x=0;x<i;x++){
				kazu=kazu+a[x];
				if(kazu>saidai){
					saidai=kazu;
				}
			}
		}
		cout<<saidai<<endl;
	}
}

C++: #include <iostream>
using namespace std;
int main(){
	for (;;){
		int a,goukei=0,max=0,b;
		cin>>a;
		if (a==0)break;
		int data[a+1]={0};
		for (int A=1;A<=a;A++){
			cin>>data[A];
			if (max<data[A])max=data[A];
			goukei+=data[A];
			data[A]=goukei;
			if (max<data[A])max=data[A];
		}
		for (int A=3;A<a;A++){
			b=A-2;
			for (int B=b;B>0;B--){
				goukei=0;
				goukei=data[A]-data[B];
				if (goukei>max) max=goukei;
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>
#define N 5001
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
    int n;
    while(cin >> n &&n!=0)
    {
        if(n==0)break;
        long int s[N];
        //memset(s,0,sizeof(int)*N);
        int t;
        long int max = 0;
        long int min = 0;
        for(int i=0;i<n;i++){
            cin >>t;
            s[i+1] = s[i]+t;
            if(max<s[i+1])max = s[i+1];
            if(min>s[i+1])min = s[i+1];
        }
        cout << max -min << endl;

    }

    return 0;
}