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>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>





using namespace std;

int main()
{
	int n;

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

		int sum = 0, input, maxer = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> input;
			sum += input;
			maxer = max(sum, maxer);
		}

		cout << maxer << endl;
	}


	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)

using namespace std;

int main(void){
	long int n , a[5005] , s[5005] , m;
	while (cin >> n && n){
		REP(i,n){
			cin >> a[i];
		}
		s[0] = 0;
		FOR(i,1,n){
			s[i] = s[i-1]+a[i-1];
		}
		m=-100000;
		REP(i,n){
			FOR(j,i+1,n+1){
				if(s[j]-s[i]>m)
					m=s[j]-s[i];
			}
		}
		cout << m << endl;
	}


	return 0;
}

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

using namespace std;
int length=0;
int* sums;

int main(){
  label:
  cin>>length;
  if(length==0)return 0;
  sums=new int[length];
  
  int s=0;
  for(int i=0;i<length;i++){
    int v=0;
    cin>>v;
    s+=v;
    sums[i]=s;
  }
  int max=INT_MIN;
  for(int i=0;i<length;i++){
    for(int j=i+1;j<length;j++){
      int diff=sums[j]-sums[i];
      if(diff>max){
        max=diff;
      }
    }
  }
  cout<<max;
  cout<<"\n";
  goto label;
  return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main (){
while (1){
long n,dset[5000],max=-99999,temp=0;
cin>>n;
if (n==0)break;
for (int i=0;i<n;i++){
        cin>>dset[i];
}
for (int i=0;i<n;i++){
        for (int j=i;j<n;j++){
                temp=temp+dset[j];
                if (max<temp){
                        max=temp;
                }
        }
temp=0;
}
printf ("%d\n",max);
}
return 0;
}

C++: #include <stdio.h>
#define mx(a,b) (a<b?b:a)
int main() {long long i,j,k,n,f;while (scanf("%lld",&n)!=EOF && n) {j=i=0,f=-5000000007;while (n--) {scanf("%lld",&k);f=mx(f,k);j+=k;i=mx(i,j);j=mx(j,0);} if (f<=0 && !i) i=f;printf("%lld\n",i);} return 0;}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int n, num[5010];

int mina(int a, int b) {
	if (a < b) return a;
	return b;
}

int main() {
	cin >> n;
	while (n != 0) {
		int sum = 0;
		int maxsum = 0;
		int minmax = -100001;
		for (int i = 0; i < n; i++) {
			cin >> num[i];
			sum += num[i];
			if (sum < 0) sum = 0;
			if (num[i] >= 0) minmax = 100000*5000+1;
			if (num[i] < 0 && num[i] > minmax) minmax = num[i];
			if (sum > maxsum) maxsum = sum;
		}
		cout << mina(maxsum, minmax) << endl;

		cin >> n;
	}

	return 0;
}

/*@@@@@@@@@@@@@@@@@@@@@@@@@*/
/*@                       @*/
/*@ debug output erased ? @*/
/*@                       @*/
/*@@@@@@@@@@@@@@@@@@@@@@@@@*/

C++: #include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
    int mod=1000000007;
    int n;
    int ans;
    for (;;) {
        scanf("%d",&n);
        if (n!=0) {
            vector<int> p(n);
            for (auto&e:p) {
                scanf("%d",&e);
            }
            ans=p[0];
            for (int i=0;i<n;i++) {
                int tmp=0;
                for (int j=i;j<n;j++) {
                    tmp+=p[j];
                    ans=max(ans,tmp);
                }
            }
        } else {
            break;
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#define INF 1500000000

using namespace std;


int main(){
	int n;
	while(cin>>n && n){
		vector<int >data;
		data.push_back(0);
		for(int i=0;i<n;i++){
			int x;
			cin>>x;
			data.push_back(x+data.back());
		}
		int ans=-1*INF;
		for(int i=0;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				ans=max(ans,data[j]-data[i]);
			}
		}
		cout<<ans<<endl;
	}
}

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++){
      for(int i=0; i<=n-l; i++){
	ibuf = sumarray(List, i, i+l);
	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 <iostream>
int main(){
	int n, v[5000], m;
	while(std::cin >> n, m=n){
		for(;m--;)std::cin >> v[m-1];

		m = *v;
		for(int i=0;i<n;i++)
			for(int j=i,k=v[i];j<n;j++,k+=v[j])
				m=k>m?k:m;

		std::cout << m << '\n';
	}	
}

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

using namespace std;

int main() {
  int n;
  vector<int> datas;
  vector<int> sums;

  while (cin >> n, n != 0) {
    int input;
    for (int n_i = 0; n_i < n; n_i++) {
      cin >> input;
      datas.push_back(input);
    }
    for (int data_i = 0; data_i < n-1; data_i++) {
      sums.push_back(datas[data_i]+datas[data_i+1]);
    }

    int max = *sums.begin();
    for (auto sum_i = sums.begin(); sum_i != sums.end(); sum_i++)
      if (max < *sum_i)
        max = *sum_i;
    cout << max << endl;
  }

  return 0;
}

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

int main()
{
	int n;
	while(cin>>n,n)
	{
		int data[n+1];
		int tmp=0,ans;
		data[0]=0;
		for (int i = 1; i <= n; ++i)
		{
			cin>>data[i];
		}
		for (int i = 1; i <= n; ++i)
		{
			data[i]=max(data[i-1]+data[i],data[i]);
			ans=max(ans,data[i]);
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

  for(int n;cin>>n&&n;){
    int a[5000],r;
    cin>>a[0];
    r=a[0];
    for(int i=1,b;i<n;i++){
      cin>>b;
      a[i]=a[i-1]+b;
      r=max(r,a[i]);
    }
    for(int i=0;i<n;i++) for(int j=i;j<n;j++) r=max(r,a[j]-a[i]);
    cout<<r<<endl;
  }
  return 0;
}

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

int main()
{

	int n, num;
	vector< long int > a;
	vector< long int > res;

	while( 1 ) {

		int Max = -100001;

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

		for( int i = 0; i < n; i++ ) {
		
			cin >> num;
			a.push_back( num );
			
		}

		//?????§???
		for( int i = 1; i < n; i++ ) {
		
			a[i - 1] + a[i] > a[i] ? a[i] = a[i - 1] + a[i] : a[i] = a[i];

			if ( a[i] > Max ) {
				Max = a[i];
			}
		
		}

		res.push_back( Max );
		a.clear();
	
	}

	if( n != 0 ) {
		for( vector< long int > :: iterator mIt = res.begin(); mIt != res.end(); ++mIt ) {
			cout << *mIt << endl;
		}
	}

	return 0;

}