Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func main() {
	sum := make([]int, 5001)
	for {
		n := nextInt()
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			a := nextInt()
			sum[i+1] = sum[i]+a
		}
		ret := sum[1]
		for i := 0; i <= n; i++ {
			for j := i + 1; j <= n; j++ {
				ret = max(ret, sum[j]-sum[i])
			}
		}
		fmt.Println(ret)
	}
}

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

int main() {
	int n;
	while (cin >> n && n) {
		int a[5001], min, max_a;
		min = a[0] = 0;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			if (i == 1) max_a = a[i] - a[0];
			a[i] += a[i - 1];
			if (a[i] - min > max_a) max_a = a[i] - min;
			if (a[i] < min) min = a[i];
		}
		cout << max_a << endl;
	}
}

C++: #include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n;
    int A[5000];
    while (cin >> n && n)
    {
        for (int i = 0; i < n; i++)
        {
            cin >> A[i];
        }
        int S[5000];
        S[0] = A[0];
        int max = A[0];
        for (int i = 1; i < n; i++)
        {
            S[i] = S[i - 1] + A[i];
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = i; j < n; j++)
            {
                int sum = 0;
                if (i != 0)
                {
                    sum = S[j] - S[i - 1];
                }
                else
                {
                    sum = S[j];
                }
                if (max < sum)
                {
                    max = sum;
                }
            }
        }
        cout << max << endl;
    }
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n,a[5000];
	while(1){
		int maxa=-10001;
		scanf("%d",&n);
		if(n==0)
			break;
		for(int i=0;i<n;i++)
			scanf("%d",&a[i]);
		for(int i=0;i<n;i++){
			int sum=0;
			for(int j=i;j<n;j++){
				sum+=a[j];
				maxa=max(maxa,sum);
			}
		}
		printf("%d\n",maxa);
	}
	return 0;
}

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

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;

int main (void){
  
    int number;
    int max;
    int l = 0;
    while(cin >> number,number)
    {
        int a[5010] = {0};
        vector<int>tempmax(5010,0);
        vector<int>tempmax2(5010,0);
        int temp = 0;
        REP(i,number)
        cin >> a[i];
        for(int j = 0; j<number;j++)
            for(int k = j;k<number;k++)
            {
                for(int l = k;l<number;l++)
                {
                    if(k == l)
                        tempmax2[k] = a[k];
                    else{
                        
                        tempmax2[k] += a[l];
                    }
                    if(temp <= tempmax2[k])
                        temp = tempmax2[k];
                }
            
            }
        //sort(tempmax.begin(),tempmax.end(),greater<int>());
        //sort(tempmax2.begin(),tempmax2.end(),greater<int>());
        //if(tempmax[0]>temp)
            //answer[l] = tempmax[0];
        //else
        // answer[l] = temp;
        printf("%d\n",temp);
        temp = 0;
    }
    return 0;
}

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++)
	{
	for(int k=i;k<=j;k++)
	{
		A=A+a[k];
		
	}	
	if(R<A)
	{
		R=A;
	}
	A=0;
	}
}
cout<<R<<endl;
}
return 0;
}

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;


bool solve(){

	while(1){
		int n;
		cin>> n;
		if(!n) break;
		
		vector<int> a(n,0);
		for(int i=0;i<n;i++){
			cin>> a[i];
		}
		int sum=0;
		for(int i=0;i<n-1;i++){
			int sum2 = a[i];
			if(sum < sum2) sum = sum2;
			for(int j=i+1;j<n;j++){
				sum2 += a[j];
				if(sum < sum2) sum = sum2;
			}
		}
		
		cout<< sum<< endl;
	}
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

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

int maxsum(const vector<int>& data){
  int maxsumval=0,n=data.size();
  for(int i=0;i<n-1;i++){
    int sum=0;
    for(int j=0;j<n;j++){
      sum+=data[i+j];
      if(sum>maxsumval)maxsumval=sum;
    }
  }
  return maxsumval;

}
int main(){
  int n;
  while(cin>>n&&n){
    vector<int> data(n);
    for(int i=0;i<n;i++){
      cin>>data[i];
    }
    int maxsumval=maxsum(data);
    cout<<maxsumval<<endl;
  }

}

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

int sumData(int data[], int s, int n) {
  int sum = 0;
  for(int i = 0; i < n; i++) {
    sum += data[s+i];
  }
  return sum;
}

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

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

    int max = INT_MIN;
    for(int i = 1; i <= n; i++) {
      for(int j = 0; j <= n-i; j++) {
	int temp = sumData(data, j, i);
	if(temp > max) max = temp;
      }
    }

    cout << max << endl;
  }
  return 0;
}

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

  cin >> n;
  while(1){

    // input part //////////////////////////////////////////

    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;

    delete List; // deallocate List

    cin >> n;
    if(n == 0) break; // if n=0, end calc
    else cout << endl;

  }

}


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

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

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

    int temp=0;
    int max;

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

      temp += list[i];
      if(i==0){
        max = list[i];
      }
      if(max<temp){
        max=temp;
      }
      if( temp<0 ){
        temp=0;
      }
    }

    cout << max << endl;
  }

  return 0;
}

C++: #include <iostream>
using namespace std;
long long int n,a[5000];
int main(){
	long long int i,j,t,tmp;
	while(cin >> n && n){
		tmp = 0;
		t = -1000000;
		for(i=0;i<n;i++){
			cin >> a[i];
		}
		for(i=0;i<n-1;i++){
			tmp += a[i];
			if(t < tmp) t = tmp;
			for(j=i+1;j<n;j++){
				tmp += a[j];
				if(t < tmp) t = tmp;
			}
			tmp = 0;
		}
		cout << t << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	long int n, m[5000] = { 0 }, max = -200000, temp = 0;
	int out;
	
	while (cin>> n && n!=0){
		for (int i = 0; i < n; i++){
			cin >> m[i];
		}
		for (int i = 0; i < n; i++){
			temp = m[i];
			for (int l = i + 1; l < n; l++){
				temp += m[l];
				if (max < temp){
					max = temp;
				}
			}temp = 0;
		}
		cout << max << endl;
		max =-2000000 ;
	}
	return 0;
}