Go: package main

import "fmt"

func main() {
	var result []int
	for {
		var n, a, maxSum int
		fmt.Scan(&n)

		if n == 0 {
			break
		}

		maxSum = 0
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Scan(&a)
			if i == 0 {
				sum = a
				maxSum = sum
			} else if sum+a < a {
				sum = a
				if maxSum < sum {
					maxSum = sum
				}
			} else {
				sum = sum + a
				if maxSum < sum {
					maxSum = sum
				}
			}
		}

		result = append(result, maxSum)
	}

	for _, v := range result {
		fmt.Println(v)
	}
}

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+1;j<=N;j++)ans=max(ans,rui[j]-rui[i]);
        }
        cout<<ans<<endl;
    }
    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=i;j<n;j++)
	{
		cout << j << " ";		
		A=A+a[j];
		
	}	
	if(R<A)
	{
		R=A;
	}
	cout<<endl;
	A=0;
	}
cout<<R<<endl;
}
return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        int ans[5050] = {0};
        int ans_mx = 0;
        for(int i = 0; i < n; i++){
            scanf("%d",&ans[i]);
            ans_mx = max(ans_mx,ans[i]);
        }
        long long int mx = -1;
        for(int i = 0; i < n; i++){
            long long int sum = 0;
            for(int j = i; j < n; j++){
                sum += ans[j];
                mx = max(mx,sum);
            }
        }
        if(ans_mx <= 0) mx = ans_mx;
        printf("%lld\n",mx);
    }
	return 0;
}

C++: #include<cstdio>
int main(){int n,i,j,s,m,a[5000];while(scanf("%d", &n)&&n){for(i=0;i<n;i++)scanf("%d",&a[i]);m=-2147483647;for(i=0;i<n;i++,s=0)for(j=i;j<n;j++)if((s+=a[j])>m)m=s;printf("%d\n",m);}}

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

using namespace std;
int n,a[5008];
int b[5008];

int solve(){
  int res= -100001;
  for(int i=0;i<=n;i++){
    for(int j=n;j>=i;j--){
      res=max(res,b[j]-b[i]);
    }
  }
  return res;
}

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

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

    printf("%d\n",solve());

  }
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.mss", "r", stdin);
	string str = "";
	int n;

	while (1){
		getline (cin, str );
		stringstream ssn(str);
		ssn >> n;
		if (n == 0){
			break;
		} // end if
		vector <int> a(n + 1, 0);
		int i,j;

		vector <int> sum (n + 1, 0);

		for (i = 1; i <= n; ++i){
			getline (cin, str );
			stringstream ss(str);
			ss >> a[i];
		} // end for
		for (i = 1; i <= n; ++i){
			sum[i] = accumulate (a.begin(), a.begin() + i + 1, 0 );
//			cout << "sum[" << i << "]:" << sum[i] << endl;
		} // end for

		int maxn = INT_MIN;
		for (i = 1; i <= n; ++i){
			for (j = i; j <= n; ++j){
//				cout << " sum[" << j << "]:" << sum[j];
//				cout << " sum[" << (i-1) << "]:" << sum[i-1];
//				cout << " sub: " << (sum[j] - sum[i-1]) << endl;
				 maxn = max (maxn , sum[j] - sum[i - 1]);
			} // end for
		} // end for
		cout << maxn << endl;			

	} // end while

	return 0;
}

C++: #include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>

int max(int a,int b){
	if(a>=b)return a;
	else return b;
}

int min(int a,int b){
	if(a>=b)return b;
	else return a;
}

void swap(int *a,int *b){
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

void babbleSort(int *data,int n){
	for(int i=0;i<n;i++){
		for(int j=n-1;j>i;j--){
			if(data[j]>=data[j-1]){
				swap(&data[j],&data[j-1]);
			}
		}
	}
}


using namespace std;

/*
cin.ignore();
	getline(cin,dataStr);
	data = new int[n];
	stringToInteger(&dataStr,data,n);
*/

void stringToInteger(string *str,int *data,int n){
	for(int i=1;i<=n;i++){
		int spaceN = str->find(' ',0);

		data[i] = atoi(str->substr(0,spaceN).c_str());
		str->erase(0,spaceN+1);
	}
}

int main(){

	int n;
	int *a;

	int ans[5001];
	int cnt=0;

	while(1){
	cin>>n;

	if(n==0)break;
	a = new int[n];

	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int max=0;
	int before=0;
	int now=0;

	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			if(j==i){
				before=a[j];
				now=before;
			}
			else{
				now=before+a[j];
			}
			
			if(max<=now){
				max = now;
	
			}
			before=now;
		}
	}
	ans[cnt]=max;
	//cout<<max<<endl;
	cnt++;

	}
	for(int i=0;i<cnt;i++){
		cout<<ans[i]<<endl;
	}


	return 0;
}

C++: while n = gets.to_i do
  break if n == 0
  s = Array.new
  d = - Float::INFINITY
  n.times do |i|
    s[i] = gets.to_i
  end
  n.times do |i|
    sum = 0
    (i..n).each do |j|
      sum = sum + s[j].to_i
      d = [d, sum].max
    end
  end
  puts d
end

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		vector<int>in(n+1);
		rep(i,n)cin>>in[i+1];
		n++;
		loop(i,1,n)in[i]+=in[i-1];
		int ma=-1e9;
		rep(i,n)loop(j,i+1,n)ma=max(ma,in[j]-in[i]);
		cout<<ma<<endl;
	}
}

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

using namespace std;

int main()
{
    int n;

    while (scanf("%d", &n), n) {
        int s[5001] = {};

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

        int ma = INT_MIN;

        for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j) {
            ma = max(ma, s[i] - s[j - 1]);
        }

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

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>

typedef long long ll;
using namespace std;

int S(int a,int b,int* num){
	int res=0;
	for(int i=a;i<=b;i++){
		res+=num[i];
	}
	return res;
}

int main()
{
	int T;
	while(~scanf("%d",&T)){
		if(T==0) break;
		int* num = new int[T]();	
		int res=numeric_limits<int>::min();
		for(int t=0;t<T;t++){
			scanf("%d",num+t);
		}

		for(int a=0;a<T;a++){
			for(int b=a;b<T;b++){
				res=max(S(a,b,num),res);
			}
		}
		
		cout << res << endl;
	}
}