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

int main()
{
    int n;
    int MAX=-500000000;
    vector<int> vt;
    while(1){
        cin >> n;
        if(n==0){
            break;
        }
        int a;
        int A=0;
        for(int i=0 ; i<n ; i++){
            cin >> a;
            A+=a;
        }
        vt.push_back(A);
    }
    vector<int>::iterator it = vt.begin();
    while(it!=vt.end()){
        if(MAX<*it){
            MAX=*it;
        }
        it++;
    }
    cout << MAX << endl;
    return 0;
}

C++: #include <iostream>

using namespace std;

inline int max (int a, int b) {
    return a > b ? a : b;
}

int main (void) {
    int n, i, j;
    while (1) {
        cin >> n;
        if (n == 0) break;
        int a[n];
        for (i = 0; i < n; i++) {
            cin >> a[i];
        }
        int sum = 0, s;
        for (i = 0; i < n; i++) {
            s = 0;
            for (j = i; j < n; j++) {
                s += a[j];
                if (i != j) sum = max(sum, s);
            }
        }
        cout << sum << 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((sum+arr[i])>0)
       { 
         sum=sum+arr[i];
         if(sum>max) max=sum;
       }        
       else sum=0;
     }       
     result[count++]=max;              
   }
   for(int i=0;i<count;i++) cout<<result[i]<<endl;
   //while(1);      
   return 0;    
 }

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

int main(){
  int i,j,n,tmp,ans,a[5000];

  while(scanf("%d",&n) && n){
    for(i=0;i<n;i++)scanf("%d",&a[i]);
    
    ans = a[0];
    for(i=0;i<n;i++){
      tmp = a[i];
      for(j=i+1;j<n;j++){
	tmp += a[j];
	ans = max(tmp,ans);
      }
    }
    printf("%d\n",ans);
  }
}

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

using namespace std;

#define FOR(a) for(int i = 0; i < a; i++)
#define FORR(a, b) for(int i = a; i < b; i++)

int main(void){
	int Max, Num = -1, In;
	vector<int>	Dat;
	while (Num != 0){
		Max = -100000;
		cin >> Num;
		FOR(Num){
			cin >> In;
			Dat.push_back(In);
		}
		FORR(1, Num){
			Dat[i] = max(Dat[i], Dat[i - 1] + Dat[i]);
			Max = max(Max, Dat[i]);
		}
		cout << Max << endl;
	}
	return 0;
}

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

int main() {
	int n;
	long 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>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(void)
{
    int a[5000], n, ans, sum;
    
    while(true)
    {
        cin >> n;
        if(n == 0) break;
        rep(i,n)
            cin >> a[i];
        
        ans = a[0];
        rep(i,n)
        {
            sum = 0;
            for(int j=i; j<n; j++)
            {
                sum += a[j];
                ans = max(ans, sum);
            }
        }
        cout << ans << endl;
    }
    
    return 0;
}

C++: #include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    while(1){
        int N;
        cin>>N;
        if(!N)break;
        int rui[10000]={0};
        for(int i=1;i<=N;i++){
            int a;
            cin>>a;
            rui[i]=rui[i-1]+a;
        }
        int ans=-2000000000;
        //for(int i=0;i<=N;i++)printf("[%d]",rui[i]);
        for(int i=0;i<=N;i++){
            for(int j=i;j<=N;j++)ans=max(ans,rui[j]-rui[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

void saiki(int num,int sum);

int term[10000],n,ans;

int main(void)
{
   while(scanf("%d",&n))
   {
      ans = -100000000;
      if(n == 0) break;
      for(int i = 0;i < n;i++) scanf("%d",&term[i]);
      for(int i = 0;i < n;i++) saiki(i+1,term[i]);

      printf("%d\n",ans);
   }
   return 0;
}

void saiki(int num,int sum)
{
   if(ans < sum) ans = sum;
   if(num >= n) return;
   saiki(num+1,sum+term[num]);

}

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

int a[5000] = {0};
int S[5000] = {0};

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

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

  int maxsum = 0;
  int sum = 0;
  for(int i = 0; i <= n-1; i++){
    for(int j = i + 1; j <= n;j++) {
      sum = S[j] - S[i];
      if(sum > maxsum)
	maxsum = sum;
      sum = 0;
    }
  }
  cout << maxsum << endl;
  }
}

C++: #include <iostream>
using namespace std;
int main(void){

	long n, max=0;
	long *a;
	long sum;

	do{
		max = 0;
		//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);
}

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

int kadaneAlg(int arr[], const int &len) {
    int max_global;
    int max_current = max_global = arr[0];

    for (int i = 1; i < len; i++) {
        max_current = std::max(arr[i], arr[i] + max_current);
        if (max_current > max_global) max_global = max_current;
    }
    return max_global;
}

int main()
{
    int N;
    while(1) {
        std::scanf("%d", &N);
        if (N == 0) break;
        int arr[N];
        for (int i = 0; i < N; i++) scanf("%d", &arr[i]);
        std::printf("%d\n", kadaneAlg(arr, N));
    }
    return 0;
}

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

int main(){

  int n,count,maxu;

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

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

    for(int i=n-1;0<=i;i--){
      for(int j=0;i+j<n;j++){
	count = 0;
	for(int k=j;k<=j+i;k++)
	  count += numbers[k];
	maxu = max(maxu,count);
      }
    }
    cout << maxu << endl;

  }

  return 0;
}

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

using namespace std;

int main(){
  int n,x[5000];
  while(1){

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

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

  int now=0;
  int Max=-100001,tmp;
  for(int i = 0;i < n; i++){
    now+=x[i];
    tmp=now;

    for(int j=0;j < i;j++){
      Max=max(Max,now);
      now-=x[j];
      }

    now=tmp;
    }
  cout << Max << endl;
} 

  return 0;
}